private void OnIntentionToUsePrimaryActionOnItem(int ItemIndex)
    {
        if (!_interactible)
        {
            return;
        }

        if (SimWorld.TryGetBufferReadOnly(Cache.LocalPawn, out DynamicBuffer <InventoryItemReference> inventory))
        {
            if (inventory.Length > ItemIndex && ItemIndex > -1)
            {
                InventoryItemReference item = inventory[ItemIndex];

                if (SimWorld.Exists(item.ItemEntity))
                {
                    Entity itemEntity = item.ItemEntity;

                    if (SimWorld.TryGetComponent(itemEntity, out ItemAction itemAction))
                    {
                        UIStateMachine.Instance.TransitionTo(UIStateType.ParameterSelection, new ParameterSelectionState.InputParam()
                        {
                            ActionInstigator = itemEntity,
                            ActionPrefab     = itemAction.Value,
                            IsItem           = true,
                            ItemIndex        = ItemIndex
                        });
                    }
                }
            }
        }
    }
Exemple #2
0
    public override void OnUpdate()
    {
        if (Input.GetMouseButtonDown(1))  // right-click cancels
        {
            StateMachine.TransitionTo(UIStateType.Gameplay);
            return;
        }

        if (_surveySMBlackboard.IsDebug)
        {
            _surveyStateMachine.Update();
            return;
        }

        if (!SimWorld.Exists(InputParameter.ActionInstigator)) // target item no longer exists, exit
        {
            StateMachine.TransitionTo(UIStateType.Gameplay);
            return;
        }

        // No currently running survey ? (or current survey done)
        if (_surveyStateMachine.CurrentState == null || ((SurveyState)_surveyStateMachine.CurrentState).Done)
        {
            bool isFinished = _surveySMBlackboard.ResultParameters.Count == _surveySMBlackboard.ParametersDescriptions.Length;
            if (isFinished)
            {
                // all done! send input and exit
                FinishAndSendSimInput();
            }
            else
            {
                // not done, begin next survey state ?
                if (_surveySMBlackboard.ResultParameters.Count == 0)
                {
                    // no data found, cancel and go back to gameplay
                    StateMachine.TransitionTo(UIStateType.Gameplay);
                    return;
                }
                else
                {
                    // begin next survey state
                    _surveyStateMachine.TransitionTo(new SurveyState());
                }
            }
        }

        _surveyStateMachine.Update();
    }