Esempio n. 1
0
 void Checker(ElectricNode other)
 {
     if (!other.isOpened && !other.isClosed)
     {
         openList.Add(other);
         other.isOpened = true;
     }
 }
Esempio n. 2
0
 private void OnNodeTouched(ElectricNode node)
 {
     if (nodesPressed.Count < 2)
     {
         if (!nodesPressed.Contains(node.nodeId))
         {
             nodesPressed.Add(node.nodeId);
         }
     }
 }
Esempio n. 3
0
    public override void CustomReset()
    {
        node1 = null;
        node2 = null;

        if (currentWire)
        {
            Destroy(currentWire);
        }

        mPoleMaker.CustomReset();
    }
Esempio n. 4
0
    void MakeTempWire(ElectricNode start, ElectricNode end)
    {
        if (currentWire)
        {
            Destroy(currentWire);
        }

        currentWire = Instantiate(buildObject, Vector3.zero, Quaternion.identity);
        var b = currentWire.GetComponent <Wire>();

        b.ResetPath(start, end);
    }
Esempio n. 5
0
        public void Initialize(GenerativeData.Difficulty data)
        {
            m_size = data.boardSize;
            List <ActivelElectricNodeAuthoring> activeNodesAuthoring = data.boardsPool[UnityEngine.Random.Range(0, data.boardsPool.Count)].activeNodes;

            nodes = new ElectricNode[m_size.x, m_size.y];

            // Calculate positions
            Vector2 lenght = new Vector2(nodeDistance * (m_size.x - 1), nodeDistance * (m_size.y - 1));

            Vector2[,] translations = new Vector2[m_size.x, m_size.y];
            for (int x = 0; x < m_size.x; x++)
            {
                for (int y = 0; y < m_size.y; y++)
                {
                    translations[x, y] = new Vector2(Mathf.Lerp(-lenght.x / 2.0f, lenght.x / 2.0f, x), Mathf.Lerp(lenght.y, 0, y));
                }
            }

            for (int x = 0; x < m_size.x; x++)
            {
                for (int y = 0; y < m_size.y; y++)
                {
                    GameObject go = Instantiate(electricNodePrefab);
                    go.transform.position = transform.position + new Vector3(translations[x, y].x, translations[x, y].y, 0);

                    nodes[x, y] = new ElectricNode
                    {
                        gameObject = go,
                    };

                    // If active node
                    if (activeNodesAuthoring.Any(n => n.position == new Vector2Int(x, y)))
                    {
                        ActivelElectricNodeAuthoring auth = activeNodesAuthoring.First(n => n.position == new Vector2Int(x, y));

                        nodes[x, y].target    = true;
                        nodes[x, y].timer     = auth.defaultTimer ? data.defaultTImer : auth.customTimer;
                        nodes[x, y].countdown = -1;
                        nodes[x, y].state     = new FiniteStateMachine();
                        nodes[x, y].state.SetStateData("READY");
                        nodes[x, y].state.SetStateData("ACTIVE");
                        nodes[x, y].state.SetStateData("INACTIVE");
                        nodes[x, y].state.SetStateData("DONE");
                        nodes[x, y].state.ChangeState("READY");
                    }
                    else
                    {
                    }
                }
            }
        }
Esempio n. 6
0
    public void ResetPath(ElectricNode start, ElectricNode end)
    {
        nodeStart = start;
        nodeEnd   = end;
        path      = new Path(nodeStart.transform, nodeEnd.transform);

        //reset controll points
        float halfDist = (nodeStart.transform.position + nodeEnd.transform.position).magnitude * 0.05f;
        var   cont1    = (nodeEnd.transform.position - nodeStart.transform.position).normalized * halfDist;

        cont1.y -= nodeStart.transform.position.y * 0.5f;
        path.MovePoint(1, nodeStart.transform.position + cont1);
        var cont2 = (-nodeEnd.transform.position + nodeStart.transform.position).normalized * halfDist;

        cont2.y -= nodeEnd.transform.position.y * 0.5f;
        path.MovePoint(2, nodeEnd.transform.position + cont2);

        MakeMesh();
    }
Esempio n. 7
0
    public override bool ParseInput(ref Ray mouseRay)
    {
        if (node1 && node2)
        {
            return(MakeWire());
        }

        RaycastHit hit;

        if (Physics.Raycast(mouseRay, out hit, playerRange, NodeMask))
        {
            if (node1)
            {
                node2 = hit.collider.GetComponent <ElectricNode>();
                if (node1 == node2 && !node2.other)
                {
                    node2 = null;
                }
            }
            else
            {
                node1 = hit.collider.GetComponent <ElectricNode>();
                if (node1.other)
                {
                    node1 = null;
                }
            }
            return(MakeWire());
        }

        if (mPoleMaker.ParseInput(ref mouseRay))
        {
            node1 = null;
            mPoleMaker.currentPole = null;
            if (currentWire)
            {
                currentWire = null;
            }
            return(true);
        }

        return(false);
    }
Esempio n. 8
0
    public void Disconect()
    {
        switch (body)
        {
        case AttachedToBody.Producer:
            break;

        case AttachedToBody.Pole:
            EchoReset();
            break;

        case AttachedToBody.Consumer:
            consumer.ShutDown();
            break;

        default:
            break;
        }
        other = null;
    }
Esempio n. 9
0
 public void Connect(ElectricNode n)
 {
     other = n;
 }