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); }
public void InitLevel(int levelId) { Clear(); LevelMapData data = LevelConfig.Instance.GetLevelMapData(levelId); foreach (var ballData in data.balls) { ServerBubble bubble = new ServerBubble(ballData.id, (ELevelBallType)ballData.type, ballData.grids); AddBubble(bubble); } m_nextId = data.maxBallId + 1; m_minCol = data.minCol; }
private void Reset() { OnRestartBattle(); m_battleField.Reset(); m_state = EBattleState.None; m_startFightTime = 0; Vector2 startPos = new Vector2(-6, 0); m_battleField.BattleFieldObj.transform.position = startPos; LevelMapData data = LevelConfig.Instance.GetLevelMapData(GameCore.Instance.m_globalData.CurrLevel); m_battleField.InitLevel(data); m_battleLocalCal.InitLevel(data, m_battleField.Balls); m_battleField.IsWaitFireBall = false; }
public void Export() { LevelMapData data = new LevelMapData(); data.mapType = MapType; data.ballRadius = GridRadius; data.minCol = MaxCol; data.maxBallId = 0; foreach (var ball in Balls) { BallData ballData = new BallData(); ballData.id = ball.Value.Id; ballData.type = (int)ball.Value.Type; ballData.localX = ball.Value.gameObject.transform.localPosition.x; ballData.localY = ball.Value.gameObject.transform.localPosition.y; ballData.grids.Add(new GridPosition(ball.Key.col, ball.Key.row)); ballData.IsRoot = ball.Key.col == 0; foreach (var connect in ball.Value.Connections) { ballData.connections.Add(connect.Id); } data.balls.Add(ballData); if (ballData.id > data.maxBallId) { data.maxBallId = ballData.id; } if (ball.Key.col < data.minCol) { data.minCol = ball.Key.col; } } FileStream file = new FileStream(GetLevelDataPath(LevelId), FileMode.Create); FileBytesWriter writer = new FileBytesWriter(file); data.Write(writer); file.Flush(); file.Close(); }
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); } }
public void InitLevel(LevelMapData data) { foreach (var ball in m_balls.Values) { GameObject.Destroy(ball); } m_balls.Clear(); foreach (var ballData in data.balls) { GameObject res = BattleResource.Instance.GetBallResource((ELevelBallType)ballData.type); if (res != null) { GameObject ball = GameObject.Instantiate(res, m_battleField.transform); ball.transform.localPosition = new Vector3(ballData.localX, ballData.localY, 0); m_balls.AddBall(ballData.id, ball, (ELevelBallType)ballData.type); } } m_missionFinishNum = 0; m_missionNum = LevelConfig.Instance.GetLevelInfo(GameCore.Instance.m_globalData.CurrLevel).targetNum; UpDataMissionProgress(0); }
public void InitLevel(LevelMapData data, BattleBallInfor balls) { m_balls = balls; }