Пример #1
0
        public override void OnInspectorGUI()
        {
            //Get our resource
            GaiaDefaults defaults = (GaiaDefaults)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;
            }

            //Create a nice text intro
            GUILayout.BeginVertical("Gaia Defaults", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("These defaults will be used by Gaia when creating new terrains, and new resources files.", m_wrapStyle);
            if (defaults.m_detailDistance > 250)
            {
                EditorGUILayout.HelpBox("The current detail distance exceeds the maximum possible range in Unity. Gaia will add an overwrite script to the terrains to allow for additional detail distance.", MessageType.Info);
            }
            GUILayout.EndVertical();

            DrawDefaultInspector();
        }
Пример #2
0
        public void OnWorldMapCreate()
        {
            m_worldMapTerrain = TerrainHelper.GetWorldMapTerrain();
            GaiaSettings gaiaSettings    = GaiaUtils.GetGaiaSettings();
            GaiaDefaults currentDefaults = gaiaSettings.m_currentDefaults;

            TerrainLoaderManager.Instance.TerrainSceneStorage.m_hasWorldMap = true;

            float worldheightmapRes = m_worldMapTerrain.terrainData.heightmapResolution / m_worldMapTerrain.terrainData.size.x;

            BoundsDouble bounds = new BoundsDouble();

            TerrainHelper.GetTerrainBounds(ref bounds);
            if (bounds.size.x > 0)
            {
                TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize            = (float)m_currentWorldCreationSettings.m_tileSize / (float)bounds.size.x;
                TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMapRelativeHeightmapPixels = (((float)bounds.size.x / m_localTileSize) * m_localHeightmapRes / m_localHeightmapRes);
            }
            else
            {
                //no bounds size means no real terrains (yet) - set these parameters according to the current settings/defaults then
                TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize            = (float)m_currentWorldCreationSettings.m_tileSize / (gaiaSettings.m_tilesX * currentDefaults.m_terrainSize);
                TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMapRelativeHeightmapPixels = ((gaiaSettings.m_tilesX * currentDefaults.m_terrainSize) / currentDefaults.m_terrainSize) * currentDefaults.m_heightmapResolution / currentDefaults.m_heightmapResolution;
            }
            SyncLocalMapToWorldMap();
            ShowWorldMapStampSpawner();
            GaiaSessionManager.OnWorldCreated -= OnWorldMapCreate;
        }
Пример #3
0
        public override void OnInspectorGUI()
        {
            //Get our resource
            GaiaDefaults defaults = (GaiaDefaults)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;
            }

            //Create a nice text intro
            GUILayout.BeginVertical("Gaia Defaults", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("These defaults will be used by Gaia when creating new terrains, and new resources files.", m_wrapStyle);
            GUILayout.EndVertical();

            //Check for and fix any issues with the settings in the editor
            string defaultIssues = defaults.GetAndFixDefaults();

            if (!string.IsNullOrEmpty(defaultIssues))
            {
                Debug.LogWarning(defaultIssues);
            }

            DrawDefaultInspector();
        }
Пример #4
0
        public Spawner CreateSpawner(bool autoAddResources = false, Transform targetTransform = null)
        {
            //Find or create gaia
            GameObject gaiaObj    = GaiaUtils.GetGaiaGameObject();
            GameObject spawnerObj = new GameObject(this.name);

            spawnerObj.AddComponent <Spawner>();
            if (targetTransform != null)
            {
                spawnerObj.transform.parent = targetTransform;
            }
            else
            {
                spawnerObj.transform.parent = gaiaObj.transform;
            }

            Spawner spawner = spawnerObj.GetComponent <Spawner>();

            spawner.LoadSettings(this);
            //spawner.m_settings.m_resources = (GaiaResource)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(this.m_resourcesGUID), typeof(GaiaResource));
            if (autoAddResources)
            {
                TerrainLayer[]    terrainLayers  = new TerrainLayer[0];
                DetailPrototype[] terrainDetails = new DetailPrototype[0];
                TreePrototype[]   terrainTrees   = new TreePrototype[0];
                GaiaDefaults.GetPrototypes(new List <BiomeSpawnerListEntry>()
                {
                    new BiomeSpawnerListEntry()
                    {
                        m_spawnerSettings = this, m_autoAssignPrototypes = true
                    }
                }, ref terrainLayers, ref terrainDetails, ref terrainTrees, Terrain.activeTerrain);

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

            //We need to check the texture prototypes in this spawner against the already created terrain layers for this session
            //- otherwise the spawner will not know about those in subsequent spawns and might create unneccessary additional layers

            //Get a list of all exisiting Terrain Layers for this session
            string path = GaiaDirectories.GetTerrainLayerPath();

#if UNITY_EDITOR
            AssetDatabase.ImportAsset(path);
            if (Directory.Exists(path))
            {
                string[] allLayerGuids = AssetDatabase.FindAssets("t:TerrainLayer", new string[1] {
                    path
                });
                List <TerrainLayer> existingTerrainLayers = new List <TerrainLayer>();
                foreach (string guid in allLayerGuids)
                {
                    try
                    {
                        TerrainLayer layer = (TerrainLayer)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(TerrainLayer));
                        if (layer != null)
                        {
                            existingTerrainLayers.Add(layer);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "")
                        {
                        }
                    }
                }
                foreach (SpawnRule sr in spawner.m_settings.m_spawnerRules)
                {
                    if (sr.m_resourceType == SpawnerResourceType.TerrainTexture)
                    {
                        ResourceProtoTexture protoTexture = spawner.m_settings.m_resources.m_texturePrototypes[sr.m_resourceIdx];
                        //if a terrainLayer with these properties exist we can assume it fits to the given spawn rule
                        TerrainLayer terrainLayer = existingTerrainLayers.FirstOrDefault(x => x.diffuseTexture == protoTexture.m_texture &&
                                                                                         x.normalMapTexture == protoTexture.m_normal &&
                                                                                         x.tileOffset == new Vector2(protoTexture.m_offsetX, protoTexture.m_offsetY) &&
                                                                                         x.tileSize == new Vector2(protoTexture.m_sizeX, protoTexture.m_sizeY)
                                                                                         );
                        if (terrainLayer != null)
                        {
                            protoTexture.m_LayerGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(terrainLayer));
                        }
                    }
                }
            }
#endif


            foreach (SpawnRule rule in spawner.m_settings.m_spawnerRules)
            {
                rule.m_spawnedInstances = 0;
            }

            if (Terrain.activeTerrains.Where(x => !TerrainHelper.IsWorldMapTerrain(x)).Count() > 0)
            {
                spawner.FitToAllTerrains();
            }
            //else
            //{
            //    spawner.FitToTerrain();
            //}
            return(spawner);
        }
Пример #5
0
        public void CreateWorldMapTerrain()
        {
            //Remove old world map terrain, if any
            Terrain oldWMTerrain = TerrainHelper.GetWorldMapTerrain();

            if (oldWMTerrain != null)
            {
#if UNITY_EDITOR
                if (EditorUtility.DisplayDialog("Delete old world map?", "You are about to create a new world map in this scene. This will delete the existing world map and the stamp tokens on it. This will only affect the small world map terrain, the actual full scene terrain tiles will not be removed. Continue?", "Continue", "Cancel"))
                {
                    DestroyImmediate(oldWMTerrain.gameObject);
                }
                else
                {
                    return;
                }
#else
                Destroy(oldWMTerrain.gameObject);
#endif
            }

            GaiaSettings       gaiaSettings    = GaiaUtils.GetGaiaSettings();
            GaiaDefaults       currentDefaults = gaiaSettings.m_currentDefaults;
            GaiaSessionManager gsm             = GaiaSessionManager.GetSessionManager();

            //Collect some info from the existing world, if any.

            //We need the average height from the terrains to create the height of the worldmap accordingly in scale
            double averageHeight = currentDefaults.m_terrainHeight;
            //We need the heightmap resolution and terrain size stored in the session
            //To properly scale between world map and local map even when one of the two is not loaded at the moment

            int count = 0;

            foreach (Terrain t in Terrain.activeTerrains)
            {
                averageHeight += t.terrainData.size.y;
                if (!TerrainHelper.IsWorldMapTerrain(t))
                {
                    m_localHeightmapRes = t.terrainData.heightmapResolution;
                    m_localTileSize     = t.terrainData.size.x;
                }

                count++;
            }
            //}
            //only calculate an average if there is at least one placeholder or terrain
            if (count > 0)
            {
                averageHeight /= count;
            }


            BoundsDouble bounds = new BoundsDouble();
            TerrainHelper.GetTerrainBounds(ref bounds);
            //Collect the new world settings for world creation
            WorldCreationSettings worldCreationSettings = ScriptableObject.CreateInstance <WorldCreationSettings>();
            worldCreationSettings.m_xTiles                = 1;
            worldCreationSettings.m_zTiles                = 1;
            worldCreationSettings.m_tileSize              = (count > 0) ? Mathd.RoundToInt(bounds.size.x) : gaiaSettings.m_tilesX * currentDefaults.m_terrainSize;
            worldCreationSettings.m_tileHeight            = currentDefaults.m_terrainHeight;
            worldCreationSettings.m_createInScene         = false;
            worldCreationSettings.m_autoUnloadScenes      = false;
            worldCreationSettings.m_applyFloatingPointFix = false;
            worldCreationSettings.m_applyFloatingPointFix = false;
            worldCreationSettings.m_centerOffset          = Vector3.zero; //(count > 0) ? new Vector2Double(bounds.center.x + bounds.extents.x + worldCreationSettings.m_tileSize, bounds.center.z) : Vector2Double.zero;
            worldCreationSettings.m_isWorldMap            = true;
            //clone defaults so we can inject our custom heightmap resolution for the worldmap
            GaiaDefaults clonedDefaults = Instantiate(currentDefaults);
            clonedDefaults.m_heightmapResolution = (int)m_heightmapResolution;

            worldCreationSettings.m_gaiaDefaults = clonedDefaults;

            m_currentWorldCreationSettings     = worldCreationSettings;
            GaiaSessionManager.OnWorldCreated -= OnWorldMapCreate;
            GaiaSessionManager.OnWorldCreated += OnWorldMapCreate;
            GaiaSessionManager.CreateWorld(worldCreationSettings);
        }
Пример #6
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);
        }