public void OnDrag(PointerEventData eventData) { if (!enabled) { return; } // Move card to mouse Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float distance; if (_dragPlane.Raycast(ray, out distance)) { _cardObject.TargetTransform.position = ray.GetPoint(distance); } // Drop area management int layerMask = LayerMask.GetMask("DropArea"); RaycastHit hit; DropArea area = null; if (Physics.Raycast(ray, out hit, 10, layerMask)) { area = hit.transform.gameObject.GetComponent <DropArea>(); } SetDropArea(area); }
public void OnEndDrag(PointerEventData eventData) { if (!enabled) { return; } _dragging = false; _cardObject.PositionDamp = _oldPositionDamp; if (DropArea != null) { var dropArea = DropArea; DropArea.OnExit(); DropArea = null; var cardInstance = MatchManager.CurrentMatch.CurrentSide.PutInRow(_cardObject.Card, dropArea.CardType); if (cardInstance != null) { cardInstance.CardObject = _cardObject; dropArea.CardSlot.AddCard(_cardObject); _cardObject.TargetTransform.rotation = Quaternion.Euler(90, 0, 0); return; } } _cardObject.TargetTransform.position = _startPosition; }
/// <summary> /// Create a new DropArea with a given name if name does no /// </summary> /// <param name="id"></param> /// <param name="obj"></param> /// <param name="rect"></param> /// <param name="types"></param> public void TryCreateDropArea(string id, object obj, Rect rect, params Type[] types) { DropArea dropArea; if (!dropAreas.TryGetValue(id, out dropArea)) { // create new DropArea dropArea = new DropArea(id, obj, rect, types); // store the DropArea with its ID dropAreas.Add(id, dropArea); // object to DropArea mapping if (dropArea.Object != null) { objectsDropArea.Add(obj, dropArea); } // Type to DropAreas mapping foreach (Type type in dropArea.Types) { List <DropArea> dropAreasOfType; if (!dropAreasByType.TryGetValue(type, out dropAreasOfType)) { dropAreasByType.Add(type, new List <DropArea>()); } dropAreasByType[type].Add(dropArea); } } else { dropArea.Rect = rect; dropArea.Types = types.ToList <Type>(); } }
void OnMouseUp() { if (otherCollidor == null) { transform.position = originalPosition; return; } DropArea dropArea = otherCollidor.gameObject.GetComponent <DropArea> (); if (dropArea == null) { transform.position = originalPosition; return; } if (!dropArea.textJawaban.text.Equals(transform.GetComponentInChildren <Text> ().text)) { transform.position = originalPosition; return; } Text text = dropArea.textJawaban; text.color = transform.GetComponentInChildren <Text> ().color; transform.GetComponent <Text> ().text = ""; transform.position = originalPosition; }
public void OnEndDrag(PointerEventData eventData) { if (!CanDrag) { return; } var results = new List <RaycastResult>(); EventSystem.current.RaycastAll(eventData, results); DropArea dropArea = null; foreach (var result in results) { dropArea = result.gameObject.GetComponent <DropArea>(); if (dropArea != null) { break; } } if (dropArea != null) { if (dropArea.Accepts(this)) { SetIndex(dropArea.name); if (dropArea.GetComponentInChildren <SetItemIcon>() != null) { GameObject temp = dropArea.GetComponentInChildren <SetItemIcon>().gameObject; temp.transform.SetParent(parentToRenturnTo); temp.transform.SetSiblingIndex(this.positionIndex); equipmentPanel.UnEquipItem(temp.GetComponent <SetItemIcon>().GetItem, index); } dropArea.Drop(this); OnEndDragHandler?.Invoke(eventData, true); transform.SetParent(dropArea.transform); equipmentPanel.EquipItem(item, index, positionIndex); return; } } if (eventData.position.x > halfScreen && startingPosition < halfScreen) { equipmentPanel.UnEquipItem(item, index); this.transform.SetParent(inventoryPosition); rectTransform.anchoredPosition = StartPosition; OnEndDragHandler?.Invoke(eventData, false); return; } this.transform.SetParent(parentToRenturnTo); rectTransform.anchoredPosition = StartPosition; //transform.SetSiblingIndex(positionIndex); //equipmentPanel.UnEquipItem(item, index); OnEndDragHandler?.Invoke(eventData, false); }
// This function starts a game round after a player chose his card and played it to the drop area // This function is an asynchronous coRoutine because all the animations need to finish before the code resumes public IEnumerator ExecuteRound(Card PlayerACard) { // Disable dragging of cards in drop area and in hand DropArea dropArea = GameObject.FindObjectOfType <DropArea> (); dropArea.GetComponentInChildren <Draggable> ().enabled = false; HandDraggable(false); // AIManager selects a card // The AI needs both the player's hand and deck in a single list List <Card> deckAndHandPlayer = new List <Card>(); deckAndHandPlayer.AddRange(deckA.GetCards()); deckAndHandPlayer.AddRange(deckA.GetHand()); Card selectedAICard = AIManager.SelectCardToPlay(settingsController.GetAILevel(), deckB.GetHand(), deckAndHandPlayer, ball.GetControllingTeam(), ball.GetBallPosition()); // AnimationManager moves the card to the played area yield return(cardsAnimationManager.MoveSelectedAICardToPlayArea(selectedAICard, playerBAreas)); // ActionManager reutrns 2 actions - first for higher rank and then for lower rank int RankA = PlayerACard.GetRank(); int RankB = selectedAICard.GetRank(); ActionManager.CardResolution[] actions = ActionManager.ComputeActions(RankA, RankB); // Resolve Actions yield return(ResolveActions(actions, RankA, RankB)); // Move played cards to discard deckA.DiscardCard(PlayerACard); deckB.DiscardCard(selectedAICard); yield return(cardsAnimationManager.MovePlayedCardsToDiscard(PlayerACard, selectedAICard, playerAAreas, playerBAreas)); // Draw a new card (or more, in case of shuffling when there are less than 3 cards in hand), check for end and release dragging on hand int numToDrawA = 3 - deckA.GetHand().Count; int numToDrawB = 3 - deckB.GetHand().Count; if ((deckA.Draw(numToDrawA).Count == 0) || (deckB.Draw(numToDrawB).Count == 0)) { // End of half or game if (currentHalf == 1) { currentHalf++; yield return(ResetBoard(false)); // Reset for second half } else { EndGame(); } } else { yield return(cardsAnimationManager.DrawToHand(deckA.GetHand(), playerAAreas, Player.A)); yield return(cardsAnimationManager.DrawToHand(deckB.GetHand(), playerBAreas, Player.B)); HandDraggable(true); } }
public void Settle(DropArea house) { beingDragged = false; house.Accept(this); home = house; lastPostition = house.transform.position; ResetPosition(); }
private void Activate() { DropArea next = GameObject.Find("Canvas/dropzone").GetComponent <DropArea>(); foreach (GameObject go in next.deactivated) { go.SetActive(true); } }
private void reposition() { DropArea dropArea = this.transform.parent.GetComponent <DropArea>(); if (dropArea != null) { this.transform.SetSiblingIndex(this.computeOnDropIndex()); } dropArea.AdjustOffset(); }
private void Deactivate(string[] str) { DropArea next = GameObject.Find("Canvas/dropzone").GetComponent <DropArea>(); foreach (string go in str) { GameObject found = GameObject.Find(go); next.deactivated.Add(found); found.SetActive(false); } }
private void OnTriggerEnter2D(Collider2D collision) { // Save DropArea when entered. DropArea droppable = collision.GetComponent <DropArea>(); if (droppable == null) { return; } _dropArea = collision.gameObject; }
private void OnTriggerExit2D(Collider2D collision) { // Clear DropArea when exited. DropArea droppable = collision.GetComponent <DropArea>(); if (droppable == null) { return; } _dropArea = null; }
private void Activate(List <string> str) { DropArea next = GameObject.Find("Canvas/dropzone").GetComponent <DropArea>(); foreach (GameObject go in next.deactivated) { if (str.Contains(go.name)) { go.SetActive(true); } } }
public void OnBeginDrag(PointerEventData eventData) { if (!enabled) { return; } _dragging = true; DropArea = null; _startPosition = transform.position; _oldPositionDamp = _cardObject.PositionDamp; _cardObject.PositionDamp = 0.1f; RestoreColor(); }
private void UseDropArea(DropArea dropArea) { if (isGathering()) { return; } if (dropArea is ResourceNode) { StartCoroutine(GatherNode(dropArea.GetComponent <ResourceNode>())); } else if (dropArea is Chapel) { m_unitInventory.depositResources(dropArea.GetComponent <SummonerInventory>()); } /*else if (dropArea is ) { * // TODO dropping on turrets * }*/ }
public void OnMouseUp() { //Reabilita o swipe do inventário GameManager gameManager = GameManager.instance; gameManager.BlockSwipe = false; currentDropArea = DropArea.GetCurrentDropArea(); //Desativa as Drop Areas foreach (Transform child in dropAreas.transform) { child.gameObject.SetActive(false); } //Verifica se area atual é permitida para o item foreach (string allowedDropArea in allowedDropAreas) { if (allowedDropArea == currentDropArea) { //Destroi o ícone do item Destroy(transform.gameObject); Destroy(slot); //Instancia o item Vector3 clickedPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); clickedPosition.z = item.transform.position.z; Instantiate(item, clickedPosition, Quaternion.identity); scrollViewInventory.GetComponent <ScrollRect>().enabled = true; return; } } //Caso item tenha sido colocado em área não permitida //Retorna item ao inventário, this.transform.position = new Vector3(slot.transform.position.x, slot.transform.position.y, -1); transform.parent = slot.transform; //Ativa o menu inventário menuInventory.SetActive(true); InventoryOpen.isInventoryOpen = true; scrollViewInventory.GetComponent <ScrollRect>().enabled = true; }
public void OnEndDrag(PointerEventData eventData) { mineblock.isAbleToAction = true; if (!CanDrag) { return; } var results = new List <RaycastResult>(); EventSystem.current.RaycastAll(eventData, results); DropArea dropArea = null; foreach (var result in results) { dropArea = result.gameObject.GetComponent <DropArea>(); if (dropArea != null) { break; } } if (dropArea != null && dropArea.transform.childCount < 1) { if (dropArea.Accepts(this)) { dropArea.Drop(this); OnEndDragHandler?.Invoke(eventData, true); transform.parent = dropArea.transform; return; } } rectTransform.anchoredPosition = StartPosition; OnEndDragHandler?.Invoke(eventData, false); }
private void SetDropArea(DropArea newArea) { DropArea oldArea = DropArea; if (newArea == oldArea) { return; } if (oldArea != null) { oldArea.OnExit(); } if (newArea != null) { bool canDrop = MatchManager.CurrentMatch.CurrentSide.CanPutInRow(_cardObject.Card, newArea.CardType); newArea.OnEnter(canDrop); } DropArea = newArea; }
public void OnEndDrag(PointerEventData eventData) { if (!CanDrag) { return; } var results = new List <RaycastResult>(); EventSystem.current.RaycastAll(eventData, results); DropArea slot = null; foreach (var result in results) { slot = result.gameObject.GetComponent <DropArea>(); if (slot != null) { break; } } if (slot != null) { if (slot.Accepts(this)) { slot.Drop(this); OnEndDragHandler?.Invoke(eventData, true); return; } } _rectTransfrom.transform.SetParent(currentParent); // revert back to old parent _rectTransfrom.anchoredPosition = _startPos; OnEndDragHandler?.Invoke(eventData, false); }
public void CheckForDrop(PointerEventData eventData) { Draggable item = null; int toInd = -1; DropArea to = null; for (int i = 0; i < dropAreas.Length; i++) { to = dropAreas[i]; if (to.DropCheck(eventData.position)) { item = Draggable.FindFloating(); toInd = i; break; } } if (!item) { Draggable.ResetPositions(); //No one was dropped into a valid DropArea } else { if (!to) { throw new Exception("Waaaaaaah!"); } //If it didn't even move... DropArea from = item.home; if (!from) { //Came from nowhere? (Initialisation) item.Settle(to); } else { if (from == to) { Draggable.ResetPositions(); return; } int fromInd = Array.IndexOf(dropAreas, from); from.Vacate(); //This is a pleasant fiction. bool empty = !to.holding; if (empty) { //case 0: //from selectus to empty selectus players.Remove(item.Value); //print("From " + fromInd + ", and there are " + players.Count); for (int i = fromInd; i < players.Count; i++) { DropArea a = dropAreas[i], b = dropAreas[i + 1]; b.holding.Settle(a); b.Vacate(); } to = dropAreas[players.Count]; item.Settle(to); players.Add(item.Value); } else { //case 4: //from selectus to occcupied selectus players.Remove(item.Value); players.Insert(toInd, item.Value); if (toInd < fromInd) { for (int i = fromInd - 1; i > toInd - 1; i--) { //print("Moving " + i + " to " + (i + 1)); DropArea a = dropAreas[i], b = dropAreas[i + 1]; a.holding.Settle(b); a.Vacate(); } } else { for (int i = fromInd; i < toInd; i++) { DropArea a = dropAreas[i], b = dropAreas[i + 1]; b.holding.Settle(a); b.Vacate(); } } item.Settle(to); } } } }
void Start() { dropArea = GameObject.FindObjectOfType <DropArea> (); gameManager = GameObject.FindObjectOfType <GameManager> (); }
protected virtual void Awake() { _dropArea = GetComponent <DropArea>() ?? gameObject.AddComponent <DropArea>(); _dropArea.OnDropHandler += OnItemDropped; _RectTranfrom = GetComponent <RectTransform>(); }
protected virtual void Awake() { DropArea = GetComponent <DropArea>() ?? gameObject.AddComponent <DropArea>(); DropArea.OnDropHandler += OnItemDropped; }
public void CheckForDrop(PointerEventData eventData) { Draggable item = null; int toInd = -1; DropArea to = null; for (int i = 0; i < dropAreas.Length; i++) { to = dropAreas[i]; if (to.DropCheck(eventData.position)) { item = Draggable.FindFloating(); toInd = i; break; } } if (!item) { Draggable.ResetPositions(); //No one was dropped into a valid DropArea } else { if (!to) { throw new Exception("Waaaaaaah!"); } //If it didn't even move... DropArea from = item.home; if (!from) { //Came from nowhere? (Initialisation) item.Settle(to); } else { if (from == to) { Draggable.ResetPositions(); return; } int fromInd = Array.IndexOf(dropAreas, from); from.Vacate(); //Oh boy. Watch out. int howDo = (to.holding ? 4 : 0) + (toInd >= 4 ? 2 : 0) + (fromInd >= 4 ? 1 : 0); //msb: destination fillled? //2nd: destination is unselected? //lsb: source is unselected? switch (howDo) { case 0: //from selectus to empty selectus players.Remove(item.Value); //print("From " + fromInd + ", and there are " + players.Count); for (int i = fromInd; i < players.Count; i++) { DropArea a = dropAreas[i], b = dropAreas[i + 1]; b.holding.Settle(a); b.Vacate(); } to = dropAreas[players.Count]; item.Settle(to); players.Add(item.Value); break; case 1: //from seligendus to empty selectus to = dropAreas[players.Count]; item.Settle(to); players.Add(item.Value); break; case 2: //from selectus to empty seligendus players.Remove(item.Value); for (int i = fromInd; i < players.Count; i++) { DropArea a = dropAreas[i], b = dropAreas[i + 1]; b.holding.Settle(a); b.Vacate(); } item.Settle(to); break; case 3: //from seligendus to empty seligendus item.Settle(to); break; //Let's dance case 4: //from selectus to occcupied selectus players.Remove(item.Value); players.Insert(toInd, item.Value); if (toInd < fromInd) { for (int i = fromInd - 1; i > toInd - 1; i--) { //print("Moving " + i + " to " + (i + 1)); DropArea a = dropAreas[i], b = dropAreas[i + 1]; a.holding.Settle(b); a.Vacate(); } } else { for (int i = fromInd; i < toInd; i++) { DropArea a = dropAreas[i], b = dropAreas[i + 1]; b.holding.Settle(a); b.Vacate(); } } item.Settle(to); break; case 5: //from seligendus to occupied selectus players.Insert(toInd, item.Value); for (int i = players.Count - 1; i > toInd; i--) { //print("Moving " + i + " to " + (i + 1)); DropArea a = dropAreas[i - 1], b = dropAreas[i]; a.holding.Settle(b); a.Vacate(); } item.Settle(to); break; case 6: //from selectus to occcupied seligendus players.Remove(item.Value); for (int i = fromInd; i < players.Count; i++) { DropArea a = dropAreas[i], b = dropAreas[i + 1]; b.holding.Settle(a); b.Vacate(); } for (int i = 4; true; i++) //I live on the edge { if (!dropAreas[i].holding) { item.Settle(dropAreas[i]); break; } } break; case 7: //from seligendus to occupied seligendus for (int i = 4; true; i++) //Enan Danger Munzar { if (!dropAreas[i].holding) { item.Settle(dropAreas[i]); break; } } break; } } } }
protected virtual void Awake() { DropArea = GetComponent <DropArea>() ?? gameObject.AddComponent <DropArea>(); DropArea.OnDropHandler += OnItemDropped; disableDropCondition = new DisableDropCondition(); }
public bool DragObjectEnd(object obj) { bool newDropPosition = false; DropArea drop; if (objectsDropArea.TryGetValue(obj, out drop)) { Event currentEvent = Event.current; if (Event.current != null) { Vector3 mouse = InputHelpers.MouseOnGUI(); if (InputHelpers.MouseDown(0) && CurrentDragObject.CurrentRect.Contains(mouse) && !somethingIsDraggingAlready) { somethingIsDraggingAlready = true; CurrentDragObject.IsDragging = true; CurrentDragObject.Ease = true; CurrentDragObject.t = 0; CurrentDragObject.EaseStartRect = CurrentDragObject.StartRect; CurrentDragObject.EaseEndRect = new Rect( mouse.x - CurrentDragObject.CurrentRect.width / 2f, mouse.y - CurrentDragObject.CurrentRect.height / 2f, CurrentDragObject.CurrentRect.width, CurrentDragObject.CurrentRect.height); } else if (InputHelpers.MouseMoved(0) && CurrentDragObject.IsDragging) { CurrentDragObject.IsDragging = true; CurrentDragObject.t = 0; CurrentDragObject.EaseStartRect = CurrentDragObject.CurrentRect; CurrentDragObject.EaseEndRect = new Rect( mouse.x - CurrentDragObject.CurrentRect.width / 2f, mouse.y - CurrentDragObject.CurrentRect.height / 2f, CurrentDragObject.CurrentRect.width, CurrentDragObject.CurrentRect.height); } else if (InputHelpers.MouseUp(0) && CurrentDragObject.IsDragging) { CurrentDragObject.t = 0; CurrentDragObject.IsDragging = false; somethingIsDraggingAlready = false; CurrentDragObject.Ease = true; DropArea selectedDropArea = null; foreach (DropArea dropArea in GetValidDropAreas(obj.GetType())) { if (dropArea.ContainsMouse() && dropArea.Object == null) { selectedDropArea = dropArea; newDropPosition = true; break; } } if (selectedDropArea != null && selectedDropArea.Object == null) { CurrentDragObject.EaseStartRect = CurrentDragObject.CurrentRect; CurrentDragObject.EaseEndRect = selectedDropArea.Rect; selectedDropArea.Object = obj; CurrentDragObject.DropArea.Object = null; objectsDropArea[obj] = selectedDropArea; CurrentDragObject.DropArea = selectedDropArea; CurrentDragObject.StartRect = CurrentDragObject.DropArea.Rect; } else { CurrentDragObject.EaseStartRect = CurrentDragObject.CurrentRect; CurrentDragObject.EaseEndRect = CurrentDragObject.StartRect; } } } easeDragObject(); dragObjectsInProgress.Pop(); } return(newDropPosition); }