Exemplo n.º 1
0
        public void LoadLevel(int levelId)
        {
            if (m_levelMapData.ContainsKey(levelId))
            {
                return;
            }

            LevelMapData data = new LevelMapData();
            string       path = Application.streamingAssetsPath + "/Config/Level_" + levelId + ".dat";

            if (path.Contains("file://"))
            {
                WWW loadNetworkwww = new WWW(path);

                while (!loadNetworkwww.isDone)
                {
                }

                data.LoadFromBytes(loadNetworkwww.bytes);
                loadNetworkwww.Dispose();
            }
            else
            {
                byte[] bytes = File.ReadAllBytes(path);
                data.LoadFromBytes(bytes);
            }

            m_levelMapData.Add(levelId, data);
        }
Exemplo n.º 2
0
        public void LoadLevelMap()
        {
            byte[]       databytes = File.ReadAllBytes(GetLevelDataPath(LevelId));
            LevelMapData data      = new LevelMapData();

            data.LoadFromBytes(databytes);
            MapType = (ELevelMapType)data.mapType;

            nextBallId = data.maxBallId + 1;

            foreach (var ballData in data.balls)
            {
                ELevelBallType type   = (ELevelBallType)ballData.type;
                int            col    = ballData.grids[0].col;
                int            row    = ballData.grids[0].row;
                int            ballId = ballData.id;

                GameObject prefab = BallPrefabs[type];
                GameObject ball   = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                ball.name = string.Format("[{0},{1}][{2}]", col, row, type.ToString());
                ball.transform.SetParent(this.transform);
                ball.transform.localPosition = GridToPosition(col, row);
                ball.hideFlags = HideFlags.HideInHierarchy;
                LevelBall newball = ball.GetComponent <LevelBall>();
                newball.Id = ballId;

                List <LevelBall> connectedBalls = new List <LevelBall>();
                GetConnectedBalls(col, row, connectedBalls);
                foreach (var b in connectedBalls)
                {
                    newball.Connections.Add(b);
                    b.Connections.Add(newball);
                }

                Balls.Add(new GridPosition(col, row), newball);
            }
        }