示例#1
0
        // Draws materials if exists
        public bool drawMaterials()
        {
            GUI.skin.box.margin = new RectOffset(10, 10, 0, 0);

            if (LoziExporter.instance.materialCollection != null &&
                LoziExporter.instance.materialCollection.materials.Count > 0)
            {
                EditorGUILayout.BeginVertical("Box");

                drawHeader();

                for (int num = 0; num < LoziExporter.instance.materialCollection.materials.Count; num++)
                {
                    tempMat             = LoziExporter.instance.materialCollection.materials[num];
                    GUI.skin.box.margin = new RectOffset(0, 0, 0, 0);
                    if (GUI.Button(EditorGUILayout.BeginHorizontal("Box"), GUIContent.none))
                    {
                        tempMat.isFoldedInUI = !tempMat.isFoldedInUI;
                    }
                    GUILayout.Label(icons[8]);

                    GUILayout.Label(tempMat.name);
                    EditorGUILayout.EndHorizontal();
                    if (tempMat.isFoldedInUI)
                    {
                        GUI.Box(EditorGUILayout.BeginVertical("Box"), GUIContent.none);
                        GUILayout.Space(5);
                        tempMat.materialType  = EditorGUILayout.Popup("Material Type", tempMat.materialType, materialTypes);
                        tempMat.transparentID = EditorGUILayout.Popup("Transparent Texture", tempMat.transparentID, tempMat.textureProperties);
                        if (materialTypesIndex != 4 && tempMat.materialType != materialTypesIndex)
                        {
                            materialTypesIndex = 4;
                        }
                        GUILayout.Label("Properties", EditorStyles.boldLabel);
                        for (int num2 = 0; num2 < tempMat.materialProps.Count; num2++)
                        {
                            matProperties = tempMat.materialProps[num2];
                            EditorGUILayout.TextField(matProperties.propertyName, propertyToString(matProperties.valObject));
                        }
                        GUILayout.Space(10);
                        EditorGUILayout.EndVertical();
                    }
                }

                EditorGUILayout.EndVertical();
                return(true);
            }
            return(false);
        }
示例#2
0
        // gets all properties of material shader and adds lightmap property if lightmapid >-1
        private void getProperties()
        {
            if (properties != null)
            {
                if (properties.Count > 0)
                {
                    for (int num = 0; num < properties.Count; num++)
                    {
                        properties[num].Dispose();
                    }
                    properties.Clear();
                }
            }
            List <string> textureProps = new List <string>();

            properties = new List <LoziMaterialProperty>();

            for (int num = 0; num < ShaderUtil.GetPropertyCount(material.shader); num++)
            {
                ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(material.shader, num);
                string property = ShaderUtil.GetPropertyName(material.shader, num);
                object value    = null;
                switch (type)
                {
                case ShaderUtil.ShaderPropertyType.Range:
                case ShaderUtil.ShaderPropertyType.Float: { value = material.GetFloat(property);  break; }

                case ShaderUtil.ShaderPropertyType.Color: { value = colorToList(material.GetColor(property)); break; }

                case ShaderUtil.ShaderPropertyType.Vector: { value = vectorToList(material.GetVector(property)); break; }

                case ShaderUtil.ShaderPropertyType.TexEnv: { value = material.GetTexture(property);  break; }
                }

                if (value != null)
                {
                    if (type == ShaderUtil.ShaderPropertyType.TexEnv)
                    {
                        textureProps.Add(property);
                        value = (value as Texture).GetInstanceID();
                    }
                    properties.Add(new LoziMaterialProperty(type, property, value));
                }
            }
            if (textureProps.Count > 0)
            {
                textureProperties    = new string[textureProps.Count + 1];
                textureProperties[0] = "None";

                for (int num = 0; num < textureProperties.Length - 1; num++)
                {
                    textureProperties[num + 1] = textureProps[num];
                }
            }
            if (lightmapId > -1)
            {
                properties.Add(new LoziMaterialProperty(ShaderUtil.ShaderPropertyType.TexEnv, "lightMap", lightmapId));
            }
            if (transparentID > 0)
            {
                string propName           = textureProperties[transparentID];
                LoziMaterialProperty prop = getPropertyByString(propName);

                if (prop != null)
                {
                    properties.Add(new LoziMaterialProperty(ShaderUtil.ShaderPropertyType.TexEnv, "transparentMap", prop.valObject));
                }
            }
        }