Exemple #1
0
    public static void WriteDebugText(SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)
    {
        StreamWriter debugWrite;
        var          path = EditorUtility.SaveFilePanel("Save Debug Text file", "", "", "txt");

        if (path.Length != 0)
        {
            FileInfo fInfo = new FileInfo(path);
            if (!fInfo.Exists)
            {
                debugWrite = fInfo.CreateText();
            }
            else
            {
                debugWrite = fInfo.CreateText(); Debug.Log("Overwriting File");
            }
            debugWrite.WriteLine(System.DateTime.Now + " Debug:");
            for (int i = 0; i < substanceToolParams.DebugStrings.Count; i++)
            {
                if (substanceToolParams.DebugStrings.Count > 1 && i > 1 && substanceToolParams.DebugStrings[i] != substanceToolParams.DebugStrings[i - 1])
                {
                    debugWrite.WriteLine(substanceToolParams.DebugStrings[i]);
                }
            }
            debugWrite.WriteLine("---Variables at current frame:---");
            debugWrite.WriteLine("Lerp: " + animationParams.lerp.ToString());
            debugWrite.WriteLine("Current Animation Time: " + animationParams.currentAnimationTime.ToString());
            debugWrite.WriteLine("Curve key count: " + animationParams.substanceCurve.keys.Length.ToString());
            debugWrite.WriteLine("Curve Float value: " + animationParams.curveFloat.ToString());
            debugWrite.WriteLine("Current Keyframe Animation Time: " + animationParams.currentKeyframeAnimationTime.ToString());
            debugWrite.WriteLine("Animate Backwards: " + animationParams.animateBackwards.ToString());
            debugWrite.WriteLine("Created debug log: " + path);
            debugWrite.Close();
            AssetDatabase.Refresh();
        }
        substanceToolParams.lastAction = MethodBase.GetCurrentMethod().Name.ToString();
    }
Exemple #2
0
 public static void SelectKeyframe(int index, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams) // select a keyframe by its number.
 {
     SubstanceTweenSetParameterUtility.SetProceduralVariablesFromList(substanceMaterialParams.MaterialVariableKeyframeList[index], substanceMaterialParams, animationParams, substanceToolParams);
     substanceMaterialParams.emissionInput = substanceMaterialParams.MaterialVariableKeyframeList[index].emissionColor;
     if (substanceMaterialParams.rend.sharedMaterial.HasProperty("_EmissionColor"))
     {
         substanceMaterialParams.rend.sharedMaterial.SetColor("_EmissionColor", substanceMaterialParams.MaterialVariableKeyframeList[index].emissionColor);
         substanceToolParams.selectedPrefabScript.emissionInput = substanceMaterialParams.MaterialVariableKeyframeList[index].emissionColor;
     }
     if (substanceMaterialParams.rend.sharedMaterial.HasProperty("_MainTex"))
     {
         substanceMaterialParams.MainTexOffset = substanceMaterialParams.MaterialVariableKeyframeList[index].MainTex;
         substanceMaterialParams.rend.sharedMaterial.SetTextureOffset("_MainTex", substanceMaterialParams.MaterialVariableKeyframeList[index].MainTex);
     }
 }
Exemple #3
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;
 }
Exemple #4
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;
 }
Exemple #5
0
    } //Writes all keyframes to JSON files

    public static void ReadAllJSON(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams) // Read JSON files and create keyframes from them.
    {
        string JsonReadFolderPath = EditorUtility.OpenFolderPanel("Load JSON files from folder", "", ""); //Creates 'Open Folder' Dialog

        if (JsonReadFolderPath.Length != 0)
        {
            string[] JsonReadFiles = Directory.GetFiles(JsonReadFolderPath);//array of selected xml file paths
            if (JsonReadFiles.Count() > 0)
            {
                animationParams.keyFrames = animationParams.keyFrameTimes.Count();
                foreach (string jsonReadFile in JsonReadFiles) //for each xml file path in the list.
                {
                    if (jsonReadFile.EndsWith(".json"))
                    {
                        string dataAsJson = File.ReadAllText(jsonReadFile);
                        var    stream     = new FileStream(jsonReadFile, FileMode.Open);                                                                                // defines how to use the file at the selected path
                        MaterialVariableListHolder jsonContainer = JsonUtility.FromJson <MaterialVariableListHolder>(dataAsJson);
                        SubstanceTweenSetParameterUtility.SetProceduralVariablesFromList(jsonContainer, substanceMaterialParams, animationParams, substanceToolParams); //Sets current substance values from list
                        substanceMaterialParams.MainTexOffset = jsonContainer.MainTex;
                        Color jsonEmissionColor = new Color(0, 0, 0, 0);
                        jsonEmissionColor = jsonContainer.emissionColor;
                        if (substanceMaterialParams.rend.sharedMaterial.HasProperty("_EmissionColor"))
                        {
                            substanceMaterialParams.emissionInput = jsonEmissionColor;
                            if (substanceToolParams.selectedPrefabScript)
                            {
                                substanceToolParams.selectedPrefabScript.emissionInput = substanceMaterialParams.emissionInput;
                            }
                            substanceMaterialParams.rend.sharedMaterial.SetColor("_EmissionColor", jsonEmissionColor);
                        }
                        stream.Close();                               //Close Xml reader
                        substanceMaterialParams.substance.RebuildTexturesImmediately();
                        if (animationParams.keyFrameTimes.Count == 0) // Create keyframe from list containing XML variables
                        {
                            if (animationParams.substanceCurve.keys.Count() > 0)
                            {
                                animationParams.substanceCurve.RemoveKey(0);
                                animationParams.substanceCurve.AddKey(0, 0);
                            }
                            substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Add(new MaterialVariableDictionaryHolder());
                            substanceMaterialParams.MaterialVariableKeyframeList.Add(new MaterialVariableListHolder());
                            substanceMaterialParams.MaterialVariableKeyframeList[0] = jsonContainer;
                            animationParams.keyFrames++;
                            animationParams.keyFrameTimes.Add(substanceMaterialParams.MaterialVariableKeyframeList[0].animationTime);
                            AnimationUtility.SetKeyBroken(animationParams.substanceCurve, 0, true);
                            AnimationUtility.SetKeyLeftTangentMode(animationParams.substanceCurve, 0, AnimationUtility.TangentMode.Linear);
                            AnimationUtility.SetKeyRightTangentMode(animationParams.substanceCurve, 0, AnimationUtility.TangentMode.Linear);
                        }
                        else if (animationParams.keyFrameTimes.Count > 0)
                        {
                            substanceMaterialParams.MaterialVariableKeyframeList.Add(new MaterialVariableListHolder());
                            substanceMaterialParams.MaterialVariableKeyframeList[animationParams.keyFrames] = jsonContainer;
                            substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Add(new MaterialVariableDictionaryHolder());
                            substanceMaterialParams.MaterialVariableKeyframeDictionaryList[animationParams.keyFrames] = new MaterialVariableDictionaryHolder();
                            animationParams.keyFrameTimes.Add(jsonContainer.animationTime);
                            animationParams.keyframeSum = 0;
                            for (int i = 0; i < substanceMaterialParams.MaterialVariableKeyframeList.Count() - 1; i++)  //  -1 to count here 6/10/17
                            {
                                animationParams.keyframeSum += substanceMaterialParams.MaterialVariableKeyframeList[i].animationTime;
                            }
                            if (jsonContainer.AnimationCurveKeyframeList.Count() >= 1)
                            {
                                animationParams.substanceCurve.AddKey(new Keyframe(animationParams.keyframeSum, animationParams.keyframeSum, jsonContainer.AnimationCurveKeyframeList[0].inTangent, jsonContainer.AnimationCurveKeyframeList[0].outTangent));
                            }
                            else
                            {
                                animationParams.substanceCurve.AddKey(new Keyframe(animationParams.keyframeSum, animationParams.keyframeSum));
                            }
                            if (animationParams.keyFrames >= 1)
                            {
                                AnimationUtility.SetKeyBroken(animationParams.substanceCurve, animationParams.keyFrames, true);
                            }
                            animationParams.keyFrames++;
                        }
                    }
                    substanceToolParams.DebugStrings.Add("Read keyframe from: " + jsonReadFile);
                }
                substanceToolParams.DebugStrings.Add(animationParams.keyFrames - 1 + " Keyframes created from XML files ");
                animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
                substanceToolParams.lastAction            = MethodBase.GetCurrentMethod().Name.ToString();
            }
            else
            {
                EditorUtility.DisplayDialog("Empty Folder", "No Files were found in the selected folder", "Ok");
            }
            SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
            SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
        }
    }
Exemple #6
0
 public static void SelectAndOverWriteAllKeyframes(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)
 {
     animationParams.keyframeSum = 0;
     for (int i = 0; i <= substanceMaterialParams.MaterialVariableKeyframeList.Count() - 1; i++)
     {
         SubstanceTweenKeyframeUtility.SelectKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
         SubstanceTweenKeyframeUtility.OverWriteKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
         animationParams.keyframeSum += animationParams.keyFrameTimes[i];
     }
     SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
 }
Exemple #7
0
    public static void CheckForRemoveOrEditFromCurveEditor(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstanceFlickerParams flickerValues)
    {
        bool         inEditKeysMode                     = false;
        int          keyframesModifiedSoFar             = 0;                                                                                               //number of keyframes deleted edited so far
        int          curvePointsCountDifference         = animationParams.substanceCurveBackup.keys.Count() - animationParams.substanceCurve.keys.Count(); // difference between number of points before the change compared to the number of points after the change
        List <float> BackupKeyframePointTimes           = new List <float>();                                                                              // points on curve before change
        List <float> CurrentKeyframePointTimes          = new List <float>();                                                                              // points on curve after change
        Keyframe     firstEditedKeyframeBeforeEdit      = new Keyframe(-1, -1);                                                                            //the first keyframe in the list that has been edited ore deleted
        int          firstEditedKeyframeIndexBeforeEdit = -1;                                                                                              // index of the first edited keyframe

        if (animationParams.substanceCurve.keys[0].time != 0)
        {
            animationParams.substanceCurve.keys[0].time = 0;
        }
        for (int i = 0; i <= animationParams.substanceCurveBackup.keys.Count() - 1; i++)
        {
            BackupKeyframePointTimes.Add(animationParams.substanceCurveBackup.keys[i].time);
        }
        for (int i = 0; i <= animationParams.substanceCurve.keys.Count() - 1; i++)
        {
            CurrentKeyframePointTimes.Add(animationParams.substanceCurve.keys[i].time);
        }

        for (int i = 0; i <= BackupKeyframePointTimes.Count() - 2; i++)
        {
            if (!CurrentKeyframePointTimes.Contains(BackupKeyframePointTimes[i]))
            { // find index of the first key that has ben edited using context menu
                firstEditedKeyframeBeforeEdit = animationParams.substanceCurveBackup.keys[i];
                float tempKeyframeTime = firstEditedKeyframeBeforeEdit.time;
                firstEditedKeyframeIndexBeforeEdit = i;
                SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues);
                break;
            }
        }

        for (int i = 0; i <= CurrentKeyframePointTimes.Count() - 2; i++)
        {
            if (!BackupKeyframePointTimes.Contains(CurrentKeyframePointTimes[i]))
            {// if  i use the context menu to edit multiple keyframes to a value that is not already on the graph i can find that new keyframe here.
             // I can tell when i have EDITED a keyframe to a new value because when deleting keyframes, every new point's time should also exist in the backup
                inEditKeysMode = true;
                float tempKeyframeTime = firstEditedKeyframeBeforeEdit.time;
                SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues); // find/set material based on first edited keyframe
                if (firstEditedKeyframeIndexBeforeEdit != -1)                                                                                                                                    // if multiple keyframes has been edited using context menu
                {
                    SubstanceTweenKeyframeUtility.OverWriteKeyframe(firstEditedKeyframeIndexBeforeEdit, substanceMaterialParams, animationParams, substanceToolParams);                          // overwrite new keyframe with material of the first edited keyframe
                }
            }
        }

        for (int i = BackupKeyframePointTimes.Count() - 1; i > 0; i--)            // Go through every key in the backup list(Before the keys got deleted)
        {
            if (!CurrentKeyframePointTimes.Contains(BackupKeyframePointTimes[i])) // if the current list of curve points does not contain this value(it was deleted in the curve editor)
            {                                                                     //Find the index of the value and delete any information that has not already been deleted in the curve editor
               // get the index of the deleted point and delete the Dictionary/List associated with that index
                keyframesModifiedSoFar++;
                animationParams.keyFrameTimes.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                substanceMaterialParams.MaterialVariableKeyframeList.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                substanceMaterialParams.MaterialVariableKeyframeDictionaryList.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                if (animationParams.keyFrames > 0)
                {
                    animationParams.keyFrames--;
                }
            }
            if (inEditKeysMode && i == 1 && keyframesModifiedSoFar > 0)
            { // if i edited multiple keyframes at the same time using the context menu I insert a keyframe when i reach the end of the for loop
                SubstanceTweenKeyframeUtility.InsertKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
            }
        }
        for (int i = 0; i <= animationParams.substanceCurve.keys.Count() - 2; i++)
        {                                                                                                                                     // rebuild/refresh animation times
            animationParams.keyFrameTimes[i] = animationParams.substanceCurve.keys[i + 1].time - animationParams.substanceCurve.keys[i].time; // this keyframe time = (next keyframe time - This keyframe time)
            substanceMaterialParams.MaterialVariableKeyframeList[i].animationTime = animationParams.substanceCurve.keys[i + 1].time - animationParams.substanceCurve.keys[i].time;
        }

        if (curvePointsCountDifference != keyframesModifiedSoFar)
        { // Because curvePoint EditDifference != keyframes Edited/changed, I know that keyframes have been changed with 'Edit Keys..' and not 'Delete'
          // when editing multipule keyframes to a new singular time that is not already on the list,
          // there should always be more edited keyframes then the difference between current curve points and backup curve points.
            if (animationParams.substanceCurve.keys[animationParams.substanceCurve.keys.Count() - 1].time > animationParams.substanceCurveBackup.keys[animationParams.substanceCurveBackup.keys.Count() - 1].time)
            {// Edited multiple keyframes to a new time that is more than the length of the backup curve
                SubstanceTweenKeyframeUtility.CreateKeyframe(substanceMaterialParams, animationParams, substanceToolParams);
            }
        }
        animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
        SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
        inEditKeysMode = false;
    }
Exemple #8
0
 public static void DeleteAllKeyframes(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams)
 {
     if (UnityEditor.EditorUtility.DisplayDialog("DELETE ALL keyframes?",
                                                 "Are you sure you want to DELETE ALL keyframes?", "YES", "NO"))
     {
         animationParams.substanceLerp = false;
         substanceMaterialParams.MaterialVariableKeyframeList.Clear();
         substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Clear();
         animationParams.keyFrameTimes.Clear();
         animationParams.keyFrames                 = 0;
         animationParams.substanceCurve.keys       = null;
         animationParams.substanceCurveBackup.keys = null;
         animationParams.currentAnimationTime      = 0;
         animationParams.currentKeyframeIndex      = 0;
         animationParams.animationTimeRestartEnd   = 0;
         animationParams.keyframeSum               = 0;
     }
 }
    void ReWriteAllKeyframeTimes(float desiredTime, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams)
    {
        List <Keyframe> tmpKeyframeList = animationParams.substanceCurve.keys.ToList();

        animationParams.keyframeSum = 0;
        for (int j = substanceMaterialParams.MaterialVariableKeyframeList.Count() - 1; j > 0; j--)// remove all keys
        {
            animationParams.substanceCurve.RemoveKey(j);
        }
        for (int j = 0; j < substanceMaterialParams.MaterialVariableKeyframeList.Count(); j++)//rewrite keys with changed times
        {
            if (j == 0)
            {
                animationParams.substanceCurve.AddKey(new Keyframe(animationParams.keyframeSum, animationParams.keyframeSum, 0.25f, tmpKeyframeList[j].outTangent));
            }
            else
            {
                animationParams.substanceCurve.AddKey(new Keyframe(animationParams.keyframeSum, animationParams.keyframeSum, tmpKeyframeList[j].inTangent, tmpKeyframeList[j].outTangent));
            }
            for (int k = 0; k < animationParams.keyFrameTimes.Count() - 1; k++)
            {
                animationParams.keyFrameTimes[k] = desiredTime;
                substanceMaterialParams.MaterialVariableKeyframeList[k].animationTime = desiredTime;
            }
            animationParams.keyframeSum += desiredTime;
        }

        /*for (int k = 0; k < animationParams.keyFrameTimes.Count() - 1; k++)
         * {
         *  animationParams.keyFrameTimes[k] = desiredTime;
         *  substanceMaterialParams.MaterialVariableKeyframeList[k].animationTime = desiredTime;
         * }
         * animationParams.keyframeSum += desiredTime;*/
    }
Exemple #10
0
 public static void CalculateAnimationLength(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams)
 {
     if (substanceMaterialParams.MaterialVariableKeyframeList.Count() >= 2)
     {
         animationParams.totalAnimationLength = 0;
         for (int i = 0; i < substanceMaterialParams.MaterialVariableKeyframeList.Count() - 1; i++)
         {
             animationParams.totalAnimationLength += animationParams.keyFrameTimes[i];
         }
     }
 }
Exemple #11
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);
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #12
0
 public static void ToggleAnimation(List <MaterialVariableDictionaryHolder> keyframeDictList, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams) //Pause-Play animation
 {
     if (keyframeDictList.Count >= 2 && keyframeDictList[0].PropertyMaterialName == substanceMaterialParams.substance.name)                                                                                                       // if you have 2 transitions and the name of the selected substance matches the name on keyframe 1
     {
         if (animationParams.substanceLerp)                                                                                                                                                                                       // pause the animation, Set all values not to cache and clear the list of animated variables, it will be rebuilt when playing the animation
         {
             substanceMaterialParams.MainTexOffset = substanceMaterialParams.MaterialVariableKeyframeDictionaryList[animationParams.currentKeyframeIndex].MainTex;
             animationParams.substanceLerp         = false;
         }
         else if (!animationParams.substanceLerp)//Play animation, find any variables that change(animated) and set them to cache then add them to a list.
         {
             SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
             animationParams.substanceLerp = true;
         }
     }
     else if (keyframeDictList.Count >= 2)
     { // If material names are different
         substanceToolParams.DebugStrings.Add("Tried to animate object: " + substanceToolParams.currentSelection + " but the Transition Material name " + keyframeDictList[0].PropertyMaterialName + " did not match the current Procedural Material name: " + substanceMaterialParams.substance.name);
         var renameMaterialOption = UnityEditor.EditorUtility.DisplayDialog(
             "error",
             "Transition Material name " + keyframeDictList[0].PropertyMaterialName + " does not match current Procedural Material name: " + substanceMaterialParams.substance.name + ". Would you like to rename " + keyframeDictList[0].PropertyMaterialName + " to " + substanceMaterialParams.substance.name + "?"
             + " (Only do this if you are sure the materials are the same and only have different names)", "Yes", "No");
         if (renameMaterialOption)
         {
             substanceToolParams.DebugStrings.Add("Renamed Material: " + keyframeDictList[0].PropertyMaterialName + " To: " + substanceMaterialParams.substance.name);
             keyframeDictList[0].PropertyMaterialName = substanceMaterialParams.substance.name; // Saves Substance name in keyframe as current substance name
             for (int i = 0; i <= keyframeDictList.Count - 1; i++)
             {
                 keyframeDictList[i].PropertyMaterialName = substanceMaterialParams.substance.name;
             }
             animationParams.substanceLerp = true;
         }
         else
         {
             substanceToolParams.DebugStrings.Add("Did not rename or take any other action.");
         }
     }
     else
     {
         UnityEditor.EditorUtility.DisplayDialog("error", "You do not have two keyframes", "OK");
     }
 }
Exemple #13
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;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #14
0
    public static void SavePrefab(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstancePerformanceParams substancePerformanceParams, SubstanceFlickerParams flickerValues) // Saves a Prefab to a specified folder
    {
        string prefabPath = EditorUtility.SaveFilePanelInProject("", "", "prefab", "");

        if (prefabPath.Length != 0)
        {
            GameObject prefab = PrefabUtility.CreatePrefab(prefabPath, substanceToolParams.currentSelection.gameObject, ReplacePrefabOptions.Default);
            if (prefab.GetComponent <PrefabProperties>() != null)
            {
                UnityEngine.Object.DestroyImmediate(prefab.GetComponent <PrefabProperties>(), true);
            }
            prefab.AddComponent <PrefabProperties>(); // adds prefab script to prefab
            PrefabProperties prefabProperties = prefab.GetComponent <PrefabProperties>();
            prefabProperties.substance = substanceMaterialParams.substance;
            Renderer prefabRend = prefab.GetComponent <Renderer>();
            prefabRend.material = substanceMaterialParams.substance;
            if (animationParams.animationType == SubstanceAnimationParams.AnimationType.Loop)
            {
                prefabProperties.animationType = PrefabProperties.AnimationType.Loop;
            }
            if (animationParams.animationType == SubstanceAnimationParams.AnimationType.BackAndForth)
            {
                prefabProperties.animationType = PrefabProperties.AnimationType.BackAndForth;
            }
            substanceToolParams.DebugStrings.Add("Created prefab: " + prefab.name);
            if (prefabRend.sharedMaterial)
            {
                substanceToolParams.DebugStrings.Add("Prefab material: " + prefabRend.sharedMaterial.name);
            }
            if (substanceMaterialParams.MaterialVariableKeyframeList.Count >= 1)
            {//writes keyfame lists to prefab(Could not serialize dictionaries)
                for (int i = 0; i <= substanceMaterialParams.MaterialVariableKeyframeList.Count - 1; i++)
                {
                    if (prefabProperties.keyFrameTimes.Count == 0)
                    {
                        prefabProperties.MaterialVariableKeyframeList.Add(new MaterialVariableListHolder());
                        prefabProperties.MaterialVariableKeyframeList[0] = substanceMaterialParams.MaterialVariableKeyframeList[0];
                        prefabProperties.MaterialVariableKeyframeList[0].PropertyMaterialName = substanceMaterialParams.substance.name;
                        prefabProperties.MaterialVariableKeyframeList[0].emissionColor        = substanceMaterialParams.MaterialVariableKeyframeList[0].emissionColor;
                        prefabProperties.MaterialVariableKeyframeList[0].MainTex = substanceMaterialParams.MaterialVariableKeyframeList[prefabProperties.keyFrames].MainTex;
                        prefabProperties.keyFrameTimes.Add(substanceMaterialParams.MaterialVariableKeyframeList[0].animationTime);
                        prefabProperties.prefabAnimationCurve = new AnimationCurve();
                        prefabProperties.prefabAnimationCurve.AddKey(new Keyframe(animationParams.substanceCurve.keys[0].time, animationParams.substanceCurve.keys[0].value, animationParams.substanceCurve.keys[0].inTangent, animationParams.substanceCurve.keys[0].outTangent));
                        AnimationUtility.SetKeyBroken(prefabProperties.prefabAnimationCurve, 0, true);
                        if (substanceMaterialParams.MaterialVariableKeyframeList[0].hasParametersWithoutRange)
                        {
                            prefabProperties.MaterialVariableKeyframeList[0].hasParametersWithoutRange = true;
                        }
                        else
                        {
                            prefabProperties.MaterialVariableKeyframeList[0].hasParametersWithoutRange = false;
                        }
                        prefabProperties.keyFrames++;
                    }
                    else // After one keyframe is created create the rest
                    {
                        prefabProperties.MaterialVariableKeyframeList.Add(new MaterialVariableListHolder());
                        prefabProperties.MaterialVariableKeyframeList[prefabProperties.keyFrames] = substanceMaterialParams.MaterialVariableKeyframeList[prefabProperties.keyFrames];
                        prefabProperties.MaterialVariableKeyframeList[prefabProperties.keyFrames].PropertyMaterialName = substanceMaterialParams.substance.name;
                        prefabProperties.MaterialVariableKeyframeList[prefabProperties.keyFrames].emissionColor        = substanceMaterialParams.MaterialVariableKeyframeList[prefabProperties.keyFrames].emissionColor;
                        prefabProperties.MaterialVariableKeyframeList[prefabProperties.keyFrames].MainTex = substanceMaterialParams.MaterialVariableKeyframeList[prefabProperties.keyFrames].MainTex;
                        prefabProperties.keyFrameTimes.Add(substanceMaterialParams.MaterialVariableKeyframeList[prefabProperties.keyFrames].animationTime);
                        prefabProperties.prefabAnimationCurve.AddKey(new Keyframe(animationParams.substanceCurve.keys[prefabProperties.keyFrames].time, animationParams.substanceCurve.keys[prefabProperties.keyFrames].value, animationParams.substanceCurve.keys[prefabProperties.keyFrames].inTangent, animationParams.substanceCurve.keys[prefabProperties.keyFrames].outTangent));
                        if (substanceMaterialParams.saveOutputParameters)
                        {
                            prefabProperties.MaterialVariableKeyframeList[prefabProperties.keyFrames].hasParametersWithoutRange = true;
                        }
                        else
                        {
                            prefabProperties.MaterialVariableKeyframeList[prefabProperties.keyFrames].hasParametersWithoutRange = false;
                        }
                        prefabProperties.keyFrames++;
                    }
                }
                prefabProperties.keyFrameTimesOriginal      = animationParams.keyFrameTimes;
                prefabProperties.prefabAnimationCurveBackup = prefabProperties.prefabAnimationCurve;

                prefabProperties.MaterialVariableKeyframeDictionaryList = substanceMaterialParams.MaterialVariableKeyframeDictionaryList;

                SubstanceTweenAnimationUtility.DeleteNonAnimatingParametersOnPrefab(prefabProperties, substanceMaterialParams, animationParams);
                if (substanceMaterialParams.MaterialVariableKeyframeList.Count >= 2)
                {
                    prefabProperties.animateOnStart     = true;
                    prefabProperties.animateBasedOnTime = true;
                }
            }
            if (animationParams.cacheSubstance)
            {
                prefabProperties.cacheAtStartup = true;
            }
            else
            {
                prefabProperties.cacheAtStartup = false;
            }
            if (animationParams.animateOutputParameters)
            {
                prefabProperties.animateOutputParameters = true;
            }
            else
            {
                prefabProperties.animateOutputParameters = false;
            }

            if (substancePerformanceParams.myProceduralCacheSize.ToString() == ProceduralCacheSize.Heavy.ToString())
            {
                prefabProperties.myProceduralCacheSize = PrefabProperties.MyProceduralCacheSize.Heavy;
            }
            else if (substancePerformanceParams.myProceduralCacheSize.ToString() == ProceduralCacheSize.Medium.ToString())
            {
                prefabProperties.myProceduralCacheSize = PrefabProperties.MyProceduralCacheSize.Medium;
            }
            else if (substancePerformanceParams.myProceduralCacheSize.ToString() == ProceduralCacheSize.NoLimit.ToString())
            {
                prefabProperties.myProceduralCacheSize = PrefabProperties.MyProceduralCacheSize.NoLimit;
            }
            else if (substancePerformanceParams.myProceduralCacheSize.ToString() == ProceduralCacheSize.None.ToString())
            {
                prefabProperties.myProceduralCacheSize = PrefabProperties.MyProceduralCacheSize.None;
            }
            else if (substancePerformanceParams.myProceduralCacheSize.ToString() == ProceduralCacheSize.Tiny.ToString())
            {
                prefabProperties.myProceduralCacheSize = PrefabProperties.MyProceduralCacheSize.Tiny;
            }
            if (substancePerformanceParams.mySubstanceProcessorUsage.ToString() == ProceduralProcessorUsage.All.ToString())
            {
                prefabProperties.mySubstanceProcessorUsage = PrefabProperties.MySubstanceProcessorUsage.All;
            }
            else if (substancePerformanceParams.mySubstanceProcessorUsage.ToString() == ProceduralProcessorUsage.Half.ToString())
            {
                prefabProperties.mySubstanceProcessorUsage = PrefabProperties.MySubstanceProcessorUsage.Half;
            }
            else if (substancePerformanceParams.mySubstanceProcessorUsage.ToString() == ProceduralProcessorUsage.One.ToString())
            {
                prefabProperties.mySubstanceProcessorUsage = PrefabProperties.MySubstanceProcessorUsage.One;
            }
            else if (substancePerformanceParams.mySubstanceProcessorUsage.ToString() == ProceduralProcessorUsage.Unsupported.ToString())
            {
                prefabProperties.mySubstanceProcessorUsage = PrefabProperties.MySubstanceProcessorUsage.Unsupported;
            }
            if (flickerValues.flickerEnabled)
            {
                prefabProperties.flickerEnabled = true;
                if (flickerValues.flickerFloatToggle)
                {
                    prefabProperties.flickerFloatToggle = true;
                }
                if (flickerValues.flickerColor3Toggle)
                {
                    prefabProperties.flickerColor3Toggle = true;
                }
                if (flickerValues.flickerColor4Toggle)
                {
                    prefabProperties.flickerColor4Toggle = true;
                }
                if (flickerValues.flickerVector2Toggle)
                {
                    prefabProperties.flickerVector2Toggle = true;
                }
                if (flickerValues.flickerVector3Toggle)
                {
                    prefabProperties.flickerVector3Toggle = true;
                }
                if (flickerValues.flickerVector4Toggle)
                {
                    prefabProperties.flickerVector4Toggle = true;
                }
                if (flickerValues.flickerEmissionToggle)
                {
                    prefabProperties.flickerEmissionToggle = true;
                }
                prefabProperties.flickerMin = flickerValues.flickerMin;
                prefabProperties.flickerMax = flickerValues.flickerMax;
            }
#if UNITY_2017_1_OR_NEWER
            prefabRend.sharedMaterial.enableInstancing = true;// enables GPU instancing
#endif
            prefabProperties.useSharedMaterial = true;

            prefabProperties.rend = prefabRend;

            substanceToolParams.DebugStrings.Add("Prefab Path: " + prefabPath);
            substanceToolParams.DebugStrings.Add(prefab.name + " has " + prefabProperties.MaterialVariableKeyframeList.Count + " keyframes");
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            substanceToolParams.lastAction = MethodBase.GetCurrentMethod().Name.ToString();
        }
        else
        {
            Debug.LogWarning("No Path/FileName specified for Prefab");
        }
    }
Exemple #15
0
    public static void InsertKeyframe(int index, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)
    {
        if (animationParams.keyFrameTimes.Count > 0)
        {
            for (int i = 0; i <= animationParams.keyFrameTimes.Count - 1; i++)
            {     // Goes through each key frame and checks if the keyframe that you are trying to create has the same number of parameters as the rest and if they all save Output parameters or not.
                if (substanceMaterialParams.saveOutputParameters && substanceMaterialParams.MaterialVariableKeyframeList[i].hasParametersWithoutRange == false)
                { //Substance designer can export special properties like '$randomSeed' that can be saved. this checks if you selected to save those objects and turned it off later
                    UnityEditor.EditorUtility.DisplayDialog("Error", "Could not save keyframe because you are saving Parameters without a range however keyframe " + (i + 1) + " does " +
                                                            "not save these variables. To fix this uncheck \"Save Output Parameters\" on this frame and try again or check \"Save Output Parameters\" then select and overWrite on every other frame. ", "OK");
                    return;
                }
                if (!substanceMaterialParams.saveOutputParameters && substanceMaterialParams.MaterialVariableKeyframeList[i].hasParametersWithoutRange == true)
                {
                    UnityEditor.EditorUtility.DisplayDialog("Error", "Could not save keyframe because you are not saving Parameters without a range however keyframe " + i + " does " +
                                                            "save these variables. To fix this check \"Save Output Parameters\" on this frame and try again or uncheck \"Save Output Parameters\" then select and overWrite on every other frame. ", "OK");
                    return;
                }
            }
            substanceMaterialParams.MaterialVariableKeyframeList.Insert(index, new MaterialVariableListHolder());
            substanceToolParams.DebugStrings.Add("Created KeyFrame: " + substanceMaterialParams.MaterialVariableKeyframeList.Count);
            substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Insert(index, new MaterialVariableDictionaryHolder());
            SubstanceTweenStorageUtility.AddProceduralVariablesToList(substanceMaterialParams.MaterialVariableKeyframeList[index], substanceMaterialParams, animationParams, substanceToolParams);
            SubstanceTweenStorageUtility.AddProceduralVariablesToDictionary(substanceMaterialParams.MaterialVariableKeyframeDictionaryList[index], substanceMaterialParams, animationParams, substanceToolParams);
            animationParams.keyframeSum = 0;
            for (int i = 0; i < index; i++)
            {
                animationParams.keyframeSum += substanceMaterialParams.MaterialVariableKeyframeList[i].animationTime;
            }
            if (index >= 1)
            {
                substanceMaterialParams.MaterialVariableKeyframeList[index - 1].animationTime = animationParams.currentAnimationTime;
                animationParams.keyFrameTimes[index - 1] = animationParams.currentAnimationTime;
            }
            else
            {
                substanceMaterialParams.MaterialVariableKeyframeList[index - 1].animationTime = animationParams.currentAnimationTime;
                animationParams.keyFrameTimes[index - 1] = animationParams.currentAnimationTime;
            }
            substanceMaterialParams.MaterialVariableKeyframeList[index].animationTime = animationParams.keyframeSum - animationParams.animationTimeRestartEnd;
            animationParams.keyFrameTimes.Insert(index, animationParams.substanceCurve.keys[index + 1].time - animationParams.substanceCurve.keys[index].time); // note: change animation time if inserting keyframe

            animationParams.keyFrames++;
        }
        animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
        SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
        SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
    }
    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;
            }
        }
    }
Exemple #17
0
    public static void DeleteKeyframe(int index, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams)
    {
        List <Keyframe> tmpKeyframeList = animationParams.substanceCurve.keys.ToList();

        animationParams.keyFrameTimes.RemoveAt(index);
        substanceMaterialParams.MaterialVariableKeyframeList.RemoveAt(index);
        substanceMaterialParams.MaterialVariableKeyframeDictionaryList.RemoveAt(index);
        animationParams.keyframeSum = 0;
        for (int i = substanceMaterialParams.MaterialVariableKeyframeList.Count(); i >= 0; i--)
        {
            animationParams.substanceCurve.RemoveKey(i);
        }
        for (int i = 0; i <= substanceMaterialParams.MaterialVariableKeyframeList.Count() - 1; i++)
        {
            animationParams.substanceCurve.AddKey(new Keyframe(animationParams.keyframeSum, animationParams.keyframeSum, tmpKeyframeList[i].inTangent, tmpKeyframeList[i].outTangent));
            animationParams.keyframeSum += animationParams.keyFrameTimes[i];
        }
        ;
        animationParams.currentAnimationTime    = 0;
        animationParams.currentKeyframeIndex    = 0;
        animationParams.animationTimeRestartEnd = 0;
        animationParams.keyframeSum             = 0;
        if (animationParams.keyFrames > 0)
        {
            animationParams.keyFrames--;
        }
        animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
        SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
        SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
    }
 public static void ResetAllProceduralValues(SubstanceDefaultMaterialParams substanceDefaultMaterialParams, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)     // Resets all procedural values to default(When the material was first selected)
 {
     for (int i = 0; i <= substanceDefaultMaterialParams.defaultSubstanceObjProperties.Count - 1; i++)
     {
         if ((substanceMaterialParams.substance.name == substanceDefaultMaterialParams.defaultSubstanceObjProperties[i].PropertyMaterialName) || (substanceMaterialParams.rend.sharedMaterial.name == substanceDefaultMaterialParams.defaultSubstanceObjProperties[i].PropertyMaterialName))
         {
             substanceMaterialParams.resettingValuesToDefault = true;
             SubstanceTweenSetParameterUtility.SetProceduralVariablesFromList(substanceDefaultMaterialParams.defaultSubstanceObjProperties[i], substanceMaterialParams, animationParams, substanceToolParams);
             substanceMaterialParams.MainTexOffset = substanceDefaultMaterialParams.defaultSubstanceObjProperties[i].MainTex;
             if (substanceMaterialParams.rend.sharedMaterial.HasProperty("_EmissionColor"))
             {
                 substanceMaterialParams.rend.sharedMaterial.EnableKeyword("_EMISSION");
                 substanceMaterialParams.emissionInput = substanceDefaultMaterialParams.defaultSubstanceObjProperties[i].emissionColor;
                 substanceMaterialParams.rend.sharedMaterial.SetColor("_EmissionColor", substanceMaterialParams.emissionInput);;
                 substanceToolParams.selectedPrefabScript.emissionInput = substanceMaterialParams.emissionInput;
             }
             substanceMaterialParams.substance.RebuildTexturesImmediately();
             substanceMaterialParams.resettingValuesToDefault = false;
             return;
         }
     }
 }
Exemple #19
0
 public static void  CheckForAddKeyFromCurveEditor(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstanceFlickerParams flickerValues)
 {
     for (int i = 0; i <= animationParams.substanceCurveBackup.keys.Count() - 1; i++)
     {
         if (i <= animationParams.substanceCurve.keys.Count() - 1 && animationParams.substanceCurve.keys[i].time != animationParams.substanceCurveBackup.keys[i].time) // find keyframe that has just been created or deleted in the curve editor
         {
             if (animationParams.substanceCurve.keys.Count() > animationParams.substanceCurveBackup.keys.Count())
             {
                 animationParams.substanceCurve.MoveKey(i, new Keyframe(animationParams.substanceCurve.keys[i].time, animationParams.substanceCurve.keys[i].time)); // lerp does not work correctly if the keyframe value is different than the time. i cant edit the key so i delete then add a new one
                 float tempKeyframeTime = animationParams.substanceCurve.keys[i].time;
                 SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues);
                 SubstanceTweenKeyframeUtility.InsertKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
                 SubstanceTweenKeyframeUtility.SelectKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
                 animationParams.currentAnimationTime      = 0;
                 animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
                 SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
                 return;
             }
         }
     }
 }
    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);
                        }
                    }
                }
            }
        }
    }
Exemple #21
0
 public static void OverWriteKeyframe(int index, SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)// Overwrites a keyframe with the current procedural values
 {
     if (animationParams.keyFrameTimes.Count >= 1)
     {
         if (index >= 0)
         {
             substanceMaterialParams.MaterialVariableKeyframeList.Remove(substanceMaterialParams.MaterialVariableKeyframeList[index]);
             substanceMaterialParams.MaterialVariableKeyframeList.Insert(index, new MaterialVariableListHolder());
             SubstanceTweenStorageUtility.AddProceduralVariablesToList(substanceMaterialParams.MaterialVariableKeyframeList[index], substanceMaterialParams, animationParams, substanceToolParams);
             substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Remove(substanceMaterialParams.MaterialVariableKeyframeDictionaryList[index]);
             substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Insert(index, new MaterialVariableDictionaryHolder());
             SubstanceTweenStorageUtility.AddProceduralVariablesToDictionary(substanceMaterialParams.MaterialVariableKeyframeDictionaryList[index], substanceMaterialParams, animationParams, substanceToolParams);
             substanceToolParams.DebugStrings.Add("OverWrote Keyframe: " + (index + 1));
         }
     }
     animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
     SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
 }
Exemple #22
0
 public static void AddDefaultMaterial(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstanceDefaultMaterialParams substanceDefaultMaterialParams)
 {
     substanceDefaultMaterialParams.defaultSubstanceObjProperties.Add(new MaterialVariableListHolder());
     substanceDefaultMaterialParams.defaultSubstance = substanceMaterialParams.rend.sharedMaterial as ProceduralMaterial;
     substanceMaterialParams.materialVariables       = substanceMaterialParams.substance.GetProceduralPropertyDescriptions();
     substanceDefaultMaterialParams.defaultSubstanceObjProperties[animationParams.defaultSubstanceIndex].PropertyMaterialName = substanceDefaultMaterialParams.defaultSubstance.name;
     SubstanceTweenStorageUtility.AddProceduralVariablesToList(substanceDefaultMaterialParams.defaultSubstanceObjProperties[animationParams.defaultSubstanceIndex], substanceMaterialParams, animationParams, substanceToolParams);
     substanceDefaultMaterialParams.defaultSubstanceObjProperties[animationParams.defaultSubstanceIndex].MainTex       = substanceMaterialParams.MainTexOffset;
     substanceDefaultMaterialParams.defaultSubstanceObjProperties[animationParams.defaultSubstanceIndex].emissionColor = substanceMaterialParams.emissionInput;
     animationParams.defaultSubstanceIndex++;
 }
Exemple #23
0
 public static void CreateKeyframe(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)
 {
     //UnityEditor.Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { substanceMaterialParams.substance, substanceToolParams.currentSelection }, "Create Keyframe " + substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Count().ToString());
     if (animationParams.keyFrameTimes.Count == 0)
     {
         substanceToolParams.DebugStrings.Add("Created Keyframe 1:");
         substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Add(new MaterialVariableDictionaryHolder());
         substanceMaterialParams.MaterialVariableKeyframeList.Add(new MaterialVariableListHolder());
         SubstanceTweenStorageUtility.AddProceduralVariablesToList(substanceMaterialParams.MaterialVariableKeyframeList[0], substanceMaterialParams, animationParams, substanceToolParams);
         SubstanceTweenStorageUtility.AddProceduralVariablesToDictionary(substanceMaterialParams.MaterialVariableKeyframeDictionaryList[0], substanceMaterialParams, animationParams, substanceToolParams);
         animationParams.keyFrames++;
         animationParams.keyFrameTimes.Add(substanceMaterialParams.MaterialVariableKeyframeList[0].animationTime);
         animationParams.substanceCurve.AddKey(new Keyframe(substanceMaterialParams.MaterialVariableKeyframeList[0].animationTime, substanceMaterialParams.MaterialVariableKeyframeList[0].animationTime));
         UnityEditor.AnimationUtility.SetKeyLeftTangentMode(animationParams.substanceCurve, 0, UnityEditor.AnimationUtility.TangentMode.Linear);
         UnityEditor.AnimationUtility.SetKeyRightTangentMode(animationParams.substanceCurve, 0, UnityEditor.AnimationUtility.TangentMode.Linear);
     }
     else if (animationParams.keyFrameTimes.Count > 0)
     {
         for (int i = 0; i <= animationParams.keyFrameTimes.Count - 1; i++)
         {     // Goes through each key frame and checks if the keyframe that you are trying to create has the same number of parameters as the rest and if they all save Output parameters or not.
             if (substanceMaterialParams.saveOutputParameters && substanceMaterialParams.MaterialVariableKeyframeList[i].hasParametersWithoutRange == false)
             { //Subsance designer can export special properties like '$randomSeed' that can be saved. this checks if you selected to save those objects and turned it off later
                 UnityEditor.EditorUtility.DisplayDialog("Error", "Could not save keyframe because you are saving Parameters without a range however keyframe " + (i + 1) + " does " +
                                                         "not save these variables. To fix this uncheck \"Save Output Parameters\" on this frame and try again or check \"Save Output Parameters\" then select and overWrite on every other frame. ", "OK");
                 return;
             }
             if (!substanceMaterialParams.saveOutputParameters && substanceMaterialParams.MaterialVariableKeyframeList[i].hasParametersWithoutRange == true)
             {
                 UnityEditor.EditorUtility.DisplayDialog("Error", "Could not save keyframe because you are not saving Parameters without a range however keyframe " + i + " does " +
                                                         "save these variables. To fix this check \"Save Output Parameters\" on this frame and try again or uncheck \"Save Output Parameters\" then select and overWrite on every other frame. ", "OK");
                 return;
             }
         }
         substanceMaterialParams.MaterialVariableKeyframeList.Add(new MaterialVariableListHolder());
         substanceToolParams.DebugStrings.Add("Created KeyFrame: " + substanceMaterialParams.MaterialVariableKeyframeList.Count);
         substanceMaterialParams.MaterialVariableKeyframeDictionaryList.Add(new MaterialVariableDictionaryHolder());
         SubstanceTweenStorageUtility.AddProceduralVariablesToList(substanceMaterialParams.MaterialVariableKeyframeList[animationParams.keyFrames], substanceMaterialParams, animationParams, substanceToolParams);
         SubstanceTweenStorageUtility.AddProceduralVariablesToDictionary(substanceMaterialParams.MaterialVariableKeyframeDictionaryList[animationParams.keyFrames], substanceMaterialParams, animationParams, substanceToolParams);
         animationParams.keyFrameTimes.Add(substanceMaterialParams.MaterialVariableKeyframeList[animationParams.keyFrames].animationTime);
         animationParams.keyframeSum = 0;
         for (int i = 0; i < substanceMaterialParams.MaterialVariableKeyframeList.Count() - 1; i++)
         {
             animationParams.keyframeSum += substanceMaterialParams.MaterialVariableKeyframeList[i].animationTime;
         }
         animationParams.substanceCurve.AddKey(new Keyframe(animationParams.keyframeSum, animationParams.keyframeSum));
         if (animationParams.keyFrames > 0)
         {
             UnityEditor.AnimationUtility.SetKeyLeftTangentMode(animationParams.substanceCurve, animationParams.keyFrames, UnityEditor.AnimationUtility.TangentMode.Linear);
         }
         UnityEditor.AnimationUtility.SetKeyRightTangentMode(animationParams.substanceCurve, animationParams.keyFrames, UnityEditor.AnimationUtility.TangentMode.Linear);
         animationParams.keyFrames++;
     }
     animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
     substanceToolParams.lastAction            = MethodBase.GetCurrentMethod().Name.ToString();
     SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
     SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
 }
Exemple #24
0
    } //  Sets current material variables from a JSON file without creating a keyframe

    public static void WriteAllJSON(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)
    {
        int          fileNumber = 1;
        StreamWriter writer;
        string       path = EditorUtility.SaveFilePanel("Save JSON Files", "", "", "json");
        FileInfo     fInfo;

        if (path.Length != 0)
        {
            for (int i = 0; i <= substanceMaterialParams.MaterialVariableKeyframeList.Count - 1; i++)      // Go through each keyframe
            {
                string[] splitPath = path.Split(new string[] { ".json" }, System.StringSplitOptions.None); // Splits json file path before '.json'
                if (i < 9)                                                                                 // helps for Lexicographical order
                {
                    fInfo = new FileInfo(splitPath[0] + '-' + 0 + fileNumber + ".json");                   //Insert filenumber and add .json to the extention
                }
                else
                {
                    fInfo = new FileInfo(splitPath[0] + '-' + +fileNumber + ".json"); //Insert filenumber and add .json to the extention
                }
                AssetDatabase.Refresh();
                if (!fInfo.Exists) // if file name does not exist
                {
                    writer = fInfo.CreateText();
                }
                else
                {
                    writer = fInfo.CreateText(); Debug.Log("Overwriting File:" + fInfo + " with keyframe " + i);
                }
                MaterialVariableListHolder jsonDescription = substanceMaterialParams.MaterialVariableKeyframeList[i];
                jsonDescription.PropertyMaterialName = substanceMaterialParams.substance.name;
                string json = JsonUtility.ToJson(jsonDescription);
                if (animationParams.keyFrameTimes.Count() >= 1)
                {
                    if (jsonDescription.AnimationCurveKeyframeList.Count <= 0)
                    {
                        if (fileNumber == 1) // if fileNumber is one make sure that there are no NAN tangents saved
                        {
                            jsonDescription.AnimationCurveKeyframeList.Add(new Keyframe(animationParams.substanceCurve.keys[i].time, animationParams.substanceCurve.keys[i].value, 0, animationParams.substanceCurve.keys[i].outTangent));
                        }
                        else
                        {
                            jsonDescription.AnimationCurveKeyframeList.Add(animationParams.substanceCurve.keys[i]);
                        }
                    }
                    else
                    {
                        if (fileNumber == 1) // if fileNumber is one make sure that there are no NAN tangents saved
                        {
                            jsonDescription.AnimationCurveKeyframeList[0] = (new Keyframe(animationParams.substanceCurve.keys[i].time, animationParams.substanceCurve.keys[i].value, 0, animationParams.substanceCurve.keys[i].outTangent));
                        }
                        else
                        {
                            jsonDescription.AnimationCurveKeyframeList[0] = (animationParams.substanceCurve.keys[i]);
                        }
                    }
                }
                writer.Write(json);
                writer.Close();
                substanceToolParams.DebugStrings.Add("Wrote  JSON file" + fileNumber + " to: " + fInfo);
                fileNumber++;
            }
        }
        substanceToolParams.DebugStrings.Add(fileNumber + " keyframes saved as XML files"); substanceToolParams.DebugStrings.Add("-----------------------------------");
        substanceToolParams.lastAction = MethodBase.GetCurrentMethod().Name.ToString();
    } //Writes all keyframes to JSON files