Ejemplo n.º 1
0
        void OnEnable()
        {
            Foliage2D foliage = (Foliage2D)target;

            if (foliage.GetComponent <MeshFilter>().sharedMesh == null)
            {
                foliage.RebuildMesh();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Custom inspector.
        /// </summary>
        private void CustomInspector(Foliage2D foliage2D)
        {
            Undo.RecordObject(target, "Modified Inspector");
            showVisuals = EditorGUILayout.Foldout(showVisuals, "Visual Properties");

            if (showVisuals)
            {
                EditorGUI.indentLevel = 1;
                InspectorBox(10, () =>
                {
                    foliage2D.pixelsPerUnit  = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Pixels To Units", "The number of pixels in 1 Unity unit."), foliage2D.pixelsPerUnit), 1, 768);
                    foliage2D.widthSegments  = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("With Segments", "The number of columns the mesh has."), foliage2D.widthSegments), 1, 100);
                    foliage2D.heightSegments = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Height Segments", "The number of rows the mesh has."), foliage2D.heightSegments), 1, 100);

                    Type utility = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor");
                    if (utility != null)
                    {
                        PropertyInfo sortingLayerNames = utility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                        if (sortingLayerNames != null)
                        {
                            string[] layerNames = sortingLayerNames.GetValue(null, null) as string[];
                            string currName     = foliage2D.GetComponent <Renderer>().sortingLayerName == "" ? "Default" : foliage2D.GetComponent <Renderer>().sortingLayerName;
                            int nameID          = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(layerNames, currName), layerNames);

                            foliage2D.GetComponent <Renderer>().sortingLayerName = layerNames[nameID];
                        }
                        else
                        {
                            foliage2D.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", foliage2D.GetComponent <Renderer>().sortingLayerID);
                        }
                    }
                    else
                    {
                        foliage2D.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", foliage2D.GetComponent <Renderer>().sortingLayerID);
                    }
                    foliage2D.GetComponent <Renderer>().sortingOrder = EditorGUILayout.IntField("Order in Layer", foliage2D.GetComponent <Renderer>().sortingOrder);
                });
            }
            EditorGUI.indentLevel = 0;

            if (GUILayout.Button("Rebuild Mesh"))
            {
                foliage2D.RebuildMesh();
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
                foliage2D.RebuildMesh();
            }

            if (Event.current.type == EventType.ValidateCommand)
            {
                switch (Event.current.commandName)
                {
                case "UndoRedoPerformed":
                    foliage2D.RebuildMesh();
                    break;
                }
            }
        }