コード例 #1
0
        public void applyPreset(string presetName, MaterialProperty[] props, Material[] materials)
        {
            ThryEditor.addUndo(Locale.editor.Get("apply_preset") + ": " + presetName);
            List <string[]> sets;

            if (presets.TryGetValue(presetName, out sets))
            {
                foreach (string[] set in sets)
                {
                    MaterialHelper.SetMaterialValue(set[0], set[1]);
                }
            }
            ThryEditor.loadValuesFromMaterial();
            ThryEditor.repaint();
        }
コード例 #2
0
        public void applyPreset(string presetName, MaterialProperty[] props, Material[] materials)
        {
            ThryEditor.addUndo("Apply preset: " + presetName);
            List <string[]> sets;

            if (presets.TryGetValue(presetName, out sets))
            {
                foreach (string[] set in sets)
                {
                    MaterialProperty p = ThryEditor.FindProperty(props, set[0]);
                    if (p != null)
                    {
                        if (p.type == MaterialProperty.PropType.Texture)
                        {
                            string[] guids = AssetDatabase.FindAssets(set[1] + " t:Texture", null);
                            if (guids.Length == 0)
                            {
                                Debug.Log("Couldn't find texture: " + set[1]);
                            }
                            else
                            {
                                string  path = AssetDatabase.GUIDToAssetPath(guids[0]);
                                Texture tex  = (Texture)EditorGUIUtility.Load(path);
                                foreach (Material m in materials)
                                {
                                    m.SetTexture(Shader.PropertyToID(set[0]), tex);
                                }
                            }
                        }
                        else if (p.type == MaterialProperty.PropType.Float || p.type == MaterialProperty.PropType.Range)
                        {
                            float value;
                            if (float.TryParse(set[1], out value))
                            {
                                foreach (Material m in materials)
                                {
                                    m.SetFloat(Shader.PropertyToID(set[0]), value);
                                }
                            }
                        }
                        else if (p.type == MaterialProperty.PropType.Vector)
                        {
                            string[] xyzw   = set[1].Split(",".ToCharArray());
                            Vector4  vector = new Vector4(float.Parse(xyzw[0]), float.Parse(xyzw[1]), float.Parse(xyzw[2]), float.Parse(xyzw[3]));
                            foreach (Material m in materials)
                            {
                                m.SetVector(Shader.PropertyToID(set[0]), vector);
                            }
                        }
                        else if (p.type == MaterialProperty.PropType.Color)
                        {
                            Color col = Helper.stringToColor(set[1]);
                            foreach (Material m in materials)
                            {
                                m.SetColor(Shader.PropertyToID(set[0]), col);
                            }
                        }
                    }
                    else if (set[0] == "render_queue")
                    {
                        int q = 0;
                        Debug.Log(set[0] + "," + set[1]);
                        if (int.TryParse(set[1], out q))
                        {
                            foreach (Material m in materials)
                            {
                                m.renderQueue = q;
                            }
                        }
                    }
                }
            }
            ThryEditor.loadValuesFromMaterial();
            ThryEditor.repaint();
        }
コード例 #3
0
        public void applyPreset(string presetName, MaterialProperty[] props, Material[] materials)
        {
            ThryEditor.addUndo(Locale.editor.Get("apply_preset") + ": " + presetName);
            List <string[]> sets;

            if (presets.TryGetValue(presetName, out sets))
            {
                foreach (string[] set in sets)
                {
                    MaterialProperty p = ThryEditor.FindProperty(props, set[0]);
                    if (p != null)
                    {
                        if (p.type == MaterialProperty.PropType.Texture)
                        {
                            Texture tex = AssetDatabase.LoadAssetAtPath <Texture>(set[1]);
                            if (tex != null)
                            {
                                foreach (Material m in materials)
                                {
                                    m.SetTexture(Shader.PropertyToID(set[0]), tex);
                                }
                            }
                        }
                        else if (p.type == MaterialProperty.PropType.Float || p.type == MaterialProperty.PropType.Range)
                        {
                            float value;
                            if (float.TryParse(set[1], out value))
                            {
                                foreach (Material m in materials)
                                {
                                    m.SetFloat(Shader.PropertyToID(set[0]), value);
                                }
                            }
                        }
                        else if (p.type == MaterialProperty.PropType.Vector)
                        {
                            string[] xyzw   = set[1].Split(",".ToCharArray());
                            Vector4  vector = new Vector4(float.Parse(xyzw[0]), float.Parse(xyzw[1]), float.Parse(xyzw[2]), float.Parse(xyzw[3]));
                            foreach (Material m in materials)
                            {
                                m.SetVector(Shader.PropertyToID(set[0]), vector);
                            }
                        }
                        else if (p.type == MaterialProperty.PropType.Color)
                        {
                            Color col = Converter.stringToColor(set[1]);
                            foreach (Material m in materials)
                            {
                                m.SetColor(Shader.PropertyToID(set[0]), col);
                            }
                        }
                    }
                    else if (set[0] == "render_queue")
                    {
                        int q = 0;
                        Debug.Log(set[0] + "," + set[1]);
                        if (int.TryParse(set[1], out q))
                        {
                            foreach (Material m in materials)
                            {
                                m.renderQueue = q;
                            }
                        }
                    }
                }
            }
            ThryEditor.loadValuesFromMaterial();
            ThryEditor.repaint();
        }