private bool CheckAimApply(MouseButtonState buttonState) { ChangeDirection(); //currently there is nothing for ghosts to interact with, they only can change facing if (PlayerManager.LocalPlayerScript.IsGhost) { return(false); } //can't do anything if we have no item in hand var handObj = UIManager.Hands.CurrentSlot.Item; if (handObj == null) { triggeredAimApply = null; secondsSinceLastAimApplyTrigger = 0; return(false); } var aimApplyInfo = AimApply.ByLocalPlayer(buttonState); if (buttonState == MouseButtonState.PRESS) { //it's being clicked down triggeredAimApply = null; //Checks for aim apply interactions which can trigger foreach (var aimApply in handObj.GetComponents <IInteractable <AimApply> >()) { var interacted = aimApply.Interact(aimApplyInfo); if (interacted) { triggeredAimApply = aimApply; secondsSinceLastAimApplyTrigger = 0; return(true); } } } else { //it's being held //if we are already triggering an AimApply, keep triggering it based on the AimApplyInterval if (triggeredAimApply != null) { secondsSinceLastAimApplyTrigger += Time.deltaTime; if (secondsSinceLastAimApplyTrigger > AimApplyInterval) { if (triggeredAimApply.Interact(aimApplyInfo)) { //only reset timer if it was actually triggered secondsSinceLastAimApplyTrigger = 0; } } //no matter what the result, we keep trying to trigger it until mouse is released. return(true); } } return(false); }
private bool CheckAimApply(MouseButtonState buttonState) { ChangeDirection(); //currently there is nothing for ghosts to interact with, they only can change facing if (PlayerManager.LocalPlayerScript.IsGhost) { return(false); } //can't do anything if we have no item in hand var handObj = UIManager.Hands.CurrentSlot.Item; if (handObj == null) { triggeredAimApply = null; secondsSinceLastAimApplyTrigger = 0; return(false); } var aimApplyInfo = AimApply.ByLocalPlayer(buttonState); if (buttonState == MouseButtonState.PRESS) { //it's being clicked down triggeredAimApply = null; //Checks for aim apply interactions which can trigger var comps = handObj.GetComponents <IBaseInteractable <AimApply> >() .Where(mb => mb != null && (mb as MonoBehaviour).enabled); var triggered = InteractionUtils.ClientCheckAndTrigger(comps, aimApplyInfo); if (triggered != null) { triggeredAimApply = triggered; secondsSinceLastAimApplyTrigger = 0; return(true); } } else { //it's being held //if we are already triggering an AimApply, keep triggering it based on the AimApplyInterval if (triggeredAimApply != null) { secondsSinceLastAimApplyTrigger += Time.deltaTime; if (secondsSinceLastAimApplyTrigger > AimApplyInterval) { if (triggeredAimApply.CheckInteract(aimApplyInfo, NetworkSide.Client)) { //only reset timer if it was actually triggered secondsSinceLastAimApplyTrigger = 0; InteractionUtils.RequestInteract(aimApplyInfo, triggeredAimApply); } } //no matter what the result, we keep trying to trigger it until mouse is released. return(true); } } return(false); }