示例#1
0
    //public static Vector3 GetDownPosition(Vector3 r)
    //{
    //    NavMeshHit hitInfo;
    //    Vector3 r1 = new Vector3(r.x, r.y - 100, r.z);
    //    CreatePoint(r1, "DownTarget", 0.1f, Color.red);
    //    if (NavMesh.Raycast(r, r1,out hitInfo, -1))
    //    {
    //        r = hitInfo.position;
    //    }
    //    else
    //    {
    //        //Debug.LogError("GetDownPosition No DownPosition ");
    //    }
    //    return r;
    //}

    public static Vector3 GetDownSample(Vector3 r, int count, float step)
    {
        Vector3 down        = r;
        float   distance    = float.MaxValue;
        float   floorHeight = 0;

        for (int i = 0; i < count; i++)
        {
            Vector3 r1 = new Vector3(r.x, r.y - i * step, r.z);
            var     p  = GetClosetPointByMeshEx(r1);

            if (IsDebug)
            {
                var t1 = NavMeshHelper.CreatePoint(r1, "DownTarget" + i, 0.1f, Color.red);
                var t2 = NavMeshHelper.CreatePoint(p, "DownTarget_Mesh" + i, 0.1f, Color.red);
                t2.transform.parent = t1.transform;
            }

            if (p.y < r.y)
            {
                if (floorHeight == 0)
                {
                    floorHeight = p.y;
                }
                var dis = Vector3.Distance(p, new Vector3(r1.x, floorHeight, r1.z));
                if (dis < distance)
                {
                    distance = dis;
                    down     = p;
                }
            }
        }
        return(down);
    }
示例#2
0
    public NavPoint(string n, Vector3 p, Vector3 target, Color color, NavMeshAgent agent)
    {
        Name     = n;
        Position = p;
        Color    = color;

        if (NavMeshHelper.IsDebug)
        {
            var         t01  = NavMeshHelper.CreatePoint(p, n, 0.1f, color);
            NavTestInfo info = t01.AddComponent <NavTestInfo>();
            info.agent  = agent;
            info.Target = target;
        }

        Layer = NavMeshHelper.GetLayer(p);
    }