Beispiel #1
0
        private void TransferReferencePropertiesToMaterial(Material target, ShaderPart p)
        {
            if (p.options.reference_properties == null || this.options.reference_properties == null)
            {
                return;
            }
            for (int i = 0; i < p.options.reference_properties.Length && i < options.reference_properties.Length; i++)
            {
                if (ShaderEditor.active.propertyDictionary.ContainsKey(this.options.reference_properties[i]) == false)
                {
                    continue;
                }

                ShaderProperty targetP = ShaderEditor.active.propertyDictionary[this.options.reference_properties[i]];
                ShaderProperty sourceP = p.shaderEditor.propertyDictionary[p.options.reference_properties[i]];
                MaterialHelper.CopyMaterialValueFromProperty(targetP.materialProperty, sourceP.materialProperty);
            }
        }
Beispiel #2
0
 public override void TransferFromMaterialAndGroup(Material m, ShaderPart p)
 {
     if (materialProperty.type != p.materialProperty.type)
     {
         return;
     }
     MaterialHelper.CopyMaterialValueFromProperty(materialProperty, p.materialProperty);
     if (keyword != null)
     {
         SetKeyword(ShaderEditor.active.materials, m.GetFloat(p.materialProperty.name) == 1);
     }
     if (is_animatable && p.is_animatable)
     {
         ShaderOptimizer.CopyAnimatedTagFromProperty(p.materialProperty, materialProperty);
     }
     this.is_animated = is_animatable && ShaderOptimizer.GetAnimatedTag(materialProperty) != "";
     this.is_renaming = is_animatable && ShaderOptimizer.GetAnimatedTag(materialProperty) == "2";
 }
Beispiel #3
0
 public static void SetMaterialPropertyValue(MaterialProperty p, Material[] materials, string value)
 {
     if (p.type == MaterialProperty.PropType.Texture)
     {
         Texture tex = AssetDatabase.LoadAssetAtPath <Texture>(value);
         if (tex != null)
         {
             foreach (Material m in materials)
             {
                 m.SetTexture(p.name, tex);
             }
         }
     }
     else if (p.type == MaterialProperty.PropType.Float || p.type == MaterialProperty.PropType.Range)
     {
         float f_value;
         if (float.TryParse(value, out f_value))
         {
             p.floatValue = f_value;
             string[] drawer = ShaderHelper.GetDrawer(p);
             if (drawer != null && drawer.Length > 1 && drawer[0] == "Toggle" && drawer[1] != "__")
             {
                 MaterialHelper.ToggleKeyword(p, drawer[1], f_value == 1);
             }
         }
     }
     else if (p.type == MaterialProperty.PropType.Vector)
     {
         string[] xyzw   = value.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(p.name, vector);
         }
     }
     else if (p.type == MaterialProperty.PropType.Color)
     {
         Color col = Converter.stringToColor(value);
         foreach (Material m in materials)
         {
             m.SetColor(p.name, col);
         }
     }
 }
Beispiel #4
0
        private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options)
        {
            if (options.reference_property != null && ShaderEditor.active.propertyDictionary.ContainsKey(options.reference_property))
            {
                GUI.Box(rect, new GUIContent("     " + content.text, content.tooltip), Styles.dropDownHeader);
                DrawIcons(rect, options, e);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x      += 5;
                togglePropertyRect.y      += 1;
                togglePropertyRect.height -= 4;
                togglePropertyRect.width   = GUI.skin.font.fontSize * 3;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.fieldWidth = 20;
                ShaderProperty prop = ShaderEditor.active.propertyDictionary[options.reference_property];

                int xOffset = prop.xOffset;
                prop.xOffset = 0;
                prop.Draw(new CRect(togglePropertyRect), new GUIContent(), isInHeader: true);
                prop.xOffset = xOffset;
                EditorGUIUtility.fieldWidth = fieldWidth;
            }
            else if (keyword != null)
            {
                GUI.Box(rect, "     " + content.text, Styles.dropDownHeader);
                DrawIcons(rect, options, e);

                Rect togglePropertyRect = new Rect(rect);
                togglePropertyRect.x    += 20;
                togglePropertyRect.width = 20;

                EditorGUI.BeginChangeCheck();
                bool keywordOn = EditorGUI.Toggle(togglePropertyRect, "", ShaderEditor.active.materials[0].IsKeywordEnabled(keyword));
                if (EditorGUI.EndChangeCheck())
                {
                    MaterialHelper.ToggleKeyword(ShaderEditor.active.materials, keyword, keywordOn);
                }
            }
            else
            {
                GUI.Box(rect, content, Styles.dropDownHeader);
                DrawIcons(rect, options, e);
            }
        }
Beispiel #5
0
 public void HanldeDropEvent(MaterialProperty prop)
 {
     string[] paths = DragAndDrop.paths;
     if (AssetDatabase.GetMainAssetTypeAtPath(paths[0]) != typeof(Texture2DArray))
     {
         Texture2DArray tex = Converter.PathsToTexture2DArray(paths);
         MaterialHelper.UpdateTargetsValue(prop, tex);
         if (ThryEditor.currentlyDrawing.currentProperty.options.reference_property != null)
         {
             ThryEditor.ShaderProperty p;
             ThryEditor.currentlyDrawing.propertyDictionary.TryGetValue(ThryEditor.currentlyDrawing.currentProperty.options.reference_property, out p);
             if (p != null)
             {
                 MaterialHelper.UpdateFloatValue(p.materialProperty, tex.depth);
             }
         }
         prop.textureValue = tex;
     }
 }
Beispiel #6
0
 private void UpdateFramesProperty(MaterialProperty prop, ShaderProperty shaderProperty, Texture2DArray tex)
 {
     if (framesProperty != null)
     {
         ShaderProperty p;
         if (ShaderEditor.active.propertyDictionary.TryGetValue(framesProperty, out p))
         {
             MaterialHelper.UpdateFloatValue(p.materialProperty, tex.depth);
         }
     }
     else if (shaderProperty.options.reference_property != null)
     {
         ShaderProperty p;
         if (ShaderEditor.active.propertyDictionary.TryGetValue(shaderProperty.options.reference_property, out p))
         {
             MaterialHelper.UpdateFloatValue(p.materialProperty, tex.depth);
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Set Material Property value or Renderqueue of current Editor.
        /// </summary>
        /// <param name="key">Property Name or "render_queue"</param>
        /// <param name="value"></param>
        public static void SetMaterialValue(string key, string value)
        {
            MaterialProperty p = ThryEditor.FindProperty(ThryEditor.currentlyDrawing.properties, key);

            Material[] materials = ThryEditor.currentlyDrawing.materials;
            if (p != null)
            {
                MaterialHelper.SetMaterialPropertyValue(p, materials, value);
            }
            else if (key == "render_queue")
            {
                int q = 0;
                if (int.TryParse(value, out q))
                {
                    foreach (Material m in materials)
                    {
                        m.renderQueue = q;
                    }
                }
            }
        }
Beispiel #8
0
        public void Perform()
        {
            switch (type)
            {
            case DefineableActionType.URL:
                Application.OpenURL(data);
                break;

            case DefineableActionType.SET_PROPERTY:
                string[] set = Regex.Split(data, @"=");
                if (set.Length > 1)
                {
                    MaterialHelper.SetMaterialValue(set[0].Trim(), set[1].Trim());
                }
                break;

            case DefineableActionType.SET_TAG:
                string[] keyValue = Regex.Split(data, @"=");
                foreach (Material m in ShaderEditor.active.materials)
                {
                    m.SetOverrideTag(keyValue[0].Trim(), keyValue[1].Trim());
                }
                break;

            case DefineableActionType.SET_SHADER:
                Shader shader = Shader.Find(data);
                if (shader != null)
                {
                    foreach (Material m in ShaderEditor.active.materials)
                    {
                        m.shader = shader;
                    }
                }
                break;
            }
        }
Beispiel #9
0
        public static void restoreAllMaterials()
        {
            if (!File.Exists(PATH.MATERIALS_BACKUP_FILE))
            {
                backupAllMaterials();
                return;
            }
            StreamReader reader = new StreamReader(PATH.MATERIALS_BACKUP_FILE);

            string l;

            while ((l = reader.ReadLine()) != null)
            {
                string[] materialData = l.Split(new string[] { ":" }, System.StringSplitOptions.None);
                Material material     = AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(materialData[0]));
                Shader   shader       = Shader.Find(materialData[1]);
                material.shader      = shader;
                material.renderQueue = int.Parse(materialData[2]);
                MaterialHelper.UpdateRenderQueue(material, shader);
            }
            ThryEditor.repaint();

            reader.Close();
        }
Beispiel #10
0
 public override void CopyToMaterial(Material m)
 {
     MaterialHelper.CopyPropertyValueToMaterial(materialProperty, m);
     CopyReferencePropertiesToMaterial(m);
 }
Beispiel #11
0
 public override void CopyToMaterial(Material m)
 {
     MaterialHelper.CopyPropertyValueToMaterial(materialProperty, m);
 }