Пример #1
0
        public override void OnPostTargetMembersGUI(GUISkin skin)
        {
            var shapeVisual = ShapeVisual.Find(Shape);

            if (shapeVisual == null)
            {
                return;
            }

            GUI.Separator();
            if (!GUI.FoldoutEx(EditorData.Instance.GetData(Shape,
                                                           "Visual",
                                                           entry => entry.Bool = true),
                               skin.button,
                               GUI.MakeLabel("Shape Visual", 12, true),
                               new GUIStyle(skin.label)
            {
                alignment = TextAnchor.UpperCenter
            }))
            {
                return;
            }

            GUI.Separator();

            GUILayout.Space(6);

            Undo.RecordObjects(shapeVisual.GetComponentsInChildren <MeshRenderer>(), "Shape visual material");

            var materials = shapeVisual.GetMaterials();

            if (materials.Length > 1)
            {
                var distinctMaterials = materials.Distinct().ToArray();
                using (GUI.AlignBlock.Center) {
                    GUILayout.Label(GUI.MakeLabel("Displays material if all materials are the same <b>(otherwise None)</b> and/or assign new material to all objects in this shape."),
                                    new GUIStyle(skin.textArea)
                    {
                        alignment = TextAnchor.MiddleCenter
                    }, GUILayout.Width(Screen.width - 60));
                }
                GUI.MaterialEditor(GUI.MakeLabel("Common material:", true),
                                   128,
                                   distinctMaterials.Length == 1 ? distinctMaterials.First() : null,
                                   skin,
                                   newMaterial => shapeVisual.SetMaterial(newMaterial));

                GUILayout.Space(6);

                GUI.Separator();

                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel("Material list", true), skin.label);

                GUI.Separator();
            }

            for (int i = 0; i < materials.Length; ++i)
            {
                var material           = materials[i];
                var showMaterialEditor = materials.Length == 1 ||
                                         GUI.Foldout(EditorData.Instance.GetData(Shape,
                                                                                 "VisualMaterial" + i),
                                                     GUI.MakeLabel(material.name), skin);
                if (showMaterialEditor)
                {
                    GUI.MaterialEditor(GUI.MakeLabel("Material:", true),
                                       64,
                                       material,
                                       skin,
                                       newMaterial => shapeVisual.ReplaceMaterial(i, newMaterial));
                }
                GUI.Separator();
            }
        }