Beispiel #1
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);
        }
Beispiel #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);
        }
    }
Beispiel #3
0
 private void Awake()
 {
     Instance    = this;
     sources     = new List <NavMeshBuildSource>();
     navMeshData = new NavMeshData();
     NavMesh.AddNavMeshData(navMeshData);
 }
    void Awake()
    {
        nvData = new NavMeshData();
        foreach (var obj in notWalkable)
        {
            NavMeshBuildMarkup navMeshBuildMarkup = new NavMeshBuildMarkup();
            navMeshBuildMarkup.area         = NavMesh.GetAreaFromName("Not Walkable");
            navMeshBuildMarkup.overrideArea = true;
            navMeshBuildMarkup.root         = obj.transform;
            objectsNotTreated.Add(navMeshBuildMarkup);
        }
        NavMesh.AddNavMeshData(nvData);
        NavMeshBuilder.CollectSources(
            new Bounds(gameObject.transform.position, new Vector3(bounds, bounds, bounds)),
            mask.value,
            NavMeshCollectGeometry.PhysicsColliders,
            0,
            objectsNotTreated,
            watchedSources);

        status = NavMeshBuilder.UpdateNavMeshDataAsync(
            nvData,
            NavMesh.GetSettingsByID(0),
            watchedSources,
            new Bounds(gameObject.transform.position, new Vector3(bounds, bounds, bounds)));
    }
Beispiel #5
0
    // Use this for initialization
    void Start()
    {
        // add 20 random big cuboids into the level.
        // The prefab has been tagged as StaticBatchingUtility Navigation in The Navigation editor
        for (int i = 0; i < 20; i++)
        {
            GameObject go = Instantiate(prefab, new Vector3(Random.Range(-25, 25), Random.Range(0, 1), Random.Range(-25, 25)), Quaternion.AngleAxis(Random.Range(-180, 180), Vector3.up));
            go.transform.parent = transform;
        }

        // 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(transform, 255, NavMeshCollectGeometry.PhysicsColliders, 0, new List <NavMeshBuildMarkup>(), results);

        // make a 100m box around the origin
        Bounds bounds = new Bounds(Vector3.zero, 100 * Vector3.one);

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

        NavMesh.AddNavMeshData(data);
        success = NavMeshBuilder.UpdateNavMeshData(data, settings, results, bounds);
    }
Beispiel #6
0
 void OnEnable()
 {
     // Construct and add navmesh
     m_NavMesh  = new NavMeshData();
     m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
     UpdateNavMesh(false);
 }
 private void Start()
 {
     NavMeshData = new NavMeshData();
     NavMesh.AddNavMeshData(NavMeshData);
     BuildNavMesh(false);
     StartCoroutine(CheckPlayerMovement());
 }
Beispiel #8
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;
     }
 }
Beispiel #9
0
    void Start()
    {
        m_Sound = GetComponent <Sound>();

        NavMesh.AddNavMeshData(m_NavMeshData);
        NavMesh.CalculateTriangulation();

        for (int i = 0; i < transform.childCount; ++i)
        {
            if (transform.GetChild(i).name.Contains("FreeCamRig"))
            {
                m_CameraRig = transform.GetChild(i).gameObject;
                break;
            }
        }

        m_EventList = new Dictionary <string, MethodInfo>();

        foreach (string e in m_Events)
        {
            string eventName = e.Split(' ')[0];
            string phaseName = e.Split(' ')[1];

            m_EventList.Add(phaseName, this[eventName]);
        }


        LoadPhasesData();
        NextPhase();
    }
Beispiel #10
0
 void OnEnable()
 {
     sources         = new List <NavMeshBuildSource> ();
     navMesh         = new NavMeshData();
     navMeshInstance = NavMesh.AddNavMeshData(navMesh);
     UpdateNavMesh(false);
 }
Beispiel #11
0
    public static void Generate()
    {
        var sources = new List <NavMeshBuildSource>();
        var meshs   = Object.FindObjectsOfType <MeshFilter>();

        foreach (var mesh in meshs)
        {
            if (!mesh.gameObject.isStatic)
            {
                continue;
            }
            var source = new NavMeshBuildSource();
            source.sourceObject = mesh.sharedMesh;
            source.area         = 0;
            source.transform    = mesh.transform.localToWorldMatrix;
            sources.Add(source);
        }
        var navMeshData = new NavMeshData();

        NavMesh.AddNavMeshData(navMeshData);
        var  id     = NavMesh.GetSettingsByID(0);
        var  bounds = new Bounds(Vector3.zero, Vector3.one * 50.0f);
        bool result = NavMeshBuilder.UpdateNavMeshData(navMeshData, id, sources, bounds);

        Debug.Log(result);
        Debug.Log(id.agentRadius);
    }
 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;
     }
 }
Beispiel #13
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);
    }
Beispiel #14
0
 void OnEnable()
 {
     if (!dontcreate)
     {
         m_NavMeshInstance = NavMesh.AddNavMeshData(m_NavMeshData);
     }
 }
Beispiel #15
0
    public AsyncOperation ResetNavMesh(AI_TYPE InType)
    {
        NavMeshDataInstance dataInstance;

        if (Map_MeshInstance.TryGetValue(InType, out dataInstance))
        {
            NavMesh.RemoveNavMeshData(dataInstance);
            Map_MeshInstance.Remove(InType);
        }

        NavMeshData meshData = new NavMeshData();

        dataInstance = NavMesh.AddNavMeshData(meshData);
        Map_MeshInstance.Add(InType, dataInstance);

        int agentIndex = (int)InType;

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

        NavMeshSourceTag.Collect(ref sources, GetArea(agentIndex), InType);

        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByIndex(agentIndex);

        //print(agentIndex + "," + defaultBuildSettings.agentRadius);

        var bounds = QuantizedBounds();

        return(NavMeshBuilder.UpdateNavMeshDataAsync(meshData, defaultBuildSettings, sources, bounds));
    }
Beispiel #16
0
 public void Default()
 {
     NavMesh.RemoveAllNavMeshData();
     meshes = new List <MeshFilter>();
     LoadMesh(stage);
     data = new NavMeshData();
     NavMesh.AddNavMeshData(data);
 }
        private void OnEnable()
        {
            _navMeshData = new NavMeshData();
            _NMDinstance = NavMesh.AddNavMeshData(_navMeshData);

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

        NavMeshInstance = NavMesh.AddNavMeshData(data);
    }
Beispiel #20
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();
 }
Beispiel #21
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 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);
 }
Beispiel #24
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);
 }
 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);
 }
Beispiel #27
0
 void AddNavMeshData()
 {
     if (NavMeshData != null)
     {
         if (NavMeshDataInstance.valid)
         {
             NavMesh.RemoveNavMeshData(NavMeshDataInstance);
         }
         NavMeshDataInstance = NavMesh.AddNavMeshData(NavMeshData);
     }
 }
Beispiel #28
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;
     }
 }
Beispiel #29
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);
    }
Beispiel #30
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);
    }