示例#1
0
        public override void OnInspectorGUI()
        {
            //Get our spawner
            m_spawnerGroup = (SpawnerGroup)target;

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            //Setup the wrap style
            if (m_wrapStyle == null)
            {
                m_wrapStyle          = new GUIStyle(GUI.skin.label);
                m_wrapStyle.wordWrap = true;
            }

            //Fix up names if necessary
            m_spawnerGroup.FixNames();

            //Create a nice text intro
            GUILayout.BeginVertical("Spawner Group", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("A Spawner Group allows you to chain a set of spawners together. The command buttons you run will be run on all sub spawners. It may take a little while so be patient.", m_wrapStyle);
            GUILayout.EndVertical();

            //Disable if spawning
            if (m_spawnerGroup.m_updateCoroutine != null)
            {
                GUI.enabled = false;
            }

            DrawDefaultInspector();

            GUILayout.BeginVertical("Terrain Helper", m_boxStyle);
            GUILayout.Space(20);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button(GetLabel("Flatten")))
            {
                if (EditorUtility.DisplayDialog("Flatten Terrain tiles ?", "Are you sure you want to flatten all terrain tiles - this can not be undone ?", "Yes", "No"))
                {
                    TerrainHelper.Flatten();
                }
            }
            if (GUILayout.Button(GetLabel("Smooth")))
            {
                if (EditorUtility.DisplayDialog("Smooth Terrain tiles ?", "Are you sure you want to smooth all terrain tiles - this can not be undone ?", "Yes", "No"))
                {
                    TerrainHelper.Smooth(1);
                }
            }
            if (GUILayout.Button(GetLabel("Clear Trees")))
            {
                if (EditorUtility.DisplayDialog("Clear Terrain trees ?", "Are you sure you want to clear all terrain trees - this can not be undone ?", "Yes", "No"))
                {
                    //outdated
                    //TerrainHelper.ClearTrees();
                }
            }
            if (GUILayout.Button(GetLabel("Clear Details")))
            {
                if (EditorUtility.DisplayDialog("Clear Terrain details ?", "Are you sure you want to clear all terrain details - this can not be undone ?", "Yes", "No"))
                {
                    //outdated
                    //TerrainHelper.ClearDetails();
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(5);
            GUILayout.EndVertical();

            //Re-enable
            GUI.enabled = true;

            //Display progress
            if (m_spawnerGroup.m_updateCoroutine != null)
            {
                GUILayout.BeginVertical("Spawner Controller", m_boxStyle);
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(GetLabel("Cancel")))
                {
                    m_spawnerGroup.CancelSpawn();
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5);
                GUILayout.EndVertical();

                //Draw the various progress bars
                for (int idx = 0; idx < m_spawnerGroup.m_spawners.Count; idx++)
                {
                    //Display progress
                    if (m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress > 0f && m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress < 1f)
                    {
                        ProgressBar(string.Format("{0} ({1:0.0}%)", m_spawnerGroup.m_spawners[idx].m_name, m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress * 100f), m_spawnerGroup.m_spawners[idx].m_spawner.m_spawnProgress);
                    }
                }
            }
            else
            {
                GUILayout.BeginVertical("Spawner Controller", m_boxStyle);
                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(GetLabel("Reset")))
                {
                    m_spawnerGroup.ResetSpawner();
                }

                if (GUILayout.Button(GetLabel("Spawn")))
                {
                    //Check that they have a single selected terrain
                    if (Gaia.TerrainHelper.GetActiveTerrainCount() != 1)
                    {
                        EditorUtility.DisplayDialog("OOPS!", "You must have only one active terrain in order to use a Spawner Group. Please either add a terrain, or deactivate all but one terrain.", "OK");
                    }
                    else
                    {
                        m_spawnerGroup.RunSpawnerIteration();
                        StartEditorUpdates();
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5f);
                GUILayout.EndVertical();
            }
        }