예제 #1
0
 public void Init(NodeButtonBehavior button)
 {
     rectTransform.anchoredPosition = button.Position;
     imageRectTransform.SetSize(button.Size);
     canvasGroup.Show();
     canvasGroup.interactable = false;
 }
예제 #2
0
    private bool AreNextToo(NodeButtonBehavior button1, NodeButtonBehavior button2)
    {
        int xDif = Mathf.Abs(downButton.XIndex - lastEnter.XIndex);
        int yDif = Mathf.Abs(downButton.YIndex - lastEnter.YIndex);

        // If only a single one of them is equal to 1
        return((xDif == 1 || yDif == 1) && xDif != yDif);
    }
예제 #3
0
 private void OnSwipeOccurred(Vector2 dir)
 {
     CurrentBoard.Behavior.Spin(dir);
     if (_downButton == null)
     {
         return;
     }
     _downButton.Deselect();
     _downButton = null;
 }
예제 #4
0
    public void ButtonExit(NodeButtonBehavior button, PointerEventData data)
    {
        if (lastEnter != null && lastEnter != downButton)
        {
            lastEnter.Unhover();
        }

        if (lastEnter == button)
        {
            lastEnter = null;
        }
    }
예제 #5
0
    public void OnPointerDown(PointerEventData eventData)
    {
        pointDown = eventData.position;
        if (lastEnter == null)
        {
            return;
        }

        var node = board.GetOffsetNode(lastEnter.XIndex, lastEnter.YIndex);

        if (node != null && node.Affiliation == BoardNodeAffiliation.Player && node.CanSend)
        {
            downButton = lastEnter;
            downButton.Select();
        }
    }
예제 #6
0
    public void OnPointerUp(PointerEventData eventData)
    {
        if (downButton != null)
        {
            if (lastEnter != null)
            {
                lastEnter.Unhover();

                if (downButton != lastEnter)
                {
                    var node = board.GetOffsetNode(lastEnter.XIndex, lastEnter.YIndex);
                    if (node != null)
                    {
                        if (AreNextToo(lastEnter, downButton))
                        {
                            if (NodeSwipeOccurred != null)
                            {
                                NodeSwipeOccurred(downButton, lastEnter, MathUtils.ClosestCardinal(eventData.position - pointDown));
                            }
                        }
                    }
                    else
                    {
                        //RaiseSwipeOccurred(eventData);
                    }
                    downButton.Deselect();
                }
                else
                {
                    downButton.Hover();
                    lastEnter = downButton;
                    //RaiseSwipeOccurred(eventData);
                }
            }
            else
            {
                downButton.Deselect();
                //RaiseSwipeOccurred(eventData);
            }
        }
        else
        {
            RaiseSwipeOccurred(eventData);
        }

        downButton = null;
    }
예제 #7
0
    private void OnNodeSwipeOccurred(NodeButtonBehavior down, NodeButtonBehavior up, Vector2 dir)
    {
        var fromNode = CurrentBoard.GetOffsetNode(down.XIndex, down.YIndex);
        var toNode   = CurrentBoard.GetOffsetNode(up.XIndex, up.YIndex);

        if (fromNode == null || toNode == null)
        {
            return;
        }
        var dist = Vector2.Distance(fromNode.Behavior.transform.position, toNode.Behavior.transform.position);

        if (!(dist <= 1.25f))
        {
            return;
        }
        fromNode.SendEnergy(toNode);
        EnergyTransferCount++;
    }
예제 #8
0
    public void ButtonEnter(NodeButtonBehavior button, PointerEventData data)
    {
        lastEnter = button;
        var node = board.GetOffsetNode(button.XIndex, button.YIndex);

        if (node != null && button != downButton)
        {
            if (downButton != null && node.CanReceive)
            {
                if (AreNextToo(downButton, button))
                {
                    lastEnter.Hover();
                }
            }
            else if (node.Affiliation == BoardNodeAffiliation.Player && node.CanSend)
            {
                lastEnter.Hover();
            }
        }
    }