コード例 #1
0
        /// <summary>
        /// Select or create a scanner
        /// </summary>
        public static GameObject CreateScanner()
        {
            GameObject gaiaObj    = GaiaUtils.GetGaiaGameObject();
            GameObject scannerObj = GameObject.Find("Scanner");

            if (scannerObj == null)
            {
                scannerObj = new GameObject("Scanner");
                scannerObj.transform.parent = gaiaObj.transform;
                GaiaSceneInfo sceneInfo = null;
                if (Terrain.activeTerrains.Length > 0)
                {
                    sceneInfo = GaiaSceneInfo.GetSceneInfo();
                }
                if (sceneInfo != null)
                {
                    Vector3 position = scannerObj.transform.position;
                    position.y = sceneInfo.m_seaLevel;
                    scannerObj.transform.position = position;
                }
                else
                {
                    scannerObj.transform.position = new Vector3(0f, 50f, 0f);
                }
                Scanner scanner = scannerObj.AddComponent <Scanner>();

                #if UNITY_EDITOR
                //Load the material to draw it
                string matPath = GaiaUtils.GetAssetPath("GaiaScannerMaterial.mat");
                if (!string.IsNullOrEmpty(matPath))
                {
                    scanner.m_previewMaterial = AssetDatabase.LoadAssetAtPath <Material>(matPath);
                }
                #endif
            }
            return(scannerObj);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            //Get our resource
            m_session = (GaiaSession)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;
            }

            //Set up the description wrap style
            if (m_descWrapStyle == null)
            {
                m_descWrapStyle          = new GUIStyle(GUI.skin.textArea);
                m_descWrapStyle.wordWrap = true;
            }

            //Create a nice text intro
            GUILayout.BeginVertical("Gaia Session", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("Contains the data used to backup, share and play back sessions. Use the session manager to view, edit or play back sessions.", m_wrapStyle);
            GUILayout.Space(4);
            GUILayout.EndVertical();

            //Make some space
            GUILayout.Space(4);

            //Wrap it up in a box
            GUILayout.BeginVertical(m_boxStyle);
            GUILayout.BeginVertical("Summary:", m_boxStyle);
            GUILayout.Space(20);

            //Display the basic details
            EditorGUILayout.LabelField("Name", m_session.m_name);
            EditorGUILayout.LabelField("Description", m_session.m_description, m_wrapStyle);
            EditorGUILayout.LabelField("Created", m_session.m_dateCreated);
            EditorGUILayout.LabelField("Dimensions", string.Format("w{0} d{1} h{2} meters", m_session.m_terrainWidth, m_session.m_terrainDepth, m_session.m_terrainHeight));
            EditorGUILayout.LabelField("Sea Level", string.Format("{0} meters", m_session.m_seaLevel));
            EditorGUILayout.LabelField("Locked", m_session.m_isLocked.ToString());

            Texture2D previewImage = m_session.m_previewImage;

            if (previewImage != null)
            {
                //Get aspect ratio and available space and display the image
                float width  = Screen.width - 43f;
                float height = previewImage.height * (width / previewImage.width);
                GUILayout.Label(previewImage, GUILayout.MaxWidth(width), GUILayout.MaxHeight(height));
            }

            GUILayout.EndVertical();

            //Iterate through the operations
            GUILayout.BeginVertical("Operations:", m_boxStyle);
            GUILayout.Space(20);

            if (m_session.m_operations.Count == 0)
            {
                GUILayout.Space(5);
                GUILayout.Label("No operations yet...");
                GUILayout.Space(5);
            }
            else
            {
                GaiaOperation op;
                EditorGUI.indentLevel++;
                for (int opIdx = 0; opIdx < m_session.m_operations.Count; opIdx++)
                {
                    op = m_session.m_operations[opIdx];

                    if (op.m_isActive)
                    {
                        op.m_isFoldedOut = EditorGUILayout.Foldout(op.m_isFoldedOut, op.m_description, true);
                    }
                    else
                    {
                        op.m_isFoldedOut = EditorGUILayout.Foldout(op.m_isFoldedOut, op.m_description + " [inactive]", true);
                    }

                    if (op.m_isFoldedOut)
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.LabelField("Description", op.m_description, m_wrapStyle);
                        EditorGUILayout.LabelField("Created", op.m_operationDateTime);
                        EditorGUILayout.LabelField("Active", op.m_isActive.ToString());
                        EditorGUI.indentLevel--;
                    }
                }
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            GUILayout.EndVertical();
            if (GUILayout.Button("Play Session"))
            {
                GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false, false);
                if (gsm == null)
                {
                    GameObject gaiaObj = GaiaUtils.GetGaiaGameObject();
                    GameObject mgrObj  = new GameObject("Session Manager");
                    gsm = mgrObj.AddComponent <GaiaSessionManager>();
                    mgrObj.transform.parent = gaiaObj.transform;
                }


                GaiaLighting.SetDefaultAmbientLight(GaiaUtils.GetGaiaSettings().m_gaiaLightingProfile);
                //make a copy of the session - otherwise there is the danger of conflicting with the old session data while playing back the session
                GaiaSession sessionCopy = Instantiate(m_session);
                sessionCopy.m_name = GaiaSessionManager.GetNewSessionName();
                sessionCopy.name   = sessionCopy.m_name;
                gsm.m_session      = sessionCopy;
                string path = GaiaDirectories.GetSessionDirectory();
                AssetDatabase.CreateAsset(sessionCopy, path + "/" + sessionCopy.m_name + ".asset");
                AssetDatabase.SaveAssets();
                GaiaSessionManager.PlaySession(sessionCopy);
            }

            if (GUILayout.Button("Open Session in Manager"))
            {
                GaiaSessionManager.LoadSession(m_session);
            }
        }
コード例 #3
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);
        }
コード例 #4
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);
        }