예제 #1
0
 public void OverrideBookmark(LocationSystem locationSystem)
 {
     if (locationSystem != null)
     {
         GaiaUtils.CopyFields(GetCurrentLocation(locationSystem), m_bookmarkedSettings[locationSystem.m_selectedBookmark]);
     }
 }
예제 #2
0
        public void OnGUI()
        {
            //Initialization
            m_editorUtils.Initialize(); // Do not remove this!
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height));

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box)
                {
                    normal    = { textColor = GUI.skin.label.normal.textColor },
                    fontStyle = FontStyle.Bold,
                    alignment = TextAnchor.UpperLeft
                };
            }

            if (m_profile == null)
            {
                m_profile = GetLocationSystem();
            }

            m_editorUtils.Panel("GlobalSettings", GlobalPanel, true);

            EditorGUILayout.EndScrollView();
        }
예제 #3
0
        /// <summary>
        /// Removes the location system
        /// </summary>
        public static void RemoveLocationSystem()
        {
            LocationSystem system = GameObject.FindObjectOfType <LocationSystem>();

            if (system != null)
            {
                GameObject.DestroyImmediate(system);
            }
        }
예제 #4
0
        //Controller Setup
        /// <summary>
        /// Sets the current controller type
        /// </summary>
        /// <param name="type"></param>
        public static void SetCurrentControllerType(GaiaConstants.EnvironmentControllerType type)
        {
            LocationSystem system = FindObjectOfType <LocationSystem>();

            if (system != null)
            {
                if (system.m_locationProfile != null)
                {
                    system.m_locationProfile.m_currentControllerType = type;
                }
            }
        }
예제 #5
0
        public void RemoveBookmark(int index, LocationSystem locationSystem)
        {
            if (locationSystem.m_selectedBookmark == m_bookmarkedLocationNames.Count - 1)
            {
                locationSystem.m_selectedBookmark--;
            }
            m_bookmarkedLocationNames.RemoveAt(index);
            m_bookmarkedSettings.RemoveAt(index);

#if UNITY_EDITOR
            EditorUtility.SetDirty(locationSystem);
#endif
        }
예제 #6
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);
        }
예제 #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);
                    }
                }
            }
        }
예제 #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;
                }
            }
        }
예제 #9
0
        public void AddNewBookmark(LocationSystem locationSystem, string overrideName = null)
        {
            bool addBookmark = true;

            for (int i = 0; i < m_bookmarkedLocationNames.Count; i++)
            {
                if (overrideName != null)
                {
                    if (m_bookmarkedLocationNames[i] == overrideName)
                    {
                        addBookmark = false;
                    }
                }
                else
                {
                    if (m_bookmarkedLocationNames[i] == locationSystem.m_bookmarkName)
                    {
                        addBookmark = false;
                    }
                }
            }

            if (addBookmark)
            {
                if (overrideName != null)
                {
                    m_bookmarkedLocationNames.Add(overrideName);
                }
                else
                {
                    m_bookmarkedLocationNames.Add(locationSystem.m_bookmarkName);
                }

                m_bookmarkedSettings.Add(GetCurrentLocation(locationSystem));

                #if UNITY_EDITOR
                EditorUtility.SetDirty(locationSystem);
                #endif
            }
            else
            {
                Debug.LogWarning("Location name " + locationSystem.m_bookmarkName + " already exists please change the name then add bookmark again.");
            }
        }
예제 #10
0
        /// <summary>
        /// Adds the system to the scene and sets it up
        /// </summary>
        /// <returns></returns>
        public static LocationSystem AddLocationSystem()
        {
            LocationSystem system  = null;
            GameObject     mainCam = GameObject.Find("Main Camera");

            if (mainCam != null)
            {
                system = mainCam.gameObject.GetComponent <LocationSystem>();
                if (system == null)
                {
                    system          = mainCam.gameObject.AddComponent <LocationSystem>();
                    system.m_camera = mainCam.transform;
                }
            }
            else
            {
                mainCam = GameObject.Find("Camera");
                if (mainCam != null)
                {
                    system = mainCam.gameObject.GetComponent <LocationSystem>();
                    if (system == null)
                    {
                        system          = mainCam.gameObject.AddComponent <LocationSystem>();
                        system.m_camera = mainCam.transform;
                    }
                }
                else
                {
                    mainCam = GameObject.Find("FlyCam");
                    if (mainCam != null)
                    {
                        system = mainCam.gameObject.GetComponent <LocationSystem>();
                        if (system == null)
                        {
                            system          = mainCam.gameObject.AddComponent <LocationSystem>();
                            system.m_camera = mainCam.transform;
                        }
                    }
                    else
                    {
                        mainCam = GameObject.Find("FirstPersonCharacter");
                        if (mainCam != null)
                        {
                            system = mainCam.gameObject.GetComponent <LocationSystem>();
                            if (system == null)
                            {
                                system          = mainCam.gameObject.AddComponent <LocationSystem>();
                                system.m_camera = mainCam.transform;
                            }
                        }
                        else
                        {
                            mainCam = GameObject.FindGameObjectWithTag("MainCamera");
                            if (mainCam != null)
                            {
                                system = mainCam.gameObject.GetComponent <LocationSystem>();
                                if (system == null)
                                {
                                    system          = mainCam.gameObject.AddComponent <LocationSystem>();
                                    system.m_camera = mainCam.transform;
                                }
                            }
                        }
                    }
                }
            }
            GameObject firstPersonController = GameObject.Find("FPSController");

            if (firstPersonController != null)
            {
                if (system != null)
                {
                    system.m_player = firstPersonController.transform;
                    return(system);
                }
            }
            GameObject thirdPersonController = GameObject.Find("ThirdPersonController");

            if (thirdPersonController != null)
            {
                if (system != null)
                {
                    system.m_player = thirdPersonController.transform;
                    return(system);
                }
            }
            GameObject fpsController = GameObject.Find("Player");

            if (fpsController != null)
            {
                if (system != null)
                {
                    system.m_player = fpsController.transform;
                    return(system);
                }
            }

            return(null);
        }
예제 #11
0
        private static LocationSystem GetLocationSystem()
        {
            LocationSystem locationSystem = FindObjectOfType <LocationSystem>();

            return(locationSystem);
        }
예제 #12
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
                    }
                }
            }
        }