Beispiel #1
0
        Vector3 Extended(Vector3 from, Vector3 to)
        {
            Vector3 point = Vector3.zero;

            point.x = HMath.directionPointX(from.x, from.z, to.x, to.z, extended);
            point.z = HMath.directionPointY(from.x, from.z, to.x, to.z, extended);
            return(point);
        }
        public void SetPath(List <Vector3> paths)
        {
            List <Vector3> list = new List <Vector3>();

            if (paths.Count >= 2)
            {
                Vector3 p1       = paths[0];
                Vector3 p2       = paths[1];
                float   distance = Vector3.Distance(p1, p2);
                Vector3 p3       = Vector3.zero;
                int     add      = 0;
                bool    begin    = false;
                bool    end      = false;
                if (distance > 1F)
                {
                    p3.x  = HMath.directionPointX(p1.x, p1.z, p2.x, p2.z, lengthRadius);
                    p3.z  = HMath.directionPointY(p1.x, p1.z, p2.x, p2.z, lengthRadius);
                    add  += 1;
                    begin = true;
                }

                p1       = paths[paths.Count - 1];
                p2       = paths[paths.Count - 2];
                distance = Vector3.Distance(p1, p2);
                Vector3 p4 = Vector3.zero;
                if (distance > 1F)
                {
                    p4.x = HMath.directionPointX(p1.x, p1.z, p2.x, p2.z, lengthRadius);
                    p4.z = HMath.directionPointY(p1.x, p1.z, p2.x, p2.z, lengthRadius);
                    add += 1;
                    end  = true;
                }


                for (int i = 0; i < paths.Count; i++)
                {
                    list.Add(paths[i]);
                    if (add > 0)
                    {
                        if (i == 0 && begin)
                        {
                            list.Add(p3);
                        }

                        if (i == paths.Count - 2 && end)
                        {
                            list.Add(p4);
                        }
                    }
                }
            }


            for (int i = 0; i < list.Count; i++)
            {
                Vector3 source = list[i];
                Vector3 pos    = new Vector3(source.x, source.y, source.z);

                if (i != 0 && i != list.Count - 1)
                {
                    float myGap = gap;
//					if(i > 1 && i < list.Count - 2)
//					{
//						myGap = turnGap;
//					}

                    if (list.Count > 4 && i < list.Count - 1)
                    {
                        myGap = turnGap;
                    }

                    Vector3 d1     = pos - list[i - 1];
                    Vector3 d2     = list[i + 1] - pos;
                    Vector3 d      = d1.normalized + d2.normalized;
                    float   radian = HMath.radian(0, 0, d.x, d.z);
                    radian += Mathf.PI * 0.5F;

                    float x = HMath.radianPointX(radian, myGap * index, pos.x);
                    float z = HMath.radianPointY(radian, myGap * index, pos.z);
                    pos.x = x;
                    pos.z = z;
                }
                this.list.Add(pos);
            }
        }