override public float Run() { RuntimeInventory runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); if (runtimeInventory) { if (giveToPlayer) { runtimeInventory.Add(invID, 1); } runtimeInventory.SelectItemByID(invID); } return(0f); }
private void ReturnMainData() { 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.previousScene = saveData.mainData.previousScene; player.transform.position = new Vector3(saveData.mainData.playerLocX, saveData.mainData.playerLocY, saveData.mainData.playerLocZ); player.transform.eulerAngles = new Vector3(0f, saveData.mainData.playerRotY, 0f); player.SetLookDirection(Vector3.zero, true); // Active path player.Halt(); Paths savedPath = Serializer.returnComponent <Paths> (saveData.mainData.playerActivePath); if (savedPath) { player.SetLockedPath(savedPath); } // Active screen arrows playerInput.RemoveActiveArrows(); ArrowPrompt loadedArrows = Serializer.returnComponent <ArrowPrompt> (saveData.mainData.playerActiveArrows); if (loadedArrows) { loadedArrows.TurnOn(); } // Active conversation playerInput.activeConversation = Serializer.returnComponent <Conversation> (saveData.mainData.playerActiveConversation); playerInput.isUpLocked = saveData.mainData.playerUpLock; playerInput.isDownLocked = saveData.mainData.playerDownLock; playerInput.isLeftLocked = saveData.mainData.playerLeftlock; playerInput.isRightLocked = saveData.mainData.playerRightLock; playerInput.runLock = (PlayerMoveLock)saveData.mainData.playerRunLock; runtimeInventory.isLocked = saveData.mainData.playerInventoryLock; playerInput.timeScale = saveData.mainData.timeScale; mainCamera.SetGameCamera(Serializer.returnComponent <GameCamera> (saveData.mainData.gameCamera)); mainCamera.transform.position = new Vector3(saveData.mainData.mainCameraLocX, saveData.mainData.mainCameraLocY, saveData.mainData.mainCameraLocZ); mainCamera.transform.eulerAngles = new Vector3(saveData.mainData.mainCameraRotX, saveData.mainData.mainCameraRotY, saveData.mainData.mainCameraRotZ); if (mainCamera.attachedCamera) { mainCamera.attachedCamera.MoveCameraInstant(); } else { Debug.LogWarning("MainCamera has no attached GameCamera"); } // Inventory AssignInventory(runtimeInventory, saveData.mainData.inventoryData); if (saveData.mainData.selectedInventoryID > -1) { runtimeInventory.SelectItemByID(saveData.mainData.selectedInventoryID); } else { runtimeInventory.SetNull(); } // Variables AssignVariables(runtimeVariables, saveData.mainData.variablesData); // StateHandler StateHandler stateHandler = runtimeInventory.GetComponent <StateHandler>(); if (playerInput.activeConversation) { stateHandler.gameState = GameState.DialogOptions; } else { stateHandler.gameState = GameState.Normal; } // Fade in camera mainCamera.FadeIn(0.5f); playerInput.ResetClick(); } else { if (player == null) { Debug.LogWarning("Load failed - no Player found."); } if (playerInput == null) { Debug.LogWarning("Load failed - no PlayerInput found."); } if (mainCamera == null) { Debug.LogWarning("Load failed - no MainCamera found."); } if (runtimeInventory == null) { Debug.LogWarning("Load failed - no RuntimeInventory found."); } if (runtimeVariables == null) { Debug.LogWarning("Load failed - no RuntimeVariables found."); } if (sceneChanger == null) { Debug.LogWarning("Load failed - no SceneChanger found."); } } }