コード例 #1
0
        public static void LoadLevel <TMap, TCodes>(string levelName) where TMap : IMap <TCodes>, new()
        {
            var tileMap = TileMap <TMap, TCodes> .GetInstance();

            CurrentLevel = levelName;
            tileMap.LoadMap(new FileStream($"{AppDomain.CurrentDomain.BaseDirectory}/Content/maps/{levelName}.map",
                                           FileMode.Open));
            Camera.UpdateWorldRectangle(tileMap);
            OnLevelLoad?.Invoke();
        }
コード例 #2
0
 public void AsnycLoadLevel(string _levelName, OnLevelLoad onLoad = null, bool isAdded = true)
 {
     if (!isLoading)
     {
         isLoading    = true;
         levelName    = _levelName;
         isLevelAdded = isAdded;
         this.onLoad  = onLoad;
         StartCoroutine(Run());
     }
 }
コード例 #3
0
    void GenerateLevel()
    {
        Texture2D level;

        if (SceneManager.GetActiveScene().name == "IterateLevel")
        {
            level = levels[Random.Range(0, levels.Length)];
        }
        else
        {
            level = levels[0];
        }


        mainCam = Camera.main;
        mainCam.orthographicSize   = (level.height / 2) + 1;
        mainCam.transform.position = new Vector3(level.width * 0.5f, (level.height * 0.5f) - 0.5f, -10);
        for (int x = 0; x < level.width; x++)
        {
            for (int y = 0; y < level.height; y++)
            {
                Color pixelColor = level.GetPixel(x, y);
                if (pixelColor == Color.black)
                {
                    Instantiate(wallObj, new Vector2(x, y), Quaternion.identity);
                }
                else if (pixelColor == Color.white)
                {
                    Instantiate(smallPelletObj, new Vector2(x, y), Quaternion.identity);
                    spawnedPellets++;
                }
                else if (pixelColor == Color.green)
                {
                    int randomPowerup = Random.Range(0, spawnablePowerups.Length);
                    Instantiate(spawnablePowerups[randomPowerup], new Vector2(x, y), Quaternion.identity);
                }
                else
                {
                    for (int i = 0; i < ColorsToSpawn.Length; i++)
                    {
                        if (pixelColor == ColorsToSpawn[i].Color)
                        {
                            Instantiate(ColorsToSpawn[i].GameObject, new Vector2(x, y), Quaternion.identity);
                        }
                    }
                }
            }
        }
        OnLevelLoad?.Invoke();
        AStarGrid.Instance.CreateGrid();
    }
コード例 #4
0
ファイル: LevelSystem.cs プロジェクト: timoheijne/PvB-Game
    private void OnSceneLoaded(Scene arg0, LoadSceneMode arg1)
    {
        if (arg0.name == MainMenuScene && _returnToLevelSelect)
        {
            _returnToLevelSelect = false;
            // TODO: Show level select.
        }

        Debug.Log("Level Loaded");
        _activeLevel = _levels.Find(l => l.SceneName == SceneManager.GetActiveScene().name);
        if (_activeLevel != null)
        {
            OnLevelLoad?.Invoke(_activeLevel);
        }
    }
コード例 #5
0
 // Update is called once per frame
 void Update()
 {
     if (isLoading)
     {
         bool isDone = null != async && async.isDone;
         if (null != onLoad)
         {
             if (isDone)
             {
                 OnLevelLoad tmp = onLoad;
                 onLoad    = null;
                 async     = null;
                 isLoading = false;
                 OnSceneLoaded();
                 tmp(1f, true);
             }
             else
             {
                 onLoad(GetProgress(), false);
             }
         }
     }
 }
コード例 #6
0
        public void AsnycLoadLevel(string _levelName, OnLevelLoad onLoad = null)
        {
            if (isLoading)
            {
                return;
            }
            isLoading = true;
            if (null != sceneAsset)
            {
                sceneAsset.Release();
                sceneAsset = null;
            }
            levelName   = _levelName;
            this.onLoad = onLoad;
            bool isAdded = string.IsNullOrEmpty(levelName) || AppEnv.IsSceneInBuild(levelName);

                        #if UNITY_EDITOR
            if (!AppEnv.UseBundleInEditor && !isAdded)
            {
                //在编辑器里使用非bundle模式的场景,目前已知必须要在build setting里
                Debug.LogError("if use raw asset in editor,you must add scene to buildsetting");
                return;
            }
                        #endif
            if (isAdded)
            {
                StartCoroutine(LoadScene());
            }
            else
            {
                sceneAsset = new SceneAsset();
                sceneAsset.Load(levelName, () =>
                {
                    StartCoroutine(LoadScene(sceneAsset.asset));
                });
            }
        }
コード例 #7
0
        private IEnumerator LoadScene(AssetBundle sceneBundle = null)
        {
            AsyncOperation async = null;

            if (switchByEmptyScene)
            {
                async = SceneManager.LoadSceneAsync("Empty");
                while (!async.isDone)
                {
                    yield return(null);
                }

                GameObjPool.Ins.Empty();
                BundleMgr.Instance.Gc(true);
                //yield return new WaitForSeconds(1f);
            }

            if (!string.IsNullOrEmpty(levelName))
            {
                async = SceneManager.LoadSceneAsync(levelName);
                while (!async.isDone)
                {
                    yield return(null);
                }
            }

            OnLevelLoad tmp = onLoad;

            onLoad    = null;
            isLoading = false;
            OnSceneLoaded();
            if (null != tmp)
            {
                tmp(1f, true);
            }
        }