Example #1
0
        private static void UpdateConnection(Interactive element, string eventName, ICommand command)
        {
            if (element is null || eventName is null)
            {
                return;
            }

            System.EventHandler handler = Handler;
            var eventInfo = element.GetType().GetEvent(eventName);

            if (command != null)
            {
                eventInfo.AddEventHandler(element, handler);
            }
            else
            {
                eventInfo.RemoveEventHandler(element, handler);
            }
        }
    public override void HandleInput()
    {
        if (stateMachine.inputManager.actionInteract.triggered)
        {
            Interactive interactive = interactiveIdentifier.PeekMostRelevantInteractive();

            if (interactive != null)
            {
                System.Type interactiveType = interactive.GetType();
                if (interactiveType == typeof(LiftableObject))
                {
                    interactiveIdentifier.PopMostrelevantInteractive();
                    interactive.Interact();
                    objectManipulator.LiftObject(interactive.gameObject);
                    base.stateMachine.ChangeState(typeof(PlayerLiftingState));
                }
                else if (interactiveType.IsSubclassOf(typeof(Activator)) && interactiveType != typeof(GroundButton) &&
                         !interactive.CompareTag("Receptor"))
                {
                    interactive.Interact();
                }
                else if (interactiveType == typeof(PushableObject))
                {
                    interactive.Interact();
                    objectManipulator.GrabObject(interactive.gameObject);
                    base.stateMachine.ChangeState(typeof(PlayerDraggingState));
                    interactiveIdentifier.SetInteractPopupShowState(false);
                }
                else if (interactiveType == typeof(InteractiveDoor) ||
                         interactiveType == typeof(ItemContainer) ||
                         interactiveType == typeof(Guardian))
                {
                    interactive.Interact(transform.parent.gameObject);
                    interactiveIdentifier.SetInteractPopupShowState(false);
                    interactiveIdentifier.PopMostrelevantInteractive();
                }
                else if (interactiveType == typeof(InteractiveShield))
                {
                    interactive.Interact(transform.parent.gameObject);
                    interactiveIdentifier.SetInteractPopupShowState(false);
                }
            }
        }
        else if (stateMachine.inputManager.actionAttack1.triggered)
        {
            if (holdAttackCheckCoroutine == null)
            {
                holdAttackCheckCoroutine = StartCoroutine(CheckForAttackHoldInput());
            }
            else
            {
                StopCoroutine(holdAttackCheckCoroutine);
                holdAttackCheckCoroutine = StartCoroutine(CheckForAttackHoldInput());
            }
            stateMachine.inputManager.actionAttack1.canceled += StopCheckForAttackHoldInputCoroutine;
        }
        else if (stateMachine.inputManager.actionDefend.triggered && canDefend)
        {
            stateMachine.ChangeState(typeof(PlayerDefendingState));
        }
    }