public void EndDrag(PointerEventData eventData, LocationCardSceneObj card) { Debug.Log("End Drag"); // -- what are we over? RaycastHit[] hits; Ray ray = Camera.main.ScreenPointToRay(eventData.position); hits = Physics.SphereCastAll(ray, 1, 1000); for (int hLoop = 0; hLoop < hits.Length; hLoop++) { RaycastHit hit = hits[hLoop]; Debug.Log("HIT : " + hit.transform.gameObject.name); if (hit.transform.gameObject.tag == "CardSlot") { if (hit.transform.gameObject.GetComponent <LocationSlot>().card == null) { PlayCard(card, hit.transform.gameObject.GetComponent <LocationSlot>()); // -- send to discard pile AddCardToDiscardPile(card); break; } } else { // -- fail to play... } } card.isDragged = false; UpdateDeckSizes(); }
void PlayCard(LocationCardSceneObj card, LocationSlot slot) { Debug.Log("PLAY CARD"); card.isWaitingToPlay = true; slot.card = card; card.GetComponent <RectTransform>().position = Camera.main.WorldToScreenPoint(slot.gameObject.transform.position); EncounterController.instance.StartEncounter(card.card.encounter); }
public void AddCardToDiscardPile(LocationCardSceneObj card) { //owner.discardPile.Add(card.card); //discardPileSizeText.text = owner.discardPile.Count.ToString(); ////card.gameObject.SetActive(false); //Vector3 targetPos = Vector3.zero; //RectTransform rt = card.GetComponent<RectTransform>(); //targetPos.z = 10000; //rt.position = targetPos; }
void Start() { handWidth = handTransform.GetComponent <RectTransform>().rect.width - GameController.instance.locationCardPrefab.GetComponent <RectTransform>().rect.width; currentDeck = startingDeck; for (int cLoop = 0; cLoop < currentDeck.cards.Count; cLoop++) { GameObject newCard = GameObject.Instantiate(GameController.instance.locationCardPrefab, handTransform); LocationCardSceneObj c = newCard.GetComponent <LocationCardSceneObj>(); RectTransform rt = c.GetComponent <RectTransform>(); rt.position = startTransform.position; c.GetComponent <LocationCardSceneObj>().SetupCard(currentDeck.cards[cLoop]); cards.Add(c); c.SetHand(this); } UpdateDeckSizes(); }
public void SetHoveredCard(LocationCardSceneObj card) { if (card == null || card.isDragged) { hoveredCard = null; hoveredCardIndex = -1; } else { hoveredCardIndex = cards.IndexOf(card); for (int i = 0; i < cards.Count; i++) { cards[i].transform.SetSiblingIndex(i); } hoveredCard = card; prevHoverIndex = hoveredCardIndex; cards[prevHoverIndex].gameObject.transform.SetAsLastSibling(); } }
public void UpdateDrag(PointerEventData eventData, LocationCardSceneObj card) { // show target at mouse cursor. target.GetComponent <RectTransform>().position = eventData.position; // keep card locked in highlighted position // -- what are we over? show color change. RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(eventData.position); if (Physics.Raycast(ray, out hit, 1000)) { if (hit.transform.gameObject.tag == "CardSlot") { // hit a valid slot target.GetComponent <Image>().color = Color.green; } else { // hit nowt target.GetComponent <Image>().color = Color.red; } } // -- if we go below y threshold cancel the drag if (eventData.position.y < CARD_DRAG_THRESHOLD && goneBeyondThreshold) { EndDrag(eventData, card); } // -- show dotted curve between card and cursor // -- check beyond threshold if (eventData.position.y > CARD_DRAG_THRESHOLD) { goneBeyondThreshold = true; } }
public void StartDrag(PointerEventData eventData, LocationCardSceneObj card) { goneBeyondThreshold = false; }