コード例 #1
0
	static int CacheProceduralProperty(IntPtr L)
	{
		LuaScriptMgr.CheckArgsCount(L, 3);
		ProceduralMaterial obj = LuaScriptMgr.GetNetObject<ProceduralMaterial>(L, 1);
		string arg0 = LuaScriptMgr.GetLuaString(L, 2);
		bool arg1 = LuaScriptMgr.GetBoolean(L, 3);
		obj.CacheProceduralProperty(arg0,arg1);
		return 0;
	}
コード例 #2
0
    //Esta funcion se llama cada que se crea un objeto nuevo
    public void LoadNewObject(GameObject parentOfSubstances)
    {
        //borrar lo que ya haya en la ui para las variables expuestas
        ClearUI();

        target = parentOfSubstances;
        if (objectWithMaterials != null)
        {
            objectWithMaterials.Clear();
        }
        else
        {
            objectWithMaterials = new List <MatClass>();
        }

        //Sacar cada objeto hijo con materiales

        foreach (Transform child in parentOfSubstances.transform)
        {
            //de cada hijo sacar todos sus materiales
            Debug.Log("Shared MAterials: " + child.GetComponent <Renderer>().sharedMaterials.Length);
            MatClass objMaterial = new MatClass();
            objMaterial.Init();
            foreach (Material mat in child.GetComponent <Renderer>().sharedMaterials)
            {
                //Tomar el susbtance como material procedural y agregarlo a lista
                ProceduralMaterial tempSubstance = mat as ProceduralMaterial;
                ProceduralMaterial.substanceProcessorUsage = ProceduralProcessorUsage.All;

                if (tempSubstance != null)
                {
                    tempSubstance.CacheProceduralProperty("_MainTex", true);

                    //Solo se va a checar el workflow con el primer objeto que tenga material
                    if (child.GetSiblingIndex() == 0)
                    {
                        //Display Material Name
                        DisplayMaterialName(tempSubstance, target.name);
                    }

                    //Guardar el material
                    objMaterial.baseMaterial.Add(mat);

                    //Creaete albedo Mat
                    Material tempMat;
                    CreateMaterialFrom("_MainTex", out tempMat, child, tempSubstance);
                    objMaterial.albedoMaterial.Add(tempMat);

                    //Create Normal Mat
                    tempMat = null;
                    CreateMaterialFrom("_BumpMap", out tempMat, child, tempSubstance, true); //_BumpMap
                    objMaterial.normalMaterial.Add(tempMat);


                    if (isMetallicWorkflow)
                    {
                        //Create Metallic Mat
                        tempMat = null;
                        CreateMaterialFrom("_MetallicGlossMap", out tempMat, child, tempSubstance);
                        objMaterial.metallicSpecMaterial.Add(tempMat);
                        //Create Roughness Mat
                        tempMat = null;
                        CreateMaterialFrom("_RoughnessMap", out tempMat, child, tempSubstance); //CHECAR QUE ASI SE LLAME EN SHADER
                        objMaterial.roughnessGlossinesMaterial.Add(tempMat);
                    }
                    else
                    {
                        tempMat = null;
                        CreateMaterialFrom("_SpecGlossMap", out tempMat, child, tempSubstance);
                        objMaterial.metallicSpecMaterial.Add(tempMat);
                        //Create Roughness Mat
                        tempMat = null;
                        CreateMaterialFrom("_GloosMap", out tempMat, child, tempSubstance);
                        objMaterial.roughnessGlossinesMaterial.Add(tempMat);
                    }

                    //Create Height Map
                    tempMat = null;
                    CreateMaterialFrom("_ParallaxMap", out tempMat, child, tempSubstance);
                    objMaterial.heightMaterial.Add(tempMat);
                    //Create Alpha Map
                    tempMat = null;
                    CreateMaterialFrom("_AlphaMap", out tempMat, child, tempSubstance); //CONFIRMAR QU ESTE SEA EL NOMBRE EN EL SHADER
                    objMaterial.alphaMaterial.Add(tempMat);
                    tempMat = null;                                                     //Create S
                    CreateMaterialFrom("_EmissionMap", out tempMat, child, tempSubstance);
                    objMaterial.emissionMaterial.Add(tempMat);

                    //Agregar a la UI
                    if (tempSubstance != null)
                    {
                        DisplaySubstanceMaterialProperties(tempSubstance);
                    }

                    //Agregar el substance a la lista
                    objMaterial.substance.Add(tempSubstance);

                    Debug.Log("Albedos: " + objMaterial.albedoMaterial.Count);
                }

                objectWithMaterials.Add(objMaterial);
                Debug.Log("Materiales: " + objectWithMaterials.Count);
            } //fin foreach material
        }     // fin foreach child
    }
コード例 #3
0
    public void ConvertAnimatedListToDictionaryandSet()
    {
        if (gameObject.GetComponent <PrefabProperties>().enabled)
        {
            rend = GetComponent <Renderer>();
#if UNITY_EDITOR
            if (UnityEditor.Selection.activeGameObject != null && UnityEditor.Selection.activeGameObject.GetComponent <SubstanceTool>() != null)
            {
                useSharedMaterial = true;
            }
            if (UnityEditor.PrefabUtility.GetPrefabType(this) == UnityEditor.PrefabType.Prefab)
            {
                Debug.Log("object is in project view");
                return;
            }
#endif
            if (useSharedMaterial && this.GetComponent <Renderer>() != null)
            {
                substance = rend.sharedMaterial as ProceduralMaterial;
            }
            else if (!useSharedMaterial && this.GetComponent <Renderer>() != null)
            {
                substance = rend.material as ProceduralMaterial;
            }
            else
            {
                Debug.LogWarning("No Renderer on " + this.name);
            }
            if (useSharedMaterial)
            {
                emissionInput = rend.sharedMaterial.GetColor("_EmissionColor");
            }
            else
            {
                emissionInput = rend.material.GetColor("_EmissionColor");
            }
            if (substance)
            {
                substance.cacheSize = (ProceduralCacheSize)myProceduralCacheSize;
                ProceduralMaterial.substanceProcessorUsage = (ProceduralProcessorUsage)mySubstanceProcessorUsage;
                substance.enableInstancing = true;
                materialVariables          = substance.GetProceduralPropertyDescriptions();
                if (MaterialVariableKeyframeList.Count > 0)
                {
                    for (int i = 0; i <= MaterialVariableKeyframeList.Count - 1; i++)
                    {
                        int index;
                        MaterialVariableKeyframeDictionaryList.Add(new MaterialVariableDictionaryHolder());
                        MaterialVariableKeyframeDictionaryList[i].PropertyMaterialName = MaterialVariableKeyframeList[0].PropertyMaterialName;
                        for (int j = 0; j < materialVariables.Length; j++)
                        {
                            ProceduralPropertyDescription materialVariable = materialVariables[j];
                            ProceduralPropertyType        propType         = materialVariables[j].type;

                            if (i == 0 && animatedParameterNames.Contains(materialVariable.name))
                            {
                                substance.CacheProceduralProperty(materialVariable.name, true);
                            }
                            if (propType == ProceduralPropertyType.Float)
                            {
                                if (MaterialVariableKeyframeList[i].myFloatKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myFloatKeys.IndexOf(materialVariable.name);
                                        float curFloat = MaterialVariableKeyframeList[i].myFloatValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curFloat);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyFloatDictionary.Add(materialVariable.name, curFloat);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralFloat(materialVariable.name, MaterialVariableKeyframeList[0].myFloatValues[MaterialVariableKeyframeList[0].myFloatKeys.IndexOf(materialVariable.name)]);
                                    }
                                }
                            }
                            else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4)
                            {
                                if (MaterialVariableKeyframeList[i].myColorKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myColorKeys.IndexOf(materialVariable.name);
                                        Color curColor = MaterialVariableKeyframeList[i].myColorValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curColor);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyColorDictionary.Add(materialVariable.name, curColor);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralColor(materialVariable.name, MaterialVariableKeyframeList[0].myColorValues[MaterialVariableKeyframeList[0].myColorKeys.IndexOf(materialVariable.name)]);
                                    }
                                }
                            }
                            else if (propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4)
                            {
                                if (propType == ProceduralPropertyType.Vector4)
                                {
                                    if (MaterialVariableKeyframeList[i].myVector4Keys.Contains(materialVariable.name))
                                    {
                                        if (animatedParameterNames.Contains(materialVariable.name))
                                        {
                                            index = MaterialVariableKeyframeList[i].myVector4Keys.IndexOf(materialVariable.name);
                                            Vector4 curVector4 = MaterialVariableKeyframeList[i].myVector4Values[index];
                                            MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector4);
                                            MaterialVariableKeyframeDictionaryList[i].PropertyVector4Dictionary.Add(materialVariable.name, curVector4);
                                            if (i == 0)
                                            {
                                                animatedMaterialVariables.Add(materialVariable);
                                            }
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector4Values[MaterialVariableKeyframeList[0].myVector4Keys.IndexOf(materialVariable.name)]);
                                    }
                                }
                                else if (propType == ProceduralPropertyType.Vector3)
                                {
                                    if (MaterialVariableKeyframeList[i].myVector3Keys.Contains(materialVariable.name))
                                    {
                                        if (animatedParameterNames.Contains(materialVariable.name))
                                        {
                                            index = MaterialVariableKeyframeList[i].myVector3Keys.IndexOf(materialVariable.name);
                                            Vector3 curVector3 = MaterialVariableKeyframeList[i].myVector3Values[index];
                                            MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector3);
                                            MaterialVariableKeyframeDictionaryList[i].PropertyVector3Dictionary.Add(materialVariable.name, curVector3);
                                            if (i == 0)
                                            {
                                                animatedMaterialVariables.Add(materialVariable);
                                            }
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector3Values[MaterialVariableKeyframeList[0].myVector3Keys.IndexOf(materialVariable.name)]);
                                    }
                                }
                                else if (propType == ProceduralPropertyType.Vector2)
                                {
                                    if (MaterialVariableKeyframeList[i].myVector2Keys.Contains(materialVariable.name))
                                    {
                                        if (animatedParameterNames.Contains(materialVariable.name))
                                        {
                                            index = MaterialVariableKeyframeList[i].myVector2Keys.IndexOf(materialVariable.name);
                                            Vector2 curVector2 = MaterialVariableKeyframeList[i].myVector2Values[index];
                                            MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector2);
                                            MaterialVariableKeyframeDictionaryList[i].PropertyVector2Dictionary.Add(materialVariable.name, curVector2);
                                            if (i == 0)
                                            {
                                                animatedMaterialVariables.Add(materialVariable);
                                            }
                                        }
                                    }
                                    if (i == 0)
                                    {
                                        substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector2Values[MaterialVariableKeyframeList[0].myVector2Keys.IndexOf(materialVariable.name)]);
                                    }
                                }
                            }
                            else if (propType == ProceduralPropertyType.Enum)
                            {
                                if (MaterialVariableKeyframeList[i].myEnumKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myEnumKeys.IndexOf(materialVariable.name);
                                        int curEnum = MaterialVariableKeyframeList[i].myEnumValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curEnum);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyEnumDictionary.Add(materialVariable.name, curEnum);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                }
                                if (i == 0)
                                {
                                    substance.SetProceduralEnum(materialVariable.name, MaterialVariableKeyframeList[0].myEnumValues[MaterialVariableKeyframeList[0].myEnumKeys.IndexOf(materialVariable.name)]);
                                }
                            }
                            else if (propType == ProceduralPropertyType.Boolean)
                            {
                                if (MaterialVariableKeyframeList[i].myBooleanKeys.Contains(materialVariable.name))
                                {
                                    if (animatedParameterNames.Contains(materialVariable.name))
                                    {
                                        index = MaterialVariableKeyframeList[i].myBooleanKeys.IndexOf(materialVariable.name);
                                        bool curBool = MaterialVariableKeyframeList[i].myBooleanValues[index];
                                        MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curBool);
                                        MaterialVariableKeyframeDictionaryList[i].PropertyBoolDictionary.Add(materialVariable.name, curBool);
                                        if (i == 0)
                                        {
                                            animatedMaterialVariables.Add(materialVariable);
                                        }
                                    }
                                }
                                if (i == 0)
                                {
                                    substance.SetProceduralBoolean(materialVariable.name, MaterialVariableKeyframeList[0].myBooleanValues[MaterialVariableKeyframeList[0].myBooleanKeys.IndexOf(materialVariable.name)]);
                                }
                            }
                        }
                        MaterialVariableKeyframeDictionaryList[i].MainTex       = MaterialVariableKeyframeList[i].MainTex;
                        MaterialVariableKeyframeDictionaryList[i].emissionColor = MaterialVariableKeyframeList[i].emissionColor;
                    }
                }
            }
            if (deleteOldListValuesOnStart)
            {
                MaterialVariableKeyframeList.Clear();
            }
        }
    }