示例#1
0
    /// <summary>
    /// 获取有效目标点
    /// </summary>
    /// <param name="targetPos"></param>
    /// <returns></returns>
    protected Vector3 GetDestination(Vector3 targetPos)
    {
        Vector3 destination = targetPos;

        InitNavMeshAgent();
        return(NavMeshHelper.GetClosetPoint(destination, agent));
    }
示例#2
0
    private IEnumerator ShowPosListAsync(List <Pos> posList)
    {
        DateTime   start  = DateTime.Now;
        List <Pos> result = null;

        InitPosPointsParent(); //删除并重新创建PosParent

        GameObject bluePrefab  = GetPrefab(Color.blue, 0.5f);
        GameObject redPrefab   = GetPrefab(Color.red, 0.5f);
        GameObject greenPrefab = GetPrefab(Color.green, 0.5f);
        GameObject blackPrefab = GetPrefab(Color.black, 0.5f);

        for (int i = 0; i < posList.Count && i < LimitCount; i++)
        {
            Pos pos = posList[i];
            //CreatePoint(pos);

            Vector3 v1 = new Vector3(pos.X, pos.Y, pos.Z);       //二维坐标
            Vector3 v2 = LocationManager.GetRealVector(v1);      //三维坐标

            Vector3 v3 = NavMeshHelper.GetClosetPoint(v2, null); //NavMesh上的坐标,这部分可能会比较花时间
            //Vector3 v4 = new Vector3(v3.x, v2.y, v3.z);//高度相同
            var dis = Vector3.Distance(v2, v3);

            GameObject prefab1 = null;
            GameObject prefab2 = blackPrefab;

            if (dis > RedDistance)//大于一个距离 5
            {
                prefab1 = redPrefab;
            }
            else if (dis < GreenDistanc)//大于一个距离 1
            {
                prefab1 = greenPrefab;
            }
            else
            {
                prefab1 = bluePrefab;
            }
            var p1 = CreatePoint(prefab1, v2, posPointParent.transform); //三维坐标
            p1.name = string.Format("{0}|{1}", i, v2);
            var p2 = CreatePoint(prefab2, v3, p1.transform);             //NavMesh上的坐标
            p2.name = "d:" + dis;
            //Gizmos.DrawLine(v2, v3);
            Debug.Log(string.Format("{0}/{1}", i, posList.Count));
            yield return(null);
        }

        GameObject.DestroyImmediate(bluePrefab);
        GameObject.DestroyImmediate(redPrefab);
        GameObject.DestroyImmediate(greenPrefab);
        GameObject.DestroyImmediate(blackPrefab);

        posPointParent.HighlightOn();

        Log.Info("ShowPosList:", (DateTime.Now - start).TotalMilliseconds + "ms");
    }