Esempio n. 1
0
        private int compareSceneSplit(SceneSplit left, SceneSplit right)
        {
            int leftDistance  = Mathf.Abs(left.posX - xPos) + /*Mathf.Abs(left.posY - yPos) +*/ Mathf.Abs(left.posZ - zPos);
            int rightDistance = Mathf.Abs(right.posX - xPos) + /*Mathf.Abs(right.posY - yPos) +*/ Mathf.Abs(right.posZ - zPos);

            return(leftDistance - rightDistance);
        }
Esempio n. 2
0
        /// <summary>
        /// Manages async scene loading
        /// </summary>
        void LoadLevelAsyncManage()
        {
            if (scenesToLoad.Count > 0 && currentlySceneLoading <= 0)
            {
                if (LoadingProgress < 1 || sceneLoadFramesNextWaited && sceneLoadFrameNext <= 0)
                {
                    sceneLoadFramesNextWaited = false;
                    sceneLoadFrameNext        = sceneLoadWaitFrames;
                    while (currentlySceneLoading < maxParallelSceneLoading && scenesToLoad.Count > 0)
                    {
                        SceneSplit split = scenesToLoad[0];

                        if (!Application.isWebPlayer || Application.isWebPlayer && Application.CanStreamedLevelBeLoaded(split.sceneName))
                        {
                            scenesToLoad.Remove(split);


                            if (!split.loaded)
                            {
                                UnityEngine.Debug.LogWarning("repeate Load:" + split.assetBundleName);
                                continue;
                            }

                            War.Base.AssetLoader.LoadLevelAsync(split.assetBundleName, split.sceneName, true, null);
                            currentlySceneLoading++;
                        }
                    }
                }
                else
                {
                    sceneLoadFramesNextWaited = true;
                    sceneLoadFrameNext--;
                }
            }
        }
Esempio n. 3
0
        //public IEnumerator UnloadAssetsWait()
        //{
        //    do
        //    {
        //        unloadNext = false;
        //        Resources.UnloadUnusedAssets();
        //        System.GC.Collect();
        //        yield return new WaitForSeconds(waitTillNextUnload);
        //    } while (unloadNext);

        //    canUnload = true;
        //}


        #endregion

        #region prepare scene

        /// <summary>
        /// Prepares the scenes array from collection
        /// </summary>
        void PrepareScenesArray()
        {
            scenesArray = new Dictionary <int[], SceneSplit>(new War.Common.IntArrayComparer());
            foreach (var sceneName in sceneCollection.names)
            {
                int posX = 0;
                int posY = 0;
                int posZ = 0;

                SceneNameToPos(sceneCollection, sceneName, out posX, out posY, out posZ);

                SceneSplit sceneSplit = new SceneSplit();
                sceneSplit.posX            = posX;
                sceneSplit.posY            = posY;
                sceneSplit.posZ            = posZ;
                sceneSplit.sceneName       = sceneName.Replace(".unity", "");
                sceneSplit.assetBundleName = (sceneCollection.path + sceneName).ToLower().Replace("assets/", "");
                scenesArray.Add(new int[] { posX, posY, posZ }, sceneSplit);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads tiles in range
        /// </summary>
        void SceneLoading()
        {
            ////show splash screen
            //if (showLoadingScreen && loadingStreamer != null) {
            //	showLoadingScreen = false;
            //	if (tilesLoaded >= tilesToLoad) {
            //		tilesToLoad = int.MaxValue;
            //		tilesLoaded = 0;
            //	}
            //}

            int tilesToLoadNew = 0;


            //int[] sceneIDPlayer = new int[] {
            //            xPos,
            //            yPos,
            //            zPos
            //        };

            if (!useLoadingRangeMin)
            {
                int x = xPos;
                int y = yPos;
                int z = zPos;

                int[] sceneID      = new int[] { x, y, z };
                float xMoveLimit   = 0;
                int   xDeloadLimit = 0;

                float yMoveLimit   = 0;
                int   yDeloadLimit = 0;

                float zMoveLimit   = 0;
                int   zDeloadLimit = 0;

                //set scene possition according to looping
                if (looping)
                {
                    if (sceneCollection.xSplitIs)
                    {
                        int xFinal = mod((x + Mathf.Abs(xLimitx)), xRange) + xLimitx;

                        xDeloadLimit = (int)Math.Ceiling((x - xLimity) / (float)xRange) * xRange;
                        xMoveLimit   = xDeloadLimit * sceneCollection.xSize;

                        sceneID[0] = xFinal;
                    }

                    if (sceneCollection.ySplitIs)
                    {
                        int yFinal = mod((y + Mathf.Abs(yLimitx)), yRange) + yLimitx;

                        yDeloadLimit = (int)Math.Ceiling((y - yLimity) / (float)yRange) * yRange;
                        yMoveLimit   = yDeloadLimit * sceneCollection.ySize;

                        sceneID[1] = yFinal;
                    }

                    if (sceneCollection.zSplitIs)
                    {
                        int zFinal = mod((z + Mathf.Abs(zLimitx)), zRange) + zLimitx;

                        zDeloadLimit = (int)Math.Ceiling((z - zLimity) / (float)zRange) * zRange;
                        zMoveLimit   = zDeloadLimit * sceneCollection.zSize;
                        sceneID[2]   = zFinal;
                    }
                }


                //load scene if scene array contains it and set up scene offset position according to looping
                if (scenesArray.ContainsKey(sceneID))
                {
                    SceneSplit split = scenesArray[sceneID];
                    if (!split.loaded)
                    {
                        split.loaded = true;

                        split.posXLimitMove = xMoveLimit;
                        split.xDeloadLimit  = xDeloadLimit;

                        split.posYLimitMove = yMoveLimit;
                        split.yDeloadLimit  = yDeloadLimit;

                        split.posZLimitMove = zMoveLimit;
                        split.zDeloadLimit  = zDeloadLimit;

                        scenesToLoad.Add(split);
                        loadedScenes.Add(split);
                        tilesToLoadNew++;
                    }
                }
            }

            // load new scenes
            for (int x = -(int)loadingRange.x + xPos; x <= (int)loadingRange.x + xPos; x++)
            {
                for (int y = -(int)loadingRange.y + yPos; y <= (int)loadingRange.y + yPos; y++)
                {
                    for (int z = -(int)loadingRange.z + zPos; z <= (int)loadingRange.z + zPos; z++)
                    {
                        if (useLoadingRangeMin)
                        {
                            if (x - xPos >= -loadingRangeMin.x && x - xPos <= loadingRangeMin.x &&
                                y - yPos >= -loadingRangeMin.y && y - yPos <= loadingRangeMin.y &&
                                z - zPos >= -loadingRangeMin.z && z - zPos <= loadingRangeMin.z)
                            {
                                continue;
                            }
                        }


                        int[] sceneID      = new int[] { x, y, z };
                        float xMoveLimit   = 0;
                        int   xDeloadLimit = 0;

                        float yMoveLimit   = 0;
                        int   yDeloadLimit = 0;

                        float zMoveLimit   = 0;
                        int   zDeloadLimit = 0;

                        //set scene possition according to looping
                        if (looping)
                        {
                            if (sceneCollection.xSplitIs)
                            {
                                int xFinal = mod((x + Mathf.Abs(xLimitx)), xRange) + xLimitx;

                                xDeloadLimit = (int)Math.Ceiling((x - xLimity) / (float)xRange) * xRange;
                                xMoveLimit   = xDeloadLimit * sceneCollection.xSize;

                                sceneID[0] = xFinal;
                            }

                            if (sceneCollection.ySplitIs)
                            {
                                int yFinal = mod((y + Mathf.Abs(yLimitx)), yRange) + yLimitx;

                                yDeloadLimit = (int)Math.Ceiling((y - yLimity) / (float)yRange) * yRange;
                                yMoveLimit   = yDeloadLimit * sceneCollection.ySize;
                                sceneID[1]   = yFinal;
                            }


                            if (sceneCollection.zSplitIs)
                            {
                                int zFinal = mod((z + Mathf.Abs(zLimitx)), zRange) + zLimitx;

                                zDeloadLimit = (int)Math.Ceiling((z - zLimity) / (float)zRange) * zRange;
                                zMoveLimit   = zDeloadLimit * sceneCollection.zSize;
                                sceneID[2]   = zFinal;
                            }
                        }

                        //load scene if scene array contains it and set up scene offset position according to looping
                        if (scenesArray.ContainsKey(sceneID))
                        {
                            SceneSplit split = scenesArray[sceneID];
                            if (!split.loaded)
                            {
                                split.loaded = true;

                                split.posXLimitMove = xMoveLimit;
                                split.xDeloadLimit  = xDeloadLimit;

                                split.posYLimitMove = yMoveLimit;
                                split.yDeloadLimit  = yDeloadLimit;

                                split.posZLimitMove = zMoveLimit;
                                split.zDeloadLimit  = zDeloadLimit;

                                scenesToLoad.Add(split);
                                loadedScenes.Add(split);
                                tilesToLoadNew++;
                            }
                        }
                    }
                }
            }

            if (scenesToLoad.Count > 0)
            {
                scenesToLoad.Sort(compareSceneSplit);
            }

            tilesToLoad = tilesToLoadNew;

            initialized = true;
        }