Example #1
0
    void Start()
    {
        for (int i = 0; i < transform.childCount - 1; i++)
        {
            fields.Add(transform.GetChild(i).GetComponent <Field>());
        }

        foreach (Int2 fc in fieldConnections)
        {
            FieldConnection fCon = Instantiate(connectionPrefab, connections).GetComponent <FieldConnection>();
            fCon.connection = fc;
            fCon.fields     = new Field[] { GetField(fc.first), GetField(fc.second) };
            fConnections.Add(fCon);

            Vector3      f = fCon.fields[0].transform.position; f.z = 1;
            Vector3      s = fCon.fields[1].transform.position; s.z = 1;
            LineRenderer l = fCon.GetComponent <LineRenderer>();
            l.SetPosition(0, f);
            l.SetPosition(1, s);

            FieldConnectionInfo i = new FieldConnectionInfo();
            i.fieldConnection = fCon;
            i.SetAngle(f, s);
            GetField(fc.first).fcInfos.Add(new FieldConnectionInfo(i));
            i.SetAngle(s, f);
            GetField(fc.second).fcInfos.Add(new FieldConnectionInfo(i));
        }
    }
Example #2
0
 public void CancelLineHighlight(bool c)
 {
     if (currentInfo != null)
     {
         currentInfo.fieldConnection.Unhighlight(c);
         currentInfo = null;
     }
 }
Example #3
0
    void DetectSwipe(Vector2 pos)
    {
#if UNITY_EDITOR
        if (Input.GetMouseButtonUp(0))
        {
            if (fieldManager.actionField)
            {
                ActionPanel ap;
                if (fieldManager.actionField.ownership == Field.Ownership.Player)
                {
                    ap = regroupPanel;
                }
                else
                {
                    ap = attackPanel;
                }
                ap.Set(swipedField.ctStrength);
                ap.Open();
            }
            else
            {
                swipedField = null;
            }

            ResetInput();

            return;
        }
        if (!Input.GetMouseButton(0))
        {
            return;
        }
#elif UNITY_ANDROID || UNITY_IOS
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
        {
            if (fieldManager.actionField)
            {
                ActionPanel ap;
                if (fieldManager.actionField.ownership == Field.Ownership.Player)
                {
                    ap = regroupPanel;
                }
                else
                {
                    ap = attackPanel;
                }
                ap.Set(swipedField.ctStrength);
                ap.Open();
            }
            else
            {
                swipedField = null;
            }

            startPos   = new Vector2(-1, -1);
            inputPhase = 1;
            idleTime   = 0;
            fieldManager.UnhighlightConnectedFields();

            return;
        }
        if (Input.touchCount == 0)
        {
            return;
        }
#endif

        RaycastHit2D hit = Physics2D.Raycast(startPos, Vector2.up, 0.01f);
        if (inputPhase == 1 && hit && hit.transform.tag == "Field")
        {
            Field f = hit.transform.GetComponent <Field>();
            if (f.ownership != Field.Ownership.Player)
            {
                return;
            }
            if (pos == startPos)
            {
                if (idleTime >= 0.6f)
                {
                    if (fieldManager.selectedField && fieldManager.selectedField != f)
                    {
                        fieldManager.selectedField.Deselect();
                    }
                    if (!fieldManager.selectedField)
                    {
                        f.Select();
                    }
                }
                idleTime += Time.deltaTime;
                return;
            }

            DeselectField();
            inputPhase  = 2;
            swipedField = f;
            fieldManager.HighlightFieldConnections(f.index);
        }
        else if (inputPhase == 2)
        {
            Vector2 sp      = swipedField.transform.position;
            Vector2 d       = pos - sp;
            float   angle   = Math.RadToDeg360(Mathf.Atan2(d.y, d.x));
            bool    inRange = false;

            foreach (FieldConnectionInfo i in swipedField.fcInfos)
            {
                if (Mathf.Abs(Mathf.DeltaAngle(i.angle, angle)) <= 20)
                {
                    inRange = true;
                    if (i == currentInfo)
                    {
                        break;
                    }

                    CancelLineHighlight(false);
                    i.fieldConnection.HighlightSwipe(swipedField.index);
                    currentInfo = i;
                }
            }
            if (!inRange)
            {
                fieldManager.actionField = null;
                CancelLineHighlight(false);
            }
        }
    }
Example #4
0
 public FieldConnectionInfo(FieldConnectionInfo i)
 {
     angle           = i.angle;
     fieldConnection = i.fieldConnection;
 }