Exemple #1
0
        public static void FinalizePlayerObjectEditor(GameObject playerObj, GaiaSettings gaiaSettings)
        {
            if (playerObj != null)
            {
                playerObj.transform.SetParent(GaiaUtils.GetPlayerObject().transform);
                #if UNITY_EDITOR
                //Adjust the scene view to see the camera
                if (SceneView.lastActiveSceneView != null)
                {
                    if (gaiaSettings.m_focusPlayerOnSetup)
                    {
                        SceneView.lastActiveSceneView.LookAtDirect(playerObj.transform.position, playerObj.transform.rotation);
                    }
                }
                #endif
            }

            GaiaSessionManager session = GaiaSessionManager.GetSessionManager();
            if (session != null)
            {
                if (session.m_session != null)
                {
                    if (playerObj.transform.position.y < session.m_session.m_seaLevel)
                    {
                        playerObj.transform.position = new Vector3(playerObj.transform.position.x, session.m_session.m_seaLevel + 5f, playerObj.transform.position.z);
                    }
                }
            }

#if GAIA_PRO_PRESENT
            //Add the simple terrain culling script, useful in any case
            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled = true;
            }
#endif

            bool dynamicLoadedTerrains = GaiaUtils.HasDynamicLoadedTerrains();
            if (dynamicLoadedTerrains)
            {
#if GAIA_PRO_PRESENT
                TerrainLoader loader = playerObj.GetComponent <TerrainLoader>();
                if (loader == null)
                {
                    loader = playerObj.AddComponent <TerrainLoader>();
                }
                loader.LoadMode = LoadMode.RuntimeAlways;
                float tileSize = 512;
                if (TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize > 0)
                {
                    tileSize = TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize;
                }
                float size = tileSize * 1.25f * 2f;
                loader.m_loadingBoundsRegular  = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size));
                loader.m_loadingBoundsImpostor = new BoundsDouble(playerObj.transform.position, new Vector3(size * 3f, size * 3f, size * 3f));
                loader.m_loadingBoundsCollider = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size));
#endif
            }
        }
Exemple #2
0
        /// <summary>
        /// Apply on disable
        /// </summary>
        private void OnDisable()
        {
            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                GaiaGlobal.Instance.SceneProfile.m_depthOfFieldFocusDistance = m_actualFocusDistance;
            }

            SetEditorDepthOfFieldSettings();
        }
Exemple #3
0
        public void UpdateCulling(GaiaSettings gaiaSettings)
        {
            if (!GaiaUtils.CheckIfSceneProfileExists())
            {
                return;
            }
            if (GaiaGlobal.Instance.m_mainCamera == null)
            {
                GaiaGlobal.Instance.m_mainCamera = GaiaUtils.GetCamera();
            }

            float farClipPlane = 2000f;

            if (GaiaGlobal.Instance.m_mainCamera != null)
            {
                farClipPlane = GaiaGlobal.Instance.m_mainCamera.farClipPlane;
            }

            if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null)
            {
                GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }

            Terrain terrain = TerrainHelper.GetActiveTerrain();

            //Objects
            m_layerDistances = new float[32];
            for (int i = 0; i < m_layerDistances.Length; i++)
            {
                string layerName = LayerMask.LayerToName(i);
                switch (layerName)
                {
                case "Default":
                case "Water":
                case "PW_VFX":
                    m_layerDistances[i] = 0f;
                    break;

                case "PW_Object_Small":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 5f);
                    break;

                case "PW_Object_Medium":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 3f);
                    break;

                case "PW_Object_Large":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment);
                    break;

                default:
                    m_layerDistances[i] = 0f;
                    break;
                }
            }
        }
Exemple #4
0
        private void Initilize()
        {
            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                m_needUpdating = GaiaGlobal.Instance.SceneProfile.m_enableReflections;
            }

            if (Player == null)
            {
                Player = GetPlayer();
            }
        }
Exemple #5
0
        public static LocationBookmarkSettings GetCurrentLocation(LocationSystem locationSystem)
        {
            LocationBookmarkSettings settings = new LocationBookmarkSettings();

            if (Application.isPlaying)
            {
                if (locationSystem.m_camera != null)
                {
                    settings.m_savedCameraPosition = locationSystem.m_camera.localPosition;
                    settings.m_savedCameraRotation = locationSystem.m_camera.localRotation;
                }

                if (locationSystem.m_player != null)
                {
                    settings.m_savedPlayerPosition = locationSystem.m_player.localPosition;
                    settings.m_savedPlayerRotation = locationSystem.m_player.localRotation;
                }

                if (GaiaUtils.CheckIfSceneProfileExists())
                {
                    settings.m_controllerUsed = GaiaGlobal.Instance.SceneProfile.m_controllerType.ToString();
                }
            }
            else
            {
#if UNITY_EDITOR
                if (SceneView.lastActiveSceneView != null)
                {
                    if (SceneView.lastActiveSceneView.camera != null)
                    {
                        settings.m_savedCameraPosition = SceneView.lastActiveSceneView.camera.transform.localPosition;
                        settings.m_savedCameraRotation = SceneView.lastActiveSceneView.camera.transform.localRotation;
                        settings.m_controllerUsed      = "Scene View (Editor)";
                    }
                }
#endif
            }

            if (SceneManager.GetActiveScene() != null)
            {
                settings.m_sceneName = SceneManager.GetActiveScene().name;
            }
            else
            {
                settings.m_sceneName = "Untitled (Recommend Saving Your Scene Then Override This Bookmark)";
            }

            return(settings);
        }
Exemple #6
0
 public void Execute()
 {
     if (Player != null)
     {
         bool checkValue = CheckPoint(ReflectionMaskerData.m_maskingTexture, Player.position, ReflectionMaskerData.m_minValue, ReflectionMaskerData.m_maxValue);
         if (DoesNeedUpdating(checkValue))
         {
             m_needUpdating = checkValue;
             if (GaiaUtils.CheckIfSceneProfileExists())
             {
                 ReflectionMaskerData.Process(GaiaGlobal.Instance.SceneProfile, checkValue);
             }
         }
     }
 }
Exemple #7
0
        private void GlobalPanel(bool helpEnabled)
        {
            if (Application.isPlaying)
            {
                if (GaiaUtils.CheckIfSceneProfileExists())
                {
                    if (m_profile.m_locationProfile.m_currentControllerType != GaiaGlobal.Instance.SceneProfile.m_controllerType)
                    {
                        EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("ControllerHasChanged"), MessageType.Warning);
                    }
                }
            }

            if (m_profile == null)
            {
                EditorGUILayout.HelpBox("Location manager allows you to track camera position at runtime and create bookmarks to load locations", MessageType.Info);
                if (m_editorUtils.Button("AddLocationManager"))
                {
                    m_profile = AddLocationSystem();
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();

                m_editorUtils.Panel("Setup", Setup);
                if (m_profile.m_locationProfile != null)
                {
                    GUI.enabled = true;
                }
                else
                {
                    GUI.enabled = false;
                }
                m_editorUtils.Panel("Controls", RuntimeControls);
                m_editorUtils.Panel("BookmarkSetup", BookmarkSetup, true);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(m_profile);
                    if (m_profile.m_locationProfile != null)
                    {
                        EditorUtility.SetDirty(m_profile.m_locationProfile);
                    }
                }
            }
        }
Exemple #8
0
        private void OnEnable()
        {
            m_profile = GetLocationSystem();

            if (m_editorUtils == null)
            {
                // Get editor utils for this
                m_editorUtils = PWApp.GetEditorUtils(this);
            }

            if (!Application.isPlaying)
            {
                if (GaiaUtils.CheckIfSceneProfileExists())
                {
                    m_profile.m_locationProfile.m_currentControllerType = GaiaGlobal.Instance.SceneProfile.m_controllerType;
                }
            }
        }
Exemple #9
0
 private void OnEnable()
 {
     if (!GaiaUtils.CheckIfSceneProfileExists())
     {
         return;
     }
     if (Application.isPlaying)
     {
         UpdateCullingDistances();
     }
     else
     {
         if (GaiaGlobal.Instance.SceneProfile.CullingProfile != null)
         {
             ApplySceneSetup(GaiaGlobal.Instance.SceneProfile.CullingProfile.m_applyToEditorCamera);
         }
     }
 }
Exemple #10
0
        public Transform GetPlayer()
        {
            Transform transform = null;

            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                if (GaiaGlobal.Instance.m_mainCamera != null)
                {
                    transform = GaiaGlobal.Instance.m_mainCamera.transform;
                }
            }

            if (transform == null)
            {
                transform = GaiaUtils.GetPlayerTransform();
            }

            return(transform);
        }
Exemple #11
0
        public static void FinalizePlayerObjectRuntime(GameObject playerObj)
        {
            GaiaSessionManager session = GaiaSessionManager.GetSessionManager();

            if (session != null)
            {
                if (session.m_session != null)
                {
                    if (playerObj.transform.position.y < session.m_session.m_seaLevel)
                    {
                        playerObj.transform.position = new Vector3(playerObj.transform.position.x, session.m_session.m_seaLevel + 5f, playerObj.transform.position.z);
                    }
                }
            }

#if GAIA_PRO_PRESENT
            //Add the simple terrain culling script, useful in any case
            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled = true;
            }
#endif

            bool dynamicLoadedTerrains = GaiaUtils.HasDynamicLoadedTerrains();
            if (dynamicLoadedTerrains)
            {
#if GAIA_PRO_PRESENT
                Terrain       terrain = TerrainHelper.GetActiveTerrain();
                TerrainLoader loader  = playerObj.GetComponent <TerrainLoader>();
                if (loader == null)
                {
                    loader = playerObj.AddComponent <TerrainLoader>();
                }
                loader.LoadMode = LoadMode.RuntimeAlways;
                float size = terrain.terrainData.size.x * 1.25f * 2f;
                loader.m_loadingBoundsRegular  = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size));
                loader.m_loadingBoundsImpostor = new BoundsDouble(playerObj.transform.position, new Vector3(size * 3f, size * 3f, size * 3f));
#endif
            }
        }
Exemple #12
0
        private void Start()
        {
            if (!GaiaUtils.CheckIfSceneProfileExists())
            {
                return;
            }

            m_camera      = GaiaGlobal.Instance.m_mainCamera;
            m_allTerrains = Terrain.activeTerrains;

            //Collect all Mesh Terrains that are present at startup
            List <MeshRenderer> tempMeshRenderers = new List <MeshRenderer>();

            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                Scene scene = SceneManager.GetSceneAt(i);
                foreach (GameObject go in scene.GetRootGameObjects())
                {
                    AddTerrainMeshRenderer(go, tempMeshRenderers);
                }
            }
            m_allTerrainMeshRenderers = tempMeshRenderers.ToArray();


            if (GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled)
            {
                SceneManager.sceneLoaded   -= OnSceneLoaded;
                SceneManager.sceneLoaded   += OnSceneLoaded;
                SceneManager.sceneUnloaded -= OnSceneUnLoaded;
                SceneManager.sceneUnloaded += OnSceneUnLoaded;
            }
            else
            {
                SceneManager.sceneLoaded   -= OnSceneLoaded;
                SceneManager.sceneUnloaded -= OnSceneUnLoaded;
            }

            UpdateCullingDistances();
        }
Exemple #13
0
        /// <summary>
        /// Do a raycast to update the focus target
        /// </summary>
        private void UpdateDofTrackingPoint()
        {
            switch (m_trackingType)
            {
            case GaiaConstants.DOFTrackingType.LeftMouseClick:
            {
                if (Input.GetMouseButton(0))
                {
                    Ray ray = m_sourceCamera.ScreenPointToRay(Input.mousePosition);
                    FocusOnRayCast(ray);
                }
                break;
            }

            case GaiaConstants.DOFTrackingType.RightMouseClick:
            {
                if (Input.GetMouseButton(1))
                {
                    Ray ray = m_sourceCamera.ScreenPointToRay(Input.mousePosition);
                    FocusOnRayCast(ray);
                }
                break;
            }

            case GaiaConstants.DOFTrackingType.FollowScreen:
            {
                Ray ray = new Ray(m_sourceCamera.transform.position, m_sourceCamera.transform.forward);
                FocusOnRayCast(ray);
                break;
            }

            case GaiaConstants.DOFTrackingType.FollowTarget:
            {
                m_dofTrackingPoint = m_targetObject.transform.position;
                break;
            }

            case GaiaConstants.DOFTrackingType.FixedOffset:
            {
                if (m_debug)
                {
                    m_debug = false;
                    Debug.Log("Debug mode is not available in Fixed Offset Tracking Mode. We have turned off Debug Mode for you.");
                }
#if UNITY_POST_PROCESSING_STACK_V2
                m_dof.focusDistance.value = m_focusOffset;
#endif
                break;
            }
            }

            if (m_debug)
            {
                if (!Vector3.Equals(m_dofTrackingPoint, Vector3.negativeInfinity) && (m_debugSphere == null || m_debugSphere.transform.position != m_dofTrackingPoint))
                {
                    if (m_debugSphere != null)
                    {
                        Destroy(m_debugSphere);
                    }
                    m_debugSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    Destroy(m_debugSphere.GetComponent <Collider>());
                    m_debugSphere.transform.position   = m_dofTrackingPoint;
                    m_debugSphere.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                }
            }

#if UNITY_POST_PROCESSING_STACK_V2
            if (m_trackingType != GaiaConstants.DOFTrackingType.FixedOffset)
            {
                SetNewDOFValue(m_dof.focusDistance.value);
            }
            m_actualFocusDistance = m_dof.focusDistance.value;
#endif
            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                GaiaGlobal.Instance.SceneProfile.m_depthOfFieldFocusDistance = m_actualFocusDistance;
            }
        }
Exemple #14
0
        public void LoadBookmark(LocationSystem locationSystem)
        {
            if (m_bookmarkedSettings.Count < 1)
            {
                return;
            }
            LocationBookmarkSettings settings = m_bookmarkedSettings[locationSystem.m_selectedBookmark];

            if (settings != null)
            {
                if (locationSystem.m_camera != null)
                {
                    if (Application.isPlaying)
                    {
                        if (GaiaUtils.CheckIfSceneProfileExists())
                        {
                            if (settings.m_controllerUsed == GaiaConstants.EnvironmentControllerType.FirstPerson.ToString())
                            {
                                switch (GaiaGlobal.Instance.SceneProfile.m_controllerType)
                                {
                                case GaiaConstants.EnvironmentControllerType.FirstPerson:
                                    CharacterController controller = FindObjectOfType <CharacterController>();
                                    if (controller != null)
                                    {
                                        controller.enabled = false;
                                        locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
                                        if (locationSystem.m_player != null)
                                        {
                                            locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
                                        }
                                        controller.enabled = true;
                                    }
                                    break;

                                case GaiaConstants.EnvironmentControllerType.Custom:
                                    locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
                                    if (locationSystem.m_player != null)
                                    {
                                        locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
                                    }
                                    break;

                                case GaiaConstants.EnvironmentControllerType.FlyingCamera:
                                    locationSystem.m_camera.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
                                    if (locationSystem.m_player != null)
                                    {
                                        locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
                                    }
                                    break;

                                case GaiaConstants.EnvironmentControllerType.ThirdPerson:
                                    locationSystem.m_camera.SetPositionAndRotation(new Vector3(0f, 100f, 0f), settings.m_savedCameraRotation);
                                    if (locationSystem.m_player != null)
                                    {
                                        locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
                                    }
                                    break;
                                }
                            }
                            else if (settings.m_controllerUsed == "Scene View (Editor)")
                            {
                                switch (GaiaGlobal.Instance.SceneProfile.m_controllerType)
                                {
                                case GaiaConstants.EnvironmentControllerType.FirstPerson:
                                    CharacterController controller = FindObjectOfType <CharacterController>();
                                    if (controller != null)
                                    {
                                        controller.enabled = false;
                                        if (locationSystem.m_player != null)
                                        {
                                            locationSystem.m_player.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
                                        }
                                        controller.enabled = true;
                                    }
                                    break;

                                case GaiaConstants.EnvironmentControllerType.Custom:
                                    if (locationSystem.m_player != null)
                                    {
                                        locationSystem.m_player.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
                                    }
                                    break;

                                case GaiaConstants.EnvironmentControllerType.FlyingCamera:
                                    locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
                                    if (locationSystem.m_player != null)
                                    {
                                        locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
                                    }
                                    break;

                                case GaiaConstants.EnvironmentControllerType.ThirdPerson:
                                    if (locationSystem.m_player != null)
                                    {
                                        locationSystem.m_player.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                locationSystem.m_camera.SetPositionAndRotation(settings.m_savedCameraPosition, settings.m_savedCameraRotation);
                                if (locationSystem.m_player != null)
                                {
                                    locationSystem.m_player.SetPositionAndRotation(settings.m_savedPlayerPosition, settings.m_savedPlayerRotation);
                                }
                            }
                        }
                    }
                    else
                    {
#if UNITY_EDITOR
                        if (SceneView.lastActiveSceneView != null)
                        {
                            if (SceneView.lastActiveSceneView.camera != null)
                            {
                                Camera    target = SceneView.lastActiveSceneView.camera;
                                Transform temp   = target.transform;
                                if (settings.m_controllerUsed == GaiaConstants.EnvironmentControllerType.FirstPerson.ToString())
                                {
                                    temp.position = settings.m_savedPlayerPosition;
                                    temp.rotation = settings.m_savedPlayerRotation;
                                }
                                else
                                {
                                    temp.position = settings.m_savedCameraPosition;
                                    temp.rotation = settings.m_savedCameraRotation;
                                }

                                SceneView.lastActiveSceneView.AlignViewToObject(temp);
                            }
                        }
#endif
                    }
                }
            }
        }
Exemple #15
0
        private void Update()
        {
            if (!Application.isPlaying)
            {
                return;
            }
            if (!GaiaUtils.CheckIfSceneProfileExists())
            {
                return;
            }

            if (!GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled || m_camera == null)
            {
                return;
            }


            Vector3 cameraForward      = m_camera.transform.forward;
            float   cameraViewDistance = m_camera.farClipPlane;

            m_cameraFOV = m_camera.fieldOfView;

            m_FOVCenter = new Vector3(cameraForward.x, cameraForward.z).normalized *cameraViewDistance;
            GeometryUtility.CalculateFrustumPlanes(m_camera, m_planes);
            if (GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled)
            {
                for (int i = 0; i < m_allTerrains.Length; i++)
                {
                    Terrain terrain = m_allTerrains[i];
                    if (terrain == null)
                    {
                        continue;
                    }
                    //Check needs to performed in world space, terrain bounds are in local space of the terrain
                    m_worldSpaceBounds        = terrain.terrainData.bounds;
                    m_worldSpaceBounds.center = new Vector3(m_worldSpaceBounds.center.x + terrain.transform.position.x, m_worldSpaceBounds.center.y + terrain.transform.position.y, m_worldSpaceBounds.center.z + terrain.transform.position.z);

                    if (GeometryUtility.TestPlanesAABB(m_planes, m_worldSpaceBounds))
                    {
                        terrain.drawHeightmap       = true;
                        terrain.drawTreesAndFoliage = true;

                        //Deactivate terrain GO entirely
                        //terrain.gameObject.SetActive(true);

                        //Activate object spawns
                        //Transform spawnsTransform = terrain.gameObject.transform.Find(GaiaConstants.defaultGOSpawnTarget);
                        //spawnsTransform.gameObject.SetActive(true);
                    }
                    else
                    {
                        terrain.drawHeightmap       = false;
                        terrain.drawTreesAndFoliage = false;

                        //Deactivate terrain GO entirely
                        //terrain.gameObject.SetActive(false);

                        //Deactivate object spawns
                        //Transform spawnsTransform = terrain.gameObject.transform.Find(GaiaConstants.defaultGOSpawnTarget);
                        //spawnsTransform.gameObject.SetActive(false);
                    }
                }
            }

            if (GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled)
            {
                for (int i = 0; i < m_allTerrainMeshRenderers.Length; i++)
                {
                    MeshRenderer mr = m_allTerrainMeshRenderers[i];
                    if (mr != null)
                    {
                        if (GeometryUtility.TestPlanesAABB(m_planes, mr.bounds))
                        {
                            mr.enabled = true;
                        }
                        else
                        {
                            mr.enabled = false;
                        }
                    }
                }
            }
        }
Exemple #16
0
        //Camera Culling
        public static void UpdateCullingDistances()
        {
            if (!GaiaUtils.CheckIfSceneProfileExists())
            {
                return;
            }

            if (GaiaGlobal.Instance.SceneProfile.CullingProfile == null)
            {
                return;
            }

#if GAIA_PRO_PRESENT
            if (ProceduralWorldsGlobalWeather.Instance != null)
            {
                if (ProceduralWorldsGlobalWeather.Instance.CheckIsNight())
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight = ProceduralWorldsGlobalWeather.Instance.m_moonLight;
                }
                else
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight = ProceduralWorldsGlobalWeather.Instance.m_sunLight;
                }
            }
            else
            {
                if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null)
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
                }
            }
#else
            if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null)
            {
                GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }
#endif

            //Make sure we have distances
            if (GaiaGlobal.Instance.SceneProfile.CullingProfile.m_layerDistances == null || GaiaGlobal.Instance.SceneProfile.CullingProfile.m_layerDistances.Length != 32)
            {
                return;
            }

            if (GaiaGlobal.Instance.SceneProfile.m_enableLayerCulling)
            {
                //Apply to main camera
                GaiaGlobal.Instance.m_mainCamera.layerCullDistances = GaiaGlobal.Instance.SceneProfile.CullingProfile.m_layerDistances;

                if (GaiaGlobal.Instance.SceneProfile.m_sunLight != null)
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight.layerShadowCullDistances = GaiaGlobal.Instance.SceneProfile.CullingProfile.m_shadowLayerDistances;
                }
            }
            else
            {
                float[] layerCulls = new float[32];
                for (int i = 0; i < layerCulls.Length; i++)
                {
                    layerCulls[i] = 0f;
                }

                //Apply to main camera
                GaiaGlobal.Instance.m_mainCamera.layerCullDistances = layerCulls;

                if (GaiaGlobal.Instance.SceneProfile.m_sunLight != null)
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight.layerShadowCullDistances = layerCulls;
                }
            }
        }
Exemple #17
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);
        }