private bool InteractHands(bool isDrag) { if (UIManager.Hands.CurrentSlot.Item != null && objectBehaviour.visibleState) { InputTrigger inputTrigger = UIManager.Hands.CurrentSlot.Item.GetComponent <InputTrigger>(); if (inputTrigger != null) { bool interacted = false; if (isDrag) { interacted = inputTrigger.TriggerDrag(); } else { interacted = inputTrigger.Trigger(); } if (interacted) { return(true); } } } return(false); }
private bool InteractHands(bool isDrag) { if (UIManager.Hands.CurrentSlot.Item != null && objectBehaviour.visibleState) { InputTrigger inputTrigger = UIManager.Hands.CurrentSlot.Item.GetComponent <InputTrigger>(); if (inputTrigger != null) { bool interacted = false; var interactPosition = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition); if (isDrag) { interacted = inputTrigger.TriggerDrag(interactPosition); } else { interacted = inputTrigger.Trigger(interactPosition); } if (interacted) { return(true); } } } return(false); }
/// <summary> /// Checks for the various interactions that can occur and delegates to the appropriate trigger classes. /// Note that only one interaction is allowed to occur in this method - the first time any trigger returns true /// (indicating that interaction logic has occurred), the method returns. /// </summary> /// <param name="_transform">transform to check the interaction of</param> /// <param name="position">position the interaction is taking place</param> /// <param name="isDrag">is this during (but not at the very start of) a drag?</param> /// <returns>true iff an interaction occurred</returns> public bool Interact(Transform _transform, Vector3 position, bool isDrag) { if (playerMove.isGhost) { return(false); } //attempt to trigger the things in range we clicked on var localPlayer = PlayerManager.LocalPlayerScript; if (localPlayer.IsInReach(Camera.main.ScreenToWorldPoint(Input.mousePosition)) || localPlayer.IsHidden) { //Check for melee triggers first. If a melee interaction occurs, stop checking for any further interactions MeleeTrigger meleeTrigger = _transform.GetComponentInParent <MeleeTrigger>(); //no melee action happens due to a drag if (meleeTrigger != null && !isDrag) { if (meleeTrigger.MeleeInteract(gameObject, UIManager.Hands.CurrentSlot.eventName)) { return(true); } } //check the actual transform for an input trigger and if there is non, check the parent InputTrigger inputTrigger = _transform.GetComponentInParent <InputTrigger>(); if (inputTrigger) { if (objectBehaviour.visibleState) { bool interacted = false; if (isDrag) { interacted = inputTrigger.TriggerDrag(position); } else { interacted = inputTrigger.Trigger(position); } if (interacted) { return(true); } //FIXME currently input controller only uses the first InputTrigger found on an object /////// some objects have more then 1 input trigger, like players for example /////// below is a solution that should be removed when InputController is refactored /////// to support multiple InputTriggers on the target object if (inputTrigger.gameObject.layer == 8) { //This is a player. Attempt to use the player based inputTrigger P2PInteractions playerInteractions = inputTrigger.gameObject.GetComponent <P2PInteractions>(); if (playerInteractions != null) { if (isDrag) { interacted = playerInteractions.TriggerDrag(position); } else { interacted = playerInteractions.Trigger(position); } } } if (interacted) { return(true); } } //Allow interact with cupboards we are inside of! ClosetControl closet = inputTrigger.GetComponent <ClosetControl>(); //no closet interaction happens when dragging if (closet && Camera2DFollow.followControl.target == closet.transform && !isDrag) { if (inputTrigger.Trigger(position)) { return(true); } } return(false); } } //if we are holding onto an item like a gun attempt to shoot it if we were not in range to trigger anything return(InteractHands(isDrag)); }
/// <summary> /// Tries to trigger InputTrigger /// </summary> private static bool TryInputTrigger(Vector3 position, bool isDrag, InputTrigger inputTrigger) { return(isDrag ? inputTrigger.TriggerDrag(position) : inputTrigger.Trigger(position)); }