Exemple #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)
                {
                    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();
        }
Exemple #2
0
 private void UpdateCurveTexture(MaterialProperty prop)
 {
     texture           = Converter.CurveToTexture(curve, imageData);
     prop.textureValue = texture;
     saved             = false;
 }