Exemple #1
0
        /// <summary>
        /// Unloads tiles out of range
        /// </summary>
        void SceneUnloading()
        {
            List <SceneSplit> scenesToDestroy = new List <SceneSplit>();

            foreach (var item in loadedScenes)
            {
                if (Mathf.Abs(item.posX + item.xDeloadLimit - xPos) > (int)deloadingRange.x ||
                    Mathf.Abs(item.posY + item.yDeloadLimit - yPos) > (int)deloadingRange.y ||
                    Mathf.Abs(item.posZ + item.zDeloadLimit - zPos) > (int)deloadingRange.x)
                {
                    if (item.sceneGo != null)
                    {
                        scenesToDestroy.Add(item);
                    }
                }

                if (useLoadingRangeMin)
                {
                    if (Mathf.Abs(item.posX + item.xDeloadLimit - xPos) <= loadingRangeMin.x &&
                        Mathf.Abs(item.posY + item.yDeloadLimit - yPos) <= loadingRangeMin.y &&
                        Mathf.Abs(item.posZ + item.zDeloadLimit - zPos) <= loadingRangeMin.z)
                    {
                        if (item.sceneGo != null)
                        {
                            scenesToDestroy.Add(item);
                        }
                    }
                }
            }

            foreach (var item in scenesToDestroy)
            {
                loadedScenes.Remove(item);

                if (item.sceneGo != null)
                {
                    Terrain childTerrain = item.sceneGo.GetComponentInChildren <Terrain>();
                    if (childTerrain)
                    {
                        GameObject childTerrainGO = childTerrain.gameObject;

                        Destroy(childTerrain);
                        childTerrain = null;
                        Destroy(childTerrainGO);
                        childTerrainGO = null;

                        if (IsMajorStreamer && FarViewManager.Instance)
                        {
                            FarViewManager.Instance.NotifyMajorStreamerUnloaded(item.posX, item.posZ);
                        }
                    }
                }

                try
                {
                    SceneManager.UnloadSceneAsync(item.sceneGo.scene.name);
                    War.Base.AssetLoader.UnloadAssetBundle(item.assetBundleName);
                }
                catch (System.Exception ex)
                {
                    Debug.Log(item.sceneName);
                    Debug.Log(item.sceneGo.name);
                    Debug.Log(item.sceneGo.scene.name);
                    Debug.LogError(ex.Message);
                }

                item.sceneGo = null;
                item.loaded  = false;
            }
            scenesToDestroy.Clear();



            if (terrainNeighbours)
            {
                terrainNeighbours.CreateNeighbours();
            }

            Streamer.UnloadAssets(this);
        }