Exemplo n.º 1
0
        private void DrawSelection(Transform t, ref int selectedCount)
        {
            var renderer = t.GetComponent <Renderer>();

            if (renderer != null)
            {
                var paintable = paintables.Find(p => p.Root == t.gameObject);

                if (paintable == null)
                {
                    EditorGUILayout.BeginHorizontal();
                    P3dHelper.BeginColor(Color.green);
                    if (GUILayout.Button("Lock", GUILayout.Width(40.0f)) == true)
                    {
                        paintable = new P3dWindowPaintable(t.gameObject);

                        paintables.Add(paintable);
                    }
                    P3dHelper.EndColor();
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.ObjectField("", t.gameObject, typeof(GameObject), true);
                    EditorGUI.EndDisabledGroup();
                    P3dHelper.BeginColor(Color.green);
                    if (GUILayout.Button("Lock & Edit", GUILayout.Width(80.0f)) == true)
                    {
                        paintable = new P3dWindowPaintable(t.gameObject);

                        paintables.Add(paintable);

                        tab            = 1;
                        paintableIndex = paintables.IndexOf(paintable);
                    }
                    P3dHelper.EndColor();
                    EditorGUILayout.EndHorizontal();
                    selectedCount++;
                }
            }

            for (var i = 0; i < t.childCount; i++)
            {
                DrawSelection(t.GetChild(i), ref selectedCount);
            }
        }
 public P3dWindowPaintableTexture(P3dWindowPaintable newParent, int newMaterial, string newSlotName)
 {
     Parent        = newParent;
     MaterialIndex = newMaterial;
     SlotName      = newSlotName;
 }
Exemplo n.º 3
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);
        }