示例#1
0
 void OnEnable()
 {
     sources         = new List <NavMeshBuildSource> ();
     navMesh         = new NavMeshData();
     navMeshInstance = NavMesh.AddNavMeshData(navMesh);
     UpdateNavMesh(false);
 }
示例#2
0
    private void OnEnable()
    {
        terrain                    = GetComponent <Terrain>();
        terrain.terrainData        = GenerateTerrain(terrain.terrainData);
        terrain.transform.position = new Vector3(-config.width / 2, 0, -config.depth / 2);

        List <NavMeshBuildSource> buildSources = new List <NavMeshBuildSource>();

        NavMeshBuilder.CollectSources(
            null,
            ~9, // TODO Custom editor so we can select layers
            NavMeshCollectGeometry.RenderMeshes,
            0,
            new List <NavMeshBuildMarkup>(),
            buildSources
            );

        NavMeshData navData = NavMeshBuilder.BuildNavMeshData(
            NavMesh.GetSettingsByID(0),
            buildSources,
            new Bounds(new Vector3(0, 0, 0), new Vector3(config.width, config.height, config.depth)),
            Vector3.zero,
            Quaternion.identity
            );

        if (navData == null)
        {
            Debug.LogError("Failed to create nav mesh data!");
        }
        else
        {
            navMeshDataInstance = NavMesh.AddNavMeshData(navData);
        }
    }
示例#3
0
 /// <summary>
 /// 地形更新处理
 /// </summary>
 public void HandleForUpdateNavMesh()
 {
     if (navMeshIsUpdating)
     {
         if (navMeshUpdateOperation.isDone)
         {
             if (navMeshInstance.valid)
             {
                 NavMesh.RemoveNavMeshData(navMeshInstance);
             }
             navMeshInstance   = NavMesh.AddNavMeshData(navMeshData);
             navMeshIsUpdating = false;
         }
     }
     else if (navMeshHasNewData)
     {
         try
         {
             navMeshUpdateOperation = NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, navMeshBuildSettings, navMeshSources.Values.ToList(), worldBounds);
             navMeshIsUpdating      = true;
         }
         catch
         {
         }
         navMeshHasNewData = false;
     }
 }
示例#4
0
 void OnEnable()
 {
     // Construct and add navmesh
     m_NavMesh  = new NavMeshData();
     m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
     UpdateNavMesh(false);
 }
示例#5
0
        public static void Build(List <GameObject> gameObjects)
        {
            List <NavMeshBuildSource> buildSources = new List <NavMeshBuildSource>();

            for (int i = 0; i < gameObjects.Count; i++)
            {
                NavMeshBuildSource navMeshSource = new NavMeshBuildSource();
                navMeshSource.shape        = NavMeshBuildSourceShape.Mesh;
                navMeshSource.sourceObject = gameObjects[i].GetComponent <MeshFilter>().sharedMesh;
                navMeshSource.transform    = gameObjects[i].transform.localToWorldMatrix;
                navMeshSource.area         = 0;
                buildSources.Add(navMeshSource);
            }

            NavMeshBuildSettings navSetting = new NavMeshBuildSettings();

            navSetting.agentRadius = 0.4f;

            NavMeshData navData = UnityEngine.AI.NavMeshBuilder.BuildNavMeshData(
                navSetting,
                buildSources,
                new Bounds(Vector3.zero, new Vector3(10000, 10000, 10000)),
                Vector3.zero,
                Quaternion.identity
                );

            navMeshDataInstance.Remove();
            navMeshDataInstance = NavMesh.AddNavMeshData(navData);
        }
示例#6
0
    public void RebuildNavmesh(bool async)
    {
        if (async && buildOperation != null && !buildOperation.isDone)
        {
            return;
        }

        buildOperation = null;

        var totalBounds = new Bounds();

        NavMeshSourceTag2D.Collect(ref buildSources, ref totalBounds);
        var buildSettings       = NavMesh.GetSettingsByID(0);
        var totalBoundsReversed = new Bounds(Plane2DRotationInverse * totalBounds.center, Plane2DRotationInverse * totalBounds.size); // We need to reverse the rotation that's going to be used for baking to get proper bounds
        var buildBounds         = new Bounds(Vector3.zero, Vector3.one * float.MaxValue);                                             //Using enclosing and empty bounds is bugged at the moment - use arbitrarily big one

        if (!data)
        {
            data = NavMeshBuilder.BuildNavMeshData(buildSettings, buildSources, buildBounds, totalBounds.center, Plane2DRotation);
        }
        else
        {
            if (async)
            {
                buildOperation = NavMeshBuilder.UpdateNavMeshDataAsync(data, buildSettings, buildSources, buildBounds);
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(data, buildSettings, buildSources, buildBounds);
            }
        }

        dataInstance.Remove();
        dataInstance = NavMesh.AddNavMeshData(data);
    }
示例#7
0
 void OnEnable()
 {
     if (!dontcreate)
     {
         m_NavMeshInstance = NavMesh.AddNavMeshData(m_NavMeshData);
     }
 }
 void UpdateNavMesh()
 {
     if (navMeshIsUpdating)
     {
         if (navMeshUpdateOperation.isDone)
         {
             if (navMeshInstance.valid)
             {
                 NavMesh.RemoveNavMeshData(navMeshInstance);
             }
             navMeshInstance   = NavMesh.AddNavMeshData(navMeshData);
             navMeshIsUpdating = false;
         }
     }
     else if (navMeshHasNewData)
     {
         try {
             navMeshUpdateOperation = NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, navMeshBuildSettings, navMeshSources, worldBounds);
             navMeshIsUpdating      = true;
         } catch (Exception ex) {
             Debug.Log(ex.ToString());
         }
         navMeshHasNewData = false;
     }
 }
        private void OnEnable()
        {
            _navMeshData = new NavMeshData();
            _NMDinstance = NavMesh.AddNavMeshData(_navMeshData);

            ReflectEventsManager.Instance.onIsDoneInstantiating += Instance_onIsDoneInstantiating;
            ReflectEventsManager.Instance.onSyncUpdateEnd       += Instance_onSyncUpdateEnd;
        }
示例#10
0
 void OnEnable()
 {
     if (!navInstance.valid)
     {
         navMesh     = new NavMeshData();
         navInstance = NavMesh.AddNavMeshData(navMesh);
     }
 }
示例#11
0
    public void SetNavMeshData(NavMeshData data)
    {
        if (NavMeshInstance.valid)
        {
            NavMeshInstance.Remove();
        }

        NavMeshInstance = NavMesh.AddNavMeshData(data);
    }
示例#12
0
 private void AddInstance()
 {
     if (Object.op_Implicit((Object)this.m_NavMesh))
     {
         this.m_Instance = NavMesh.AddNavMeshData(this.m_NavMesh, ((Component)this).get_transform().get_position(), ((Component)this).get_transform().get_rotation());
     }
     this.m_Rotation = ((Component)this).get_transform().get_rotation();
     this.m_Position = ((Component)this).get_transform().get_position();
 }
 void InitNavMesh()
 {
     navMeshBuildSettings            = NavMesh.GetSettingsByIndex(0);
     navMeshBuildSettings.agentClimb = 1f;
     navMeshBuildSettings.agentSlope = 60;
     navMeshSources  = GetList <NavMeshBuildSource> (2048);
     navMeshData     = new NavMeshData();
     navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
     worldBounds     = new Bounds();
 }
 private void OnEnable()
 {
     _navMesh  = new NavMeshData();
     _instance = NavMesh.AddNavMeshData(_navMesh);
     if (Tracked == null)
     {
         Tracked = transform;
     }
     UpdateNavMesh(false);
 }
示例#15
0
 private void bake()
 {
     m_NavMesh  = new NavMeshData();
     m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
     if (m_Tracked == null)
     {
         m_Tracked = transform;
     }
     UpdateNavMesh(false);
 }
 public void LevelReadyForNavmesh()
 {
     m_NavMesh  = new NavMeshData();
     m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
     if (m_Tracked == null)
     {
         m_Tracked = transform;
     }
     UpdateNavMesh(false);
 }
示例#17
0
 private void OnEnable()
 {
     this.m_NavMesh  = new NavMeshData();
     this.m_Instance = NavMesh.AddNavMeshData(this.m_NavMesh);
     if (Object.op_Equality((Object)this.m_Tracked, (Object)null))
     {
         this.m_Tracked = ((Component)this).get_transform();
     }
     this.UpdateNavMesh(false);
 }
 void OnEnable()
 {
     // Construct and add navmesh
     m_NavMesh  = new NavMeshData();
     m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
     if (m_Tracked == null)
     {
         m_Tracked = transform;
     }
     UpdateNavMesh(false);
 }
示例#19
0
 void AddNavMeshData()
 {
     if (NavMeshData != null)
     {
         if (NavMeshDataInstance.valid)
         {
             NavMesh.RemoveNavMeshData(NavMeshDataInstance);
         }
         NavMeshDataInstance = NavMesh.AddNavMeshData(NavMeshData);
     }
 }
示例#20
0
 public void FinishBuildingNavmesh()
 {
     if (BuildingOperation != null && BuildingOperation.isDone)
     {
         if (!NavMeshDataInstance.valid)
         {
             NavMeshDataInstance = NavMesh.AddNavMeshData(NavMeshData);
         }
         UnityEngine.Debug.Log($"Navmesh Build took {BuildTimer.Elapsed.TotalSeconds:0.00} seconds");
         BuildingOperation = null;
     }
 }
示例#21
0
    public void BuildNavigation()
    {
        var data = NavMeshBuilder.BuildNavMeshData(NavMesh.GetSettingsByID(m_AgentTypeID), GetSource(),
                                                   new Bounds(Vector3.zero, Vector3.one * 100000f), Vector3.zero, Quaternion.identity);

        if (NavMeshData.valid)
        {
            NavMeshData.Remove();
        }

        NavMeshData = NavMesh.AddNavMeshData(data);
    }
示例#22
0
        private void Awake()
        {
            reflectEventsManager = FindObjectOfType <ReflectEventsManager>();

            _navMeshData = new NavMeshData();
            _NMDinstance = NavMesh.AddNavMeshData(_navMeshData);

            if (reflectEventsManager == null)
            {
                enabled = false;
            }
        }
 void AddNavMeshData()
 {
     if (NavMeshData != null)
     {
         if (NavMeshDataInstance.valid)
         {
             Debug.Log("Seems to be a NavMesh, removing.");
             NavMesh.RemoveNavMeshData(NavMeshDataInstance);
         }
         NavMeshDataInstance = NavMesh.AddNavMeshData(NavMeshData);
     }
 }
示例#24
0
        public void AddData()
        {
            if (navMeshDataInstance.valid)
            {
                return;
            }

            if (navMeshData != null)
            {
                navMeshDataInstance       = NavMesh.AddNavMeshData(navMeshData, transform.position, transform.rotation);
                navMeshDataInstance.owner = this;
            }
        }
示例#25
0
    void BakeNavMesh()
    {
        navMeshData = new NavMeshData(0);


        NavMeshSourceTag.Collect(ref sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = new Bounds(center, size);

        NavMeshBuilder.UpdateNavMeshData(navMeshData, defaultBuildSettings, sources, bounds);
        navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
        //NavMeshBuilder.BuildNavMeshData(defaultBuildSettings, sources, bounds, this.gameObject.transform.position, this.gameObject.transform.rotation);
    }
示例#26
0
 public void FinishBuildingNavmesh()
 {
     if (this.BuildingOperation == null || !this.BuildingOperation.get_isDone())
     {
         return;
     }
     if (!((NavMeshDataInstance) ref this.NavMeshDataInstance).get_valid())
     {
         this.NavMeshDataInstance = NavMesh.AddNavMeshData(this.NavMeshData);
     }
     Debug.Log((object)string.Format("Monument Navmesh Build took {0:0.00} seconds", (object)this.BuildTimer.Elapsed.TotalSeconds));
     this.BuildingOperation = (AsyncOperation)null;
 }
示例#27
0
    public void generateNavMesh()
    {
        //https://community.gamedev.tv/t/modify-navmesh-dynamically/25849/3
        List <NavMeshBuildSource> buildSources = new List <NavMeshBuildSource>();

        NavMeshBuilder.CollectSources(transform, navMeshLayers, NavMeshCollectGeometry.RenderMeshes, 0, new List <NavMeshBuildMarkup>(), buildSources);

        NavMeshData navData = NavMeshBuilder.BuildNavMeshData(navSettings, buildSources, new Bounds(Vector3.zero, new Vector3(10000, 10000, 10000)), Vector3.down,
                                                              Quaternion.Euler(Vector3.up));

        navMeshDataInstance = NavMesh.AddNavMeshData(navData);
        //Debug.Log(buildSources.Count);
        //Debug.Log("Map Built");
    }
示例#28
0
    private void OnEnable()
    {
        navMeshData         = new NavMeshData();
        navMeshDataInstance = NavMesh.AddNavMeshData(navMeshData);

        //	場当たりだけど、メッシュがセットされていなければ開始時にナビメッシュを作成しない
        //	テストと実際の使用時の違いの吸収
        if (targetMeshes.Count > 0)
        {
            StartCoroutine(updateNavMesh());
        }

        StartCoroutine(createNavMesh());
    }
示例#29
0
    /// <summary>
    /// 初始化寻路数据
    /// </summary>
    public void InitNavMesh()
    {
        navMeshSources = new Dictionary <Vector3Int, NavMeshBuildSource>();

        navMeshData = new NavMeshData();

        navMeshBuildSettings             = NavMesh.GetSettingsByIndex(0);
        navMeshBuildSettings.agentClimb  = 1.5f;
        navMeshBuildSettings.agentSlope  = 60;
        navMeshBuildSettings.agentHeight = 1.8f;

        navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
        worldBounds     = new Bounds();
    }
示例#30
0
 private void OnEnable()
 {
     this._navMesh  = new NavMeshData();
     this._instance = NavMesh.AddNavMeshData(this._navMesh);
     if (Object.op_Equality((Object)this._tracked, (Object)null))
     {
         this._tracked = ((Component)this).get_transform();
     }
     if (this._enumerator == null)
     {
         this._enumerator = this.LoadNavMesh();
     }
     this.StartCoroutine(this._enumerator);
 }