Exemplo n.º 1
0
    //Draws the arrows for a path, updating them relative to the node and its followers in the path.
    void setArrowsFor(Node n)
    {
        // two -> one -> node

        Node one = null;
        Node two = null;

        Quaternion q = new Quaternion();

        //if we're the start node
        if (path.IndexOf(n) == 0)
        {
            return;
        }

        //one is the node directly following node
        one = path[path.IndexOf(n) - 1];

        //two is the node directly following one
        if (path.IndexOf(n) - 2 > 0)
        {
            two = path[path.IndexOf(n) - 2];
        }


        Vector3 delta01 = Vector3.zero;
        Vector3 delta12 = Vector3.zero;

        //find the positional difference between node and one
        delta01 = n.position - one.position;

        //find the positional difference between one and two
        if (two != null)
        {
            delta12 = one.position - two.position;
        }
        else
        {
            delta12 = one.position - caster.transform.position;
        }

        //Check the the differences between node and one, finding the angle, then finding the differences between one and two, finding their angle.
        // From there, we can tell if we need to have keep the arrow straight, or bend it.

        //SPEEDUP: Use a pool for this.
        if (Mathfx.CompareXZ(delta01, Vector3.forward))
        {
            q.eulerAngles = Vector3.zero;

            if (one != path[0])
            {
                if (Mathfx.CompareXZ(delta12, Vector3.forward) || Mathfx.CompareXZ(delta12, Vector3.back))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_straight") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.right))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_left") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.left))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_right") as GameObject, one.position, q) as GameObject).transform);
                }
            }
        }
        else if (Mathfx.CompareXZ(delta01, Vector3.back))
        {
            q.eulerAngles = new Vector3(0f, 180f, 0f);

            if (one != path[0])
            {
                if (Mathfx.CompareXZ(delta12, Vector3.forward) || Mathfx.CompareXZ(delta12, Vector3.back))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_straight") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.right))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_right") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.left))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_left") as GameObject, one.position, q) as GameObject).transform);
                }
            }
        }
        else if (Mathfx.CompareXZ(delta01, Vector3.left))
        {
            q.eulerAngles = new Vector3(0f, -90f, 0f);

            if (one != path[0])
            {
                if (Mathfx.CompareXZ(delta12, Vector3.forward))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_left") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.back))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_right") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.right) || Mathfx.CompareXZ(delta12, Vector3.left))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_straight") as GameObject, one.position, q) as GameObject).transform);
                }
            }
        }
        else if (Mathfx.CompareXZ(delta01, Vector3.right))
        {
            q.eulerAngles = new Vector3(0f, 90f, 0f);

            if (one != path[0])
            {
                if (Mathfx.CompareXZ(delta12, Vector3.forward))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_right") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.back))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_left") as GameObject, one.position, q) as GameObject).transform);
                }
                else if (Mathfx.CompareXZ(delta12, Vector3.right) || Mathfx.CompareXZ(delta12, Vector3.left))
                {
                    one.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_straight") as GameObject, one.position, q) as GameObject).transform);
                }
            }
        }
        n.tile.setHighlightObject((GameObject.Instantiate(Resources.Load("prefabs/path/path_arrow") as GameObject, n.position, q) as GameObject).transform);
    }