Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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++;
 }
Ejemplo n.º 3
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);
    }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
    public static void WriteJSON(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams) //  Write current material variables to a JSON file
    {
        StreamWriter writer;
        var          path = EditorUtility.SaveFilePanel("Save JSON file", "", "", "json");

        if (path.Length != 0)
        {
            FileInfo fInfo = new FileInfo(path);
            AssetDatabase.Refresh();
            if (!fInfo.Exists)
            {
                writer = fInfo.CreateText();
            }
            else
            {
                writer = fInfo.CreateText(); Debug.Log("Overwriting File");
            }
            MaterialVariableListHolder jsonDescription = new MaterialVariableListHolder();//Creates empty list to be saved to a JSON file
            SubstanceTweenStorageUtility.AddProceduralVariablesToList(jsonDescription, substanceMaterialParams, animationParams, substanceToolParams);
            jsonDescription.PropertyMaterialName = substanceMaterialParams.substance.name;
            jsonDescription.emissionColor        = substanceMaterialParams.emissionInput;
            jsonDescription.MainTex = substanceMaterialParams.MainTexOffset;
            string json = JsonUtility.ToJson(jsonDescription);
            writer.Write(json);
            writer.Close();//Closes the Json writer
            substanceToolParams.DebugStrings.Add("-----------------------------------");
            substanceToolParams.DebugStrings.Add("Wrote JSON file to: " + fInfo + ", File has: ");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyName.Count + " Total Properties ");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyFloat.Count + " Float Properties");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyColor.Count + " Color Properties");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyVector4.Count + " Vector4 Properties");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyVector3.Count + " Vector3 Properties");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyVector2.Count + " Vector2 Properties");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyEnum.Count + " Enum Properties");
            substanceToolParams.DebugStrings.Add(jsonDescription.PropertyBool.Count + " Boolean Properties");
            substanceToolParams.DebugStrings.Add(jsonDescription.myKeys.Count + " Keys");
            substanceToolParams.DebugStrings.Add(jsonDescription.myValues.Count + " Values");
            substanceToolParams.DebugStrings.Add("Material Name: " + jsonDescription.PropertyMaterialName);
            substanceToolParams.DebugStrings.Add("Substance Texture Size: " + substanceMaterialParams.substanceWidth + " " + substanceMaterialParams.substanceHeight);
            substanceToolParams.DebugStrings.Add("-----------------------------------");
        }
        substanceToolParams.lastAction = MethodBase.GetCurrentMethod().Name.ToString();
    }
Ejemplo n.º 6
0
    public static void WriteXML(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams) // Write current material variables to a XML file.
    {
        StreamWriter writer;
        var          path = EditorUtility.SaveFilePanel("Save XML file", "", "", "xml");

        if (path.Length != 0)
        {
            FileInfo fInfo = new FileInfo(path);
            AssetDatabase.Refresh();
            if (!fInfo.Exists)
            {
                writer = fInfo.CreateText();
            }
            else
            {
                writer = fInfo.CreateText(); Debug.Log("Overwriting File");
            }
            MaterialVariableListHolder xmlDescription = new MaterialVariableListHolder();                                                             //Creates empty list to be saved to a XMl file
            XmlSerializer serializer = new XmlSerializer(typeof(MaterialVariableListHolder));
            SubstanceTweenStorageUtility.AddProceduralVariablesToList(xmlDescription, substanceMaterialParams, animationParams, substanceToolParams); // Writes current variables to a list to be saved to a XML file
            xmlDescription.PropertyMaterialName = substanceMaterialParams.substance.name;
            xmlDescription.emissionColor        = substanceMaterialParams.emissionInput;
            xmlDescription.MainTex = substanceMaterialParams.MainTexOffset;
            serializer.Serialize(writer, xmlDescription); //Writes the xml file using the fileInfo and the list we want to write.
            writer.Close();                               //Closes the XML writer
            substanceToolParams.DebugStrings.Add("-----------------------------------");
            substanceToolParams.DebugStrings.Add("Wrote XML file to: " + fInfo + ", File has: ");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyName.Count + " Total Properties ");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyFloat.Count + " Float Properties");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyColor.Count + " Color Properties");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyVector4.Count + " Vector4 Properties");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyVector3.Count + " Vector3 Properties");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyVector2.Count + " Vector2 Properties");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyEnum.Count + " Enum Properties");
            substanceToolParams.DebugStrings.Add(xmlDescription.PropertyBool.Count + " Boolean Properties");
            substanceToolParams.DebugStrings.Add(xmlDescription.myKeys.Count + " Keys");
            substanceToolParams.DebugStrings.Add(xmlDescription.myValues.Count + " Values");
            substanceToolParams.DebugStrings.Add("Material Name: " + xmlDescription.PropertyMaterialName);
            //DebugStrings.Add("Substance Texture Size: " + substanceWidth + " " + substanceHeight);
            substanceToolParams.DebugStrings.Add("-----------------------------------");
        }
        substanceToolParams.lastAction = MethodBase.GetCurrentMethod().Name.ToString();
    }