public bool Interact(Transform _transform, Vector3 position) { if (playerMove.isGhost) { return(false); } //attempt to trigger the things in range we clicked on if (PlayerManager.LocalPlayerScript.IsInReach(Camera.main.ScreenToWorldPoint(Input.mousePosition))) { //Check for melee triggers first: MeleeTrigger meleeTrigger = _transform.GetComponentInParent <MeleeTrigger>(); if (meleeTrigger != null) { 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) { inputTrigger.Trigger(position); //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) { playerInteractions.Trigger(position); } } return(true); } //Allow interact with cupboards we are inside of! ClosetControl cCtrl = inputTrigger.GetComponent <ClosetControl>(); if (cCtrl && cCtrl.transform.position == PlayerManager.LocalPlayerScript.transform.position) { 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()); }
/// <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)); }