public void Setup(CardID ID, GameManager gm, int playerNumWhoPlayedThis) { this.gm = gm; template = ID.GetTemplate(); template.authorPlayer = playerNumWhoPlayedThis; // setup visuals titleText.text = template.cardName; descriptionText.text = template.description; costText.text = template.playCost.ToString(); isConcealed = false; mouseTargetable = GetComponent <MouseTargetable>(); mouseTargetable.OnMouseUpAsButtonActions.Add(OnClick); mouseDraggable = GetComponent <MouseDraggable>(); mouseDraggable.OnPickUp.Add(this.OnPickUp); mouseDraggable.OnDrop.Add(this.OnDrop); UpdateTargetingGroupForPlayability(); if (template.isChargeable) { chargeableInterface.SetActive(true); SetIsCharged(false); } else { chargeableInterface.SetActive(false); } sortingLayerManager = GetComponent <SortingLayerManager>(); sortingLayerManager.Setup(); sortingLayerManager.SetSortingLayer("CardInHand"); }
private void CheckMouseInput() { if (EventSystem.current.IsPointerOverGameObject()) { //don't do any game world interactions if we are over the UI return; } if (UIManager.IsMouseInteractionDisabled) { //still allow tooltips CheckHover(); return; } //do we have a loaded gun var loadedGun = GetLoadedGunInActiveHand(); if (CommonInput.GetMouseButtonDown(0)) { //check ctrl+click for dragging if (KeyboardInputManager.IsControlPressed()) { //even if we didn't drag anything, nothing else should happen CheckInitiatePull(); return; } //check the alt click and throw, which doesn't have any special logic if (CheckAltClick()) { return; } if (CheckThrow()) { return; } if (loadedGun != null) { //if we are on harm intent with loaded gun, //don't do anything else, just shoot (trigger the AimApply). if (UIManager.CurrentIntent == Intent.Harm) { CheckAimApply(MouseButtonState.PRESS); } else { //proceed to normal click interaction CheckClickInteractions(true); } } else { //we don't have a loaded gun //Are we over something draggable? var draggable = GetDraggable(); if (draggable != null) { //We are over a draggable. We need to wait to see if the user //tries to drag the object or lifts the mouse. potentialDraggable = draggable; dragStartOffset = MouseWorldPosition - potentialDraggable.transform.position; clickDuration = 0; } else { //no possibility of dragging something, proceed to normal click logic CheckClickInteractions(true); } } } else if (CommonInput.GetMouseButton(0)) { //mouse button being held down. //increment the time since they initially clicked the mouse clickDuration += Time.deltaTime; //If we are possibly dragging and have exceeded the drag distance, initiate the drag if (potentialDraggable != null) { var currentOffset = MouseWorldPosition - potentialDraggable.transform.position; if (((Vector2)currentOffset - dragStartOffset).magnitude > MouseDragDeadzone) { potentialDraggable.BeginDrag(); potentialDraggable = null; } } //continue to trigger the aim apply if it was initially triggered CheckAimApply(MouseButtonState.HOLD); } else if (CommonInput.GetMouseButtonUp(0)) { //mouse button is lifted. //If we were waiting for mouseup to trigger a click, trigger it if we're still within //the duration threshold if (potentialDraggable != null) { if (clickDuration < MaxClickDuration) { //we are lifting the mouse, so AimApply should not be performed but other //clicks can. CheckClickInteractions(false); } clickDuration = 0; potentialDraggable = null; } //no more triggering of the current aim apply triggeredAimApply = null; secondsSinceLastAimApplyTrigger = 0; } else { CheckHover(); } }