コード例 #1
0
    public void Interact()
    {
        if (_isNoMoreUse)
        {
            GameManager.Inst.UIManager.SetConsoleText(NoMoreUseMessage);
            return;
        }

        //if there is UI sound, play
        if (!string.IsNullOrEmpty(UISound))
        {
            AudioClip clip = GameManager.Inst.SoundManager.GetClip(UISound);
            GameManager.Inst.SoundManager.UI.PlayOneShot(clip, 0.1f);
        }

        if (!IsReady)
        {
            GameManager.Inst.UIManager.SetConsoleText(NotReadyMessage);
            return;
        }



        //check if player has required items
        if (RequireItemID.Length > 0)
        {
            CharacterInventory playerInventory = GameManager.Inst.PlayerControl.SelectedPC.Inventory;
            int itemCount = playerInventory.CountItemsInBackpack(RequireItemID);
            if (itemCount < RequireItemQuantity)
            {
                //display message and return
                GameManager.Inst.UIManager.SetConsoleText(NotReadyMessage);
                return;
            }
        }

        //if there is confirm message, display it
        if (ConfirmMessage.Length > 0)
        {
            UIEventHandler.Instance.TriggerConfirm();
            GameManager.Inst.UIManager.ConfirmPanel.SetupPanel(ConfirmMessage, InteractConfirmed);
        }
        else
        {
            InteractConfirmed();
        }
    }
コード例 #2
0
    public void InteractConfirmed()
    {
        if (RequireItemID.Length > 0)
        {
            CharacterInventory playerInventory = GameManager.Inst.PlayerControl.SelectedPC.Inventory;
            int itemCount = playerInventory.CountItemsInBackpack(RequireItemID);
            if (itemCount >= RequireItemQuantity)
            {
                //remove item from player
                playerInventory.RemoveItemsFromBackpack(RequireItemID, RequireItemQuantity);
                _isNoMoreUse = true;
            }
            else
            {
                //display message and return
                GameManager.Inst.UIManager.SetConsoleText(NotReadyMessage);
                return;
            }
        }

        if (!IsOn || IsTrigger)
        {
            //turn it on
            if (OnEvent.Length > 0)
            {
                GameManager.Inst.QuestManager.Scripts[OnEvent].Trigger(new object[] {});
            }

            if (IsTrigger)
            {
                _isNoMoreUse = true;
            }

            IsOn = true;
            if (NextObject != null)
            {
                NextObject.IsReady = true;
            }

            if (OnSound != null)
            {
                OnSound.TurnOn();
            }

            GameManager.Inst.UIManager.SetConsoleText(TriggerMessage);
        }
        else
        {
            //turn it off
            if (OffEvent.Length > 0)
            {
                GameManager.Inst.QuestManager.Scripts[OffEvent].Trigger(new object[] {});
            }

            IsOn = false;
            if (NextObject != null)
            {
                NextObject.IsReady = false;
            }

            if (OnSound != null)
            {
                OnSound.TurnOff();
            }
        }
    }