Beispiel #1
0
    public static void ReadJSON(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)
    {
        string path = EditorUtility.OpenFilePanel("", "", "json"); // 'Open' Dialog that only accepts JSON files

        if (path.Length != 0)
        {
            string dataAsJson = File.ReadAllText(path);
            var    stream     = new FileStream(path, FileMode.Open);
            if (stream.Length != 0)
            {
                MaterialVariableListHolder jsonContainer = JsonUtility.FromJson <MaterialVariableListHolder>(dataAsJson);
                SubstanceTweenSetParameterUtility.SetProceduralVariablesFromList(jsonContainer, substanceMaterialParams, animationParams, substanceToolParams);
                substanceMaterialParams.MainTexOffset = jsonContainer.MainTex;
                Color jsonEmissionColor = new Color(0, 0, 0, 0);
                jsonEmissionColor = jsonContainer.emissionColor;
                if (substanceMaterialParams.rend.sharedMaterial.HasProperty("_EmissionColor"))
                {
                    substanceMaterialParams.emissionInput = jsonEmissionColor;
                    substanceMaterialParams.rend.sharedMaterial.SetColor("_EmissionColor", jsonEmissionColor);
                    substanceToolParams.selectedPrefabScript.emissionInput = substanceMaterialParams.emissionInput;
                }
                stream.Close();
                substanceToolParams.DebugStrings.Add("-----------------------------------");
                substanceToolParams.DebugStrings.Add("Read XML file " + " from: " + stream.Name + ", File has: ");
                if (jsonContainer.PropertyMaterialName != null)
                {
                    substanceToolParams.DebugStrings.Add("Material Name: " + jsonContainer.PropertyMaterialName);
                }
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyName.Count + " Total Properties");
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyFloat.Count + " Float Properties");
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyColor.Count + " Color Properties ");
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyVector4.Count + " Vector4 Properties");
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyVector3.Count + " Vector3 Properties");
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyVector2.Count + " Vector2 Properties");
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyEnum.Count + " Enum Properties");
                substanceToolParams.DebugStrings.Add(jsonContainer.PropertyBool.Count + " Boolean Properties");
                substanceToolParams.DebugStrings.Add(jsonContainer.myKeys.Count + " Keys");
                substanceToolParams.DebugStrings.Add(jsonContainer.myValues.Count + " Values");
                substanceToolParams.DebugStrings.Add("_EmissionColor = " + jsonContainer.emissionColor);
                substanceToolParams.DebugStrings.Add("_MainTex = " + substanceMaterialParams.MainTexOffset);
                substanceToolParams.DebugStrings.Add("-----------------------------------");
                substanceMaterialParams.substance.RebuildTexturesImmediately();
            }
        }
        substanceToolParams.lastAction = MethodBase.GetCurrentMethod().Name.ToString();
        SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
    } //  Sets current material variables from a JSON file without creating a keyframe
Beispiel #2
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();
    }
Beispiel #3
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();
    }
Beispiel #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;
 }
Beispiel #5
0
 public static void AddProceduralVariablesToDictionaryFromList(MaterialVariableDictionaryHolder dictionary, MaterialVariableListHolder list, ProceduralPropertyDescription[] materialVariables, bool saveOutputParameters) // sorts items from a list into a dictionary
 {
     if (materialVariables != null)
     {
         for (int i = 0; i < materialVariables.Length; i++)
         {
             ProceduralPropertyDescription materialVariable = materialVariables[i];
             ProceduralPropertyType        propType         = materialVariables[i].type;
             if (propType == ProceduralPropertyType.Float && (materialVariable.hasRange || (saveOutputParameters && !materialVariable.hasRange)))
             {
                 if (!dictionary.PropertyFloatDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, list.myFloatValues[list.myFloatKeys.IndexOf(materialVariable.name)]);
                     dictionary.PropertyFloatDictionary.Add(materialVariable.name, list.myFloatValues[list.myFloatKeys.IndexOf(materialVariable.name)]);
                 }
                 else // if it already contains the key overwrite it
                 {
                     dictionary.PropertyFloatDictionary[materialVariable.name] = list.myFloatValues[list.myFloatKeys.IndexOf(materialVariable.name)];
                 }
             }
             if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
             {
                 Color propColor = list.myColorValues[list.myColorKeys.IndexOf(materialVariable.name)];
                 if (!dictionary.PropertyColorDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, propColor);
                     dictionary.PropertyColorDictionary.Add(materialVariable.name, propColor);
                 }
                 else
                 {
                     dictionary.PropertyColorDictionary[materialVariable.name] = propColor;
                 }
             }
             if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) && (materialVariable.hasRange || (saveOutputParameters && !materialVariable.hasRange)))
             {
                 if (propType == ProceduralPropertyType.Vector4)
                 {
                     Vector4 propVector4 = list.myVector4Values[list.myVector4Keys.IndexOf(materialVariable.name)];
                     if (!dictionary.PropertyVector4Dictionary.ContainsKey(materialVariable.name))
                     {
                         dictionary.PropertyDictionary.Add(materialVariable.name, propVector4);
                         dictionary.PropertyVector4Dictionary.Add(materialVariable.name, propVector4);
                     }
                     else
                     {
                         dictionary.PropertyVector4Dictionary[materialVariable.name] = propVector4;
                     }
                 }
                 else if (propType == ProceduralPropertyType.Vector3)
                 {
                     Vector3 propVector3 = list.myVector3Values[list.myVector3Keys.IndexOf(materialVariable.name)];
                     if (!dictionary.PropertyVector3Dictionary.ContainsKey(materialVariable.name))
                     {
                         dictionary.PropertyDictionary.Add(materialVariable.name, propVector3);
                         dictionary.PropertyVector3Dictionary.Add(materialVariable.name, propVector3);
                     }
                     else
                     {
                         dictionary.PropertyVector3Dictionary[materialVariable.name] = propVector3;
                     }
                 }
                 else if (propType == ProceduralPropertyType.Vector2)
                 {
                     Vector2 propVector2 = list.myVector2Values[list.myVector2Keys.IndexOf(materialVariable.name)];
                     if (!dictionary.PropertyVector2Dictionary.ContainsKey(materialVariable.name))
                     {
                         dictionary.PropertyDictionary.Add(materialVariable.name, propVector2);
                         dictionary.PropertyVector2Dictionary.Add(materialVariable.name, propVector2);
                     }
                     else
                     {
                         dictionary.PropertyVector2Dictionary[materialVariable.name] = propVector2;
                     }
                 }
             }
             if (propType == ProceduralPropertyType.Enum)
             {
                 int propEnum = list.myEnumValues[list.myEnumKeys.IndexOf(materialVariable.name)];
                 if (!dictionary.PropertyEnumDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, propEnum);
                     dictionary.PropertyEnumDictionary.Add(materialVariable.name, propEnum);
                 }
                 else
                 {
                     dictionary.PropertyEnumDictionary[materialVariable.name] = propEnum;
                 }
             }
             if (propType == ProceduralPropertyType.Boolean)
             {
                 bool propBool = list.myBooleanValues[list.myBooleanKeys.IndexOf(materialVariable.name)];
                 if (!dictionary.PropertyBoolDictionary.ContainsKey(materialVariable.name))
                 {
                     dictionary.PropertyDictionary.Add(materialVariable.name, propBool);
                     dictionary.PropertyBoolDictionary.Add(materialVariable.name, propBool);
                 }
                 else
                 {
                     dictionary.PropertyBoolDictionary[materialVariable.name] = propBool;
                 }
             }
         }
         dictionary.MainTex       = list.MainTex;
         dictionary.emissionColor = list.emissionColor;
     }
 }
    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);
                        }
                    }
                }
            }
        }
    }
Beispiel #7
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);
        }
    }
Beispiel #8
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