Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            m_editorUtils.Initialize(); // Do not remove this!
            m_biomePreset = (BiomePreset)target;
            serializedObject.Update();

            m_editorUtils.Panel("BiomeSettings", DrawBiomeSettings, true);

            if (GUILayout.Button(m_editorUtils.GetContent("AddToScene")))
            {
                BiomeController newBiome = m_biomePreset.CreateBiome(true);
                Selection.activeGameObject = newBiome.gameObject;
            }
        }
Exemplo n.º 2
0
        private void DrawLoaders(bool helpEnabled)
        {
            bool originalGUIState = GUI.enabled;

            EditorGUIUtility.labelWidth = 20;
#if GAIA_PRO_PRESENT
            foreach (TerrainLoader terrainLoader in m_terrainLoaders)
            {
                if (terrainLoader != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(terrainLoader.name);
                    terrainLoader.LoadMode = (LoadMode)EditorGUILayout.EnumPopup(terrainLoader.LoadMode);
                    if (m_editorUtils.Button("SelectLoader", GUILayout.MaxWidth(100)))
                    {
                        Selection.activeGameObject = terrainLoader.gameObject;
                        EditorGUIUtility.PingObject(Selection.activeObject);

                        //Try to find out which kind of Gaia Tool that is, and open / highlight the terrain loading settings where appropiate
                        Stamper stamper = terrainLoader.gameObject.GetComponent <Stamper>();
                        if (stamper != null)
                        {
                            stamper.HighlightLoadingSettings();
                        }

                        BiomeController biomeController = terrainLoader.gameObject.GetComponent <BiomeController>();
                        if (biomeController != null)
                        {
                            biomeController.HighlightLoadingSettings();
                        }

                        Spawner spawner = terrainLoader.gameObject.GetComponent <Spawner>();
                        if (spawner != null)
                        {
                            spawner.HighlightLoadingSettings();
                        }

                        MaskMapExport maskMapExport = terrainLoader.gameObject.GetComponent <MaskMapExport>();
                        if (maskMapExport != null)
                        {
                            maskMapExport.HighlightLoadingSettings();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
#endif
            EditorGUIUtility.labelWidth = 0;
        }
Exemplo n.º 3
0
        public static void DrawListElement_AdvancedTab(Rect rect, AdvancedTabBiomeListEntry listEntry, EditorUtils m_editorUtils)
        {
            int oldIndent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;


            Rect labelRect = rect;

            //260 is the total width of the controls at the end of each row
            labelRect.width  = rect.width - 280;
            labelRect.height = EditorGUIUtility.singleLineHeight;

            EditorGUI.LabelField(labelRect, listEntry.m_biomePreset.name);

            EditorGUIUtility.AddCursorRect(labelRect, MouseCursor.Zoom);
            if (labelRect.Contains(Event.current.mousePosition) && Event.current.clickCount > 0)
            {
                Selection.activeObject = listEntry.m_biomePreset;
                EditorGUIUtility.PingObject(Selection.activeObject);
            }

            labelRect.x     = rect.width - 230;
            labelRect.width = 110f;

            EditorGUI.LabelField(labelRect, m_editorUtils.GetContent("SpawnerListAutoAssignPrototypes"));

            labelRect.x     = rect.width - 130f;
            labelRect.width = 20f;

            listEntry.m_autoAssignPrototypes = EditorGUI.Toggle(labelRect, listEntry.m_autoAssignPrototypes);

            labelRect.x     = rect.width - 80f;
            labelRect.width = 100f;
            if (GUI.Button(labelRect, m_editorUtils.GetContent("AdvancedTabAddBiome")))
            {
                BiomeController newBiome = listEntry.m_biomePreset.CreateBiome(listEntry.m_autoAssignPrototypes);
                Selection.activeGameObject = newBiome.gameObject;
            }


            EditorGUI.indentLevel = oldIndent;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draws the data fields for each operation
        /// </summary>
        /// <param name="op"></param>
        public static void DrawOperationFields(GaiaOperation op, EditorUtils editorUtils, GaiaSessionManager sessionManager, bool helpEnabled, int currentIndex)
        {
            //shared default fields first
            //op.m_isActive = m_editorUtils.Toggle("Active", op.m_isActive, helpEnabled);
            bool currentGUIState = GUI.enabled;

            GUI.enabled      = op.m_isActive;
            op.m_description = editorUtils.TextField("Description", op.m_description, helpEnabled);
            editorUtils.LabelField("DateTime", new GUIContent(op.m_operationDateTime), helpEnabled);
            EditorGUI.indentLevel++;
            op.m_terrainsFoldedOut = editorUtils.Foldout(op.m_terrainsFoldedOut, "AffectedTerrains", helpEnabled);

            if (op.m_terrainsFoldedOut)
            {
                foreach (string name in op.m_affectedTerrainNames)
                {
                    EditorGUILayout.LabelField(name);
                }
            }
            EditorGUI.indentLevel--;

            //type specific fields, switch by op type to draw additional fields suitable for the op type

            switch (op.m_operationType)
            {
            case GaiaOperation.OperationType.CreateWorld:
                editorUtils.LabelField("xTiles", new GUIContent(op.WorldCreationSettings.m_xTiles.ToString()), helpEnabled);
                editorUtils.LabelField("zTiles", new GUIContent(op.WorldCreationSettings.m_zTiles.ToString()), helpEnabled);
                editorUtils.LabelField("TileSize", new GUIContent(op.WorldCreationSettings.m_tileSize.ToString()), helpEnabled);
                break;

            case GaiaOperation.OperationType.Spawn:
                editorUtils.LabelField("NumberOfSpawners", new GUIContent(op.SpawnOperationSettings.m_spawnerSettingsList.Count.ToString()), helpEnabled);
                float size = (float)Mathd.Max(op.SpawnOperationSettings.m_spawnArea.size.x, op.SpawnOperationSettings.m_spawnArea.size.z);
                editorUtils.LabelField("SpawnSize", new GUIContent(size.ToString()), helpEnabled);
                break;
            }
            GUI.enabled = currentGUIState;
            //Button controls
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            if (editorUtils.Button("Delete"))
            {
                if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupDeleteTitle"), editorUtils.GetTextValue("PopupDeleteText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel")))
                {
                    try
                    {
                        if (!String.IsNullOrEmpty(op.scriptableObjectAssetGUID))
                        {
                            AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(op.scriptableObjectAssetGUID));
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError("Error while deleting one of the operation data files: " + ex.Message + " Stack Trace:" + ex.StackTrace);
                    }

                    sessionManager.RemoveOperation(currentIndex);
                    EditorGUIUtility.ExitGUI();
                }
            }
            GUI.enabled = op.m_isActive;
            if (editorUtils.Button("Play"))
            {
                if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupPlayTitle"), editorUtils.GetTextValue("PopupPlayText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel")))
                {
                    GaiaSessionManager.ExecuteOperation(op);
                    //Destroy all temporary tools used while executing
                    //not if it is a spawn operation since that is asynchronous
                    if (op.m_operationType != GaiaOperation.OperationType.Spawn)
                    {
                        GaiaSessionManager.DestroyTempSessionTools();
                    }
                }
            }
            GUI.enabled = currentGUIState;
            //EditorGUILayout.EndHorizontal();
            //EditorGUILayout.BeginHorizontal();
            //GUILayout.Space(20);
            if (editorUtils.Button("ViewData"))
            {
                switch (op.m_operationType)
                {
                case GaiaOperation.OperationType.CreateWorld:
                    Selection.activeObject = op.WorldCreationSettings;
                    break;

                case GaiaOperation.OperationType.Stamp:
                    Selection.activeObject = op.StamperSettings;
                    break;

                case GaiaOperation.OperationType.Spawn:
                    Selection.activeObject = op.SpawnOperationSettings;
                    break;

                case GaiaOperation.OperationType.FlattenTerrain:
                    Selection.activeObject = op.FlattenOperationSettings;
                    break;

                case GaiaOperation.OperationType.StampUndo:
                    Selection.activeObject = op.UndoRedoOperationSettings;
                    break;

                case GaiaOperation.OperationType.StampRedo:
                    Selection.activeObject = op.UndoRedoOperationSettings;
                    break;

                case GaiaOperation.OperationType.ClearSpawns:
                    Selection.activeObject = op.ClearOperationSettings;
                    break;

                case GaiaOperation.OperationType.RemoveNonBiomeResources:
                    Selection.activeObject = op.RemoveNonBiomeResourcesSettings;
                    break;

                case GaiaOperation.OperationType.MaskMapExport:
                    Selection.activeObject = op.ExportMaskMapOperationSettings;
                    break;
                }

                EditorGUIUtility.PingObject(Selection.activeObject);
            }
            switch (op.m_operationType)
            {
            case GaiaOperation.OperationType.Stamp:
                if (editorUtils.Button("PreviewInStamper"))
                {
                    Stamper stamper = GaiaSessionManager.GetOrCreateSessionStamper();
                    stamper.LoadSettings(op.StamperSettings);
#if GAIA_PRO_PRESENT
                    if (GaiaUtils.HasDynamicLoadedTerrains())
                    {
                        //We got placeholders, activate terrain loading
                        stamper.m_loadTerrainMode = LoadMode.EditorSelected;
                    }
#endif
                    Selection.activeObject = stamper.gameObject;
                }

                break;

            case GaiaOperation.OperationType.Spawn:
                if (editorUtils.Button("PreviewInSpawner"))
                {
                    BiomeController bmc         = null;
                    List <Spawner>  spawnerList = null;
                    Selection.activeObject = GaiaSessionManager.GetOrCreateSessionSpawners(op.SpawnOperationSettings, ref bmc, ref spawnerList);
                }

                break;

            case GaiaOperation.OperationType.MaskMapExport:
#if GAIA_PRO_PRESENT
                if (editorUtils.Button("PreviewInExport"))
                {
                    MaskMapExport mme = null;
                    Selection.activeObject = GaiaSessionManager.GetOrCreateMaskMapExporter(op.ExportMaskMapOperationSettings.m_maskMapExportSettings, ref mme);
                }
#endif
                break;
            }

            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 5
0
        public BiomeController CreateBiome(bool autoAssignPrototypes)
        {
            int totalSteps  = m_spawnerPresetList.Count;
            int currentStep = 0;

#if !UNITY_POST_PROCESSING_STACK_V2
            //Workaround to disable warnings for "unused" field m_postProcessingProfileGUID
            //This is just a "harmless" piece of code to make the compiler think the field is in use
            if (m_postProcessingProfileGUID == "")
            {
                currentStep = 0;
            }
#endif

            GaiaSessionManager sessionManager = GaiaSessionManager.GetSessionManager();
            Transform          gaiaTransform  = GaiaUtils.GetGaiaGameObject().transform;
            GameObject         newGO          = new GameObject();
            newGO.name             = this.name + " Biome";
            newGO.transform.parent = gaiaTransform;

            BiomeController biomeController = newGO.AddComponent <BiomeController>();

            RefreshSpawnerListEntries();

            //Track created spawners
            List <Spawner> createdSpawners = new List <Spawner>();
            foreach (BiomeSpawnerListEntry spawnerListEntry in m_spawnerPresetList)
            {
                if (spawnerListEntry != null)
                {
                    if (spawnerListEntry.m_spawnerSettings != null)
                    {
                        createdSpawners.Add(spawnerListEntry.m_spawnerSettings.CreateSpawner(false, biomeController.transform));
                        //GaiaUtils.DisplayProgressBarNoEditor("Creating Tools", "Creating Biome " + this.name, ++currentStep / totalSteps);
                        if (ProgressBar.Show(ProgressBarPriority.CreateBiomeTools, "Creating Biome", "Creating Tools", ++currentStep, totalSteps, false, true))
                        {
                            break;
                        }
                    }
                }
            }
            if (createdSpawners.Count > 0)
            {
                biomeController.m_settings.m_range = createdSpawners[0].m_settings.m_spawnRange;
            }

            for (int i = 0; i < createdSpawners.Count; i++)
            {
                Spawner spawner = createdSpawners[i];
                biomeController.m_autoSpawners.Add(new AutoSpawner()
                {
                    isActive = m_spawnerPresetList[i].m_isActiveInBiome, status = AutoSpawnerStatus.Initial, spawner = spawner
                });
            }
            if (autoAssignPrototypes)
            {
                //prepare resource prototype arrays once, so the same prototypes can be added to all the tiles.
                TerrainLayer[]    terrainLayers  = new TerrainLayer[0];
                DetailPrototype[] terrainDetails = new DetailPrototype[0];
                TreePrototype[]   terrainTrees   = new TreePrototype[0];
                GaiaDefaults.GetPrototypes(m_spawnerPresetList.Where(x => x.m_autoAssignPrototypes == true).ToList(), ref terrainLayers, ref terrainDetails, ref terrainTrees, Terrain.activeTerrain);

                foreach (Terrain t in Terrain.activeTerrains)
                {
                    GaiaDefaults.ApplyPrototypesToTerrain(t, terrainLayers, terrainDetails, terrainTrees);
                }
            }

            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                GaiaGlobal.Instance.SceneProfile.CullingProfile = GaiaSceneCullingProfile;
            }


#if UNITY_POST_PROCESSING_STACK_V2
            biomeController.m_postProcessProfile = postProcessProfile;
#endif
            ProgressBar.Clear(ProgressBarPriority.CreateBiomeTools);

            return(biomeController);
        }