예제 #1
0
    void PropertiesGUI(int guiID)
    {
        scroll = GUILayout.BeginScrollView(scroll);

        int i = 0;

        while (i < creatureProperties.Length)
        {
            ProceduralPropertyDescription creatureProperty = creatureProperties[i];
            ProceduralPropertyType        creatureType     = creatureProperties[i].type;

            if (creatureProperty.hasRange)
            {
                if (creatureType == ProceduralPropertyType.Float)
                {
                    GUILayout.Label(creatureProperty.name);
                    float creatureFloat = creatureSubstance.GetProceduralFloat(creatureProperty.name);
                    float oldFloat      = creatureFloat;
                    creatureFloat = GUILayout.HorizontalSlider(creatureFloat, creatureProperty.minimum, creatureProperty.maximum);
                    if (creatureFloat != oldFloat)
                    {
                        creatureSubstance.SetProceduralFloat(creatureProperty.name, creatureFloat);
                    }
                }
            }
            else if (creatureType == ProceduralPropertyType.Color4)
            {
                GUILayout.Label(creatureProperty.name);
                Color creatureColor = creatureSubstance.GetProceduralColor(creatureProperty.name);
                Color oldColor      = creatureColor;

                Rect creatureRect = GUILayoutUtility.GetLastRect();

                if (GUILayout.RepeatButton(colorPicker))
                {
                    Vector2 mousePosition     = Event.current.mousePosition;
                    float   currentPickerPosX = mousePosition.x - creatureRect.x - 10.0f;
                    float   currentPickerPosY = (mousePosition.y - creatureRect.y + 5.0f) * (-1.0f);

                    int x = Convert.ToInt32(currentPickerPosX);
                    int y = Convert.ToInt32(currentPickerPosY);

                    Color col = colorPicker.GetPixel(x, y);
                    creatureColor = col;
                }

                if (creatureColor != oldColor)
                {
                    creatureSubstance.SetProceduralColor(creatureProperty.name, creatureColor);
                }
            }


            i++;
        }

        creatureSubstance.RebuildTextures();

        GUILayout.EndScrollView();
    }
예제 #2
0
    private string GetValueStringByName(ProceduralMaterial pm,
                                        ProceduralPropertyDescription des, string name)
    {
        if (des.type == ProceduralPropertyType.Boolean)
        {
            return(pm.GetProceduralBoolean(name).ToString());
        }
        else if (des.type == ProceduralPropertyType.Float)
        {
            return(pm.GetProceduralFloat(name).ToString());
        }
        else if (des.type == ProceduralPropertyType.Vector4 ||
                 des.type == ProceduralPropertyType.Vector3 ||
                 des.type == ProceduralPropertyType.Vector2)
        {
            return(pm.GetProceduralVector(name).ToString());
        }
        else if (des.type == ProceduralPropertyType.Color4 ||
                 des.type == ProceduralPropertyType.Color3)
        {
            return(pm.GetProceduralColor(name).ToString());
        }

        return("");
    }
 public static void SetAllProceduralValuesToMax(SubstanceMaterialParams substanceMaterialParams) // Sets all procedural values to the maximum value
 {
     UnityEditor.Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { substanceMaterialParams.substance }, "Set all values to Maximum");
     for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
     {
         ProceduralPropertyDescription materialVariable = substanceMaterialParams.materialVariables[i];
         if (substanceMaterialParams.substance.IsProceduralPropertyVisible(materialVariable.name))
         {
             ProceduralPropertyType propType = substanceMaterialParams.materialVariables[i].type;
             if (propType == ProceduralPropertyType.Float)
             {
                 substanceMaterialParams.substance.SetProceduralFloat(materialVariable.name, substanceMaterialParams.materialVariables[i].maximum);
             }
             if (propType == ProceduralPropertyType.Vector2 && materialVariable.hasRange)
             {
                 substanceMaterialParams.substance.SetProceduralVector(materialVariable.name, new Vector2(substanceMaterialParams.materialVariables[i].maximum, substanceMaterialParams.materialVariables[i].maximum));
             }
             if (propType == ProceduralPropertyType.Vector3 && materialVariable.hasRange)
             {
                 substanceMaterialParams.substance.SetProceduralVector(materialVariable.name, new Vector3(substanceMaterialParams.materialVariables[i].maximum, substanceMaterialParams.materialVariables[i].maximum, substanceMaterialParams.materialVariables[i].maximum));
             }
             if (propType == ProceduralPropertyType.Vector4 && materialVariable.hasRange)
             {
                 substanceMaterialParams.substance.SetProceduralVector(materialVariable.name, new Vector4(substanceMaterialParams.materialVariables[i].maximum, substanceMaterialParams.materialVariables[i].maximum, substanceMaterialParams.materialVariables[i].maximum, substanceMaterialParams.materialVariables[i].maximum));
             }
             if (propType == ProceduralPropertyType.Enum)
             {
                 substanceMaterialParams.substance.SetProceduralEnum(materialVariable.name, substanceMaterialParams.materialVariables[i].enumOptions.Count() - 1);
             }
         }
     }
     substanceMaterialParams.substance.RebuildTexturesImmediately();
 }
 void SetSpecificMaterialParamsAndCreateKeyframes(float keyframesToCreate, params string[] paramsNames) // needs float for division
 {                                                                                                      //  creates a certain amount of keyframes from a amount of parameter names. sets them based on
     for (int i = 0; i <= keyframesToCreate - 1; i++)
     {
         foreach (string param in paramsNames)
         {
             if (testingScript.substanceMaterialParams.materialVariableNames.Contains(param))
             {
                 int index = testingScript.substanceMaterialParams.materialVariableNames.IndexOf(param);
                 ProceduralPropertyDescription materialVariable = testingScript.substanceMaterialParams.materialVariables[index];
                 ProceduralPropertyType        propType         = testingScript.substanceMaterialParams.materialVariables[index].type;
                 if (propType == ProceduralPropertyType.Float)
                 {
                     testingScript.substanceMaterialParams.substance.SetProceduralFloat(param, (materialVariable.maximum / keyframesToCreate) * i); // set current parameter to (max value of parameter divided by the total # of keyframes to create) multiplyed by current keyframe(i)
                 }
                 else if (propType == ProceduralPropertyType.Color3)
                 {
                     testingScript.substanceMaterialParams.substance.SetProceduralColor(param, new Color(i / keyframesToCreate, 0, 0));
                 }
                 else if (propType == ProceduralPropertyType.Color4)
                 {
                     testingScript.substanceMaterialParams.substance.SetProceduralColor(param, new Color(i / keyframesToCreate, 0, 0, 254));
                 }
                 else if (propType == ProceduralPropertyType.Vector2)
                 {
                     testingScript.substanceMaterialParams.substance.SetProceduralVector(param, new Vector2(materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i, materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i));
                 }
                 else if (propType == ProceduralPropertyType.Vector3)
                 {
                     testingScript.substanceMaterialParams.substance.SetProceduralVector(param, new Vector3(materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i, materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i, materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i));
                 }
                 else if (propType == ProceduralPropertyType.Vector4)
                 {
                     testingScript.substanceMaterialParams.substance.SetProceduralVector(param, new Vector4(materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i, materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i, materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i, materialVariable.minimum + (materialVariable.maximum / keyframesToCreate) * i));
                 }
                 else if (propType == ProceduralPropertyType.Boolean)
                 {
                     if (i % 2 == 0)
                     {
                         testingScript.substanceMaterialParams.substance.SetProceduralBoolean(param, true);
                     }
                     else
                     {
                         testingScript.substanceMaterialParams.substance.SetProceduralBoolean(param, false);
                     }
                 }
                 else if (propType == ProceduralPropertyType.Enum)
                 {
                     testingScript.substanceMaterialParams.substance.SetProceduralEnum(param, (int)Random.Range(materialVariable.minimum, materialVariable.maximum));
                 }
             }
             //ProceduralPropertyDescription materialVariable = testingScript.substanceMaterialParams.materialVariables[ArrayUtility.IndexOf( testingScript.substanceMaterialParams.materialVariables,param)];
         }
         CreateKeyframe();
     }
 }
예제 #5
0
    public void SlideSubstanceProperty(ProceduralPropertyDescription input, Slider slider, ProceduralMaterial mySubstance)
    {
        float inputFloat    = mySubstance.GetProceduralFloat(input.name);
        float oldInputFloat = inputFloat;

        //print("VALUE CHANGED!" + inputFloat + " SLIDER VAL " + slider.value);
        inputFloat = slider.value;//GUILayout.HorizontalSlider(inputFloat, input.minimum, input.maximum);
        if (inputFloat != oldInputFloat)
        {
            mySubstance.SetProceduralFloat(input.name, inputFloat);
            mySubstance.RebuildTextures();
        }
    }
    static int _CreateProceduralPropertyDescription(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 0)
        {
            ProceduralPropertyDescription obj = new ProceduralPropertyDescription();
            LuaScriptMgr.PushObject(L, obj);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: ProceduralPropertyDescription.New");
        }

        return(0);
    }
 public static void RandomizeProceduralValues(SubstanceMaterialParams substanceMaterialParams, SubstanceRandomizeParams randomizeSettings) // Sets all procedural values to a random value
 {
     for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
     {
         ProceduralPropertyDescription materialVariable = substanceMaterialParams.materialVariables[i];
         if (substanceMaterialParams.substance.IsProceduralPropertyVisible(materialVariable.name))
         {
             ProceduralPropertyType propType = substanceMaterialParams.materialVariables[i].type;
             if (propType == ProceduralPropertyType.Float && materialVariable.name[0] != '$' && randomizeSettings.randomizeProceduralFloatToggle)
             {
                 substanceMaterialParams.substance.SetProceduralFloat(materialVariable.name, UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum));
             }
             if (propType == ProceduralPropertyType.Color3 && randomizeSettings.randomizeProceduralColorRGBToggle)
             {
                 substanceMaterialParams.substance.SetProceduralColor(materialVariable.name, new Color(UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f)));
             }
             if (propType == ProceduralPropertyType.Color4 && randomizeSettings.randomizeProceduralColorRGBAToggle)
             {
                 substanceMaterialParams.substance.SetProceduralColor(materialVariable.name, new Color(UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f)));
             }
             if (propType == ProceduralPropertyType.Vector2 && materialVariable.name[0] != '$' && randomizeSettings.randomizeProceduralVector2Toggle)
             {
                 substanceMaterialParams.substance.SetProceduralVector(materialVariable.name, new Vector2(UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum), UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum)));
             }
             if (propType == ProceduralPropertyType.Vector3 && randomizeSettings.randomizeProceduralVector3Toggle)
             {
                 substanceMaterialParams.substance.SetProceduralVector(materialVariable.name, new Vector3(UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum), UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum), UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum)));
             }
             if (propType == ProceduralPropertyType.Vector4 && randomizeSettings.randomizeProceduralVector4Toggle)
             {
                 substanceMaterialParams.substance.SetProceduralVector(materialVariable.name, new Vector4(UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum), UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum), UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum), UnityEngine.Random.Range(substanceMaterialParams.materialVariables[i].minimum, substanceMaterialParams.materialVariables[i].maximum)));
             }
             if (propType == ProceduralPropertyType.Enum && randomizeSettings.randomizeProceduralEnumToggle)
             {
                 substanceMaterialParams.substance.SetProceduralEnum(materialVariable.name, UnityEngine.Random.Range(0, substanceMaterialParams.materialVariables[i].enumOptions.Count()));
             }
             if (propType == ProceduralPropertyType.Boolean && randomizeSettings.randomizeProceduralBooleanToggle)
             {
                 substanceMaterialParams.substance.SetProceduralBoolean(materialVariable.name, (UnityEngine.Random.value > 0.5f));
             }
         }
     }
     substanceMaterialParams.substance.RebuildTexturesImmediately();
 }
    static int set_step(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name step");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index step on a nil value");
            }
        }

        ProceduralPropertyDescription obj = (ProceduralPropertyDescription)o;

        obj.step = (float)LuaScriptMgr.GetNumber(L, 3);
        return(0);
    }
    static int set_componentLabels(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name componentLabels");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index componentLabels on a nil value");
            }
        }

        ProceduralPropertyDescription obj = (ProceduralPropertyDescription)o;

        obj.componentLabels = LuaScriptMgr.GetNetObject <String[]>(L, 3);
        return(0);
    }
    static int set_hasRange(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name hasRange");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index hasRange on a nil value");
            }
        }

        ProceduralPropertyDescription obj = (ProceduralPropertyDescription)o;

        obj.hasRange = LuaScriptMgr.GetBoolean(L, 3);
        return(0);
    }
    static int get_label(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name label");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index label on a nil value");
            }
        }

        ProceduralPropertyDescription obj = (ProceduralPropertyDescription)o;

        LuaScriptMgr.Push(L, obj.label);
        return(1);
    }
예제 #12
0
    public static void DeleteNonAnimatingParametersOnPrefab(PrefabProperties prefabProperties, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams)//deletes unused parameters past the first keyframe for optimizing animations for prefabs.
    {
        float   floatValue;
        Color   ColorValue;
        Vector2 Vector2Value;
        Vector3 Vector3Value;
        Vector4 Vector4Value;
        bool    boolValue;
        int     enumValue;

        for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
        {// search for variables that never change in animation and delete them from the dictionary.
            ProceduralPropertyDescription MaterialVariable = substanceMaterialParams.materialVariables[i];
            ProceduralPropertyType        propType         = substanceMaterialParams.materialVariables[i].type;
            bool varChanged = false;
            if (propType == ProceduralPropertyType.Float)
            {
                float propertyFloatAnimationCheck = 0;
                for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                {
                    if (!varChanged && prefabProperties.MaterialVariableKeyframeList[j].myFloatKeys.Contains(substanceMaterialParams.materialVariables[i].name))
                    {
                        //MaterialVariableKeyframeDictionaryList[j].PropertyFloatDictionary.TryGetValue(materialVariables[i].name, out floatValue);
                        floatValue = prefabProperties.MaterialVariableKeyframeList[j].myFloatValues[prefabProperties.MaterialVariableKeyframeList[j].myFloatKeys.IndexOf(substanceMaterialParams.materialVariables[i].name)];
                        if (j == 0)
                        {
                            propertyFloatAnimationCheck = floatValue;
                        }
                        else if (j > 0 && floatValue != propertyFloatAnimationCheck)
                        {
                            prefabProperties.animatedParameterNames.Add(MaterialVariable.name);
                            varChanged = true;
                        }
                        else if (j == animationParams.keyFrameTimes.Count - 1 && floatValue == propertyFloatAnimationCheck)
                        {
                            for (int k = 1; k <= animationParams.keyFrameTimes.Count - 1; k++) // skips first keyframe
                            {
                                prefabProperties.MaterialVariableKeyframeList[k].myFloatValues.RemoveAt(prefabProperties.MaterialVariableKeyframeList[j].myFloatKeys.IndexOf(substanceMaterialParams.materialVariables[i].name));
                                prefabProperties.MaterialVariableKeyframeList[k].myFloatKeys.Remove(substanceMaterialParams.materialVariables[i].name);
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
            {
                Color propertyColorAnimationCheck = Color.white;
                for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                {
                    if (!varChanged && prefabProperties.MaterialVariableKeyframeList[j].myColorKeys.Contains(substanceMaterialParams.materialVariables[i].name))
                    {
                        ColorValue = prefabProperties.MaterialVariableKeyframeList[j].myColorValues[prefabProperties.MaterialVariableKeyframeList[j].myColorKeys.IndexOf(substanceMaterialParams.materialVariables[i].name)];
                        if (j == 0)
                        {
                            propertyColorAnimationCheck = ColorValue;
                        }
                        else if (j > 0 && ColorValue != propertyColorAnimationCheck)
                        {
                            prefabProperties.animatedParameterNames.Add(MaterialVariable.name);
                            varChanged = true;
                        }
                        else if (j == animationParams.keyFrameTimes.Count - 1 && ColorValue == propertyColorAnimationCheck)
                        {
                            for (int k = 1; k <= animationParams.keyFrameTimes.Count - 1; k++) // skips first keyframe
                            {
                                prefabProperties.MaterialVariableKeyframeList[k].myColorValues.RemoveAt(prefabProperties.MaterialVariableKeyframeList[j].myColorKeys.IndexOf(substanceMaterialParams.materialVariables[i].name));
                                prefabProperties.MaterialVariableKeyframeList[k].myColorKeys.Remove(substanceMaterialParams.materialVariables[i].name);
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Vector4)
            {
                Vector4 propertyVector4AnimationCheck = Vector4.zero;
                for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                {
                    if (!varChanged && prefabProperties.MaterialVariableKeyframeList[j].myVector4Keys.Contains(substanceMaterialParams.materialVariables[i].name))
                    {
                        Vector4Value = prefabProperties.MaterialVariableKeyframeList[j].myVector4Values[prefabProperties.MaterialVariableKeyframeList[j].myVector4Keys.IndexOf(substanceMaterialParams.materialVariables[i].name)];
                        if (j == 0)
                        {
                            propertyVector4AnimationCheck = Vector4Value;
                        }
                        else if (j > 0 && Vector4Value != propertyVector4AnimationCheck)
                        {
                            prefabProperties.animatedParameterNames.Add(MaterialVariable.name);
                            varChanged = true;
                        }
                        else if (j == animationParams.keyFrameTimes.Count - 1 && Vector4Value == propertyVector4AnimationCheck)
                        {
                            for (int k = 1; k <= animationParams.keyFrameTimes.Count - 1; k++) // skips first keyframe
                            {
                                prefabProperties.MaterialVariableKeyframeList[k].myVector4Values.RemoveAt(prefabProperties.MaterialVariableKeyframeList[j].myVector4Keys.IndexOf(substanceMaterialParams.materialVariables[i].name));
                                prefabProperties.MaterialVariableKeyframeList[k].myVector4Keys.Remove(substanceMaterialParams.materialVariables[i].name);
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Vector3)
            {
                Vector3 propertyVector3AnimationCheck = Vector3.zero;
                for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                {
                    if (!varChanged && prefabProperties.MaterialVariableKeyframeList[j].myVector3Keys.Contains(substanceMaterialParams.materialVariables[i].name))
                    {
                        Vector3Value = prefabProperties.MaterialVariableKeyframeList[j].myVector3Values[prefabProperties.MaterialVariableKeyframeList[j].myVector3Keys.IndexOf(substanceMaterialParams.materialVariables[i].name)];
                        if (j == 0)
                        {
                            propertyVector3AnimationCheck = Vector3Value;
                        }
                        else if (j > 0 && Vector3Value != propertyVector3AnimationCheck)
                        {
                            prefabProperties.animatedParameterNames.Add(MaterialVariable.name);
                            varChanged = true;
                        }
                        else if (j == animationParams.keyFrameTimes.Count - 1 && Vector3Value == propertyVector3AnimationCheck)
                        {
                            for (int k = 1; k <= animationParams.keyFrameTimes.Count - 1; k++) // skips first keyframe
                            {
                                prefabProperties.MaterialVariableKeyframeList[k].myVector3Values.RemoveAt(prefabProperties.MaterialVariableKeyframeList[j].myVector3Keys.IndexOf(substanceMaterialParams.materialVariables[i].name));
                                prefabProperties.MaterialVariableKeyframeList[k].myVector3Keys.Remove(substanceMaterialParams.materialVariables[i].name);
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Vector2)
            {
                Vector2 propertyVector2AnimationCheck = Vector2.zero;
                for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                {
                    if (!varChanged && prefabProperties.MaterialVariableKeyframeList[j].myVector2Keys.Contains(substanceMaterialParams.materialVariables[i].name))
                    {
                        Vector2Value = prefabProperties.MaterialVariableKeyframeList[j].myVector2Values[prefabProperties.MaterialVariableKeyframeList[j].myVector2Keys.IndexOf(substanceMaterialParams.materialVariables[i].name)];
                        if (j == 0)
                        {
                            propertyVector2AnimationCheck = Vector2Value;
                        }
                        else if (j > 0 && Vector2Value != propertyVector2AnimationCheck)
                        {
                            prefabProperties.animatedParameterNames.Add(MaterialVariable.name);
                            varChanged = true;
                        }
                        else if (j == animationParams.keyFrameTimes.Count - 1 && Vector2Value == propertyVector2AnimationCheck)
                        {
                            for (int k = 1; k <= animationParams.keyFrameTimes.Count - 1; k++) // skips first keyframe
                            {
                                prefabProperties.MaterialVariableKeyframeList[k].myVector2Values.RemoveAt(prefabProperties.MaterialVariableKeyframeList[j].myVector2Keys.IndexOf(substanceMaterialParams.materialVariables[i].name));
                                prefabProperties.MaterialVariableKeyframeList[k].myVector2Keys.Remove(substanceMaterialParams.materialVariables[i].name);
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Enum)
            {
                int propertyEnumAnimationCheck = 9999;
                for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                {
                    if (!varChanged && prefabProperties.MaterialVariableKeyframeList[j].myEnumKeys.Contains(substanceMaterialParams.materialVariables[i].name))
                    {
                        enumValue = prefabProperties.MaterialVariableKeyframeList[j].myEnumValues[prefabProperties.MaterialVariableKeyframeList[j].myEnumKeys.IndexOf(substanceMaterialParams.materialVariables[i].name)];
                        if (j == 0)
                        {
                            propertyEnumAnimationCheck = enumValue;
                        }
                        else if (j > 0 && enumValue != propertyEnumAnimationCheck)
                        {
                            prefabProperties.animatedParameterNames.Add(MaterialVariable.name);
                            varChanged = true;
                        }
                        else if (j == animationParams.keyFrameTimes.Count - 1 && enumValue == propertyEnumAnimationCheck)
                        {
                            for (int k = 1; k <= animationParams.keyFrameTimes.Count - 1; k++) // skips first keyframe
                            {
                                prefabProperties.MaterialVariableKeyframeList[k].myEnumValues.RemoveAt(prefabProperties.MaterialVariableKeyframeList[j].myEnumKeys.IndexOf(substanceMaterialParams.materialVariables[i].name));
                                prefabProperties.MaterialVariableKeyframeList[k].myEnumKeys.Remove(substanceMaterialParams.materialVariables[i].name);
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Boolean)
            {
                bool propertyBoolAnimationCheck = false;
                for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                {
                    if (!varChanged && prefabProperties.MaterialVariableKeyframeList[j].myBooleanKeys.Contains(substanceMaterialParams.materialVariables[i].name))
                    {
                        boolValue = prefabProperties.MaterialVariableKeyframeList[j].myBooleanValues[prefabProperties.MaterialVariableKeyframeList[j].myBooleanKeys.IndexOf(substanceMaterialParams.materialVariables[i].name)];
                        if (j == 0)
                        {
                            propertyBoolAnimationCheck = boolValue;
                        }
                        else if (j > 0 && boolValue != propertyBoolAnimationCheck)
                        {
                            prefabProperties.animatedParameterNames.Add(MaterialVariable.name);
                            varChanged = true;
                        }
                        else if (j == animationParams.keyFrameTimes.Count - 1 && boolValue == propertyBoolAnimationCheck)
                        {
                            for (int k = 1; k <= animationParams.keyFrameTimes.Count - 1; k++) // skips first keyframe
                            {
                                prefabProperties.MaterialVariableKeyframeList[k].myBooleanValues.RemoveAt(prefabProperties.MaterialVariableKeyframeList[j].myBooleanKeys.IndexOf(substanceMaterialParams.materialVariables[i].name));
                                prefabProperties.MaterialVariableKeyframeList[k].myBooleanKeys.Remove(substanceMaterialParams.materialVariables[i].name);
                            }
                        }
                    }
                }
            }
        }
    }
    public static void SetProceduralMaterialBasedOnAnimationTime(ref float desiredTime, SubstanceMaterialParams substanceMaterialVariables, SubstanceAnimationParams substanceAnimationParams, SubstanceToolParams substanceToolParams, SubstanceFlickerParams flickerValues)
    {
        for (int i = 0; i <= substanceAnimationParams.substanceCurveBackup.keys.Count() - 1; i++)
        {
            if (substanceAnimationParams.substanceCurveBackup.keys[i].time > desiredTime)                                                                                                                                                       // find first key time that is greater than the desiredAnimationTime
            {
                float newLerp = (desiredTime - substanceAnimationParams.substanceCurveBackup.keys[i - 1].time) / (substanceAnimationParams.substanceCurveBackup.keys[i].time - substanceAnimationParams.substanceCurveBackup.keys[i - 1].time); // Finds point between two keyrames  - finds percentage of desiredtime between substanceCurveBackup.keys[i - 1].time and substanceCurveBackup.keys[i].time
                substanceAnimationParams.currentAnimationTime    = Mathf.Lerp(0, substanceAnimationParams.keyFrameTimes[i - 1], newLerp);
                substanceAnimationParams.animationTimeRestartEnd = desiredTime;
                substanceAnimationParams.currentKeyframeIndex    = i - 1;
                if (EditorWindow.focusedWindow && EditorWindow.focusedWindow.ToString() != " (UnityEditor.CurveEditorWindow)")
                {
                    substanceAnimationParams.lerp = newLerp;
                }

                for (int j = 0; j < substanceMaterialVariables.animatedMaterialVariables.Count; j++)// search through dictionary for variable names and if they match animate them
                {
                    ProceduralPropertyDescription animatedMaterialVariable = substanceMaterialVariables.animatedMaterialVariables[j];
                    ProceduralPropertyType        propType = substanceMaterialVariables.animatedMaterialVariables[j].type;
                    if (substanceMaterialVariables.materialVariableNames.Contains(animatedMaterialVariable.name))
                    {
                        if (propType == ProceduralPropertyType.Float)
                        {
                            substanceMaterialVariables.substance.SetProceduralFloat(animatedMaterialVariable.name, Mathf.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyFloatDictionary[animatedMaterialVariable.name], substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].PropertyFloatDictionary[animatedMaterialVariable.name], newLerp * flickerValues.flickerFloatCalc));
                        }
                        else if (propType == ProceduralPropertyType.Color3)
                        {
                            substanceMaterialVariables.substance.SetProceduralColor(animatedMaterialVariable.name, Color.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyColorDictionary[animatedMaterialVariable.name], substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].PropertyColorDictionary[animatedMaterialVariable.name], newLerp * flickerValues.flickerColor3Calc));
                        }
                        else if (propType == ProceduralPropertyType.Color4)
                        {
                            substanceMaterialVariables.substance.SetProceduralColor(animatedMaterialVariable.name, Color.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyColorDictionary[animatedMaterialVariable.name], substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].PropertyColorDictionary[animatedMaterialVariable.name], newLerp * flickerValues.flickerColor4Calc));
                        }
                        else if (propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4)
                        {
                            if (propType == ProceduralPropertyType.Vector4)
                            {
                                substanceMaterialVariables.substance.SetProceduralVector(animatedMaterialVariable.name, Vector4.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyVector4Dictionary[animatedMaterialVariable.name], substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].PropertyVector4Dictionary[animatedMaterialVariable.name], newLerp * flickerValues.flickerVector4Calc));
                            }
                            else if (propType == ProceduralPropertyType.Vector3)
                            {
                                substanceMaterialVariables.substance.SetProceduralVector(animatedMaterialVariable.name, Vector3.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyVector3Dictionary[animatedMaterialVariable.name], substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].PropertyVector3Dictionary[animatedMaterialVariable.name], newLerp * flickerValues.flickerVector3Calc));
                            }
                            else if (propType == ProceduralPropertyType.Vector2)
                            {
                                substanceMaterialVariables.substance.SetProceduralVector(animatedMaterialVariable.name, Vector2.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyVector2Dictionary[animatedMaterialVariable.name], substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].PropertyVector2Dictionary[animatedMaterialVariable.name], newLerp * flickerValues.flickerVector2Calc));
                            }
                        }
                        else if (propType == ProceduralPropertyType.Enum)
                        {
                            substanceMaterialVariables.substance.SetProceduralEnum(animatedMaterialVariable.name, substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyEnumDictionary[animatedMaterialVariable.name]);
                        }
                        else if (propType == ProceduralPropertyType.Boolean)
                        {
                            substanceMaterialVariables.substance.SetProceduralBoolean(animatedMaterialVariable.name, substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].PropertyBoolDictionary[animatedMaterialVariable.name]);
                        }
                    }
                }
                if (substanceMaterialVariables.rend.sharedMaterial.HasProperty("_EmissionColor"))
                {
                    substanceMaterialVariables.emissionInput = Color.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].emissionColor, substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].emissionColor, newLerp * flickerValues.flickerCalc);
                    substanceMaterialVariables.rend.sharedMaterial.SetColor("_EmissionColor", substanceMaterialVariables.emissionInput);
                    substanceToolParams.selectedPrefabScript.emissionInput = substanceMaterialVariables.emissionInput;
                }
                if (substanceMaterialVariables.rend.sharedMaterial.HasProperty("_MainTex"))
                {
                    substanceMaterialVariables.rend.sharedMaterial.SetTextureOffset("_MainTex", Vector2.Lerp(substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i - 1].MainTex, substanceMaterialVariables.MaterialVariableKeyframeDictionaryList[i].MainTex, newLerp * flickerValues.flickerCalc));
                }
                substanceMaterialVariables.substance.RebuildTextures();
                return;
            }
        }
    }
예제 #14
0
    public void DisplaySubstanceMaterialProperties(ProceduralMaterial mySubstance)
    {
        ProceduralPropertyDescription[] inputs = mySubstance.GetProceduralPropertyDescriptions();
        int i = 0;

        while (i < inputs.Length)
        {
            ProceduralPropertyDescription input = inputs[i];
            ProceduralPropertyType        type  = input.type;
            //Para variables booleanas
            if (type == ProceduralPropertyType.Boolean)
            {
                GameObject holder = GameObject.Instantiate(propertyHolderTogglePrefab, propertyParent.transform);
                holder.GetComponentInChildren <Toggle>().GetComponentInChildren <Text>().text = input.label;
                holder.GetComponentInChildren <Toggle>().onValueChanged.AddListener(delegate { ToggleSubtanceProperty(input.name, mySubstance, holder.GetComponentInChildren <Toggle>()); });
            }
            //Para variables expuestas flotantes
            else if (type == ProceduralPropertyType.Float)
            {
                if (input.hasRange)
                {
                    GameObject holder = GameObject.Instantiate(propertyHoldeSliderPrefab, propertyParent.transform);
                    holder.transform.Find("txt").GetComponent <Text>().text = input.label;
                    holder.GetComponentInChildren <Slider>().onValueChanged.AddListener(delegate { SlideSubstanceProperty(input, holder.GetComponentInChildren <Slider>(), mySubstance); });
                }
                else if (type == ProceduralPropertyType.Vector2 || type == ProceduralPropertyType.Vector3 || type == ProceduralPropertyType.Vector4)
                {
                    if (input.hasRange)
                    {
                        GUILayout.Label(input.name);
                        int vectorComponentAmount = 4;
                        if (type == ProceduralPropertyType.Vector2)
                        {
                            vectorComponentAmount = 2;
                        }

                        if (type == ProceduralPropertyType.Vector3)
                        {
                            vectorComponentAmount = 3;
                        }

                        Vector4 inputVector    = mySubstance.GetProceduralVector(input.name);
                        Vector4 oldInputVector = inputVector;
                        int     c = 0;
                        while (c < vectorComponentAmount)
                        {
                            inputVector[c] = GUILayout.HorizontalSlider(inputVector[c], input.minimum, input.maximum);
                            c++;
                        }
                        if (inputVector != oldInputVector)
                        {
                            mySubstance.SetProceduralVector(input.name, inputVector);
                        }
                    }
                    else if (type == ProceduralPropertyType.Color3 || type == ProceduralPropertyType.Color4)
                    {
                        GUILayout.Label(input.label);
                        int   colorComponentAmount = ((type == ProceduralPropertyType.Color3) ? 3 : 4);
                        Color colorInput           = mySubstance.GetProceduralColor(input.name);
                        Color oldColorInput        = colorInput;
                        int   d = 0;
                        while (d < colorComponentAmount)
                        {
                            colorInput[d] = GUILayout.HorizontalSlider(colorInput[d], 0, 1);
                            d++;
                        }
                        if (colorInput != oldColorInput)
                        {
                            mySubstance.SetProceduralColor(input.name, colorInput);
                        }
                    }
                    else if (type == ProceduralPropertyType.Enum)
                    {
                        GUILayout.Label(input.label);
                        int      enumInput    = mySubstance.GetProceduralEnum(input.name);
                        int      oldEnumInput = enumInput;
                        string[] enumOptions  = input.enumOptions;
                        enumInput = GUILayout.SelectionGrid(enumInput, enumOptions, 1);
                        if (enumInput != oldEnumInput)
                        {
                            mySubstance.SetProceduralEnum(input.name, enumInput);
                        }
                    }
                }
            }
            i++;
        }
        mySubstance.RebuildTextures();
    }
    void AddSetProceduralVariablesBeforeChangeToKeyValue(ProceduralMaterial inputMaterialBeforeChange, ProceduralPropertyDescription[] materialVariablesListBeforeChange, List <string> keysList, List <string> valuesList)
    { // Specify current material variables as the 'beforeChange' material and what to check against after a change happens
        if (keysList.Count > 0)
        {
            keysList.Clear();
        }
        if (valuesList.Count > 0)
        {
            valuesList.Clear();
        }
        for (int i = 0; i < materialVariablesBeforeChange.Length; i++)//loop through properties and make them the default properties for this object
        {
            ProceduralPropertyDescription materialVariable = materialVariablesBeforeChange[i];
            ProceduralPropertyType        propType         = materialVariablesBeforeChange[i].type;
            if (propType == ProceduralPropertyType.Float /*&& (materialVariable.hasRange )*/)
            {
                float propFloat = inputMaterialBeforeChange.GetProceduralFloat(materialVariable.name);
                keysList.Add(materialVariable.name);
                valuesList.Add(propFloat.ToString());
            }
            if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
            {
                Color propColor = inputMaterialBeforeChange.GetProceduralColor(materialVariable.name);
                keysList.Add(materialVariable.name);
                valuesList.Add("#" + ColorUtility.ToHtmlStringRGBA(propColor));
            }
            if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) /* && (objProperty.hasRange || (saveParametersWithoutRange && !objProperty.hasRange))*/)
            {
                if (propType == ProceduralPropertyType.Vector4)
                {
                    Vector4 propVector4 = inputMaterialBeforeChange.GetProceduralVector(materialVariable.name);
                    keysList.Add(materialVariable.name);
                    valuesList.Add(propVector4.ToString());
                }
                else if (propType == ProceduralPropertyType.Vector3)
                {
                    Vector3 propVector3 = inputMaterialBeforeChange.GetProceduralVector(materialVariable.name);
                    keysList.Add(materialVariable.name);
                    valuesList.Add(propVector3.ToString());
                }
                else if (propType == ProceduralPropertyType.Vector2)
                {
                    Vector2 propVector2 = inputMaterialBeforeChange.GetProceduralVector(materialVariable.name);
                    keysList.Add(materialVariable.name);
                    valuesList.Add(propVector2.ToString());
                }
            }
            else if (propType == ProceduralPropertyType.Enum)
            {
                int propEnum = inputMaterialBeforeChange.GetProceduralEnum(materialVariable.name);
                keysList.Add(materialVariable.name);
                valuesList.Add(propEnum.ToString());
            }
            else if (propType == ProceduralPropertyType.Boolean)
            {
                bool propBoolean = inputMaterialBeforeChange.GetProceduralBoolean(materialVariable.name);
                keysList.Add(materialVariable.name);
                valuesList.Add(propBoolean.ToString());
            }
        }
        // materialVariables.animationTime = animationTime;

        // sets a procedural material based on custom dictionary. I do this because copies of Procedural Materials get changed with their originals. This does not happen if i set values based on parsed values.
        for (int i = 0; i < materialVariablesBeforeChange.Length; i++)
        {
            ProceduralPropertyDescription materialVariables = materialVariablesBeforeChange[i];
            ProceduralPropertyType        propType          = materialVariablesBeforeChange[i].type;
            if (propType == ProceduralPropertyType.Float && (materialVariables.hasRange /*|| (saveParametersWithoutRange && !materialVariables.hasRange) || resettingValuesToDefault)*/))
            {
                for (int j = 0; j < keysList.Count; j++)
                {
                    if (keysList[j] == materialVariables.name)
                    {
                        if (keysList[j] == materialVariables.name)
                        {
                            inputMaterialBeforeChange.SetProceduralFloat(materialVariables.name, float.Parse(valuesList[j]));
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
            {
                for (int j = 0; j < keysList.Count; j++)
                {
                    if (keysList[j] == materialVariables.name)
                    {
                        Color curColor;
                        ColorUtility.TryParseHtmlString(valuesList[j], out curColor);
                        inputMaterialBeforeChange.SetProceduralColor(materialVariables.name, curColor);
                    }
                }
            }
            else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) && (materialVariables.hasRange /*|| (saveParametersWithoutRange && !materialVariables.hasRange) || resettingValuesToDefault)*/))
            {
                if (propType == ProceduralPropertyType.Vector4)
                {
                    for (int j = 0; j < keysList.Count; j++)
                    {
                        if (keysList[j] == materialVariables.name)
                        {
                            Vector4 curVector4 = StringToVector(valuesList[j], 4);
                            inputMaterialBeforeChange.SetProceduralVector(materialVariables.name, curVector4);
                        }
                    }
                }
                else if (propType == ProceduralPropertyType.Vector3)
                {
                    for (int j = 0; j < keysList.Count; j++)
                    {
                        if (keysList[j] == materialVariables.name)
                        {
                            Vector3 curVector3 = StringToVector(valuesList[j], 3);
                            inputMaterialBeforeChange.SetProceduralVector(materialVariables.name, curVector3);
                        }
                    }
                }
                else if (propType == ProceduralPropertyType.Vector2)
                {
                    for (int j = 0; j < keysList.Count; j++)
                    {
                        if (keysList[j] == materialVariables.name)
                        {
                            Vector2 curVector2 = StringToVector(valuesList[j], 2);
                            inputMaterialBeforeChange.SetProceduralVector(materialVariables.name, curVector2);
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Enum)
            {
                for (int j = 0; j < keysList.Count; j++)
                {
                    if (keysList[j] == materialVariables.name)
                    {
                        int curEnum = int.Parse(valuesList[j]);
                        inputMaterialBeforeChange.SetProceduralEnum(materialVariables.name, curEnum);
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Boolean)
            {
                for (int j = 0; j < keysList.Count; j++)
                {
                    if (keysList[j] == materialVariables.name)
                    {
                        bool curBool = bool.Parse(valuesList[j]);
                        inputMaterialBeforeChange.SetProceduralBoolean(materialVariables.name, curBool);
                    }
                }
            }
        }
    }
    void CheckForNoChangeInMaterialParams(ProceduralMaterial inputMaterialBeforeChange, ProceduralPropertyDescription[] materialVariablesListBeforeChange, List <string> keysList, List <string> valuesList)
    {// checks if the material variables have not changed from a given material.
        int variablesChanged = 0;

        for (int i = 0; i <= materialVariablesListBeforeChange.Count() - 1; i++)
        {
            ProceduralPropertyDescription materialVariableCurrent      = testingScript.substanceMaterialParams.materialVariables[i];
            ProceduralPropertyDescription materialVariableBeforeChange = materialVariablesListBeforeChange[i];
            ProceduralPropertyType        propType = testingScript.substanceMaterialParams.materialVariables[i].type;

            if (propType == ProceduralPropertyType.Float)
            {
                float propFloatCurrent      = testingScript.substanceMaterialParams.substance.GetProceduralFloat(materialVariableCurrent.name);
                float propFloatBeforeChange = float.Parse(valuesList[keysList.IndexOf(materialVariableCurrent.name)]);
                if (propFloatCurrent != propFloatBeforeChange)
                {
                    variablesChanged++;
                }
            }
            else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
            {
                Color propColorCurrent = testingScript.substanceMaterialParams.substance.GetProceduralColor(materialVariableCurrent.name);
                Color curColor;
                ColorUtility.TryParseHtmlString(valuesList[keysList.IndexOf(materialVariableCurrent.name)], out curColor);
                Color propColorBeforeChange = curColor;
                if (propColorCurrent != propColorBeforeChange)
                {
                    variablesChanged++;
                }
            }
            else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4))
            {
                if (propType == ProceduralPropertyType.Vector4)
                {
                    Vector4 propVector4Current      = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name);
                    Vector4 propVector4BeforeChange = StringToVector(valuesList[keysList.IndexOf(materialVariableCurrent.name)], 4);
                    if (propVector4Current != propVector4BeforeChange)
                    {
                        variablesChanged++;
                    }
                }
                else if (propType == ProceduralPropertyType.Vector3)
                {
                    Vector3 propVector3Current      = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name);
                    Vector3 propVector3BeforeChange = StringToVector(valuesList[keysList.IndexOf(materialVariableCurrent.name)], 3);
                    if (propVector3Current != propVector3BeforeChange)
                    {
                        variablesChanged++;
                    }
                }
                else if (propType == ProceduralPropertyType.Vector2)
                {
                    Vector2 propVector2Current      = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name);
                    Vector2 propVector2BeforeChange = StringToVector(valuesList[keysList.IndexOf(materialVariableCurrent.name)], 2);
                    if (propVector2Current != propVector2BeforeChange)
                    {
                        variablesChanged++;
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Enum)
            {
                int propEnumCurrent      = testingScript.substanceMaterialParams.substance.GetProceduralEnum(materialVariableCurrent.name);
                int propEnumBeforeChange = int.Parse(valuesList[keysList.IndexOf(materialVariableCurrent.name)]);
                if (propEnumCurrent != propEnumBeforeChange)
                {
                    variablesChanged++;
                }
            }
            else if (propType == ProceduralPropertyType.Boolean)
            {
                bool propBoolCurrent      = testingScript.substanceMaterialParams.substance.GetProceduralBoolean(materialVariableCurrent.name);
                bool propBoolBeforeChange = materialBeforeChange.GetProceduralBoolean(materialVariableBeforeChange.name);
                if (propBoolCurrent != propBoolBeforeChange)
                {
                    variablesChanged++;
                }
            }
            if (variablesChanged > 0)
            {
                Assert.Fail("Material not the same as original");
                break;
            }
            if (i == materialVariablesBeforeChange.Count() - 1 && variablesChanged == 0)
            {
                Debug.Log("Material same as original, Success?");
            }
        }
    }
예제 #17
0
 /// <summary>
 /// Functions for storing/converting Procedural variables
 /// </summary>
 public static void AddProceduralVariablesToList(MaterialVariableListHolder materialVariableList, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)  // Adds current procedural values to a list
 {
     for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
     {
         ProceduralPropertyDescription materialVariable = substanceMaterialParams.materialVariables[i];
         ProceduralPropertyType        propType         = substanceMaterialParams.materialVariables[i].type;
         if (propType != ProceduralPropertyType.Texture) // Texture Type not supported
         {
             materialVariableList.PropertyName.Add(materialVariable.name);
         }
         if (propType == ProceduralPropertyType.Float && (materialVariable.hasRange || (substanceMaterialParams.saveOutputParameters && !materialVariable.hasRange)))
         {
             float propFloat = substanceMaterialParams.substance.GetProceduralFloat(materialVariable.name);
             materialVariableList.PropertyFloat.Add(propFloat);
             materialVariableList.myFloatKeys.Add(materialVariable.name);
             materialVariableList.myFloatValues.Add(propFloat);
         }
         else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
         {
             Color propColor = substanceMaterialParams.substance.GetProceduralColor(materialVariable.name);
             materialVariableList.PropertyColor.Add(propColor);
             materialVariableList.myColorKeys.Add(materialVariable.name);
             materialVariableList.myColorValues.Add(propColor);
         }
         else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) && (materialVariable.hasRange || (substanceMaterialParams.saveOutputParameters && !materialVariable.hasRange)))
         {
             if (propType == ProceduralPropertyType.Vector4)
             {
                 Vector4 propVector4 = substanceMaterialParams.substance.GetProceduralVector(materialVariable.name);
                 materialVariableList.PropertyVector4.Add(propVector4);
                 materialVariableList.myVector4Keys.Add(materialVariable.name);
                 materialVariableList.myVector4Values.Add(propVector4);
             }
             else if (propType == ProceduralPropertyType.Vector3)
             {
                 Vector3 propVector3 = substanceMaterialParams.substance.GetProceduralVector(materialVariable.name);
                 materialVariableList.PropertyVector3.Add(propVector3);
                 materialVariableList.myVector3Keys.Add(materialVariable.name);
                 materialVariableList.myVector3Values.Add(propVector3);
             }
             else if (propType == ProceduralPropertyType.Vector2)
             {
                 Vector2 propVector2 = substanceMaterialParams.substance.GetProceduralVector(materialVariable.name);
                 materialVariableList.PropertyVector2.Add(propVector2);
                 materialVariableList.myVector2Keys.Add(materialVariable.name);
                 materialVariableList.myVector2Values.Add(propVector2);
             }
         }
         else if (propType == ProceduralPropertyType.Enum)
         {
             int propEnum = substanceMaterialParams.substance.GetProceduralEnum(materialVariable.name);
             materialVariableList.PropertyEnum.Add(propEnum);
             materialVariableList.myEnumKeys.Add(materialVariable.name);
             materialVariableList.myEnumValues.Add(propEnum);
         }
         else if (propType == ProceduralPropertyType.Boolean)
         {
             bool propBool = substanceMaterialParams.substance.GetProceduralBoolean(materialVariable.name);
             materialVariableList.PropertyBool.Add(propBool);
             materialVariableList.myBooleanKeys.Add(materialVariable.name);
             materialVariableList.myBooleanValues.Add(propBool);
         }
     }
     materialVariableList.PropertyMaterialName = substanceMaterialParams.substance.name;
     materialVariableList.emissionColor        = substanceMaterialParams.emissionInput;
     materialVariableList.MainTex = substanceMaterialParams.MainTexOffset;
     if (substanceMaterialParams.saveOutputParameters)
     {
         materialVariableList.hasParametersWithoutRange = true;
     }
     else
     {
         materialVariableList.hasParametersWithoutRange = false;
     }
     materialVariableList.animationTime = animationParams.defaultAnimationTime;
 }
예제 #18
0
 public static void CacheAnimatedProceduralVariables(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, bool prefab = false) //Checks which variables change throughout keyframes and add them to a list that contains animated variables.If cacheSubstance is true it will also set those variables to cache
 {
     if (animationParams.cacheSubstance && substanceMaterialParams.materialVariables != null)
     {
         substanceMaterialParams.animatedMaterialVariables.Clear(); // Makes sure if a variable stops being animatable it the list will clear and  refresh later
         for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
         {
             substanceMaterialParams.substance.CacheProceduralProperty(substanceMaterialParams.materialVariables[i].name, false);// Makes sure if a variable stops being animatable it the list will  refresh
         }
         if (substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Count >= 2)
         {
             for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
             {
                 ProceduralPropertyDescription MaterialVariable = substanceMaterialParams.materialVariables[i];
                 ProceduralPropertyType        propType         = substanceMaterialParams.materialVariables[i].type;
                 bool varChanged = false;
                 if (propType == ProceduralPropertyType.Float)
                 {
                     float variableAnimationCheck = 0;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, float> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyFloatDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)// find value of current parameter on first frame;
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 else if (j > 0 && keyValue.Value != variableAnimationCheck) // if value of parameter on this keyframe is diffrent then the the value on the first keyframe.
                                 {
                                     substanceMaterialParams.substance.CacheProceduralProperty(keyValue.Key, true);
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
                 {
                     Color variableAnimationCheck = Color.white;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Color> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyColorDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 else if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     substanceMaterialParams.substance.CacheProceduralProperty(keyValue.Key, true);
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 else if (propType == ProceduralPropertyType.Vector2)
                 {
                     Vector2 variableAnimationCheck = new Vector2(0, 0);
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Vector2> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyVector2Dictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 else if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     substanceMaterialParams.substance.CacheProceduralProperty(keyValue.Key, true);
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 else if (propType == ProceduralPropertyType.Vector3)
                 {
                     Vector3 variableAnimationCheck = new Vector3(0, 0, 0);
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Vector3> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyVector3Dictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 else if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     substanceMaterialParams.substance.CacheProceduralProperty(keyValue.Key, true);
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 else if (propType == ProceduralPropertyType.Vector4)
                 {
                     Vector4 variableAnimationCheck = new Vector4(0, 0, 0, 0);
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Vector4> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyVector4Dictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 else if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     substanceMaterialParams.substance.CacheProceduralProperty(keyValue.Key, true);
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 else if (propType == ProceduralPropertyType.Boolean)
                 {
                     bool variableAnimationCheck = false;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Boolean> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyBoolDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 else if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     substanceMaterialParams.substance.CacheProceduralProperty(keyValue.Key, true);
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 else if (propType == ProceduralPropertyType.Enum)
                 {
                     int variableAnimationCheck = 0;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, int> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyEnumDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 else if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     substanceMaterialParams.substance.CacheProceduralProperty(keyValue.Key, true);
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else if (!animationParams.cacheSubstance && substanceMaterialParams.materialVariables != null) // add variables if the animate but do not cache them.
     {
         substanceMaterialParams.animatedMaterialVariables.Clear();
         for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
         {
             substanceMaterialParams.substance.CacheProceduralProperty(substanceMaterialParams.materialVariables[i].name, false);
         }
         if (substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Count >= 2)
         {
             for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
             {
                 ProceduralPropertyDescription MaterialVariable = substanceMaterialParams.materialVariables[i];
                 ProceduralPropertyType        propType         = substanceMaterialParams.materialVariables[i].type;
                 bool varChanged = false;
                 if (propType == ProceduralPropertyType.Float)
                 {
                     float variableAnimationCheck = 0;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, float> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyFloatDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
                 {
                     Color variableAnimationCheck = Color.white;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Color> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyColorDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 if (propType == ProceduralPropertyType.Vector2)
                 {
                     Vector2 variableAnimationCheck = new Vector2(0, 0);
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Vector2> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyVector2Dictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 if (propType == ProceduralPropertyType.Vector3)
                 {
                     Vector3 variableAnimationCheck = new Vector3(0, 0, 0);
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Vector3> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyVector3Dictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 if (propType == ProceduralPropertyType.Vector4)
                 {
                     Vector4 variableAnimationCheck = new Vector4(0, 0, 0, 0);
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Vector4> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyVector4Dictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 if (propType == ProceduralPropertyType.Boolean)
                 {
                     bool variableAnimationCheck = false;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, Boolean> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyBoolDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
                 if (propType == ProceduralPropertyType.Enum)
                 {
                     int variableAnimationCheck = 0;
                     for (int j = 0; j <= animationParams.keyFrameTimes.Count - 1; j++)
                     {
                         foreach (KeyValuePair <string, int> keyValue in substanceMaterialParams.MaterialVariableKeyframeDictionaryList[j].PropertyEnumDictionary)
                         {
                             if (!varChanged && keyValue.Key == substanceMaterialParams.materialVariables[i].name)
                             {
                                 if (j == 0)
                                 {
                                     variableAnimationCheck = keyValue.Value;
                                 }
                                 if (j > 0 && keyValue.Value != variableAnimationCheck)
                                 {
                                     if (substanceMaterialParams.animatedMaterialVariables.Contains(MaterialVariable) == false)
                                     {
                                         substanceMaterialParams.animatedMaterialVariables.Add(MaterialVariable);
                                     }
                                     varChanged = true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
예제 #19
0
        void ProceduralPropertiesGUI(int windowId)
        {
            scrolling = GUILayout.BeginScrollView(scrolling);
            if (GUILayout.Button("Copy Preset"))
            {
                levelEditor.currentPreset = piece.Material.preset;
            }
            if (GUILayout.Button("Paste Preset"))
            {
                piece.Material.preset = levelEditor.currentPreset;
            }
            GUILayout.Space(10);
            if (GUILayout.Button("Save Changes"))
            {
                piece.preset = piece.Material.preset;
            }
            if (GUILayout.Button("Revert Changes"))
            {
                Reload();
            }
            GUILayout.Space(10);
            if (GUILayout.Button("Remove Piece"))
            {
                core.RemovePiece(piece);
            }
            GUILayout.Space(10);
            ProceduralPropertyDescription[] inputs = piece.Material.GetProceduralPropertyDescriptions();
            int i = 0;

            while (i < inputs.Length)
            {
                ProceduralPropertyDescription input = inputs[i];
                ProceduralPropertyType        type  = input.type;
                if (type == ProceduralPropertyType.Boolean)
                {
                    bool inputBool    = piece.Material.GetProceduralBoolean(input.name);
                    bool oldInputBool = inputBool;
                    inputBool = GUILayout.Toggle(inputBool, input.name);
                    if (inputBool != oldInputBool)
                    {
                        piece.Material.SetProceduralBoolean(input.name, inputBool);
                    }
                }
                else if (type == ProceduralPropertyType.Float)
                {
                    if (input.hasRange)
                    {
                        float inputFloat    = piece.Material.GetProceduralFloat(input.name);
                        float oldInputFloat = inputFloat;
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(input.name);
                        GUILayout.FlexibleSpace();
                        GUILayout.Label(inputFloat.ToString());
                        GUILayout.EndHorizontal();
                        inputFloat = GUILayout.HorizontalSlider(inputFloat, input.minimum, input.maximum);
                        if (inputFloat != oldInputFloat)
                        {
                            piece.Material.SetProceduralFloat(input.name, inputFloat);
                        }
                    }
                }
                else if (type == ProceduralPropertyType.Vector2 || type == ProceduralPropertyType.Vector3 || type == ProceduralPropertyType.Vector4)
                {
                    if (input.hasRange)
                    {
                        GUILayout.Label(input.name);
                        int vectorComponentAmount = 4;
                        if (type == ProceduralPropertyType.Vector2)
                        {
                            vectorComponentAmount = 2;
                        }

                        if (type == ProceduralPropertyType.Vector3)
                        {
                            vectorComponentAmount = 3;
                        }

                        Vector4 inputVector    = piece.Material.GetProceduralVector(input.name);
                        Vector4 oldInputVector = inputVector;
                        int     c = 0;
                        while (c < vectorComponentAmount)
                        {
                            inputVector[c] = GUILayout.HorizontalSlider(inputVector[c], input.minimum, input.maximum);
                            c++;
                        }
                        if (inputVector != oldInputVector)
                        {
                            piece.Material.SetProceduralVector(input.name, inputVector);
                        }
                    }
                }
                else if (type == ProceduralPropertyType.Color3 || type == ProceduralPropertyType.Color4)
                {
                    GUILayout.Label(input.name);
                    int   colorComponentAmount = ((type == ProceduralPropertyType.Color3) ? 3 : 4);
                    Color colorInput           = piece.Material.GetProceduralColor(input.name);
                    Color oldColorInput        = colorInput;
                    int   d = 0;
                    while (d < colorComponentAmount)
                    {
                        GUILayout.BeginHorizontal();
                        var dd = "R";//ed Channel";
                        if (d == 1)
                        {
                            dd = "G";//reen Channel";
                        }
                        else if (d == 2)
                        {
                            dd = "B";//lue Channel";
                        }
                        else if (d == 3)
                        {
                            dd = "A";//lpha Channel";
                        }
                        GUILayout.Label(dd);
                        GUILayout.FlexibleSpace();
                        var s = Mathf.Round(float.Parse(colorInput[d].ToString()) * 255);
                        GUILayout.Label(s.ToString());
                        GUILayout.EndHorizontal();
                        colorInput[d] = GUILayout.HorizontalSlider(colorInput[d], 0, 1);
                        d++;
                    }
                    if (colorInput != oldColorInput)
                    {
                        piece.Material.SetProceduralColor(input.name, colorInput);
                    }
                }
                else if (type == ProceduralPropertyType.Enum)
                {
                    GUILayout.Label(input.name);
                    int      enumInput    = piece.Material.GetProceduralEnum(input.name);
                    int      oldEnumInput = enumInput;
                    string[] enumOptions  = input.enumOptions;
                    enumInput = GUILayout.SelectionGrid(enumInput, enumOptions, 1);
                    if (enumInput != oldEnumInput)
                    {
                        piece.Material.SetProceduralEnum(input.name, enumInput);
                    }
                }
                i++;
            }
            piece.Material.RebuildTextures();
            GUILayout.EndScrollView();
        }
예제 #20
0
    void VehiclePropertiesGUI(int guiID)
    {
        //start GUI Layout
        scrollVal = GUILayout.BeginScrollView(scrollVal);


        //loop through properties
        int i = 0;

        while (i < curProperties.Length)
        {
            ProceduralPropertyDescription curProperty = curProperties[i];

            ProceduralPropertyType curtype = curProperties[i].type;


            //create some slider for the floats
            if (curtype == ProceduralPropertyType.Float)
            {
                if (curProperty.hasRange)
                {
                    GUILayout.Label(curProperty.name);
                    float curFloat = lightcapSubstance.GetProceduralFloat(curProperty.name);
                    float oldFloat = curFloat;
                    curFloat = GUILayout.HorizontalSlider(curFloat, curProperty.minimum, curProperty.maximum);
                    if (curFloat != oldFloat)
                    {
                        lightcapSubstance.SetProceduralFloat(curProperty.name, curFloat);
                    }
                }
            }
            else if (curtype == ProceduralPropertyType.Color4)
            {
                GUILayout.Label(curProperty.name);
                Color curColor = lightcapSubstance.GetProceduralColor(curProperty.name);
                Color oldColor = curColor;


                //get the last rectangle for this picker
                //Rect curRect = GUILayoutUtility.GetLastRect();


                if (curColor != oldColor)
                {
                    lightcapSubstance.SetProceduralColor(curProperty.name, curColor);
                }
            }
            else if (curtype == ProceduralPropertyType.Enum)
            {
                GUILayout.Label(curProperty.name);
                int      enumVal     = lightcapSubstance.GetProceduralEnum(curProperty.name);
                int      oldEnumVal  = enumVal;
                string[] enumOptions = curProperty.enumOptions;
                enumVal = GUILayout.SelectionGrid(enumVal, enumOptions, 1);
                if (enumVal != oldEnumVal)
                {
                    lightcapSubstance.SetProceduralEnum(curProperty.name, enumVal);
                }
            }

            i++;
        }


        //rebuild the substance material
        lightcapSubstance.RebuildTextures();

        GUILayout.EndScrollView();
    }
예제 #21
0
    void ProceduralPropertiesGUI(int windowId)
    {
        scrolling = GUILayout.BeginScrollView(scrolling);
        ProceduralMaterial substance = rend.sharedMaterial as ProceduralMaterial;

        ProceduralPropertyDescription[] inputs = substance.GetProceduralPropertyDescriptions();
        int i = 0;

        while (i < inputs.Length)
        {
            ProceduralPropertyDescription input = inputs[i];
            ProceduralPropertyType        type  = input.type;
            if (type == ProceduralPropertyType.Boolean)
            {
                bool inputBool    = substance.GetProceduralBoolean(input.name);
                bool oldInputBool = inputBool;
                inputBool = GUILayout.Toggle(inputBool, input.name);
                if (inputBool != oldInputBool)
                {
                    substance.SetProceduralBoolean(input.name, inputBool);
                }
            }
            else if (type == ProceduralPropertyType.Float)
            {
                if (input.hasRange)
                {
                    GUILayout.Label(input.name);
                    float inputFloat    = substance.GetProceduralFloat(input.name);
                    float oldInputFloat = inputFloat;
                    inputFloat = GUILayout.HorizontalSlider(inputFloat, input.minimum, input.maximum);
                    if (inputFloat != oldInputFloat)
                    {
                        substance.SetProceduralFloat(input.name, inputFloat);
                    }
                }
                else if (type == ProceduralPropertyType.Vector2 || type == ProceduralPropertyType.Vector3 || type == ProceduralPropertyType.Vector4)
                {
                    if (input.hasRange)
                    {
                        GUILayout.Label(input.name);
                        int vectorComponentAmount = 4;
                        if (type == ProceduralPropertyType.Vector2)
                        {
                            vectorComponentAmount = 2;
                        }

                        if (type == ProceduralPropertyType.Vector3)
                        {
                            vectorComponentAmount = 3;
                        }

                        Vector4 inputVector    = substance.GetProceduralVector(input.name);
                        Vector4 oldInputVector = inputVector;
                        int     c = 0;
                        while (c < vectorComponentAmount)
                        {
                            inputVector[c] = GUILayout.HorizontalSlider(inputVector[c], input.minimum, input.maximum);
                            c++;
                        }
                        if (inputVector != oldInputVector)
                        {
                            substance.SetProceduralVector(input.name, inputVector);
                        }
                    }
                    else if (type == ProceduralPropertyType.Color3 || type == ProceduralPropertyType.Color4)
                    {
                        GUILayout.Label(input.name);
                        int   colorComponentAmount = ((type == ProceduralPropertyType.Color3) ? 3 : 4);
                        Color colorInput           = substance.GetProceduralColor(input.name);
                        Color oldColorInput        = colorInput;
                        int   d = 0;
                        while (d < colorComponentAmount)
                        {
                            colorInput[d] = GUILayout.HorizontalSlider(colorInput[d], 0, 1);
                            d++;
                        }
                        if (colorInput != oldColorInput)
                        {
                            substance.SetProceduralColor(input.name, colorInput);
                        }
                    }
                    else if (type == ProceduralPropertyType.Enum)
                    {
                        GUILayout.Label(input.name);
                        int      enumInput    = substance.GetProceduralEnum(input.name);
                        int      oldEnumInput = enumInput;
                        string[] enumOptions  = input.enumOptions;
                        enumInput = GUILayout.SelectionGrid(enumInput, enumOptions, 1);
                        if (enumInput != oldEnumInput)
                        {
                            substance.SetProceduralEnum(input.name, enumInput);
                        }
                    }
                }
            }
            i++;
        }
        substance.RebuildTextures();
        GUILayout.EndScrollView();
    }
    public static void SetProceduralVariablesFromList(MaterialVariableListHolder propertyList, SubstanceMaterialParams substanceMaterialVariables, SubstanceAnimationParams substanceAnimationParams, SubstanceToolParams substanceToolParams) // Sets current substance parameters from a List
    {
        for (int i = 0; i < substanceMaterialVariables.materialVariables.Length; i++)
        {
            ProceduralPropertyDescription materialVariable = substanceMaterialVariables.materialVariables[i];
            ProceduralPropertyType        propType         = substanceMaterialVariables.materialVariables[i].type;
            if (propType == ProceduralPropertyType.Float && (materialVariable.hasRange || (substanceMaterialVariables.saveOutputParameters && !materialVariable.hasRange) || substanceMaterialVariables.resettingValuesToDefault))
            {
                if (propertyList.myFloatKeys.Count > 0)
                {
                    for (int j = 0; j < propertyList.myFloatKeys.Count; j++)
                    {
                        if (propertyList.myFloatKeys[j] == materialVariable.name)
                        {
                            if (propertyList.myFloatKeys[j] == materialVariable.name)
                            {
                                substanceMaterialVariables.substance.SetProceduralFloat(materialVariable.name, propertyList.myFloatValues[j]);
                            }
                        }
                    }
                }
                else //note: for old versions of tool, remove later?
                {
                    for (int j = 0; j < propertyList.myKeys.Count; j++)
                    {
                        if (propertyList.myKeys[j] == materialVariable.name)
                        {
                            if (propertyList.myKeys[j] == materialVariable.name)
                            {
                                substanceMaterialVariables.substance.SetProceduralFloat(materialVariable.name, float.Parse(propertyList.myValues[j]));
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
            {
                if (propertyList.myColorKeys.Count > 0)
                {
                    for (int j = 0; j < propertyList.myColorKeys.Count; j++)
                    {
                        if (propertyList.myColorKeys[j] == materialVariable.name)
                        {
                            Color curColor = propertyList.myColorValues[j];
                            substanceMaterialVariables.substance.SetProceduralColor(materialVariable.name, curColor);
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < propertyList.myKeys.Count; j++)
                    {
                        if (propertyList.myKeys[j] == materialVariable.name)
                        {
                            Color curColor;
                            ColorUtility.TryParseHtmlString(propertyList.myValues[j], out curColor);
                            substanceMaterialVariables.substance.SetProceduralColor(materialVariable.name, curColor);
                        }
                    }
                }
            }
            else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) && (materialVariable.hasRange || (substanceMaterialVariables.saveOutputParameters && !materialVariable.hasRange) || substanceMaterialVariables.resettingValuesToDefault))
            {
                if (propType == ProceduralPropertyType.Vector4)
                {
                    if (propertyList.myVector4Keys.Count > 0)
                    {
                        for (int j = 0; j < propertyList.myVector4Keys.Count; j++)
                        {
                            if (propertyList.myVector4Keys[j] == materialVariable.name)
                            {
                                Vector4 curVector4 = propertyList.myVector4Values[j];
                                substanceMaterialVariables.substance.SetProceduralVector(materialVariable.name, curVector4);
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < propertyList.myKeys.Count; j++)
                        {
                            if (propertyList.myKeys[j] == materialVariable.name)
                            {
                                Vector4 curVector4 = SubstanceTweenMiscUtility.StringToVector(propertyList.myValues[j], 4);
                                substanceMaterialVariables.substance.SetProceduralVector(materialVariable.name, curVector4);
                            }
                        }
                    }
                }
                else if (propType == ProceduralPropertyType.Vector3)
                {
                    if (propertyList.myVector3Keys.Count > 0)
                    {
                        for (int j = 0; j < propertyList.myVector3Keys.Count; j++)
                        {
                            if (propertyList.myVector3Keys[j] == materialVariable.name)
                            {
                                Vector3 curVector3 = propertyList.myVector3Values[j];
                                substanceMaterialVariables.substance.SetProceduralVector(materialVariable.name, curVector3);
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < propertyList.myKeys.Count; j++)
                        {
                            if (propertyList.myKeys[j] == materialVariable.name)
                            {
                                Vector3 curVector3 = SubstanceTweenMiscUtility.StringToVector(propertyList.myValues[j], 3);
                                substanceMaterialVariables.substance.SetProceduralVector(materialVariable.name, curVector3);
                            }
                        }
                    }
                }
                else if (propType == ProceduralPropertyType.Vector2)
                {
                    if (propertyList.myVector2Keys.Count > 0)
                    {
                        for (int j = 0; j < propertyList.myVector2Keys.Count; j++)
                        {
                            if (propertyList.myVector2Keys[j] == materialVariable.name)
                            {
                                Vector2 curVector2 = propertyList.myVector2Values[j];
                                substanceMaterialVariables.substance.SetProceduralVector(materialVariable.name, curVector2);
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < propertyList.myKeys.Count; j++)
                        {
                            if (propertyList.myKeys[j] == materialVariable.name)
                            {
                                Vector2 curVector2 = SubstanceTweenMiscUtility.StringToVector(propertyList.myValues[j], 2);
                                substanceMaterialVariables.substance.SetProceduralVector(materialVariable.name, curVector2);
                            }
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Enum)
            {
                if (propertyList.myEnumKeys.Count > 0)
                {
                    for (int j = 0; j < propertyList.myEnumKeys.Count; j++)
                    {
                        if (propertyList.myEnumKeys[j] == materialVariable.name)
                        {
                            int curEnum = propertyList.myEnumValues[j];
                            substanceMaterialVariables.substance.SetProceduralEnum(materialVariable.name, curEnum);
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < propertyList.myKeys.Count; j++)
                    {
                        if (propertyList.myKeys[j] == materialVariable.name)
                        {
                            int curEnum = int.Parse(propertyList.myValues[j]);
                            substanceMaterialVariables.substance.SetProceduralEnum(materialVariable.name, curEnum);
                        }
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Boolean)
            {
                if (propertyList.myBooleanKeys.Count > 0)
                {
                    for (int j = 0; j < propertyList.myBooleanKeys.Count; j++)
                    {
                        if (propertyList.myBooleanKeys[j] == materialVariable.name)
                        {
                            bool curBool = propertyList.myBooleanValues[j];
                            substanceMaterialVariables.substance.SetProceduralBoolean(materialVariable.name, curBool);
                        }
                    }
                }

                else
                {
                    for (int j = 0; j < propertyList.myKeys.Count; j++)
                    {
                        if (propertyList.myKeys[j] == materialVariable.name)
                        {
                            bool curBool = bool.Parse(propertyList.myValues[j]);
                            substanceMaterialVariables.substance.SetProceduralBoolean(materialVariable.name, curBool);
                        }
                    }
                }
            }
        }
    }
예제 #23
0
    void Update()
    {
        if (animationToggle && !isCustomInstance)
        {
            substance.cacheSize = (ProceduralCacheSize)myProceduralCacheSize;
            if (flickerEnabled)
            {
                ChangeFlicker();
            }
            currentKeyframeAnimationTime = keyFrameTimes[currentKeyframeIndex];
            if (animationType == AnimationType.BackAndForth && animateBackwards && currentKeyframeIndex <= animationEndKeyframe && currentKeyframeIndex > 0)
            {
                currentKeyframeAnimationTime = keyFrameTimes[currentKeyframeIndex - 1];
            }

            if (animateObjectBasedOnPosition != AnimateObjectBasedOnPosition.None && customObject)
            {
                playerDistanceToObject = Vector3.Distance(customObject.transform.position, this.transform.position);
                if (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.SlowerOnApproach)
                {
                    if (playerDistanceToObject < objectMaxDistance && playerDistanceToObject > objectMinDistance - 0.1f)
                    {
                        distanceLerpCalc = Mathf.InverseLerp(objectMaxDistance, objectMinDistance, playerDistanceToObject);
                    }
                }
                if (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.FasterOnApproach)
                {
                    if (playerDistanceToObject < objectMaxDistance && playerDistanceToObject > objectMinDistance + 0.1f)
                    {
                        distanceLerpCalc = Mathf.InverseLerp(objectMinDistance, objectMaxDistance, playerDistanceToObject);
                    }
                    else if (playerDistanceToObject < objectMinDistance)
                    {
                        distanceLerpCalc = Mathf.InverseLerp(objectMinDistance, objectMaxDistance, objectMinDistance + 0.1f);
                    }
                    else if (playerDistanceToObject > objectMaxDistance)
                    {
                        distanceLerpCalc = Mathf.InverseLerp(objectMinDistance, objectMaxDistance, objectMaxDistance - 0.1f);
                    }
                }
            }
            if (animationType == AnimationType.Loop)
            {
                currentKeyframeAnimationTime = keyFrameTimes[currentKeyframeIndex];
                if (animateBasedOnTime)
                {
                    currentAnimationTime    += Time.deltaTime;
                    animationTimeRestartEnd += Time.deltaTime;

                    if (animateObjectBasedOnPosition != AnimateObjectBasedOnPosition.None)
                    {
                        currentAnimationTime    /= distanceLerpCalc;
                        animationTimeRestartEnd /= Time.deltaTime;
                    }
                }
                else
                {
                    if (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.SlowerOnApproach)
                    {
                        currentAnimationTime    += distanceLerpCalc / Time.deltaTime;
                        animationTimeRestartEnd += distanceLerpCalc / Time.deltaTime;
                    }
                    else if (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.FasterOnApproach)
                    {
                        currentAnimationTime    += Mathf.Lerp(1, 0, distanceLerpCalc) / 5;
                        animationTimeRestartEnd += Mathf.Lerp(1, 0, distanceLerpCalc) / 5;
                    }
                }
                curveFloat = prefabAnimationCurve.Evaluate(animationTimeRestartEnd);
                if (keyFrameTimes.Count > 2 && currentAnimationTime > currentKeyframeAnimationTime && currentKeyframeIndex <= animationEndKeyframe - 2)
                {
                    currentAnimationTime = 0;
                    currentKeyframeIndex++;
                }
                else if (keyFrameTimes.Count > 2 && currentKeyframeIndex >= animationEndKeyframe - 1)
                {
                    currentAnimationTime    = 0;
                    animationTimeRestartEnd = CalculateAnimationStartTime(animationStartKeyframe);
                    currentKeyframeIndex    = animationStartKeyframe;
                    curveFloat = prefabAnimationCurve.Evaluate(animationTimeRestartEnd);
                    lerp       = Mathf.InverseLerp(prefabAnimationCurve.keys[currentKeyframeIndex].time, prefabAnimationCurve.keys[currentKeyframeIndex + 1].time, curveFloat);
                    if (playOnce)
                    {
                        animationToggle = false;
                    }
                }
                else if (keyFrameTimes.Count == 2 && currentAnimationTime > currentKeyframeAnimationTime)
                {
                    currentAnimationTime    = 0;
                    animationTimeRestartEnd = 0;
                    currentKeyframeIndex    = 0;
                }
                if (currentKeyframeIndex <= animationEndKeyframe - 1)
                {
                    lerp = Mathf.InverseLerp(prefabAnimationCurve.keys[currentKeyframeIndex].time, prefabAnimationCurve.keys[currentKeyframeIndex + 1].time, curveFloat);
                }
            }

            else if (animationType == AnimationType.BackAndForth)
            {
                if (animateBasedOnTime)
                {
                    if (!animateBackwards)
                    {
                        currentAnimationTime    += Time.deltaTime;
                        animationTimeRestartEnd += Time.deltaTime;
                    }
                    else if (animateBackwards)
                    {
                        currentAnimationTime    -= Time.deltaTime;
                        animationTimeRestartEnd -= Time.deltaTime;
                    }

                    if (animateObjectBasedOnPosition != AnimateObjectBasedOnPosition.None)
                    {
                        currentAnimationTime    /= distanceLerpCalc;
                        animationTimeRestartEnd /= Time.deltaTime;
                    }
                }

                else
                {
                    if (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.SlowerOnApproach)
                    {
                        if (!animateBackwards)
                        {
                            currentAnimationTime    += distanceLerpCalc / Time.deltaTime;
                            animationTimeRestartEnd += distanceLerpCalc / Time.deltaTime;
                        }

                        else if (animateBackwards)
                        {
                            currentAnimationTime    -= distanceLerpCalc / Time.deltaTime;
                            animationTimeRestartEnd -= distanceLerpCalc / Time.deltaTime;
                        }
                    }
                    else if (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.FasterOnApproach)
                    {
                        if (!animateBackwards)
                        {
                            currentAnimationTime    += Mathf.Lerp(1, 0, distanceLerpCalc) / 5;
                            animationTimeRestartEnd += Mathf.Lerp(1, 0, distanceLerpCalc) / 5;
                        }
                        if (animateBackwards)
                        {
                            currentAnimationTime    -= Mathf.Lerp(1, 0, distanceLerpCalc) / 5;
                            animationTimeRestartEnd -= Mathf.Lerp(1, 0, distanceLerpCalc) / 5;
                        }
                    }
                }

                curveFloat = prefabAnimationCurve.Evaluate(animationTimeRestartEnd);
                if (keyFrameTimes.Count > 2 && (animationEndKeyframe - 1) - animationStartKeyframe > 1 && !animateBackwards && currentAnimationTime > currentKeyframeAnimationTime && currentKeyframeIndex < animationEndKeyframe) // reach next keyframe when going forwards
                {
                    if (currentKeyframeIndex == animationEndKeyframe - 2)
                    {
                        animateBackwards = true;
                    }
                    else
                    {
                        currentKeyframeIndex++;
                        currentAnimationTime = 0;
                    }
                }
                else if (keyFrameTimes.Count > 2 && animateBackwards && currentAnimationTime <= 0 && currentKeyframeIndex <= animationEndKeyframe - 1 && currentKeyframeIndex > animationStartKeyframe) // reach next keyframe when going backwards
                {
                    currentAnimationTime = currentKeyframeAnimationTime;
                    currentKeyframeIndex--;
                    curveFloat = prefabAnimationCurve.Evaluate(animationTimeRestartEnd);
                    lerp       = (Mathf.Lerp(1, 0, Mathf.InverseLerp(prefabAnimationCurve.keys[currentKeyframeIndex + 1].time, prefabAnimationCurve.keys[currentKeyframeIndex].time, curveFloat)));
                }
                else if ((keyFrameTimes.Count == 2 || (animationEndKeyframe - 1) - animationStartKeyframe == 1))
                {
                    animateBackwards     = true;
                    currentAnimationTime = currentKeyframeAnimationTime;
                }
                if (animateBackwards && currentKeyframeIndex == animationStartKeyframe && currentAnimationTime <= 0) // if you reach the last keyframe when going backwards go forwards.
                {
                    animateBackwards        = false;
                    currentAnimationTime    = 0;
                    animationTimeRestartEnd = CalculateAnimationStartTime(animationStartKeyframe);
                    if (playOnce)
                    {
                        animationToggle = false;
                    }
                }
                if (!animateBackwards && currentKeyframeIndex < animationEndKeyframe - 1)
                {
                    lerp = Mathf.InverseLerp(prefabAnimationCurve.keys[currentKeyframeIndex].time, prefabAnimationCurve.keys[currentKeyframeIndex + 1].time, curveFloat);
                }
                else if (keyFrameTimes.Count > 2 && (animationEndKeyframe - 1) - animationStartKeyframe > 1 && animateBackwards && currentAnimationTime != currentKeyframeAnimationTime && currentKeyframeIndex != animationEndKeyframe - 1)
                {
                    lerp = (Mathf.Lerp(1, 0, Mathf.InverseLerp(prefabAnimationCurve.keys[currentKeyframeIndex + 1].time, prefabAnimationCurve.keys[currentKeyframeIndex].time, curveFloat)));
                }
                else if ((keyFrameTimes.Count == 2 || (animationEndKeyframe - 1) - animationStartKeyframe == 1) && animateBackwards && currentAnimationTime != currentKeyframeAnimationTime)
                {
                    lerp = curveFloat / currentKeyframeAnimationTime;
                }
            }

            if (materialVariables != null)
            {
                if (playerDistanceToObject <= LodFarDistance)
                {
                    for (int i = 0; i < animatedMaterialVariables.Count; i++)
                    {
                        ProceduralPropertyDescription materialVariable = animatedMaterialVariables[i];
                        ProceduralPropertyType        propType         = animatedMaterialVariables[i].type;
                        switch (propType)
                        {
                        case ProceduralPropertyType.Float:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1 && (materialVariable.name[0] != '$' || (materialVariable.name[0] == '$' && animateOutputParameters)))
                            {
                                substance.SetProceduralFloat(materialVariable.name, Mathf.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyFloatDictionary[materialVariable.name], MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].PropertyFloatDictionary[materialVariable.name], lerp * flickerFloatCalc));
                            }
                        }
                        break;

                        case ProceduralPropertyType.Color3:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1)
                            {
                                substance.SetProceduralColor(materialVariable.name, Color.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyColorDictionary[materialVariable.name], MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].PropertyColorDictionary[materialVariable.name], lerp * flickerColor3Calc));
                            }
                        }
                        break;

                        case ProceduralPropertyType.Color4:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1)
                            {
                                substance.SetProceduralColor(materialVariable.name, Color.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyColorDictionary[materialVariable.name], MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].PropertyColorDictionary[materialVariable.name], lerp * flickerColor4Calc));
                            }
                        }
                        break;

                        case ProceduralPropertyType.Vector4:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1)
                            {
                                substance.SetProceduralVector(materialVariable.name, Vector4.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyVector4Dictionary[materialVariable.name], MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].PropertyVector4Dictionary[materialVariable.name], lerp * flickerVector4Calc));
                            }
                        }
                        break;

                        case ProceduralPropertyType.Vector3:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1)
                            {
                                substance.SetProceduralVector(materialVariable.name, Vector3.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyVector3Dictionary[materialVariable.name], MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].PropertyVector3Dictionary[materialVariable.name], lerp * flickerVector3Calc));
                            }
                        }
                        break;

                        case ProceduralPropertyType.Vector2:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1 && (materialVariable.name[0] != '$' || (materialVariable.name[0] == '$' && animateOutputParameters)))
                            {
                                substance.SetProceduralVector(materialVariable.name, Vector2.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyVector2Dictionary[materialVariable.name], MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].PropertyVector2Dictionary[materialVariable.name], lerp * flickerVector2Calc));
                            }
                        }
                        break;

                        case ProceduralPropertyType.Enum:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1 && (currentAnimationTime == 0 || currentAnimationTime == currentKeyframeAnimationTime))
                            {
                                substance.SetProceduralEnum(materialVariable.name, MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyEnumDictionary[materialVariable.name]);
                            }
                        }
                        break;

                        case ProceduralPropertyType.Boolean:
                        {
                            if (currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1 && (currentAnimationTime == 0 || currentAnimationTime == currentKeyframeAnimationTime))
                            {
                                substance.SetProceduralBoolean(materialVariable.name, MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].PropertyBoolDictionary[materialVariable.name]);
                            }
                        }
                        break;
                        }
                    }
                }
                if (rend.sharedMaterial.HasProperty("_EmissionColor") && currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1)
                {
                    rend.sharedMaterial.SetColor("_EmissionColor", Color.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].emissionColor, MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].emissionColor, lerp * flickerEmissionCalc));
                }
                if (rend.sharedMaterial.HasProperty("_MainTex") && currentKeyframeIndex + 1 <= MaterialVariableKeyframeDictionaryList.Count - 1)
                {
                    rend.sharedMaterial.SetTextureOffset("_MainTex", Vector2.Lerp(MaterialVariableKeyframeDictionaryList[currentKeyframeIndex].MainTex, MaterialVariableKeyframeDictionaryList[currentKeyframeIndex + 1].MainTex, lerp * flickerCalc));
                }

                if (playerDistanceToObject <= LodNearDistance)
                {
                    substance.SetProceduralVector("$outputsize", originalOutputSize);
                }
                else if (playerDistanceToObject >= LodNearDistance && playerDistanceToObject <= LodMidDistance)
                {
                    substance.SetProceduralVector("$outputsize", new Vector2(originalOutputSize.x - 1, originalOutputSize.y - 1));
                }
                else if (playerDistanceToObject >= LodMidDistance && playerDistanceToObject <= LodFarDistance)
                {
                    substance.SetProceduralVector("$outputsize", new Vector2(originalOutputSize.x - 2, originalOutputSize.y - 2));
                }
                if (!rebuildSubstanceImmediately && (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.None || animateObjectBasedOnPosition != AnimateObjectBasedOnPosition.None && rend.isVisible))
                {
                    substance.RebuildTextures();
                }
                else if (rebuildSubstanceImmediately && (animateObjectBasedOnPosition == AnimateObjectBasedOnPosition.None || animateObjectBasedOnPosition != AnimateObjectBasedOnPosition.None && rend.isVisible))
                {
                    substance.RebuildTexturesImmediately();
                }
            }
        }
    }
예제 #24
0
 public static void AddProceduralVariablesToDictionaryFromList(MaterialVariableDictionaryHolder dictionary, MaterialVariableListHolder list, ProceduralPropertyDescription[] materialVariables, bool saveOutputParameters) // sorts items from a list into a dictionary
 {
     if (materialVariables != null)
     {
         for (int i = 0; i < materialVariables.Length; i++)
         {
             ProceduralPropertyDescription materialVariable = materialVariables[i];
             ProceduralPropertyType        propType         = materialVariables[i].type;
             if (propType == ProceduralPropertyType.Float && (materialVariable.hasRange || (saveOutputParameters && !materialVariable.hasRange)))
             {
                 if (!dictionary.PropertyFloatDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, list.myFloatValues[list.myFloatKeys.IndexOf(materialVariable.name)]);
                     dictionary.PropertyFloatDictionary.Add(materialVariable.name, list.myFloatValues[list.myFloatKeys.IndexOf(materialVariable.name)]);
                 }
                 else // if it already contains the key overwrite it
                 {
                     dictionary.PropertyFloatDictionary[materialVariable.name] = list.myFloatValues[list.myFloatKeys.IndexOf(materialVariable.name)];
                 }
             }
             if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
             {
                 Color propColor = list.myColorValues[list.myColorKeys.IndexOf(materialVariable.name)];
                 if (!dictionary.PropertyColorDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, propColor);
                     dictionary.PropertyColorDictionary.Add(materialVariable.name, propColor);
                 }
                 else
                 {
                     dictionary.PropertyColorDictionary[materialVariable.name] = propColor;
                 }
             }
             if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) && (materialVariable.hasRange || (saveOutputParameters && !materialVariable.hasRange)))
             {
                 if (propType == ProceduralPropertyType.Vector4)
                 {
                     Vector4 propVector4 = list.myVector4Values[list.myVector4Keys.IndexOf(materialVariable.name)];
                     if (!dictionary.PropertyVector4Dictionary.ContainsKey(materialVariable.name))
                     {
                         dictionary.PropertyDictionary.Add(materialVariable.name, propVector4);
                         dictionary.PropertyVector4Dictionary.Add(materialVariable.name, propVector4);
                     }
                     else
                     {
                         dictionary.PropertyVector4Dictionary[materialVariable.name] = propVector4;
                     }
                 }
                 else if (propType == ProceduralPropertyType.Vector3)
                 {
                     Vector3 propVector3 = list.myVector3Values[list.myVector3Keys.IndexOf(materialVariable.name)];
                     if (!dictionary.PropertyVector3Dictionary.ContainsKey(materialVariable.name))
                     {
                         dictionary.PropertyDictionary.Add(materialVariable.name, propVector3);
                         dictionary.PropertyVector3Dictionary.Add(materialVariable.name, propVector3);
                     }
                     else
                     {
                         dictionary.PropertyVector3Dictionary[materialVariable.name] = propVector3;
                     }
                 }
                 else if (propType == ProceduralPropertyType.Vector2)
                 {
                     Vector2 propVector2 = list.myVector2Values[list.myVector2Keys.IndexOf(materialVariable.name)];
                     if (!dictionary.PropertyVector2Dictionary.ContainsKey(materialVariable.name))
                     {
                         dictionary.PropertyDictionary.Add(materialVariable.name, propVector2);
                         dictionary.PropertyVector2Dictionary.Add(materialVariable.name, propVector2);
                     }
                     else
                     {
                         dictionary.PropertyVector2Dictionary[materialVariable.name] = propVector2;
                     }
                 }
             }
             if (propType == ProceduralPropertyType.Enum)
             {
                 int propEnum = list.myEnumValues[list.myEnumKeys.IndexOf(materialVariable.name)];
                 if (!dictionary.PropertyEnumDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, propEnum);
                     dictionary.PropertyEnumDictionary.Add(materialVariable.name, propEnum);
                 }
                 else
                 {
                     dictionary.PropertyEnumDictionary[materialVariable.name] = propEnum;
                 }
             }
             if (propType == ProceduralPropertyType.Boolean)
             {
                 bool propBool = list.myBooleanValues[list.myBooleanKeys.IndexOf(materialVariable.name)];
                 if (!dictionary.PropertyBoolDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, propBool);
                     dictionary.PropertyBoolDictionary.Add(materialVariable.name, propBool);
                 }
                 else
                 {
                     dictionary.PropertyBoolDictionary[materialVariable.name] = propBool;
                 }
             }
         }
         dictionary.MainTex       = list.MainTex;
         dictionary.emissionColor = list.emissionColor;
     }
 }
예제 #25
0
    public void ConvertAnimatedListToDictionaryandSet()
    {
        if (gameObject.GetComponent <PrefabProperties>().enabled)
        {
            rend = GetComponent <Renderer>();
#if UNITY_EDITOR
            if (UnityEditor.Selection.activeGameObject != null && UnityEditor.Selection.activeGameObject.GetComponent <SubstanceTool>() != null)
            {
                useSharedMaterial = true;
            }
            if (UnityEditor.PrefabUtility.GetPrefabType(this) == UnityEditor.PrefabType.Prefab)
            {
                Debug.Log("object is in project view");
                return;
            }
#endif
            if (useSharedMaterial && this.GetComponent <Renderer>() != null)
            {
                substance = rend.sharedMaterial as ProceduralMaterial;
            }
            else if (!useSharedMaterial && this.GetComponent <Renderer>() != null)
            {
                substance = rend.material as ProceduralMaterial;
            }
            else
            {
                Debug.LogWarning("No Renderer on " + this.name);
            }
            if (useSharedMaterial)
            {
                emissionInput = rend.sharedMaterial.GetColor("_EmissionColor");
            }
            else
            {
                emissionInput = rend.material.GetColor("_EmissionColor");
            }
            if (substance)
            {
                substance.cacheSize = (ProceduralCacheSize)myProceduralCacheSize;
                ProceduralMaterial.substanceProcessorUsage = (ProceduralProcessorUsage)mySubstanceProcessorUsage;
                substance.enableInstancing = true;
                materialVariables          = substance.GetProceduralPropertyDescriptions();
                if (MaterialVariableKeyframeList.Count > 0)
                {
                    for (int i = 0; i <= MaterialVariableKeyframeList.Count - 1; i++)
                    {
                        int index;
                        MaterialVariableKeyframeDictionaryList.Add(new MaterialVariableDictionaryHolder());
                        MaterialVariableKeyframeDictionaryList[i].PropertyMaterialName = MaterialVariableKeyframeList[0].PropertyMaterialName;
                        for (int j = 0; j < materialVariables.Length; j++)
                        {
                            ProceduralPropertyDescription materialVariable = materialVariables[j];
                            ProceduralPropertyType        propType         = materialVariables[j].type;

                            if (i == 0 && animatedParameterNames.Contains(materialVariable.name))
                            {
                                substance.CacheProceduralProperty(materialVariable.name, true);
                            }
                            if (propType == ProceduralPropertyType.Float)
                            {
                                if (MaterialVariableKeyframeList[i].myFloatKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myFloatKeys.IndexOf(materialVariable.name);
                                        float curFloat = MaterialVariableKeyframeList[i].myFloatValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curFloat);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyFloatDictionary.Add(materialVariable.name, curFloat);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralFloat(materialVariable.name, MaterialVariableKeyframeList[0].myFloatValues[MaterialVariableKeyframeList[0].myFloatKeys.IndexOf(materialVariable.name)]);
                                    }
                                }
                            }
                            else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
                            {
                                if (MaterialVariableKeyframeList[i].myColorKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myColorKeys.IndexOf(materialVariable.name);
                                        Color curColor = MaterialVariableKeyframeList[i].myColorValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curColor);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyColorDictionary.Add(materialVariable.name, curColor);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralColor(materialVariable.name, MaterialVariableKeyframeList[0].myColorValues[MaterialVariableKeyframeList[0].myColorKeys.IndexOf(materialVariable.name)]);
                                    }
                                }
                            }
                            else if (propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4)
                            {
                                if (propType == ProceduralPropertyType.Vector4)
                                {
                                    if (MaterialVariableKeyframeList[i].myVector4Keys.Contains(materialVariable.name))
                                    {
                                        if (animatedParameterNames.Contains(materialVariable.name))
                                        {
                                            index = MaterialVariableKeyframeList[i].myVector4Keys.IndexOf(materialVariable.name);
                                            Vector4 curVector4 = MaterialVariableKeyframeList[i].myVector4Values[index];
                                            MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector4);
                                            MaterialVariableKeyframeDictionaryList[i].PropertyVector4Dictionary.Add(materialVariable.name, curVector4);
                                            if (i == 0)
                                            {
                                                animatedMaterialVariables.Add(materialVariable);
                                            }
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector4Values[MaterialVariableKeyframeList[0].myVector4Keys.IndexOf(materialVariable.name)]);
                                    }
                                }
                                else if (propType == ProceduralPropertyType.Vector3)
                                {
                                    if (MaterialVariableKeyframeList[i].myVector3Keys.Contains(materialVariable.name))
                                    {
                                        if (animatedParameterNames.Contains(materialVariable.name))
                                        {
                                            index = MaterialVariableKeyframeList[i].myVector3Keys.IndexOf(materialVariable.name);
                                            Vector3 curVector3 = MaterialVariableKeyframeList[i].myVector3Values[index];
                                            MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector3);
                                            MaterialVariableKeyframeDictionaryList[i].PropertyVector3Dictionary.Add(materialVariable.name, curVector3);
                                            if (i == 0)
                                            {
                                                animatedMaterialVariables.Add(materialVariable);
                                            }
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector3Values[MaterialVariableKeyframeList[0].myVector3Keys.IndexOf(materialVariable.name)]);
                                    }
                                }
                                else if (propType == ProceduralPropertyType.Vector2)
                                {
                                    if (MaterialVariableKeyframeList[i].myVector2Keys.Contains(materialVariable.name))
                                    {
                                        if (animatedParameterNames.Contains(materialVariable.name))
                                        {
                                            index = MaterialVariableKeyframeList[i].myVector2Keys.IndexOf(materialVariable.name);
                                            Vector2 curVector2 = MaterialVariableKeyframeList[i].myVector2Values[index];
                                            MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector2);
                                            MaterialVariableKeyframeDictionaryList[i].PropertyVector2Dictionary.Add(materialVariable.name, curVector2);
                                            if (i == 0)
                                            {
                                                animatedMaterialVariables.Add(materialVariable);
                                            }
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector2Values[MaterialVariableKeyframeList[0].myVector2Keys.IndexOf(materialVariable.name)]);
                                    }
                                }
                            }
                            else if (propType == ProceduralPropertyType.Enum)
                            {
                                if (MaterialVariableKeyframeList[i].myEnumKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myEnumKeys.IndexOf(materialVariable.name);
                                        int curEnum = MaterialVariableKeyframeList[i].myEnumValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curEnum);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyEnumDictionary.Add(materialVariable.name, curEnum);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                }
                                if (i == 0)
                                {
                                    substance.SetProceduralEnum(materialVariable.name, MaterialVariableKeyframeList[0].myEnumValues[MaterialVariableKeyframeList[0].myEnumKeys.IndexOf(materialVariable.name)]);
                                }
                            }
                            else if (propType == ProceduralPropertyType.Boolean)
                            {
                                if (MaterialVariableKeyframeList[i].myBooleanKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myBooleanKeys.IndexOf(materialVariable.name);
                                        bool curBool = MaterialVariableKeyframeList[i].myBooleanValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curBool);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyBoolDictionary.Add(materialVariable.name, curBool);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                }
                                if (i == 0)
                                {
                                    substance.SetProceduralBoolean(materialVariable.name, MaterialVariableKeyframeList[0].myBooleanValues[MaterialVariableKeyframeList[0].myBooleanKeys.IndexOf(materialVariable.name)]);
                                }
                            }
                        }
                        MaterialVariableKeyframeDictionaryList[i].MainTex       = MaterialVariableKeyframeList[i].MainTex;
                        MaterialVariableKeyframeDictionaryList[i].emissionColor = MaterialVariableKeyframeList[i].emissionColor;
                    }
                }
            }
            if (deleteOldListValuesOnStart)
            {
                MaterialVariableKeyframeList.Clear();
            }
        }
    }
예제 #26
0
 public static void AddProceduralVariablesToDictionary(MaterialVariableDictionaryHolder materialVariableDictionary, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams) // Adds current procedural values to a dictionary
 {
     for (int i = 0; i < substanceMaterialParams.materialVariables.Length; i++)
     {
         ProceduralPropertyDescription materialVariable = substanceMaterialParams.materialVariables[i];
         ProceduralPropertyType        propType         = substanceMaterialParams.materialVariables[i].type;
         if (propType != ProceduralPropertyType.Texture)
         {
             materialVariableDictionary.PropertyName.Add(materialVariable.name);
         }
         if (propType == ProceduralPropertyType.Float && (materialVariable.hasRange || (substanceMaterialParams.saveOutputParameters && !materialVariable.hasRange)))
         {
             float propFloat = substanceMaterialParams.substance.GetProceduralFloat(materialVariable.name);
             materialVariableDictionary.PropertyDictionary.Add(materialVariable.name, propFloat);
             materialVariableDictionary.PropertyFloatDictionary.Add(materialVariable.name, propFloat);
         }
         else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
         {
             Color propColor = substanceMaterialParams.substance.GetProceduralColor(materialVariable.name);
             materialVariableDictionary.PropertyDictionary.Add(materialVariable.name, propColor);
             materialVariableDictionary.PropertyColorDictionary.Add(materialVariable.name, propColor);
         }
         else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) && (materialVariable.hasRange || (substanceMaterialParams.saveOutputParameters && !materialVariable.hasRange)))
         {
             if (propType == ProceduralPropertyType.Vector4)
             {
                 Vector4 propVector4 = substanceMaterialParams.substance.GetProceduralVector(materialVariable.name);
                 materialVariableDictionary.PropertyDictionary.Add(materialVariable.name, propVector4);
                 materialVariableDictionary.PropertyVector4Dictionary.Add(materialVariable.name, propVector4);
             }
             else if (propType == ProceduralPropertyType.Vector3)
             {
                 Vector3 propVector3 = substanceMaterialParams.substance.GetProceduralVector(materialVariable.name);
                 materialVariableDictionary.PropertyDictionary.Add(materialVariable.name, propVector3);
                 materialVariableDictionary.PropertyVector3Dictionary.Add(materialVariable.name, propVector3);
             }
             else if (propType == ProceduralPropertyType.Vector2)
             {
                 Vector2 propVector2 = substanceMaterialParams.substance.GetProceduralVector(materialVariable.name);
                 materialVariableDictionary.PropertyDictionary.Add(materialVariable.name, propVector2);
                 materialVariableDictionary.PropertyVector2Dictionary.Add(materialVariable.name, propVector2);
             }
         }
         else if (propType == ProceduralPropertyType.Enum)
         {
             int propEnum = substanceMaterialParams.substance.GetProceduralEnum(materialVariable.name);
             materialVariableDictionary.PropertyDictionary.Add(materialVariable.name, propEnum);
             materialVariableDictionary.PropertyEnumDictionary.Add(materialVariable.name, propEnum);
         }
         else if (propType == ProceduralPropertyType.Boolean)
         {
             bool propBool = substanceMaterialParams.substance.GetProceduralBoolean(materialVariable.name);
             materialVariableDictionary.PropertyDictionary.Add(materialVariable.name, propBool);
             materialVariableDictionary.PropertyBoolDictionary.Add(materialVariable.name, propBool);
         }
     }
     materialVariableDictionary.PropertyMaterialName = substanceMaterialParams.substance.name;
     materialVariableDictionary.emissionColor        = substanceMaterialParams.emissionInput;
     materialVariableDictionary.MainTex = substanceMaterialParams.MainTexOffset;
     if (substanceMaterialParams.saveOutputParameters)
     {
         materialVariableDictionary.hasParametersWithoutRange = true;
     }
     else
     {
         materialVariableDictionary.hasParametersWithoutRange = false;
     }
     materialVariableDictionary.animationTime = animationParams.defaultAnimationTime;
 }
    void CheckForChangedMaterialParams(ProceduralPropertyDescription[] materialVariablesListBeforeChange)
    { // check if material variables have changed after the beforeChange was saved
        int variablesChanged = 0;

        for (int i = 0; i <= materialVariablesListBeforeChange.Count() - 1; i++)
        {
            ProceduralPropertyDescription materialVariableCurrent      = testingScript.substanceMaterialParams.materialVariables[i];
            ProceduralPropertyDescription materialVariableBeforeChange = materialVariablesListBeforeChange[i];
            ProceduralPropertyType        propType = testingScript.substanceMaterialParams.materialVariables[i].type;

            if (propType == ProceduralPropertyType.Float)
            {
                float propFloatCurrent      = testingScript.substanceMaterialParams.substance.GetProceduralFloat(materialVariableCurrent.name);
                float propFloatBeforeChange = float.Parse(materialValuesBeforeChange[materialKeysBeforeChange.IndexOf(materialVariableCurrent.name)]);
                if (propFloatCurrent != propFloatBeforeChange)
                {
                    variablesChanged++;
                }
            }
            else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
            {
                Color propColorCurrent = testingScript.substanceMaterialParams.substance.GetProceduralColor(materialVariableCurrent.name);
                Color curColor;
                ColorUtility.TryParseHtmlString(materialValuesBeforeChange[materialKeysBeforeChange.IndexOf(materialVariableCurrent.name)], out curColor);
                Color propColorBeforeChange = curColor;
                if (propColorCurrent != propColorBeforeChange)
                {
                    variablesChanged++;
                }
            }
            else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4))
            {
                if (propType == ProceduralPropertyType.Vector4)
                {
                    Vector4 propVector4Current      = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name);
                    Vector4 propVector4BeforeChange = StringToVector(materialValuesBeforeChange[materialKeysBeforeChange.IndexOf(materialVariableCurrent.name)], 4);
                    if (propVector4Current != propVector4BeforeChange)
                    {
                        variablesChanged++;
                    }
                }
                else if (propType == ProceduralPropertyType.Vector3)
                {
                    Vector3 propVector3Current      = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name);
                    Vector3 propVector3BeforeChange = StringToVector(materialValuesBeforeChange[materialKeysBeforeChange.IndexOf(materialVariableCurrent.name)], 3);
                    if (propVector3Current != propVector3BeforeChange)
                    {
                        variablesChanged++;
                    }
                }
                else if (propType == ProceduralPropertyType.Vector2)
                {
                    Vector2 propVector2Current      = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name);
                    Vector2 propVector2BeforeChange = StringToVector(materialValuesBeforeChange[materialKeysBeforeChange.IndexOf(materialVariableCurrent.name)], 2);
                    if (propVector2Current != propVector2BeforeChange)
                    {
                        variablesChanged++;
                    }
                }
            }
            else if (propType == ProceduralPropertyType.Enum)
            {
                int propEnumCurrent      = testingScript.substanceMaterialParams.substance.GetProceduralEnum(materialVariableCurrent.name);
                int propEnumBeforeChange = int.Parse(materialValuesBeforeChange[materialKeysBeforeChange.IndexOf(materialVariableCurrent.name)]);
                if (propEnumCurrent != propEnumBeforeChange)
                {
                    variablesChanged++;
                }
            }
            else if (propType == ProceduralPropertyType.Boolean)
            {
                bool propBoolCurrent      = testingScript.substanceMaterialParams.substance.GetProceduralBoolean(materialVariableCurrent.name);
                bool propBoolBeforeChange = materialBeforeChange.GetProceduralBoolean(materialVariableBeforeChange.name);
                if (propBoolCurrent != propBoolBeforeChange)
                {
                    variablesChanged++;
                }
            }
            if (variablesChanged > 0)
            {
                Assert.True(variablesChanged > 0);
                break;
            }
            if (i == materialVariablesBeforeChange.Count() - 1 && variablesChanged == 0)
            {
                Assert.Fail("Material did not change");
            }
        }
    }