예제 #1
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);
        }
예제 #2
0
        private void Update()
        {
            if (Application.isPlaying)
            {
                if (m_camera == null || m_locationProfile == null)
                {
                    return;
                }

                if (m_trackPlayer)
                {
                    m_locationProfile.SaveLocation(m_camera, m_player);
                }

                if (Input.GetKey(m_locationProfile.m_mainKey) && Input.GetKeyDown(m_locationProfile.m_prevBookmark))
                {
                    m_selectedBookmark--;
                    if (m_selectedBookmark < 0)
                    {
                        m_selectedBookmark = m_locationProfile.m_bookmarkedLocationNames.Count - 1;
                    }

                    m_locationProfile.LoadBookmark(this);
                }

                if (Input.GetKey(m_locationProfile.m_mainKey) && Input.GetKeyDown(m_locationProfile.m_nextBookmark))
                {
                    m_selectedBookmark++;
                    if (m_selectedBookmark > m_locationProfile.m_bookmarkedLocationNames.Count - 1)
                    {
                        m_selectedBookmark = 0;
                    }

                    m_locationProfile.LoadBookmark(this);
                }

                if (Input.GetKey(m_locationProfile.m_mainKey) && Input.GetKeyDown(m_locationProfile.m_addBookmarkKey))
                {
                    LocationBookmarkSettings settings = LocationSystemScriptableObject.GetCurrentLocation(this);
                    string name = "Bookmark " + " Position(" + settings.m_savedCameraPosition.x + ", " +
                                  settings.m_savedCameraPosition.y + ", " +
                                  settings.m_savedCameraPosition.z + ")";

                    m_locationProfile.AddNewBookmark(this, name);
                    m_selectedBookmark = m_locationProfile.m_bookmarkedLocationNames.Count - 1;
                    Debug.Log("New Bookmark: " + name);
                }
            }
        }
예제 #3
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
                    }
                }
            }
        }