Beispiel #1
0
        private Material DrawMaterial(P3dWindowPaintable paintable, Material material, int materialIndex)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Material " + materialIndex, EditorStyles.boldLabel, GUILayout.Width(120.0f));
            material = (Material)EditorGUILayout.ObjectField("", material, typeof(Material), false);
            EditorGUILayout.EndHorizontal();

            if (material != null)
            {
                if (material.hideFlags != HideFlags.None)
                {
                    EditorGUILayout.HelpBox("This may be a shared material, so you should clone it before modification.", MessageType.Warning);
                }

                if (GUILayout.Button("Clone") == true)
                {
                    material = Instantiate(material);
                }

                if (MaterialIsShared(material) == true && GUILayout.Button("Shared Clone") == true)
                {
                    var oldMaterial = material;

                    material = Instantiate(material);

                    MaterialIsShared(oldMaterial, material);
                }

                if (P3dHelper.IsAsset(material) == false && GUILayout.Button("Save As Asset") == true)
                {
                    var path = P3dHelper.SaveDialog("Save Material As Asset", "Assets", material.name, "mat");

                    if (string.IsNullOrEmpty(path) == false)
                    {
                        var textures = P3dHelper.CopyTextures(material);

                        AssetDatabase.CreateAsset(material, path);

                        P3dHelper.PasteTextures(material, textures);
                    }
                }

                var texEnvs = P3dHelper.GetTexEnvs(material);

                if (texEnvs.Count > 0)
                {
                    for (var j = 0; j < texEnvs.Count; j++)
                    {
                        var texEnv           = texEnvs[j];
                        var rect             = P3dHelper.Reserve();
                        var paintableTexture = paintable.PaintableTextures.Find(t => t.MaterialIndex == materialIndex && t.SlotName == texEnv.Name);

                        EditorGUI.BeginDisabledGroup(paintableTexture != null && paintableTexture.Locked == true);
                        var texture = EditorGUI.ObjectField(rect, default(string), material.GetTexture(texEnv.Name), typeof(Texture), true) as Texture;
                        EditorGUI.EndDisabledGroup();

                        // Make sure this is done after the texture field so it can be edited
                        var expand = EditorGUI.Foldout(rect, paintableTexture != null, new GUIContent(texEnv.Name, texEnv.Desc), false);

                        if (expand == true)
                        {
                            if (paintableTexture == null)
                            {
                                paintableTexture = new P3dWindowPaintableTexture(paintable, materialIndex, texEnv.Name); paintable.PaintableTextures.Add(paintableTexture);
                            }

                            paintableTexture.Revert();

                            paintableTexture.OldTexture = material.GetTexture(texEnv.Name) as Texture2D;

                            EditorGUILayout.BeginVertical("box");
                            texture = DrawObject(paintableTexture, material, texture);
                            EditorGUILayout.EndVertical();
                        }
                        else
                        {
                            if (paintableTexture != null)
                            {
                                paintableTexture.Unlock();

                                paintable.PaintableTextures.Remove(paintableTexture);
                            }
                        }

                        material.SetTexture(texEnv.Name, texture);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This material's shader has no texture slots.", MessageType.Info);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no material in this material slot.", MessageType.Info);
            }

            return(material);
        }