Ejemplo n.º 1
0
    public void runConnection()
    {
        connectsTo = new pathPoint[pathMeshs.Length];

        for (int i = 0; i < pathMeshs.Length; i++)
        {
            //generate our list of path vertices from the armature children
            List <Vector3> path = new List <Vector3> ();
            Transform      t    = pathMeshs [i].transform.GetChild(0);
            while (true)
            {
                //add the position
                path.Add(t.position);

                //find next point
                if (t.childCount == 1)
                {
                    t = t.GetChild(0);
                }
                else if (t.childCount > 1)
                {
                    Debug.LogError("too many children");
                }
                else
                {
                    break;
                }
            }
            //if the path is followed backward, simply reverse this array
            if (!followPathForward)
            {
                path.Reverse();
            }

            //finally set variables based on aboce
            pathVertices [i] = path.ToArray <Vector3> ();
            pathStart        = pathVertices [i] [0];
            pathEnds [i]     = pathVertices [i].Last();

            foreach (GameObject go in GameObject.FindGameObjectsWithTag("pathPoint"))
            {
                //get the pathPoint from other object
                pathPoint pa = go.GetComponent <pathPoint> ();

                //make sure it is not this point
                if (pa.getID() == gameObject.transform.parent.gameObject.GetInstanceID())
                {
                    continue;
                }

                //check if that point meets this endpoint
                if (Vector3.Distance(pa.getStartPoint(), pathEnds [i]) < 0.01f)
                {
                    connectsTo [i] = pa;
                }

                //check if that start point meets this startpoint
                //(this is checked more than necessary, but makes for a more understandable program)
                if (Vector3.Distance(pa.getStartPoint(), pathStart) < 0.01f)
                {
                    connectsFrom = pa;
                }

                //check if this point meets that point
                pa.checkEnds(this);
            }
        }

        int p = pathVertices[0].Length - 3;

        trainDropPoint = trackUtility.utility.lerp2(pathVertices [0] [p], pathVertices [0] [p + 1], pathVertices [0] [p + 2], 0.5f);
        totalLength    = trackUtility.utility.pathDistance(this);
        lengths        = trackUtility.utility.secDistance(this);
    }