Exemplo n.º 1
0
        void copyMaterialProperty(Material from, Material to, MaterialPropertyExport property)
        {
            int fromID = property.fromID;

            if (fromID == -1)
            {
                fromID = Shader.PropertyToID(property.fromName);
            }
            int toID = property.toID;

            if (toID == -1)
            {
                toID = Shader.PropertyToID(property.toName);
            }

            switch (property.type)
            {
            case MaterialPropertyExport.PropertyType.Color:
                to.SetColor(toID, from.GetColor(fromID));
                break;

            case MaterialPropertyExport.PropertyType.ColorArray:
                to.SetColorArray(toID, from.GetColorArray(fromID));
                break;

            case MaterialPropertyExport.PropertyType.Float:
                to.SetFloat(toID, from.GetFloat(fromID));
                break;

            case MaterialPropertyExport.PropertyType.FloatArray:
                to.SetFloatArray(toID, from.GetFloatArray(fromID));
                break;

            case MaterialPropertyExport.PropertyType.Int:
                to.SetInt(toID, from.GetInt(fromID));
                break;

            case MaterialPropertyExport.PropertyType.Matrix:
                to.SetMatrix(toID, from.GetMatrix(fromID));
                break;

            case MaterialPropertyExport.PropertyType.MatrixArray:
                to.SetMatrixArray(toID, from.GetMatrixArray(fromID));
                break;

            case MaterialPropertyExport.PropertyType.Texture:
                to.SetTexture(toID, from.GetTexture(fromID));
                break;

            case MaterialPropertyExport.PropertyType.Vector:
                to.SetVector(toID, from.GetVector(fromID));
                break;

            case MaterialPropertyExport.PropertyType.VectorArray:
                to.SetVectorArray(toID, from.GetVectorArray(fromID));
                break;
            }
        }
Exemplo n.º 2
0
        void fillMaterialInfos(Renderer r, string[] matNames, List <MaterialPropertyExport>[] matProperties)
        {
            int childCount = r.transform.childCount;

            for (int i = 0; i < childCount; i++)
            {
                var name = r.transform.GetChild(i).name.ToLower();
                if (!name.StartsWith("#"))
                {
                    continue;
                }
                name = name.Remove(0, 1);
                var s = name.Split(';');
                if (s.Length == 0)
                {
                    continue;
                }
                if (s[0].Contains("mat"))
                {
                    if (s.Length != 3)
                    {
                        ErrorList.add(s[0] + " property on " + r.gameObject.FullName() + " must have 2 arguments");
                        continue;
                    }
                    int index = 0;
                    if (!int.TryParse(s[1], out index))
                    {
                        ErrorList.add("First argument of " + s[0] + " on " + r.gameObject.FullName() + " property must be a number");
                        continue;
                    }
                    if (index < matNames.Length)
                    {
                        matNames[index] = s[2];
                    }
                }
                else if (s[0].Contains("export"))
                {
                    if (s.Length != 5)
                    {
                        ErrorList.add(s[0] + " property on " + r.gameObject.FullName() + " must have 4 arguments");
                        continue;
                    }
                    int index = 0;
                    if (!int.TryParse(s[1], out index))
                    {
                        ErrorList.add("First argument of " + s[0] + " on " + r.gameObject.FullName() + " property must be a number");
                        continue;
                    }
                    if (index >= matNames.Length)
                    {
                        continue;
                    }
                    MaterialPropertyExport p = new MaterialPropertyExport();
                    bool found = false;

                    foreach (MaterialPropertyExport.PropertyType pType in Enum.GetValues(typeof(MaterialPropertyExport.PropertyType)))
                    {
                        if (s[2] == pType.ToString().ToLower())
                        {
                            found  = true;
                            p.type = pType;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ErrorList.add("The property " + s[2] + " on " + r.gameObject.FullName() + " is not valid");
                        continue;
                    }
                    if (!int.TryParse(s[3], out p.fromID))
                    {
                        p.fromName = s[3];
                    }
                    if (!int.TryParse(s[4], out p.toID))
                    {
                        p.toName = s[4];
                    }

                    matProperties[index].Add(p);
                }
            }
        }