private void AssignInventory(RuntimeInventory runtimeInventory, string inventoryData) { if (runtimeInventory) { runtimeInventory.localItems.Clear(); if (inventoryData.Length > 0) { string[] countArray = inventoryData.Split("|"[0]); foreach (string chunk in countArray) { string[] chunkData = chunk.Split(":"[0]); int _id = 0; int.TryParse(chunkData[0], out _id); int _count = 0; int.TryParse(chunkData[1], out _count); runtimeInventory.Add(_id, _count); } } } }
private void OnDestroy() { stateHandler = null; runtimeInventory = null; playerInput = null; playerInteraction = null; }
private void OnDestroy() { playerInput = null; sceneSettings = null; stateHandler = null; runtimeInventory = null; player = null; }
public override void RecalculateSize() { if (GameObject.FindWithTag(Tags.persistentEngine) && GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>()) { runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); numSlots = runtimeInventory.localItems.Count; runtimeInventory = null; } base.RecalculateSize(); }
private void Start() { if (GameObject.FindWithTag(Tags.persistentEngine) && GameObject.FindWithTag(Tags.persistentEngine).GetComponent <StateHandler>()) { stateHandler = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <StateHandler>(); } if (GameObject.FindWithTag(Tags.persistentEngine) && GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>()) { runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); } }
public string GetLabel(int slot) { runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); string label = ""; if (runtimeInventory) { label = runtimeInventory.localItems [slot].label; runtimeInventory = null; } return(label); }
private Texture2D GetTexture(int slot) { runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); if (runtimeInventory) { Texture2D texture = runtimeInventory.localItems [slot].tex; runtimeInventory = null; return(texture); } return(null); }
private bool CheckCondition() { RuntimeInventory runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); int count = runtimeInventory.GetCount(invID); if (doCount) { if (intCondition == IntCondition.EqualTo) { if (count == intValue) { return(true); } } else if (intCondition == IntCondition.NotEqualTo) { if (count != intValue) { return(true); } } else if (intCondition == IntCondition.LessThan) { if (count < intValue) { return(true); } } else if (intCondition == IntCondition.MoreThan) { if (count > intValue) { return(true); } } } else if (count > 0) { return(true); } return(false); }
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 string GetCount(int slot) { if (GameObject.FindWithTag(Tags.persistentEngine) && GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>()) { runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); int count = runtimeInventory.localItems [slot].count; runtimeInventory = null; if (count > 1) { return(count.ToString()); } } return(""); }
override public float Run() { RuntimeInventory runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); if (runtimeInventory) { if (invAction == InvAction.Add) { runtimeInventory.Add(invID, amount); } else { runtimeInventory.Remove(invID, amount); } } return(0f); }
private string CreateInventoryData(RuntimeInventory runtimeInventory) { System.Text.StringBuilder inventoryString = new System.Text.StringBuilder(); foreach (InvItem item in runtimeInventory.localItems) { inventoryString.Append(item.id.ToString()); inventoryString.Append(":"); inventoryString.Append(item.count.ToString()); inventoryString.Append("|"); } if (runtimeInventory && runtimeInventory.localItems.Count > 0) { inventoryString.Remove(inventoryString.Length - 1, 1); } return(inventoryString.ToString()); }
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."); } } }
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 }
private void Update () { if (stateHandler && settingsManager && playerInput && playerInteraction && options && dialog && menuSystem && Time.time > 0f) { if (stateHandler.gameState == GameState.Paused) { Time.timeScale = 0f; } else { Time.timeScale = playerInput.timeScale; } playerInput.mouseOverMenu = false; foreach (Menu menu in menuSystem.menus) { menu.HandleFade (); if (settingsManager) { if (settingsManager.inputType == InputType.Controller && menu.IsEnabled () && (stateHandler.gameState == GameState.Paused || stateHandler.gameState == GameState.DialogOptions)) { playerInput.selected_option = menu.ControlSelected (playerInput.selected_option); } } else { Debug.LogWarning ("A settings manager is not present."); } if (menu.appearType == AppearType.Gameplay) { if (stateHandler.gameState == GameState.Normal) { menu.TurnOn (true); if (menu.GetRect ().Contains (playerInput.invertedMouse)) { playerInput.mouseOverMenu = true; if (playerInteraction.hotspot) { playerInteraction.hotspot.DeselectInstant (); playerInteraction.hotspot = null; } } } else { menu.TurnOff (true); } } else if (menu.appearType == AppearType.MouseOverInventory) { RuntimeInventory runtimeInventory = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeInventory>(); if (runtimeInventory && !runtimeInventory.isLocked) { if (settingsManager.alwaysOnInventory) { if (stateHandler.gameState == GameState.Normal) { menu.TurnOn (true); if (menu.GetRect ().Contains (playerInput.invertedMouse)) { playerInput.mouseOverMenu = true; if (playerInteraction.hotspot) { playerInteraction.hotspot.DeselectInstant (); playerInteraction.hotspot = null; } } } else { menu.TurnOff (true); } } else { if (menu.GetRect ().Contains (playerInput.invertedMouse) && stateHandler.gameState == GameState.Normal) { menu.TurnOn (true); playerInput.mouseOverMenu = true; if (playerInteraction.hotspot) { playerInteraction.hotspot.DeselectInstant (); playerInteraction.hotspot = null; } } else { menu.TurnOff (true); } } } } else if (menu.appearType == AppearType.DialogOptions && stateHandler.gameState != GameState.Paused) { if (playerInput.activeConversation != null) { menu.TurnOn (true, GameState.DialogOptions); } else { menu.TurnOff (true); } } else if (menu.appearType == AppearType.OnMenuButton) { try { if (Input.GetButtonDown ("Menu")) { if (!menu.IsEnabled ()) { if (playerInteraction.hotspot) { hotspotLabel = ""; playerInteraction.hotspot.DeselectInstant (); playerInteraction.hotspot = null; } if (stateHandler.gameState != GameState.Paused) { menu.SetPreviousState (stateHandler.gameState); } menu.CrossFade (GameState.Paused); } else { menu.TurnOffAndReturnState (true); } } } catch { if (settingsManager.inputType != InputType.TouchScreen) { Debug.LogWarning ("No 'Menu' button exists - please define one in the Input Manager."); } } } else if (menu.appearType == AppearType.OnHotspot) { menu.SetCentre (new Vector2 (playerInput.invertedMouse.x / Screen.width, playerInput.invertedMouse.y / Screen.height - 0.05f)); if (hotspotLabel != "" && stateHandler.gameState == GameState.Normal) { menuSystem.hotspot_Label.label = hotspotLabel; menu.TurnOn (true); } else { menu.TurnOff (true); } } else if (menu.appearType == AppearType.OnSpeech) { if (stateHandler.gameState != GameState.Paused) { if (dialog.GetLine () != "" && stateHandler.gameState != GameState.DialogOptions) { if (options.optionsData.showSubtitles || (settingsManager.forceSubtitles && !dialog.foundAudio)) { menuSystem.subs_Speaker.label = dialog.GetSpeaker (); menuSystem.subs_Line.label = dialog.GetLine (); // Auto-resize subtitles label Vector2 size = menuSystem.subs_Line.GetSize (); GUIContent content = new GUIContent (dialog.GetFullLine ()); size.y = menuSystem.normalStyle.CalcHeight (content, size.x); menuSystem.subs_Line.SetAbsoluteSize (size); menu.AutoResize (); menu.TurnOn (true); } else { menu.TurnOff (true); } } else { menu.TurnOff (true); } } } } } if (crossFadeFrom != null && crossFadeTo != null && !crossFadeFrom.IsEnabled ()) { crossFadeTo.TurnOn (true); crossFadeTo = null; } if (menuSystem && stateHandler) { if ((lockSave || stateHandler.gameState == GameState.Cutscene || stateHandler.gameState == GameState.DialogOptions) && menuSystem.pause_SaveButton.isVisible) { menuSystem.pause_SaveButton.isVisible = false; } else if (!lockSave && stateHandler.gameState == GameState.Normal && !menuSystem.pause_SaveButton.isVisible) { menuSystem.pause_SaveButton.isVisible = true; } } }
public void ProcessClick(Menu _menu, MenuElement _element, int _slot, int _buttonPressed) { // Pause menu if (_menu == pauseMenu) { if (_buttonPressed == 2) { pauseMenu.TurnOffAndReturnState(true); } else if (_element == pause_ResumeButton) { pauseMenu.TurnOffAndReturnState(true); } else if (options && _element == pause_OptionsButton) { options_Speech.amount = options.optionsData.speechVolume; options_Sfx.amount = options.optionsData.sfxVolume; options_Music.amount = options.optionsData.musicVolume; options_Subs.isOn = options.optionsData.showSubtitles; options_Language.selected = options.optionsData.language; optionsMenu.CrossFade(); } else if (_element == pause_SaveButton) { if (SaveSystem.GetNumSlots() < 6) { save_NewButton.isVisible = true; } else { save_NewButton.isVisible = false; } saveMenu.CrossFade(); } else if (_element == pause_LoadButton) { loadMenu.CrossFade(); } else if (_element == pause_QuitButton) { Application.Quit(); } } // Options menu else if (_menu == optionsMenu) { if (_buttonPressed == 2) { pauseMenu.CrossFade(); } else if (options) { if (_element == options_Speech || _element == options_Sfx || _element == options_Music) { MenuSlider slider = (MenuSlider)_element; slider.Change(); if (_element == options_Speech) { options.optionsData.speechVolume = options_Speech.amount; } else if (_element == options_Sfx) { options.optionsData.sfxVolume = options_Sfx.amount; options.SetVolume(SoundType.SFX); } else if (_element == options_Music) { options.optionsData.musicVolume = options_Music.amount; options.SetVolume(SoundType.Music); } options.SavePrefs(); } else if (_element == options_Language) { options_Language.Cycle(); options.optionsData.language = options_Language.selected; options.SavePrefs(); } else if (_element == options_Subs) { options_Subs.Toggle(); options.optionsData.showSubtitles = options_Subs.isOn; options.SavePrefs(); } else if (_element == options_BackButton) { pauseMenu.CrossFade(); } } } // Save menu else if (_menu == saveMenu) { if (_buttonPressed == 2) { pauseMenu.CrossFade(); } else if (saveSystem) { if (_element == save_SavesList) { saveMenu.TurnOff(true, GameState.Normal); saveSystem.SaveGame(_slot); } else if (_element == save_NewButton) { saveMenu.TurnOff(true, GameState.Normal); saveSystem.SaveNewGame(); } else if (_element == save_BackButton) { pauseMenu.CrossFade(); } } } // Load menu else if (_menu == loadMenu) { if (_buttonPressed == 2) { pauseMenu.CrossFade(); } else if (saveSystem) { if (_element == load_SavesList) { loadMenu.TurnOff(false); saveSystem.LoadGame(_slot); } else if (_element == load_BackButton) { pauseMenu.CrossFade(); } } } // Inventory menu else if (_menu == inventoryMenu) { RuntimeInventory runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); if (runtimeInventory && _element == inventory_Box) { if (_buttonPressed == 1) { if (runtimeInventory.selectedID == -1) { runtimeInventory.Use(_slot); } else { runtimeInventory.Combine(_slot); } } else if (_buttonPressed == 2) { runtimeInventory.Look(_slot); } } } // InGame menu else if (_menu == inGameMenu) { if (_element == inGame_MenuButton) { pauseMenu.SetPreviousState(GameState.Normal); pauseMenu.CrossFade(GameState.Paused); } } // Dialog menu else if (_menu == conversationMenu) { if (_element == dialog_Box) { dialog_Box.RunOption(_slot); } } }
override public float Run() { PlayerInput playerInput = GameObject.FindWithTag(Tags.gameEngine).GetComponent <PlayerInput>(); PlayerMenus playerMenus = playerInput.GetComponent <PlayerMenus>(); RuntimeInventory runtimeInventory = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <RuntimeInventory>(); Player player = GameObject.FindWithTag(Tags.player).GetComponent <Player>(); if (playerInput) { if (doUpLock == LockType.Disabled) { playerInput.isUpLocked = true; } else if (doUpLock == LockType.Enabled) { playerInput.isUpLocked = false; } if (doDownLock == LockType.Disabled) { playerInput.isDownLocked = true; } else if (doDownLock == LockType.Enabled) { playerInput.isDownLocked = false; } if (doLeftLock == LockType.Disabled) { playerInput.isLeftLocked = true; } else if (doLeftLock == LockType.Enabled) { playerInput.isLeftLocked = false; } if (doRightLock == LockType.Disabled) { playerInput.isRightLocked = true; } else if (doRightLock == LockType.Enabled) { playerInput.isRightLocked = false; } if (doRunLock != PlayerMoveLock.NoChange) { playerInput.runLock = doRunLock; } } if (runtimeInventory) { if (doInventoryLock == LockType.Disabled) { runtimeInventory.isLocked = true; } else if (doInventoryLock == LockType.Enabled && runtimeInventory.localItems.Count > 0) { runtimeInventory.isLocked = false; } } if (playerMenus) { if (doSaveLock == LockType.Disabled) { playerMenus.lockSave = true; } else if (doSaveLock == LockType.Enabled) { playerMenus.lockSave = false; } } if (player) { if (movePath) { player.SetLockedPath(movePath); player.SetMoveDirectionAsForward(); } else if (player.activePath) { player.SetPath(null); } } return(0f); }
private void OnDestroy() { stateHandler = null; runtimeInventory = null; settingsManager = null; }