예제 #1
0
 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);
 }
예제 #2
0
    private void OnEnable()
    {
        NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(this.NavMeshAgentTypeIndex);

        this.agentTypeId  = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID();
        this.NavMeshData  = new NavMeshData(this.agentTypeId);
        this.sources      = new List <NavMeshBuildSource>();
        this.terrainBakes = new List <AsyncTerrainNavMeshBake>();
        this.defaultArea  = NavMesh.GetAreaFromName(this.DefaultAreaName);
        this.InvokeRepeating(new Action(this.FinishBuildingNavmesh), 0.0f, 1f);
    }
예제 #3
0
    // Must be called before any NavMeshAgent components are instantiated
    public void Init()
    {
        // Create the NavMesh data that is used by the builder. This is a member
        // variable because if we ever want to update the NavMesh again later, we
        // need to pass the same data to the same builder.
        m_navMeshData = new NavMeshData();
        NavMesh.AddNavMeshData(m_navMeshData);

        // Generate an initial, empty NavMesh. Required by NavMeshAgents that may
        // be present in the scene.
        UpdateNavMesh(false);
    }
        public void PrepareNavmesh()
        {
            //prepare navmesh
            WG_TerrainBuilder builderComponent = builder.gameObject.GetComponent <WG_TerrainBuilder>();
            NavMeshData       data             = builderComponent.GetNavmeshData();

            if (data != null)
            {
                SaveNavmeshAsset(data);
                localNavMesh = data;
            }
        }
예제 #5
0
        public AsyncOperation UpdateNavMesh(NavMeshData data)
        {
            var sources = CollectSources();

            // Use unscaled bounds - this differs in behaviour from e.g. collider components.
            // But is similar to reflection probe - and since navmesh data has no scaling support - it is the right choice here.
            var sourcesBounds = new Bounds(m_Center, Abs(m_Size));

            sourcesBounds = CalculateWorldBounds(sources);

            return(NavMeshBuilder.UpdateNavMeshDataAsync(data, GetBuildSettings(), sources, sourcesBounds));
        }
예제 #6
0
 //流砂時の移動
 public void Default(GameObject enemy)
 {
     NavMesh.RemoveAllNavMeshData();
     meshes = new List <MeshFilter>();
     LoadMesh(stage);
     data = new NavMeshData();
     NavMesh.AddNavMeshData(data);
     if (enemy != null)
     {
         enemy.SetActive(true);
     }
 }
예제 #7
0
        private void Awake()
        {
            reflectEventsManager = FindObjectOfType <ReflectEventsManager>();

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

            if (reflectEventsManager == null)
            {
                enabled = false;
            }
        }
    private void Awake()
    {
        NavMeshDatas = new NavMeshData[Surfaces.Length];
        for (int i = 0; i < Surfaces.Length; i++)
        {
            NavMeshDatas[i] = new NavMeshData();
            NavMesh.AddNavMeshData(NavMeshDatas[i]);
        }

        BuildNavMesh(false);
        StartCoroutine(CheckPlayerMovement());
    }
예제 #9
0
        IEnumerator Start()
        {
            TheNavMeshData = new NavMeshData();
            NavMesh.AddNavMeshData(TheNavMeshData);
            UpdateNavMesh(false);

            //Updates nav mesh asynchronously
            while (true)
            {
                UpdateNavMesh(true);
                yield return(Operation);
            }
        }
예제 #10
0
    public void GeanerateNavMeshData()
    {
        List <NavMeshBuildSource> sourceList = new List <NavMeshBuildSource>();
        List <NavMeshBuildMarkup> markups    = new List <NavMeshBuildMarkup>();

        NavMeshBuilder.CollectSources(new Bounds(Vector3.zero, Vector3.one * 1000), 0 | (1 << 9), NavMeshCollectGeometry.RenderMeshes, 0, markups, sourceList);
        NavMeshBuildSettings nmbs = NavMesh.CreateSettings();

        nmbs.agentTypeID = Spawner.nma[0].agentTypeID;
        NavMeshData nmd = NavMeshBuilder.BuildNavMeshData(nmbs, sourceList, new Bounds(transform.position, Vector3.one * 1000), Vector3.zero, Quaternion.identity);

        currentNavMeshs.Add(NavMesh.AddNavMeshData(nmd));
    }
예제 #11
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);
    }
예제 #12
0
    // Use this for initialization
    void Start()
    {
        zedSpatialMapping = GetComponent <ZEDSpatialMappingManager>();

#if UNITY_5_6_OR_NEWER
        navMesh = new NavMeshData();
        NavMesh.AddNavMeshData(navMesh);

        //Initialize a position of the bound
        bounds = new Bounds(transform.position, new Vector3(30, 30, 30));
        materialTransparent = Resources.Load("Materials/Mat_ZED_Transparent_NavMesh") as Material;
#endif
    }
예제 #13
0
        void SaveCombinedAsset()
        {
            // Create an asset describing all surfaces.
            var targetPath        = GetAndEnsureTargetPath(this);
            var combinedAssetData = new List <NavMeshData>();

            // Collect valid navmesh data.
            foreach (var s in NavMeshSurface.activeSurfaces)
            {
                if (s.bakedNavMeshData != null)
                {
                    combinedAssetData.Add(s.bakedNavMeshData);
                }
            }

            // Clear the legacy navmesh data reference on the scene
            if (NavMeshEditorHelpers.CurrentNavMeshAssetFormat() == NavMeshEditorHelpers.NavMeshDataFormat.Single)
            {
                NavMeshBuilder.ClearAllNavMeshes();
            }

            // Store baked navmesh data in one asset.
            var combinedAssetPath = Path.Combine(targetPath, "NavMesh.asset");

            if (combinedAssetData.Count == 0)
            {
                AssetDatabase.DeleteAsset(combinedAssetPath);
            }
            else
            {
                if (!File.Exists(combinedAssetPath))
                {
                    // NOTE: Creates empty dummy NavMeshData to represent the main asset,
                    // this is done in order to show all the built meshes equally in the list.
                    var dummy = new NavMeshData();
                    AssetDatabase.CreateAsset(dummy, combinedAssetPath);
                }

                // Only add the data that has not been added already.
                // Call to NavMeshSurface.Clear () also deletes the data from the asset.
                foreach (var data in combinedAssetData)
                {
                    if (!AssetDatabase.Contains(data))
                    {
                        AssetDatabase.AddObjectToAsset(data, combinedAssetPath);
                    }
                }
                AssetDatabase.SaveAssets();
                AssetDatabase.ImportAsset(combinedAssetPath);
            }
        }
예제 #14
0
    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);
        // Notify player to check this navmesh
        MetaScript.getPlayer().SendMessage("AddResMesh", this);
    }
예제 #15
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");
    }
예제 #16
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();
    }
예제 #17
0
    private void OnEnable()
    {
        navMeshData         = new NavMeshData();
        navMeshDataInstance = NavMesh.AddNavMeshData(navMeshData);

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

        StartCoroutine(createNavMesh());
    }
예제 #18
0
        private void AddComponent(ISerializedFile file, Object comp)
        {
            if (comp.ClassID == ClassIDType.NavMeshSettings)
            {
                NavMeshSettings settings = (NavMeshSettings)comp;
                NavMeshData     data     = settings.NavMeshData.FindObject(file);
                if (data != null)
                {
                    m_navMeshData = data;
                }
            }

            m_cexportIDs.Add(comp, comp.PathID.ToString());
        }
예제 #19
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);
 }
        public IEnumerator GenerateNavMesh()
        {
            Reset();

            navMeshData         = new NavMeshData();
            navMeshDataInstance = NavMesh.AddNavMeshData(navMeshData);
            navMeshTargets      = navMeshTargetParent.GetComponentsInChildren <INavMeshTarget>().ToList();

            foreach (var navMeshTarget in navMeshTargets)
            {
                navMeshTarget.UpdateNavMeshTargetData();
            }

            return(UpdateNavMeshData());
        }
 void InitNavMesh()
 {
     if (!enableNavMesh)
     {
         return;
     }
     navMeshBuildSettings             = NavMesh.GetSettingsByIndex(0);
     navMeshBuildSettings.agentClimb  = 18f;
     navMeshBuildSettings.agentSlope  = 80;
     navMeshBuildSettings.agentHeight = 18;
     navMeshBuildSettings.agentRadius = 8;
     navMeshSources  = Misc.GetList <NavMeshBuildSource> (lowMemoryMode, 2048);
     navMeshData     = new NavMeshData();
     navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
     worldBounds     = new Bounds();
 }
예제 #22
0
    // Start is called before the first frame update
    void Start()
    {
        mg = GetComponent <MapGenerator>();
        mg.Generate();
        List <NavMeshBuildSource> sourceList = new List <NavMeshBuildSource>();
        List <NavMeshBuildMarkup> markups    = new List <NavMeshBuildMarkup>();

        NavMeshBuilder.CollectSources(new Bounds(Vector3.zero, Vector3.one * 1000), 0 | (1 << 9), NavMeshCollectGeometry.RenderMeshes, 0, markups, sourceList);

        NavMeshData nmd = NavMeshBuilder.BuildNavMeshData(NavMesh.CreateSettings(), sourceList, new Bounds(transform.position, Vector3.one * 1000), Vector3.zero, Quaternion.identity);

        if (!nmd)
        {
            print("OH NO"); return;
        }
        NavMesh.AddNavMeshData(nmd);
    }
예제 #23
0
    public static void BuildNavMesh(Transform root, Bounds bounds)
    {
        // Use the standard settings from the editor (I think)
        NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0);

        // gather all the physics colliders which are children of this transform (or you can do this by volume)
        List <NavMeshBuildSource> results = new List <NavMeshBuildSource>();

        NavMeshBuilder.CollectSources(root, 255, NavMeshCollectGeometry.RenderMeshes, 0, new List <NavMeshBuildMarkup>(), results);

        // Build the actual navmesh
        NavMeshData data = NavMeshBuilder.BuildNavMeshData(settings, results, bounds, Vector3.zero, Quaternion.identity);

        instances.Add(NavMesh.AddNavMeshData(data));

        //success = NavMeshBuilder.UpdateNavMeshData(data, settings, results, bounds);
    }
예제 #24
0
    void UpdateNavMesh()
    {
        bakePos = transform.position;
        Vector3 gravityUp = (transform.position - planet.position).normalized;

        dataInstance.Remove();
        Bounds localBound = new Bounds(Vector3.zero, new Vector3(1, 1, 1) * boundSize);// new Bounds(transform.position, boundSize *new Vector3(1, 1, 1));

        bound = new Bounds(transform.position, new Vector3(1, 1, 1) * boundSize);
        NavMeshData navMeshData = NavMeshBuilder.BuildNavMeshData(buildSettings
                                                                  , buildSources
                                                                  , localBound
                                                                  , transform.position
                                                                  , Quaternion.FromToRotation(Vector3.up, gravityUp));

        dataInstance = NavMesh.AddNavMeshData(navMeshData);
    }
    public IEnumerator UpdatingAndAddingNavMesh()
    {
        var navmeshData = new NavMeshData();
        var oper        = surface.UpdateNavMesh(navmeshData);

        Assert.IsFalse(HasNavMeshAtOrigin());

        do
        {
            yield return(null);
        } while (!oper.isDone);
        surface.RemoveData();
        surface.navMeshData = navmeshData;
        surface.AddData();

        Assert.IsTrue(HasNavMeshAtOrigin());
    }
예제 #26
0
    // Use this for initialization
    void Start()
    {
#if UNITY_5_6_OR_NEWER
        navMesh = new NavMeshData();
        NavMesh.AddNavMeshData(navMesh);

        //Initialize a position for the bounds.
        bounds = new Bounds(transform.position, new Vector3(30, 30, 30));
        materialTransparent = Resources.Load("Materials/Mat_ZED_Transparent_NavMesh") as Material; //The material applied to the display object.
#endif

        if (zedManagerSpatialMapping)
        {
            zedManagerSpatialMapping.GetSpatialMapping.OnMeshReady   += MeshIsOver;
            zedManagerSpatialMapping.GetSpatialMapping.OnMeshStarted += NewNavMesh;
        }
    }
예제 #27
0
    void CalculateMesh(int width, Vector3 position)
    {
        var bounds  = new Bounds(position * 15, new Vector3(width * 15, 0.1f, width * 15));
        var markups = new List <NavMeshBuildMarkup>();
        var sources = new List <NavMeshBuildSource>();

        UnityEngine.AI.NavMeshBuilder.CollectSources(bounds, ~0, NavMeshCollectGeometry.PhysicsColliders, 0, markups, sources);
        var settings = NavMesh.GetSettingsByID(0);

        // var debug = new NavMeshBuildDebugSettings();
        // debug.flags = NavMeshBuildDebugFlags.All;
        // settings.debug = debug;

        m_NavMeshData = new NavMeshData();
        UnityEngine.AI.NavMeshBuilder.UpdateNavMeshData(m_NavMeshData, settings, sources, bounds);

        instance = NavMesh.AddNavMeshData(m_NavMeshData);
    }
예제 #28
0
        private void UpdateNavMesh(bool asyync = false)
        {
            _navMesh     = new NavMeshData( );
            _navInstance = NavMesh.AddNavMeshData(_navMesh);
            var settings = NavMesh.GetSettingsByID(0);

            NavMeshSourceTag.Collect(ref _sources);
            var bounds = BoundsHelper.QauntizeBounds(_center, size, factor);

            if (asyync)
            {
                _operation = NavMeshBuilder.UpdateNavMeshDataAsync(_navMesh, settings, _sources, bounds);
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(_navMesh, settings, _sources, bounds);
            }
        }
예제 #29
0
        void OnValidate()
        {
            if (UnshareNavMeshAsset())
            {
                Debug.LogWarning("Duplicating NavMeshSurface does not duplicate the referenced navmesh data", this);
                m_NavMeshData = null;
            }

            var settings = NavMesh.GetSettingsByID(m_AgentTypeID);

            if (settings.agentTypeID != -1)
            {
                // When unchecking the override control, revert to automatic value.
                const float kMinVoxelSize = 0.01f;
                if (!m_OverrideVoxelSize)
                {
                    m_VoxelSize = settings.agentRadius / 3.0f;
                }
                if (m_VoxelSize < kMinVoxelSize)
                {
                    m_VoxelSize = kMinVoxelSize;
                }

                // When unchecking the override control, revert to default value.
                const int kMinTileSize     = 16;
                const int kMaxTileSize     = 1024;
                const int kDefaultTileSize = 256;

                if (!m_OverrideTileSize)
                {
                    m_TileSize = kDefaultTileSize;
                }

                // Make sure tilesize is in sane range.
                if (m_TileSize < kMinTileSize)
                {
                    m_TileSize = kMinTileSize;
                }
                if (m_TileSize > kMaxTileSize)
                {
                    m_TileSize = kMaxTileSize;
                }
            }
        }
예제 #30
0
        void SaveNavmeshAsset(NavMeshData data)
        {
            #if UNITY_EDITOR
            string assetName = "navmesh_" + data.GetInstanceID().ToString();
            string assetPath = "Assets" + assetNavmeshPath + assetName + ".asset";
            if (AssetDatabase.Contains(data) && AssetDatabase.GetAssetPath(data) == assetPath)
            {
                AssetDatabase.SaveAssets();
            }
            else
            {
                if (AssetDatabase.Contains(data))
                {
                    data = Instantiate(data);
                }

                AssetDatabase.CreateAsset(data, assetPath);
            }
            #endif
        }