Esempio n. 1
0
    public static bool CanWalkTo(Vector3 dst)
    {
        Actor localPlayer = Game.GetInstance().GetLocalPlayer();

        if (localPlayer != null)
        {
            var     path      = new XNavMeshPath();
            Vector3 playerPos = localPlayer.transform.position;
            dst = PhysicsHelp.GetPosition(dst.x, dst.z);
            XNavMesh.CalculatePath(playerPos, dst, LevelManager.GetInstance().AreaExclude, path);
//            GameDebug.LogWarning("NavMesh.CalculatePath src: " + playerPos);
//            GameDebug.LogWarning("NavMesh.CalculatePath dst: " + dst);
//            GameDebug.LogWarning("NavMesh.CalculatePath status: " + path.status);
//            string str = "NavMesh.CalculatePath corners:";
//            for (int i = 0; i < path.corners.Length; ++i)
//            {
//                str += " " + path.corners[i];
//            }
//            GameDebug.LogWarning(str);
            if (path.status == XNavMeshPathStatus.PathComplete)
            {
                return(true);
            }
        }

        return(false);
    }
Esempio n. 2
0
        private IEnumerator CoLoadNavmeshFile(string path)
        {
            SGameEngine.AssetResource result = new SGameEngine.AssetResource();

            yield return(MainGame.HeartBehavior.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_asset(path, typeof(TextAsset), result)));

            // 加载好的数据是否是当前场景的数据
            uint   stage_id     = SceneHelp.GetFirstStageId(SceneHelp.Instance.CurSceneID);
            uint   map_id       = SceneHelp.GetMapIdByStageId(stage_id);
            string navmesh_file = "Assets/Res/NavMesh/" + map_id.ToString() + ".txt";

            if (navmesh_file.Equals(path) == false)
            {
                yield break;
            }

            if (result.asset_ == null)
            {
                IsLoadingNavmeshFile = false;
                yield break;
            }

            TextAsset textAsset = result.asset_ as TextAsset;

            if (textAsset == null || textAsset.text == null)
            {
                IsLoadingNavmeshFile = false;
                Debug.LogError("LevelManager::CoLoadNavmeshFile, can not read navmesh file:" + path);
                yield break;
            }

            bool ret = XNavMesh.LoadBuffer(textAsset.bytes);

            if (!ret)
            {
                mCurNavmeshFile = string.Empty;
                GameDebug.LogError("navmesh LoadBuffer error : " + path);
            }
            else
            {
                mCurNavmeshFile = path;
            }

            result.destroy();

            IsLoadingNavmeshFile = false;
        }
Esempio n. 3
0
    public static Vector3 ClampInWalkableRange(Vector3 raw, Vector3 defaultPos, out bool result, float maxDistance = 30)
    {
        XNavMeshHit nearestHit;

        result = XNavMesh.SamplePosition(raw, out nearestHit, maxDistance, LevelManager.GetInstance().AreaExclude);

        if (result)
        {
            return(nearestHit.position);
        }
        else
        {
            GameDebug.Log("Instance Helper::ClampInWalkableRange can not clamp position:" + raw.ToString());

            return(defaultPos);
        }
    }