private void CheckAtPositionForNodesFromStreetPoint(Collider[] colls, GameObject streetPoint, NodeStreet curNode)
 {
     foreach (Collider c in colls)
     {
         var nextNode  = c.gameObject.GetComponent <NodeHandler>().node;
         var curStreet = new ArcStreet(curNode, nextNode);
         curNode.AddStreet(curStreet);
     }
 }
    private void CheckAtPositionForNodesFromCross(Vector3 checkPos, NodeStreet curNode, float radius = 2f)
    {
        var colls = Physics.OverlapSphere(checkPos, radius, LayerMask.GetMask("network"));

        foreach (Collider c in colls)
        {
            var nextNode  = c.gameObject.GetComponent <NodeHandler>().node;
            var curStreet = new ArcStreet(curNode, nextNode);
            curNode.AddStreet(curStreet);
        }
    }
    private float GetDistance(NodeStreet a, NodeStreet b)
    {
        // Checking if nodes are connected
        ArcStreet connectingStreet = null;
        bool      isConnected      = false;

        foreach (ArcStreet fromA in a.availableStreets)
        {
            if (fromA.arrivalNode.Equals(b))
            {
                isConnected      = true;
                connectingStreet = fromA;
                break;
            }
        }
        if (!isConnected)
        {
            return(Vector3.Distance(a.nodePosition, b.nodePosition));
        }
        //return Mathf.Infinity;

        return(connectingStreet.lenght);
    }
Beispiel #4
0
    private IEnumerator Connect(Vector3 PosToCheck)
    {
        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        var colls = Physics.OverlapSphere(PosToCheck, 5f, LayerMask.GetMask("network"));

        if (colls.Length == 0)
        {
            StartCoroutine(Connect(transform.position + transform.forward * 7 + transform.right * 3));
            yield return(null);
        }
        else
        {
            NodeStreet nearestNode = colls[0].gameObject.GetComponent <NodeHandler>().node;
            foreach (Collider c in colls)
            {
                var nextNode = c.gameObject.GetComponent <NodeHandler>().node;

                if (Vector3.Distance(transform.position, c.gameObject.transform.position) <
                    Vector3.Distance(transform.position, nearestNode.nodePosition))
                {
                    nearestNode = nextNode;
                }
            }

            // Linking it to me
            var linkingStret = new ArcStreet(nearestNode, node);
            nearestNode.AddStreet(linkingStret);

            // Linking me to it
            var curStreet = new ArcStreet(node, nearestNode);
            node.AddStreet(curStreet);
        }
    }
 public void RemoveStreet(ArcStreet street)
 {
     availableStreets.Remove(street);
 }
 public void AddStreet(ArcStreet street)
 {
     availableStreets.Add(street);
 }