Esempio n. 1
0
    public override void OnEnable()
    {
        serializedObject.Update();
        var theShader = serializedObject.FindProperty("m_Shader");

        if (!theShader.hasMultipleDifferentValues && theShader.objectReferenceValue != null)
        {
            Shader shader   = theShader.objectReferenceValue as Shader;
            var    material = target as Material;
            for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
            {
                if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    var fxTextureType = FXMaterialHelper.GetFXTextureType(ShaderUtil.GetPropertyDescription(shader, i));
                    if (fxTextureType != null)
                    {
                        material.SetTexture(name, null);
                    }
                }
            }
        }

        base.OnEnable();

        FXMaterialHelper.ResetCache();
    }
Esempio n. 2
0
    public static void HandleAssignments(Material material, List <FXTextureAssigner.RenderTextureAssignment> assignments)
    {
        var fxTextureSlots = new List <FXTextureSlot>();

        if (material)
        {
            var shader = material.shader;

            for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
            {
                var isFxTexture = ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv &&
                                  FXMaterialHelper.GetFXTextureType(ShaderUtil.GetPropertyDescription(shader, i)) != null;

                if (isFxTexture)
                {
                    var match = Regex.Match(ShaderUtil.GetPropertyDescription(shader, i), @"(.*)\(\w*\).*", RegexOptions.IgnoreCase);

                    fxTextureSlots.Add(new FXTextureSlot()
                    {
                        Name        = ShaderUtil.GetPropertyName(shader, i),
                        Description = match.Groups[1].Value.Trim()
                    });
                }
            }
        }

        var currentSlots  = assignments.Select(a => a.TextureName);
        var slotsToRemove = currentSlots.Except(fxTextureSlots.Select(slot => slot.Name)).ToArray();
        var slotsToAdd    = fxTextureSlots.Where(slot => !currentSlots.Any(s => s == slot.Name)).ToArray();

        foreach (var toRemove in slotsToRemove)
        {
            assignments.Remove(assignments.First(a => a.TextureName == toRemove));
        }

        foreach (var toAdd in slotsToAdd)
        {
            assignments.Add(new FXTextureAssigner.RenderTextureAssignment()
            {
                TextureName        = toAdd.Name,
                TextureDescription = toAdd.Description
            });
        }

        foreach (var assignment in assignments)
        {
            assignment.RenderTexture = (FXRenderTexture)EditorGUILayout.ObjectField(assignment.TextureDescription, assignment.RenderTexture, typeof(FXRenderTexture), false);
        }
    }
Esempio n. 3
0
    private void ShaderPropertyImpl(Material owner, Shader shader, int propertyIndex)
    {
        int    i            = propertyIndex;
        string label        = ShaderUtil.GetPropertyDescription(shader, i);
        string propertyName = ShaderUtil.GetPropertyName(shader, i);

        switch (ShaderUtil.GetPropertyType(shader, i))
        {
        case ShaderUtil.ShaderPropertyType.Range:     // float ranges
        {
            GUILayout.BeginHorizontal();
            float v2 = ShaderUtil.GetRangeLimits(shader, i, 1);
            float v3 = ShaderUtil.GetRangeLimits(shader, i, 2);
            RangeProperty(propertyName, label, v2, v3);
            GUILayout.EndHorizontal();

            break;
        }

        case ShaderUtil.ShaderPropertyType.Float:     // floats
        {
            FloatProperty(propertyName, label);
            break;
        }

        case ShaderUtil.ShaderPropertyType.Color:     // colors
        {
            ColorProperty(propertyName, label);
            break;
        }

        case ShaderUtil.ShaderPropertyType.TexEnv:     // textures
        {
            var fxTextureType = FXMaterialHelper.GetFXTextureType(ShaderUtil.GetPropertyDescription(shader, i));
            if (fxTextureType != null)
            {
                if (!(Selection.activeObject is GameObject))
                {
                    if (DisplayHelpTexts)
                    {
                        GUILayout.Label(label);
                        EditorGUILayout.HelpBox(label + " is a FXTexture, you can use a FXTextureAssigner or a FXPostProcess component to set this Texture.", MessageType.Info);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    var             match              = Regex.Match(label, @"(.*)\(\w*\).*", RegexOptions.IgnoreCase);
                    var             description        = match.Groups[1].Value.Trim();
                    var             name               = ShaderUtil.GetPropertyName(shader, i);
                    FXRenderTexture oldFxRenderTexture = GetRenderTextureForProperty(owner, shader, name);
                    var             newFxRenderTexture = (FXRenderTexture)EditorGUILayout.ObjectField(description + " (FXRenderTexture)", oldFxRenderTexture, typeof(FXRenderTexture), false);
                    SetRenderTextureForProperty(owner, shader, name, description, newFxRenderTexture);
                }
            }
            else
            {
                ShaderUtil.ShaderPropertyTexDim desiredTexdim = ShaderUtil.GetTexDim(shader, i);
                TextureProperty(propertyName, label, desiredTexdim);
            }

            GUILayout.Space(6);
            break;
        }

        case ShaderUtil.ShaderPropertyType.Vector:     // vectors
        {
            VectorProperty(propertyName, label);
            break;
        }

        default:
        {
            GUILayout.Label("Unknown " + label + " : " + ShaderUtil.GetPropertyType(shader, i));
            break;
        }
        }
    }
Esempio n. 4
0
 public override void OnInspectorGUI()
 {
     FXMaterialHelper.DrawRequiredFXTextures(target as Material);
     DrawMaterialProperties();
 }
    public override void OnEnable()
    {
        base.OnEnable();

        FXMaterialHelper.ResetCache();
    }
Esempio n. 6
0
 public void OnEnable()
 {
     FXMaterialHelper.ResetCache();
     FXRenderTextureData.OnApply += OnApply;
 }