using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 关卡信息类
/// </summary>
public class LevelInfo {
public int bigLevelID;
public int levelID;
public List<GridPoint.GridState> gridStateList;
public List<GridPoint.GridIndex> monsterPathList;
public List<Round.RoundInfo> roundInfoList;
}
怪物波次的信息类:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Round
{
[System.Serializable]
public struct RoundInfo
{
public int[] mMonsterIDList;
}
public RoundInfo roundInfo;
protected Round mNextRound;
protected int mRoundID;
protected Level mLevel;
public Round(int[] monsterIDList, int roundID, Level level)
{
roundInfo.mMonsterIDList = monsterIDList;
mRoundID = roundID;
mLevel = level;
}
public void SetNextHandle(Round nextRound)
{
mNextRound = nextRound;
}
/// <summary>
/// 根据波次ID进行产怪
/// </summary>
/// <param name="roundID"></param>
public void Handle(int roundID)
{
if (mRoundID < roundID)
{
mNextRound.Handle(roundID);
}
else
{
//产怪
GameController.Instance.mMonsterIDList = roundInfo.mMonsterIDList;
GameController.Instance.CreateMonster();
GameController.Instance.creatingMonster = true;
}
}
}
关卡类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Level
{
public int totalRound;
public Round[] roundList;
public int currentRound;
public Level(int totalRoundNum, List<Round.RoundInfo> roundInfoList)
{
totalRound = totalRoundNum;
roundList = new Round[totalRound];
//对Round数组赋值
for (int i = 0; i < totalRound; i++)
{
roundList[i] = new Round(roundInfoList[i].mMonsterIDList, i, this);
}
//设置责任链
for (int i = 0; i < totalRound; i++)
{
if (i == totalRound - 1)
{
break;
}
roundList[i].SetNextHandle(roundList[i + 1]);
}
}
public void HandleRound()
{
Debug.Log(currentRound+":"+ totalRound);
if (currentRound >= totalRound)
{
//TODO 胜利
}
else if (currentRound == totalRound - 1)
{
//TODO 最后一波怪的UI显示 与 音乐播放.
HandleLastRound();
}
else
{
roundList[currentRound].Handle(currentRound);
}
}
public void HandleLastRound()
{
roundList[currentRound].Handle(currentRound);
}
public void AddRoundNun()
{
currentRound++;
}
}
MapMaker中重写对地图加载的方法:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System.IO;
public class MapMaker : MonoBehaviour
{
#if Tool
//是否画线
public bool drawLine;
//格子预制体
public GameObject gridGO;
public static MapMaker _instance;
public static MapMaker Instance
{
get { return _instance; }
}
#endif
//当前关卡索引
public int bigLevelID;
public int levelID;
//地图
public float mapWidth;
public float mapHeight;
//格子
public float gridWidth;
public float gridHeight;
//全部的格子对象
public GridPoint[,] gridPoints;
//行列
public int xColumn = 12;
public int yRow = 8;
private SpriteRenderer bg