Unity-地形编辑器-编辑器拓展功能类
生活随笔
收集整理的這篇文章主要介紹了
Unity-地形编辑器-编辑器拓展功能类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//==========================
// - FileName: MapTool.cs
// - Created: true.
// - CreateTime: 2020/04/04 23:37:18
// - Email: 1670328571@qq.com
// - Region: China WUHAN
// - Description: 編輯器拓展
//==========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;#if Tool
[CustomEditor(typeof(MapMaker))]
public class MapTool : Editor
{//對象的引用private MapMaker mapMaker; //拿到文件、關卡文件列表private List<FileInfo> fileList = new List<FileInfo>();//名字列表private string[] fileNameList;//當前編輯關卡索引號private int selectIndex = -1;public override void OnInspectorGUI(){//添加的東西寫在下方base.OnInspectorGUI();//只有程序在運行的時候if (Application.isPlaying){
#region 第一行mapMaker = MapMaker.Instance;//開始水平EditorGUILayout.BeginHorizontal();//獲取操作的文件名fileNameList = GetNames(fileList);//下拉列表int currentIndex = EditorGUILayout.Popup(selectIndex, fileNameList);//判斷當前索引是否為選擇的索引 、當前選擇對象是否改變if (currentIndex != selectIndex){//更改索引selectIndex = currentIndex;//實例化地圖的方法mapMaker.InitMap();//加載當前選擇的 Level 文件mapMaker.LoadLevelFile(mapMaker.LoadLevelInfoFile(fileNameList[selectIndex]));//讀取關卡列表}if (GUILayout.Button("讀取關卡列表")){//讀取關卡列表LoadLevelFiles();}//結束EditorGUILayout.EndHorizontal();#endregion#region 第二行EditorGUILayout.BeginHorizontal();if (GUILayout.Button("恢復地圖編輯器默認狀態")){mapMaker.RecoverTowerPoint();}if (GUILayout.Button("清楚怪物路點")){mapMaker.ClearMonsterPath();}EditorGUILayout.EndHorizontal();
#endregion#region 第三行if (GUILayout.Button("保存當前關卡數據文件")){mapMaker.SaveLevelFileByJson();}#endregion}}//加載關卡數據private void LoadLevelFiles(){ClearList();//加載文件列表、關卡數據fileList = GetLevelFiles();}//清楚文件列表private void ClearList(){fileList.Clear();selectIndex = -1;}//獲取當前關卡列表private List<FileInfo> GetLevelFiles(){//獲取文件string[] files = Directory.GetFiles(Application.dataPath + "/Resources/Json/Level/","*.json");List<FileInfo> list = new List<FileInfo>();//遍歷對象for (int i = 0; i < files.Length; i++){FileInfo file = new FileInfo(files[i]);//對象添加進列表list.Add(file);}return list;}//獲取關卡文件的名字private string[] GetNames(List<FileInfo> files){List<string> names = new List<string>();//遍歷傳遞的列表foreach (FileInfo file in files){names.Add(file.Name);}return names.ToArray();}
}#endif
//==========================
// - FileName: GridPoint.cs
// - Created: true.
// - CreateTime: 2020/03/16 17:03:43
// - Email: 1670328571@qq.com
// - Region: China WUHAN
// - Description: 信息存儲、交互
//==========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.EventSystems;public class GridPoint : MonoBehaviour
{//渲染處理(屬性)private SpriteRenderer spriteRenderer;//格子的圖片private Sprite gridSprite;public GridState gridState;public GridIndex gridIndex;//格子狀態(沒有建塔的時候建塔、有塔的時候升級塔)public bool hasTower;//當前格子道具、開始精靈圖片private Sprite startSprite;//不可建塔private Sprite coutBuildSprite;//引用private GameControl gameControl;//當前關卡建塔列表private GameObject towerListGo;//有塔的按鈕畫布private GameObject handleTowerCanvasGo;//兩個按鈕的引用private Transform upLevelBtnTrans;private Transform sellTowerBtnTrans;//按鈕的初始位置private Vector3 upLevelBtnInitPos;private Vector3 sellTowerBtnInitPos;#if Tool//怪物路點圖片private Sprite monsterPathSprite;//所有道具public GameObject[] itemPrefabs;public GameObject currentItem;
#endif[SerializeField]//類信息(格子狀態)public struct GridState{//是否可以建塔 public bool canBuild;//是否是怪物路點public bool isMonsterPoint;//是否有道具public bool hasItem;//道具 IDpublic int itemID;}[SerializeField]//格子索引(格子的點)public struct GridIndex{public int xIndex;public int yIndex;}private void Awake(){
#if Tool//獲取格子gridSprite = Resources.Load<Sprite>("Pictures/NormalMordel/Game/Grid");//怪物路點monsterPathSprite = Resources.Load<Sprite>("Pictures/NormalMordel/Game/1/Monster/6-1");itemPrefabs = new GameObject[10];//大關卡索引路徑string PrefabsPath = "Prefabs/Game/" + MapMaker.Instance.bigLevelID.ToString() + "/Item/";for (int i = 0; i < itemPrefabs.Length; i++){//加載的游戲物體存儲進數組itemPrefabs[i] = Resources.Load<GameObject>(PrefabsPath + i);//是否加載完成、如果沒有該路徑if (!itemPrefabs[i]){Debug.Log("加載失敗、失敗路徑" + PrefabsPath + i);}}
#endifspriteRenderer = GetComponent<SpriteRenderer>();//初始化格子狀態InitGrid();
#if GamegameControl = GameControl.Instance;//格子資源gridSprite = gameControl.GetSprite("NormalMordel/Game/Grid");startSprite = gameControl.GetSprite("NormalMordel/Game/StartSprite");coutBuildSprite = gameControl.GetSprite("NormalMordel/Game/cantBuild");//初始化spriteRenderer.sprite = startSprite;//動畫播放Tween t = DOTween.To(() => spriteRenderer.color, tocolor => spriteRenderer.color = tocolor, new Color(1, 1, 1, 0.2f), 3f);//回調函數動畫t.OnComplete(ChangeSpriteToGrid);towerListGo = gameControl.towerListGo;handleTowerCanvasGo = gameControl.handleTowerCanvasGo;upLevelBtnTrans = handleTowerCanvasGo.transform.Find("Btn_UpLevel");sellTowerBtnTrans = handleTowerCanvasGo.transform.Find("Btn_SellTower");upLevelBtnInitPos = upLevelBtnTrans.localPosition;sellTowerBtnInitPos = sellTowerBtnTrans.localPosition;
#endif}//還原樣式private void ChangeSpriteToGrid(){//關閉渲染spriteRenderer.enabled = false;spriteRenderer.color = new Color(1, 1, 1, 1);//可以建塔if (gridState.canBuild){spriteRenderer.sprite = gridSprite;}else{//不可建塔spriteRenderer.sprite = coutBuildSprite;}}//初始化方法public void InitGrid(){gridState.canBuild = true;gridState.isMonsterPoint = false;gridState.hasItem = false;spriteRenderer.enabled = true;gridState.itemID = -1;
#if Tool//更改圖片spriteRenderer.sprite = gridSprite;//銷毀道具Destroy(currentItem);
#endif}#if Game//更新格子狀態public void UpdateGrid(){//可以建塔if (gridState.canBuild){spriteRenderer.enabled = true;//有道具 的時候if (gridState.hasItem){CreateItem();}}else{spriteRenderer.enabled = false;}}//創建物品private void CreateItem(){//加載道具GameObject itemGo = GameControl.Instance.GetGameObjectResource(GameControl.Instance.mapMaker.bigLevelID.ToString() + "/Item/" + gridState.itemID);itemGo.transform.SetParent(GameControl.Instance.transform);//偏移Vector3 createPos = transform.position - new Vector3(0, 0, 3);if (gridState.itemID <= 2){//自身加上偏移createPos += new Vector3(GameControl.Instance.mapMaker.gridWidth, -GameControl.Instance.mapMaker.gridHeight) / 2;}else if (gridState.itemID <= 4){createPos += new Vector3(GameControl.Instance.mapMaker.gridWidth, 0) / 2;}itemGo.transform.position = createPos;itemGo.GetComponent<Item>().gridPoint = this;}private void OnMouseDown(){// //選中的時候為 UI return//#pragma warning disable CS0472 // 由于此類型的值永不等于 "null",該表達式的結果始終相同// if (EventSystem.current.IsPointerOverGameObject() == null)//#pragma warning restore CS0472 // 由于此類型的值永不等于 "null",該表達式的結果始終相同// {// return;// }Debug.Log("鼠標點擊事件");gameControl.HandleGrid(this);}//建完塔之后的處理方法public void AfterBuild(){spriteRenderer.enabled = false;//塔的后續處理Debug.Log("隱藏");}//顯示格子public void ShowGird(){//當前有無塔if (!hasTower){spriteRenderer.enabled = true;//顯示建塔列表towerListGo.transform.position = CorrectTowerListGoPosition();towerListGo.SetActive(true);}else{handleTowerCanvasGo.transform.position = transform.position;CorrectHandleTowerCanvasGoPosition();handleTowerCanvasGo.SetActive(true);//顯示攻擊范圍//TODO}}//隱藏上一個格子public void HideGrid(){//沒有塔的時候if (!hasTower){//隱藏建塔列表towerListGo.SetActive(false);}else{//有塔handleTowerCanvasGo.SetActive(false);//顯示塔的范圍}spriteRenderer.enabled = false;}//不可建塔public void ShowCantBuild(){spriteRenderer.enabled = true;Tween t = DOTween.To(() => spriteRenderer.color, tocolor => spriteRenderer.color = tocolor, new Color(1, 1, 1, 0), 2f);t.OnComplete(() =>{//關閉渲染spriteRenderer.enabled = false;//初始化spriteRenderer.color = new Color(1, 1, 1, 1);});}//糾正建塔列表位置private Vector3 CorrectTowerListGoPosition(){Vector3 createPositon = Vector3.zero;//左邊緣if (gridIndex.xIndex <= 3 && gridIndex.xIndex >= 0){createPositon += new Vector3(gameControl.mapMaker.gridWidth, 0, 0);}else if (gridIndex.xIndex <= 11 && gridIndex.xIndex >= 8){createPositon -= new Vector3(gameControl.mapMaker.gridWidth, 0, 0);}if (gridIndex.yIndex <= 3 && gridIndex.yIndex >= 0){createPositon += new Vector3(0, gameControl.mapMaker.gridHeight, 0);}else if (gridIndex.yIndex <= 7 && gridIndex.yIndex >= 4){createPositon -= new Vector3(0, gameControl.mapMaker.gridHeight, 0);}createPositon += transform.position;return createPositon;}//糾正畫布private void CorrectHandleTowerCanvasGoPosition(){//初始化位置upLevelBtnTrans.localPosition = Vector3.zero;sellTowerBtnTrans.localPosition = Vector3.zero;if (gridIndex.yIndex <= 0){//當前塔在最左邊if (gridIndex.xIndex == 0){//偏移sellTowerBtnTrans.position += new Vector3(gameControl.mapMaker.gridWidth * 3 / 4, 0, 0);}else{sellTowerBtnTrans.position -= new Vector3(gameControl.mapMaker.gridWidth * 3 / 4, 0, 0);}//升級按鈕處理upLevelBtnTrans.localPosition = upLevelBtnInitPos;}else if (gridIndex.yIndex >= 6) {if (gridIndex.xIndex == 0){upLevelBtnTrans.position += new Vector3(gameControl.mapMaker.gridWidth * 3 / 4, 0, 0);}else{upLevelBtnTrans.position -= new Vector3(gameControl.mapMaker.gridWidth * 3 / 4, 0, 0);}sellTowerBtnTrans.localPosition = sellTowerBtnInitPos;}else{upLevelBtnTrans.localPosition = upLevelBtnInitPos;sellTowerBtnTrans.localPosition = sellTowerBtnInitPos;}}#endif#if Tool//怪物路點private void OnMouseDown(){//玩家按左鍵的時候 、 怪物路點if (Input.GetKey(KeyCode.P)){//不能建塔gridState.canBuild = false;//打開渲染spriteRenderer.enabled = true;//回調、取非gridState.isMonsterPoint = !gridState.isMonsterPoint; //是怪物路點的時候if (gridState.isMonsterPoint){MapMaker.Instance.monsterPath.Add(gridIndex);//控制渲染spriteRenderer.sprite = monsterPathSprite;}else{//不是怪物路點的時候、刪除列表MapMaker.Instance.monsterPath.Remove(gridIndex);//改變格子渲染spriteRenderer.sprite = gridSprite;//可以建塔gridState.canBuild = true;}}else if(Input.GetKey(KeyCode.I)){//道具gridState.itemID++;//超出索引、當前格子從持有道具轉換為沒有道具if (gridState.itemID == itemPrefabs.Length){gridState.itemID = -1;Destroy(currentItem);//是否持有道具gridState.hasItem = false;return;}if (currentItem == null){//產生道具CreateItem();}else{//本身掛載有道具Destroy(currentItem);//產生道具的方法CreateItem();}gridState.hasItem = true;}else if (!gridState.isMonsterPoint){//沒有鍵盤操作的時候且不是怪物路點gridState.isMonsterPoint = false;//取非gridState.canBuild = !gridState.canBuild;if (gridState.canBuild){spriteRenderer.enabled= true;}else{spriteRenderer.enabled = false;}}}//生成道具的方法private void CreateItem(){Vector3 createPos = transform.position;if (gridState.itemID <= 2){createPos += new Vector3(MapMaker.Instance.gridWidth, -MapMaker.Instance.gridHeight) / 2;}else if (gridState.itemID <= 4){createPos += new Vector3(MapMaker.Instance.gridWidth,0) / 2;}GameObject itemGo = Instantiate(itemPrefabs[gridState.itemID], createPos, Quaternion.identity);currentItem = itemGo;}//更新格子狀態public void UpdateGrid(){//判斷格子狀態能否尖塔if (gridState.canBuild){spriteRenderer.sprite = gridSprite;//渲染打開spriteRenderer.enabled = true;//是否是道具if (gridState.hasItem){CreateItem();}}else{//格子是否是怪物路店點if (gridState.isMonsterPoint){spriteRenderer.sprite = monsterPathSprite;}else{//當前格子點無法建塔spriteRenderer.enabled = false;}}}
#endif}
//==========================
// - FileName: Level.cs
// - Created: true.
// - CreateTime: 2020/04/09 16:41:52
// - Email: 1670328571@qq.com
// - Region: China WUHAN
// - Description: 控制任務鏈疊加、賦值
//==========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Level
{//當前關卡波次怪物public int totalRound;//public Round[] roundList;//當前的 roundpublic int currentRound;public Level(int roundNum, List<Round.RoundInfo> roundInfoList){totalRound = roundNum;roundList = new Round[totalRound];//具體內容、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].SetNextRound(roundList[i + 1]);}}//控制者public void HandleRound(){//當前回合大于等于 最后一關if (currentRound >= totalRound){//游戲勝利}else if (currentRound == totalRound-1){//最后一波怪 的 UI 、音樂}else{//普通波次roundList[currentRound].Handle(currentRound);}}//調用最后一回合的 Handle 方法public void HandleLastRound(){roundList[currentRound].Handle(currentRound);}//public void AddRoundNum(){currentRound++;}
}
//==========================
// - FileName: LevelInfo.cs
// - Created: true.
// - CreateTime: 2020/04/06 17:54:32
// - Email: 1670328571@qq.com
// - Region: China WUHAN
// - Description:
//==========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class LevelInfo
{//需要存儲的信息//大關卡 IDpublic int bigLevelID;//小關卡 IDpublic int levelID;//所有格子狀態、避免使用二維數組public List<GridPoint.GridState> gridPoints;//怪物路徑點、使用索引存儲public List<GridPoint.GridIndex> monsterPath;//當前關卡信息public List<Round.RoundInfo> roundInfo;
}
//==========================
// - FileName: MapMaker.cs
// - Created: true.
// - CreateTime: 2020/03/16 14:27:09
// - Email: 1670328571@qq.com
// - Region: China WUHAN
// - Description: 地圖編輯器工具、游戲中作為地圖產生工具
//==========================
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;//在游戲中不是單例、在工具中才是單例private static MapMaker _instance;public static MapMaker Instance{get{return _instance;}}
#endif//地圖寬private float mapWidth;//高private float mapHeight;[HideInInspector]//格子寬public float gridWidth;[HideInInspector]//格子高public float gridHeight;[HideInInspector]//當前關數索引public int bigLevelID;[HideInInspector]public int LevelID;//地圖的全部格子對象public GridPoint[,] gridPoints;//行數public const int yRow = 8; //列數public const int xColumn = 12;[HideInInspector]//怪物路徑點具體位置public List<Vector3> monsterPathPos;//背景渲染private SpriteRenderer bgSR;//地圖的加載渲染private SpriteRenderer roadSR;[HideInInspector]//怪物路徑點、格子索引public List<GridPoint.GridIndex> monsterPath;//每一波次產生的怪物ID列表public List<Round.RoundInfo> roundInfoList;[HideInInspector]public Carrot carrot;private void Awake(){
#if Tool_instance = this;//InitMapMaker();
#endif}//初始化地圖public void InitMapMaker(){CalculateSize();//實例化數組gridPoints = new GridPoint[xColumn, yRow];monsterPath = new List<GridPoint.GridIndex>();//生成格子for (int x = 0; x < xColumn; x++){for (int y = 0; y < yRow; y++){
#if Tool//生成格子對象GameObject itemGo = Instantiate(gridGo, transform.position, transform.rotation);
#endif
#if GameGameObject itemGo = GameControl.Instance.GetGameObjectResource("Grid");
#endif//設置屬性itemGo.transform.position = CorretPositon(x * gridWidth, y * gridHeight);itemGo.transform.SetParent(transform);//獲取格子點gridPoints[x, y] = itemGo.GetComponent<GridPoint>();gridPoints[x, y].gridIndex.xIndex = x;gridPoints[x, y].gridIndex.xIndex = y;}}//獲取渲染組件bgSR = transform.Find("BG").GetComponent<SpriteRenderer>();roadSR = transform.Find("Road").GetComponent<SpriteRenderer>();}//加載地圖
#if Gamepublic void LoadMap(int bigLevel,int Level){bigLevelID = bigLevel;LevelID = Level;//加載文件LoadLevelFile(LoadLevelInfoFile("Level" + bigLevelID.ToString() + "_" + LevelID.ToString() + ".json"));monsterPathPos = new List<Vector3>();//遍歷怪物路徑列表for (int i = 0; i < monsterPath.Count; i++){//位置添加進列表monsterPathPos.Add(gridPoints[monsterPath[i].xIndex,monsterPath[i].yIndex].transform.position); }//起始點與終止點GameObject startPointGo = GameControl.Instance.GetGameObjectResource("startPoint");//怪物點的第一個位置startPointGo.transform.position = monsterPathPos[0];startPointGo.transform.SetParent(transform);GameObject endPointGo = GameControl.Instance.GetGameObjectResource("Carrot");//怪物點的第一個位置endPointGo.transform.position = monsterPathPos[monsterPathPos.Count - 1];endPointGo.transform.SetParent(transform);carrot = endPointGo.GetComponent<Carrot>();}
#endif//糾正預制件的起始位置public Vector3 CorretPositon(float x,float y){return new Vector3(x - mapWidth / 2 + gridWidth / 2, y- mapHeight / 2 + gridHeight / 2);}//計算地圖格子的寬高private void CalculateSize(){//左下角Vector3 leftDown = new Vector3(0, 0);//右上角Vector3 rightUp = new Vector3(1, 1);//視口坐標轉世界坐標 、 左下角的世界坐標Vector3 posOne = Camera.main.ViewportToWorldPoint(leftDown);//右上角Vector3 posTwo = Camera.main.ViewportToWorldPoint(rightUp);//地圖寬mapWidth = posTwo.x - posOne.x;//地圖高mapHeight = posTwo.y - posOne.y;//格子的寬gridWidth = mapWidth / xColumn;//格子高gridHeight = mapHeight / yRow;}#if Tool//畫格子private void OnDrawGizmos(){//畫線if (drawLine){//計算格子的大小CalculateSize();//格子的顏色Gizmos.color = Color.green;//畫出行數 這里的值應該是要等于行數的for (int y = 0; y <= yRow; y++){//起始位置Vector3 startPos = new Vector3(-mapWidth / 2, -mapHeight / 2 + y * gridHeight);//終點坐標Vector3 endPos = new Vector3(mapWidth / 2, -mapHeight / 2 + y * gridHeight);//畫線Gizmos.DrawLine(startPos, endPos);}//畫列for (int x = 0; x <= xColumn; x++){Vector3 startPos = new Vector3(-mapWidth / 2 + gridWidth * x, mapHeight / 2);Vector3 endPos = new Vector3(-mapWidth / 2 + x * gridWidth, -mapHeight / 2);Gizmos.DrawLine(startPos, endPos);}}else{return;}}
#endif//清除怪物路點public void ClearMonsterPath(){monsterPath.Clear();}//恢復地圖編輯默認狀態public void RecoverTowerPoint(){//清除怪物路點ClearMonsterPath();for (int x = 0; x < xColumn; x++){for (int y = 0; y < yRow; y++){//初始化塔點gridPoints[x, y].InitGrid();}}}//初始化地圖public void InitMap(){//大小關卡 ID 置0 bigLevelID = 0;LevelID = 0;RecoverTowerPoint();//清除怪物路經roundInfoList.Clear();//渲染清除bgSR.sprite = null;roadSR.sprite = null;}#if Tool//生成 LevelInfo 對象,保存文件private LevelInfo CreateLevelInfoGo(){LevelInfo levelInfo = new LevelInfo(){bigLevelID = this.bigLevelID,levelID = this.LevelID,};levelInfo.gridPoints = new List<GridPoint.GridState>();//遍歷for (int x = 0; x < xColumn; x++){for (int y = 0; y < yRow; y++){//添加進信息對象列表levelInfo.gridPoints.Add(gridPoints[x, y].gridState);}}levelInfo.monsterPath = new List<GridPoint.GridIndex>();//遍歷怪物路徑for (int i = 0; i < monsterPath.Count; i++){levelInfo.monsterPath.Add(monsterPath[i]);}//產生怪物的 ID 列表levelInfo.roundInfo = new List<Round.RoundInfo>();for (int i = 0; i < roundInfoList.Count; i++){levelInfo.roundInfo.Add(roundInfoList[i]);}Debug.Log("保存成功");return levelInfo;}//保存成 Json、保存當前關卡public void SaveLevelFileByJson(){LevelInfo levelInfoGo = CreateLevelInfoGo();//路徑string filePath = Application.dataPath + "/Resources/Json/Level/" + bigLevelID.ToString() + "_" + LevelID.ToString() + ".json";//對象轉換字符串string saveJsonStr = JsonMapper.ToJson(levelInfoGo); //文件流StreamWriter sw = new StreamWriter(filePath);//寫的內容 sw.Write(saveJsonStr);//關閉文件流sw.Close();}
#endif//讀取關卡文件、解析Josn 轉換為對象public LevelInfo LoadLevelInfoFile(string fileName){LevelInfo levelInfo = new LevelInfo(); //完善路徑string filePath = Application.dataPath + "/Resources/Json/Level/" + fileName;//文件讀取流、判斷路徑是否存在if (File.Exists(filePath)){//如果存在StreamReader sr = new StreamReader(filePath);//讀成字符串string jsonStr = sr.ReadToEnd();//關閉文件流sr.Close();//取得對象levelInfo = JsonMapper.ToObject<LevelInfo>(jsonStr);return levelInfo;}Debug.Log("文件加載失敗、失敗路徑"+filePath);return null;}//信息轉換public void LoadLevelFile(LevelInfo levelInfo){bigLevelID = levelInfo.bigLevelID;LevelID = levelInfo.levelID;for (int x = 0; x < xColumn; x++){for (int y = 0; y < yRow; y++){//更新信息gridPoints[x, y].gridState = levelInfo.gridPoints[y + x * yRow];//更新格子狀態gridPoints[x, y].UpdateGrid();}}//清除monsterPath.Clear();//怪物路徑for (int i = 0; i < levelInfo.monsterPath.Count; i++){monsterPath.Add(levelInfo.monsterPath[i]);}roundInfoList = new List<Round.RoundInfo>();for (int i = 0; i < levelInfo.roundInfo.Count; i++){roundInfoList.Add(levelInfo.roundInfo[i]);}//設置地圖的圖片切換bgSR.sprite = Resources.Load<Sprite>("Pictures/NormalMordel/Game/" + bigLevelID.ToString() + "/" + "BG" + (LevelID / 3).ToString());roadSR.sprite = Resources.Load<Sprite>("Pictures/NormalMordel/Game/" + bigLevelID.ToString() + "/" + "Road" + LevelID);}}
//==========================
// - FileName: Round.cs
// - Created: true.
// - CreateTime: 2020/04/06 17:24:47
// - Email: 1670328571@qq.com
// - Region: China WUHAN
// - Description:
//==========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;public class Round
{[Serializable]//存儲信息 public struct RoundInfo{//怪物列表信息public int[] mMonsterIDList;}//對象public RoundInfo roundInfo;//下一個對象protected Round mNextRound;//當前關卡的編號protected int mRoundID;//Level 對象protected Level mlevel;public Round(int[] monsterIDList, int roundID, Level level){mlevel = level;roundInfo.mMonsterIDList = monsterIDList;mRoundID = roundID;}//下一個任務鏈public void SetNextRound(Round nextRound){mNextRound = nextRound;}//責任鏈的判定public void Handle(int roundID){//如果當前回合并不是理想中 的 IDif (mRoundID < roundID){mNextRound.Handle(roundID);}else{//當前任務鏈大于等于 ID 、產生怪物GameControl.Instance.mMonsterIDList = roundInfo.mMonsterIDList;GameControl.Instance.CreateMonster();}}}
//==========================
// - FileName: Stage.cs
// - Created: true.
// - CreateTime: 2020/03/11 19:05:34
// - Email: 1670328571@qq.com
// - Region: China WUHAN
// - Description: 存儲所有的關卡信息
//==========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Stage
{//public int[] mTowerIDList;//具體長度public int mTowerIDListLength;//當前關卡是否清除所有道具public bool mAllClear;//蘿卜狀態public int mCarrotState;//小關卡ID public int mLevelID;//大關卡IDpublic int mBigLevelID;//當前關卡是否解鎖public bool unLocked;//當前關卡是否為獎勵、隱藏關卡public bool mIsRewardLevel;//當前怪物波數public int mTotalRound;//使用構造進行賦值public Stage(int totalRound, int towerIDListLength, int[] towerIDList,bool allClear, int carrotState, int levelID, int bigLevelID, bool locked, bool isRewardLevel){mTotalRound = totalRound;mTowerIDListLength = towerIDListLength;mTowerIDList = towerIDList;mAllClear = allClear;mCarrotState = carrotState;mLevelID = levelID;mBigLevelID = bigLevelID;unLocked = locked;mIsRewardLevel = isRewardLevel;}
}
總結
以上是生活随笔為你收集整理的Unity-地形编辑器-编辑器拓展功能类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机科学 征稿,计算机科学征稿函.do
- 下一篇: Execution failed for