Exemple #1
0
        private void initialize()
        {
            if (!eventSystemPrefab || !interactionManagerPrefab || !playerPrefab || !inputManagerPrefab || !saveLoadManagerPrefab || !menuPrefab)
            {
                Debug.LogError("FPECore:: Missing prefab for core component. Game will not function correctly. See Inspector for object '" + gameObject.name + "' to ensure all fields are populated correctly.");
            }

            Instantiate(eventSystemPrefab, null);
            Instantiate(interactionManagerPrefab, null);

            GameObject             player        = Instantiate(playerPrefab, null);
            FPEPlayerStartLocation startLocation = GameObject.FindObjectOfType <FPEPlayerStartLocation>();

            if (startLocation != null)
            {
                player.transform.position = startLocation.gameObject.transform.position;
                player.transform.rotation = startLocation.gameObject.transform.rotation;
            }
            else
            {
                Debug.LogWarning("FPECore:: No FPEPlayerStartLocation was found. Placing player at origin");
                player.transform.position = Vector3.zero;
                player.transform.rotation = Quaternion.identity;
            }

            Instantiate(inputManagerPrefab, null);
            Instantiate(saveLoadManagerPrefab, null);
            Instantiate(menuPrefab, null);

            FPEInteractionManagerScript.Instance.initialize();

            // Lastly, load game options
            FPESaveLoadManager.Instance.LoadGameOptions();
        }
Exemple #2
0
        /// <summary>
        /// Moves the player to the currently loaded scene's most appropriate starting position. If a
        /// new game (previous scene was not "real level" - less than firstLevelSceneBuildIndex), a
        /// FPEPlayerStartLocation is searched for. If not, a Doorway Entrance is searched for. If
        /// neither can be found, an error is printed and the player is placed at the world origin.
        /// </summary>
        private void movePlayerToSuitableEntranceOrStartPosition()
        {
            GameObject thePlayer = FPEPlayer.Instance.gameObject;

            // If previous scene was LESS than our first known real level, we assume this is a new game
            if (previousSceneIndex < firstLevelSceneBuildIndex)
            {
                FPEPlayerStartLocation startLocation = GameObject.FindObjectOfType <FPEPlayerStartLocation>();

                // Yield to start location if there is one present
                if (startLocation != null)
                {
                    thePlayer.transform.position = startLocation.gameObject.transform.position;
                    thePlayer.transform.rotation = startLocation.gameObject.transform.rotation;
                }
                else
                {
                    Debug.LogWarning("FPESaveLoadManager:: No FPEPlayerStartLocation was found in scene. Placing player at origin instead.");
                    thePlayer.transform.position = Vector3.zero;
                    thePlayer.transform.rotation = Quaternion.identity;
                }
            }
            // Otherwise, yield to the appropriate doorway.
            else
            {
                FPEDoorway[] doorways     = GameObject.FindObjectsOfType <FPEDoorway>();
                bool         foundDoorway = false;

                for (int d = 0; d < doorways.Length; d++)
                {
                    if (doorways[d].ConnectedSceneIndex == previousSceneIndex)
                    {
                        thePlayer.transform.position = doorways[d].DoorwayEntranceTransform.position;
                        thePlayer.transform.rotation = doorways[d].DoorwayEntranceTransform.rotation;
                        foundDoorway = true;
                        break;
                    }
                }

                if (foundDoorway == false)
                {
                    Debug.LogWarning("FPESaveLoadManager:: No FPEDoorway was found that matched connected scene '" + previousSceneIndex + "'. Placing player at origin instead.");
                    thePlayer.transform.position = Vector3.zero;
                    thePlayer.transform.rotation = Quaternion.identity;
                }
            }
        }
Exemple #3
0
        private void initialize()
        {
            if (!HUDPrefab || !eventSystemPrefab || !interactionManagerPrefab || !playerPrefab || !inputManagerPrefab || !saveLoadManagerPrefab || !menuPrefab)
            {
                Debug.LogError("FPECore:: Missing prefab for core component. Game will not function correctly. See Inspector for object '" + gameObject.name + "' to ensure all fields are populated correctly.");
            }

            Instantiate(eventSystemPrefab, null);

            Instantiate(HUDPrefab, null);
            Instantiate(interactionManagerPrefab, null);


            GameObject             player        = Instantiate(playerPrefab, null);
            FPEPlayerStartLocation startLocation = GameObject.FindObjectOfType <FPEPlayerStartLocation>();

            if (startLocation != null)
            {
                player.transform.position = startLocation.gameObject.transform.position;
                player.transform.rotation = startLocation.gameObject.transform.rotation;
            }
            else
            {
                Debug.LogWarning("FPECore:: No FPEPlayerStartLocation was found. Placing player at origin");
                player.transform.position = Vector3.zero;
                player.transform.rotation = Quaternion.identity;
            }

            Instantiate(inputManagerPrefab, null);
            Instantiate(saveLoadManagerPrefab, null);
            Instantiate(menuPrefab, null);

            FPEHUD.Instance.initialize();
            FPEInteractionManagerScript.Instance.initialize();

            // Lastly, load game options
            FPESaveLoadManager.Instance.LoadGameOptions();


            // Helper checks //

            // Check if we're in the 0th scene. If we are, and there is no FPEMainMenu object, this will cause issues with player controls. Print an error and exit play mode.
            if (GameObject.FindObjectOfType <FPEMainMenu>() == null && SceneManager.GetActiveScene().buildIndex == 0)
            {
                Debug.LogError("FPECore:: The scene '" + SceneManager.GetActiveScene().name + "' is at index 0, but index 0 is reserved for the Main Menu. This scene does not contain an FPEMainMenu object. You must add one or controls will not work as expected.");
            }
        }