Ejemplo n.º 1
0
    /********
    * Init *
    ********/

    void Start()
    {
        navMesh = GetComponentInChildren <UnityEngine.AI.NavMeshSurface>();
        mainCamera.movementRestrictor = floorBounds;

        InitCanvas();
        AdjustDisplay2();
        PopulateWorld();
    }
Ejemplo n.º 2
0
 void Start()
 {
     nav = GetComponent <UnityEngine.AI.NavMeshSurface>();
     //SetOptimization();
     Bake();
     if (timerEnable)
     {
         InvokeRepeating("UpdateNavMesh", 0, timef);
     }
 }
Ejemplo n.º 3
0
        static void Register(NavMeshSurface surface)
        {
#if UNITY_EDITOR
            var isInPreviewScene = EditorSceneManager.IsPreviewSceneObject(surface);
            var isPrefab         = isInPreviewScene || EditorUtility.IsPersistent(surface);
            if (isPrefab)
            {
                //Debug.LogFormat("NavMeshData from {0}.{1} will not be added to the NavMesh world because the gameObject is a prefab.",
                //    surface.gameObject.name, surface.name);
                return;
            }
#endif
            if (s_NavMeshSurfaces.Count == 0)
            {
                NavMesh.onPreUpdate += UpdateActive;
            }

            if (!s_NavMeshSurfaces.Contains(surface))
            {
                s_NavMeshSurfaces.Add(surface);
            }
        }
Ejemplo n.º 4
0
        public void BuildNavMesh()
        {
            List <NavMeshBuildSource> sources = this.CollectSources();
            Bounds localBounds = new Bounds(this.m_Center, NavMeshSurface.Abs(this.m_Size));

            if (this.m_CollectObjects == CollectObjects.All || this.m_CollectObjects == CollectObjects.Children)
            {
                localBounds = this.CalculateWorldBounds(sources);
            }
            NavMeshData navMeshData = NavMeshBuilder.BuildNavMeshData(this.GetBuildSettings(), sources, localBounds, base.transform.position, base.transform.rotation);

            if (navMeshData != null)
            {
                navMeshData.name = base.gameObject.name;
                this.RemoveData();
                this.m_NavMeshData = navMeshData;
                if (base.isActiveAndEnabled)
                {
                    this.AddData();
                }
            }
        }
Ejemplo n.º 5
0
 private static void Register(NavMeshSurface surface)
 {
     if (NavMeshSurface.s_NavMeshSurfaces.Count == 0)
     {
         // ISSUE: variable of the null type
         __Null onPreUpdate = NavMesh.onPreUpdate;
         // ISSUE: reference to a compiler-generated field
         if (NavMeshSurface.\u003C\u003Ef__mg\u0024cache0 == null)
         {
             // ISSUE: reference to a compiler-generated field
             // ISSUE: method pointer
             NavMeshSurface.\u003C\u003Ef__mg\u0024cache0 = new NavMesh.OnNavMeshPreUpdate((object)null, __methodptr(UpdateActive));
         }
         // ISSUE: reference to a compiler-generated field
         NavMesh.OnNavMeshPreUpdate fMgCache0 = NavMeshSurface.\u003C\u003Ef__mg\u0024cache0;
         NavMesh.onPreUpdate = (__Null)Delegate.Combine((Delegate)onPreUpdate, (Delegate)fMgCache0);
     }
     if (NavMeshSurface.s_NavMeshSurfaces.Contains(surface))
     {
         return;
     }
     NavMeshSurface.s_NavMeshSurfaces.Add(surface);
 }
Ejemplo n.º 6
0
        private Bounds CalculateWorldBounds(List <NavMeshBuildSource> sources)
        {
            Matrix4x4 lhs = Matrix4x4.TRS(base.transform.position, base.transform.rotation, Vector3.one);

            lhs = lhs.inverse;
            Bounds result = default(Bounds);

            foreach (NavMeshBuildSource navMeshBuildSource in sources)
            {
                switch (navMeshBuildSource.shape)
                {
                case NavMeshBuildSourceShape.Mesh:
                {
                    Mesh mesh = navMeshBuildSource.sourceObject as Mesh;
                    result.Encapsulate(NavMeshSurface.GetWorldBounds(lhs * navMeshBuildSource.transform, mesh.bounds));
                    break;
                }

                case NavMeshBuildSourceShape.Terrain:
                {
                    TerrainData terrainData = navMeshBuildSource.sourceObject as TerrainData;
                    result.Encapsulate(NavMeshSurface.GetWorldBounds(lhs * navMeshBuildSource.transform, new Bounds(0.5f * terrainData.size, terrainData.size)));
                    break;
                }

                case NavMeshBuildSourceShape.Box:
                case NavMeshBuildSourceShape.Sphere:
                case NavMeshBuildSourceShape.Capsule:
                case NavMeshBuildSourceShape.ModifierBox:
                    result.Encapsulate(NavMeshSurface.GetWorldBounds(lhs * navMeshBuildSource.transform, new Bounds(Vector3.zero, navMeshBuildSource.size)));
                    break;
                }
            }
            result.Expand(0.1f);
            return(result);
        }
Ejemplo n.º 7
0
 void Bake()
 {
     UnityEngine.AI.NavMeshSurface nav = GetComponent <UnityEngine.AI.NavMeshSurface>();
     nav.BuildNavMesh();
 }
Ejemplo n.º 8
0
    static System.Collections.IEnumerator buildnavmesh(GameObject gameObject)
    {
        GameObject game = PrefabUtility.InstantiatePrefab(gameObject) as GameObject;

        Debug.Log("烘培: " + game.name);

        List <UnityEngine.AI.NavMeshSurface> navMeshSurfaces = new List <UnityEngine.AI.NavMeshSurface>();

        for (int e = 0; e < UnityEngine.AI.NavMesh.GetSettingsCount(); e++)
        {
            bool build = true;
            UnityEngine.AI.NavMeshBuildSettings navMeshBuildSettings = UnityEngine.AI.NavMesh.GetSettingsByIndex(e);
            foreach (var item in game.GetComponents <UnityEngine.AI.NavMeshSurface>())
            {
                if (item.agentTypeID == navMeshBuildSettings.agentTypeID)
                {
                    build = false;
                    break;
                }
            }

            if (build)
            {
                UnityEngine.AI.NavMeshSurface navMeshSurface = game.AddComponent <UnityEngine.AI.NavMeshSurface>();
                LayerMask layerMask = new LayerMask();
                layerMask = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Ground") | 1 << LayerMask.NameToLayer("Terrain");
                navMeshSurface.agentTypeID    = navMeshBuildSettings.agentTypeID;
                navMeshSurface.collectObjects = UnityEngine.AI.CollectObjects.Children;
                navMeshSurface.useGeometry    = UnityEngine.AI.NavMeshCollectGeometry.PhysicsColliders;
                navMeshSurface.layerMask      = layerMask;
                navMeshSurfaces.Add(navMeshSurface);
                //UnityEditor.AI.NavMeshAssetManager.instance.StartBakingSurfaces(gameObject.GetComponents<UnityEngine.AI.NavMeshSurface>());
            }
        }

        if (navMeshSurfaces.Count != 0)
        {
            UnityEditor.AI.NavMeshAssetManager.instance.StartBakingSurfaces(navMeshSurfaces.ToArray());
            EditorUtility.SetDirty(game);

            //UnityEditor.AI.NavMeshAssetManager.instance.overUpdate = () =>
            //{
            //    AssetDatabase.SaveAssets();
            //    Tang.Tools.Destroy(game);
            //};


            while (true)
            {
                if (UnityEditor.AI.NavMeshAssetManager.instance.GetBakeOperationsCout() > 0)
                {
                    yield return(0);
                }
                else
                {
                    Debug.Log("保存烘培: " + game.name);

                    PrefabUtility.SaveAsPrefabAsset(game, AssetDatabase.GetAssetPath(gameObject));
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    Tang.Tools.Destroy(game);
                    break;
                }
            }
        }
        else
        {
            Debug.Log("保存烘培: " + gameObject.name);
            Tang.Tools.Destroy(game);
        }
    }
Ejemplo n.º 9
0
 private void OnDisable()
 {
     this.RemoveData();
     NavMeshSurface.Unregister(this);
 }
Ejemplo n.º 10
0
 private void OnEnable()
 {
     NavMeshSurface.Register(this);
     this.AddData();
 }