示例#1
0
    public void ChangeScene(int sceneNumber, bool saveRoomData)
    {
        LevelStorage levelStorage = this.GetComponent <LevelStorage>();

        if (saveRoomData)
        {
            levelStorage.StoreCurrentLevelData();
            previousScene = Application.loadedLevel;
        }

        StateHandler stateHandler = this.GetComponent <StateHandler>();

        stateHandler.gameState = GameState.Normal;

        Application.LoadLevel(sceneNumber);
    }
示例#2
0
    public void SaveGame(int slot)
    {
                #if !UNITY_WEBPLAYER
        if (!HasAutoSave() || slot == -1)
        {
            slot++;
        }

        levelStorage.StoreCurrentLevelData();

        saveData = new SaveData();

        Player           player           = GameObject.FindWithTag(Tags.player).GetComponent <Player>();
        PlayerInput      playerInput      = GameObject.FindWithTag(Tags.gameEngine).GetComponent <PlayerInput>();
        MainCamera       mainCamera       = GameObject.FindWithTag(Tags.mainCamera).GetComponent <MainCamera>();
        RuntimeInventory runtimeInventory = this.GetComponent <RuntimeInventory>();
        RuntimeVariables runtimeVariables = runtimeInventory.GetComponent <RuntimeVariables>();
        SceneChanger     sceneChanger     = this.GetComponent <SceneChanger>();

        if (player && playerInput && mainCamera && runtimeInventory && runtimeVariables && sceneChanger)
        {
            // Assign "Main Data"
            saveData.mainData.currentScene  = Application.loadedLevel;
            saveData.mainData.previousScene = sceneChanger.previousScene;

            saveData.mainData.playerLocX = player.transform.position.x;
            saveData.mainData.playerLocY = player.transform.position.y;
            saveData.mainData.playerLocZ = player.transform.position.z;
            saveData.mainData.playerRotY = player.transform.eulerAngles.y;

            if (player.GetPath() && player.lockedPath && player.GetPath() != player.GetComponent <Paths>())
            {
                saveData.mainData.playerActivePath = Serializer.GetConstantID(player.GetPath().gameObject);
            }

            if (playerInput.activeArrows)
            {
                saveData.mainData.playerActiveArrows = Serializer.GetConstantID(playerInput.activeArrows.gameObject);
            }

            if (playerInput.activeConversation)
            {
                saveData.mainData.playerActiveConversation = Serializer.GetConstantID(playerInput.activeConversation.gameObject);
            }

            saveData.mainData.playerUpLock        = playerInput.isUpLocked;
            saveData.mainData.playerDownLock      = playerInput.isDownLocked;
            saveData.mainData.playerLeftlock      = playerInput.isLeftLocked;
            saveData.mainData.playerRightLock     = playerInput.isRightLocked;
            saveData.mainData.playerRunLock       = (int)playerInput.runLock;
            saveData.mainData.playerInventoryLock = runtimeInventory.isLocked;

            saveData.mainData.timeScale = playerInput.timeScale;

            if (mainCamera.attachedCamera)
            {
                saveData.mainData.gameCamera = Serializer.GetConstantID(mainCamera.attachedCamera.gameObject);
            }

            saveData.mainData.mainCameraLocX = mainCamera.transform.position.x;
            saveData.mainData.mainCameraLocY = mainCamera.transform.position.y;
            saveData.mainData.mainCameraLocZ = mainCamera.transform.position.z;

            saveData.mainData.mainCameraRotX = mainCamera.transform.eulerAngles.x;
            saveData.mainData.mainCameraRotY = mainCamera.transform.eulerAngles.y;
            saveData.mainData.mainCameraRotZ = mainCamera.transform.eulerAngles.z;

            saveData.mainData.inventoryData       = CreateInventoryData(runtimeInventory);
            saveData.mainData.selectedInventoryID = runtimeInventory.selectedID;
            saveData.mainData.variablesData       = CreateVariablesData(runtimeVariables);

            string mainData  = Serializer.SerializeObjectBinary(saveData);
            string levelData = Serializer.SerializeObjectBinary(levelStorage.allLevelData);
            string allData   = mainData + "||" + levelData;

            Serializer.CreateSaveFile(GetSaveFileName(slot), allData);
        }
        else
        {
            if (player == null)
            {
                Debug.LogWarning("Save failed - no Player found.");
            }
            if (playerInput == null)
            {
                Debug.LogWarning("Save failed - no PlayerInput found.");
            }
            if (mainCamera == null)
            {
                Debug.LogWarning("Save failed - no MainCamera found.");
            }
            if (runtimeInventory == null)
            {
                Debug.LogWarning("Save failed - no RuntimeInventory found.");
            }
            if (runtimeVariables == null)
            {
                Debug.LogWarning("Save failed - no RuntimeVariables found.");
            }
            if (sceneChanger == null)
            {
                Debug.LogWarning("Save failed - no SceneChanger found.");
            }
        }
                #endif
    }