// ---------------------------------------------------------------------------------------------------------------------------
        // Draw ProceduralTree inspector GUI
        // ---------------------------------------------------------------------------------------------------------------------------

        public override void OnInspectorGUI()
        {
            UpdateNotifications.Update();

            var tree = (ProceduralTree)target;

            var pt = PrefabUtility.GetPrefabType(tree);

            if (pt != PrefabType.None && pt != PrefabType.DisconnectedPrefabInstance) // Prefabs are not dynamic
            {
                EditorGUILayout.HelpBox("Prefabs are static snapshots of a Procedural Tree. To edit tree parameters, select GameObject > Break Prefab Instance.", MessageType.Info);
                GUI.enabled = false;
                DrawDefaultInspector();
                return;
            }

            EditorGUILayout.HelpBox(tree.MeshInfo, MessageType.Info);

            DrawDefaultInspector();

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Rand Seed")) // Randomize tree seed
                {
                    UpdateNotifications.AddUsage();
                    Undo.RecordObject(tree, "Random seed " + tree.name);
                    tree.Seed = Random.Range(0, 65536);
                    tree.Update();
                }
                if (GUILayout.Button("Rand Tree")) // Randomize all tree parameters
                {
                    UpdateNotifications.AddUsage();
                    Undo.RecordObject(tree, "Random tree " + tree.name);
                    Undo.RecordObject(tree.Renderer, "Random tree material " + tree.name);
                    tree.Update();
                }
                if (GUILayout.Button("Help")) // Take the user to the help page
                {
                    UpdateNotifications.AddUsage();
                    Application.OpenURL("http://www.wasabimole.com/procedural-tree");
                }
                if (UpdateNotifications.HasNotification) // Draw '!' icon if there's a notification
                {
                    GUILayout.Label(iconGUIContent, iconGUIStyle, GUILayout.Width(25));
                    if (Event.current.type == EventType.MouseDown && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                    {
                        UpdateNotifications.AttendNotification();
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
Пример #2
0
        // ---------------------------------------------------------------------------------------------------------------------------
        // Draw ProceduralTree inspector GUI
        // ---------------------------------------------------------------------------------------------------------------------------

        public override void OnInspectorGUI()
        {
            UpdateNotifications.Update();

            var tree = (ProceduralTree)target;

            var pt = PrefabUtility.GetPrefabType(tree);

            if (pt != PrefabType.None && pt != PrefabType.DisconnectedPrefabInstance) // Prefabs are not dynamic
            {
                EditorGUILayout.HelpBox("Prefabs are static snapshots of a Procedural Tree. To edit tree parameters, select GameObject > Break Prefab Instance.", MessageType.Info);
                GUI.enabled = false;
                DrawDefaultInspector();
                return;
            }

            EditorGUILayout.HelpBox(tree.MeshInfo, MessageType.Info);

            DrawDefaultInspector();

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Rand Seed")) // Randomize tree seed
                {
                    UpdateNotifications.AddUsage();
                    Undo.RecordObject(tree, "Random seed " + tree.name);
                    tree.Seed = Random.Range(0, 65536);
                    tree.Update();
                }
                if (GUILayout.Button("Rand Tree")) // Randomize all tree parameters
                {
                    UpdateNotifications.AddUsage();
                    Undo.RecordObject(tree, "Random tree " + tree.name);
                    Undo.RecordObject(tree.Renderer, "Random tree material " + tree.name);
                    tree.Seed              = Random.Range(0, 65536);
                    tree.MaxNumVertices    = 1024 << Random.Range(1, 6);
                    tree.NumberOfSides     = NumSides[Random.Range(0, NumSides.Length)];
                    tree.BaseRadius        = Random.Range(0.25f, 4f);
                    tree.RadiusStep        = Random.Range(0.875f, 0.95f);
                    tree.MinimumRadius     = Random.Range(0.01f, 0.2f);
                    tree.BranchRoundness   = Random.value;
                    tree.SegmentLength     = Random.Range(0.25f, 0.75f);
                    tree.Twisting          = Random.Range(0f, 40f);
                    tree.BranchProbability = Random.Range(0f, 0.25f);
                    tree.Update();

                    // Randomize material only when tree has no material, or it's using one of the sample ones
                    if (tree.Renderer.sharedMaterial != null)
                    {
                        if (AssetDatabase.GetAssetPath(tree.Renderer.sharedMaterial).StartsWith(GetSampleMaterialsPath(tree)))
                        {
                            GetSampleMaterial(tree);
                        }
                    }
                    else
                    {
                        GetSampleMaterial(tree);
                    }
                }
                if (GUILayout.Button("Help")) // Take the user to the help page
                {
                    UpdateNotifications.AddUsage();
                    Application.OpenURL("http://www.wasabimole.com/procedural-tree");
                }
                if (UpdateNotifications.HasNotification) // Draw '!' icon if there's a notification
                {
                    GUILayout.Label(iconGUIContent, iconGUIStyle, GUILayout.Width(25));
                    if (Event.current.type == EventType.mouseDown && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                    {
                        UpdateNotifications.AttendNotification();
                    }
                }
            }
            GUILayout.EndHorizontal();
        }