日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Unity-地形编辑器-编辑器拓展功能类

發(fā)布時(shí)間:2024/1/1 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity-地形编辑器-编辑器拓展功能类 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//========================== // - 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; //拿到文件、關(guān)卡文件列表private List<FileInfo> fileList = new List<FileInfo>();//名字列表private string[] fileNameList;//當(dāng)前編輯關(guān)卡索引號private int selectIndex = -1;public override void OnInspectorGUI(){//添加的東西寫在下方base.OnInspectorGUI();//只有程序在運(yùn)行的時(shí)候if (Application.isPlaying){ #region 第一行mapMaker = MapMaker.Instance;//開始水平EditorGUILayout.BeginHorizontal();//獲取操作的文件名fileNameList = GetNames(fileList);//下拉列表int currentIndex = EditorGUILayout.Popup(selectIndex, fileNameList);//判斷當(dāng)前索引是否為選擇的索引 、當(dāng)前選擇對象是否改變if (currentIndex != selectIndex){//更改索引selectIndex = currentIndex;//實(shí)例化地圖的方法mapMaker.InitMap();//加載當(dāng)前選擇的 Level 文件mapMaker.LoadLevelFile(mapMaker.LoadLevelInfoFile(fileNameList[selectIndex]));//讀取關(guān)卡列表}if (GUILayout.Button("讀取關(guān)卡列表")){//讀取關(guān)卡列表LoadLevelFiles();}//結(jié)束EditorGUILayout.EndHorizontal();#endregion#region 第二行EditorGUILayout.BeginHorizontal();if (GUILayout.Button("恢復(fù)地圖編輯器默認(rèn)狀態(tài)")){mapMaker.RecoverTowerPoint();}if (GUILayout.Button("清楚怪物路點(diǎn)")){mapMaker.ClearMonsterPath();}EditorGUILayout.EndHorizontal(); #endregion#region 第三行if (GUILayout.Button("保存當(dāng)前關(guān)卡數(shù)據(jù)文件")){mapMaker.SaveLevelFileByJson();}#endregion}}//加載關(guān)卡數(shù)據(jù)private void LoadLevelFiles(){ClearList();//加載文件列表、關(guān)卡數(shù)據(jù)fileList = GetLevelFiles();}//清楚文件列表private void ClearList(){fileList.Clear();selectIndex = -1;}//獲取當(dāng)前關(guān)卡列表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]);//對象添加進(jìn)列表list.Add(file);}return list;}//獲取關(guān)卡文件的名字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;//格子狀態(tài)(沒有建塔的時(shí)候建塔、有塔的時(shí)候升級塔)public bool hasTower;//當(dāng)前格子道具、開始精靈圖片private Sprite startSprite;//不可建塔private Sprite coutBuildSprite;//引用private GameControl gameControl;//當(dāng)前關(guān)卡建塔列表private GameObject towerListGo;//有塔的按鈕畫布private GameObject handleTowerCanvasGo;//兩個(gè)按鈕的引用private Transform upLevelBtnTrans;private Transform sellTowerBtnTrans;//按鈕的初始位置private Vector3 upLevelBtnInitPos;private Vector3 sellTowerBtnInitPos;#if Tool//怪物路點(diǎn)圖片private Sprite monsterPathSprite;//所有道具public GameObject[] itemPrefabs;public GameObject currentItem; #endif[SerializeField]//類信息(格子狀態(tài))public struct GridState{//是否可以建塔 public bool canBuild;//是否是怪物路點(diǎn)public bool isMonsterPoint;//是否有道具public bool hasItem;//道具 IDpublic int itemID;}[SerializeField]//格子索引(格子的點(diǎn))public struct GridIndex{public int xIndex;public int yIndex;}private void Awake(){ #if Tool//獲取格子gridSprite = Resources.Load<Sprite>("Pictures/NormalMordel/Game/Grid");//怪物路點(diǎn)monsterPathSprite = Resources.Load<Sprite>("Pictures/NormalMordel/Game/1/Monster/6-1");itemPrefabs = new GameObject[10];//大關(guān)卡索引路徑string PrefabsPath = "Prefabs/Game/" + MapMaker.Instance.bigLevelID.ToString() + "/Item/";for (int i = 0; i < itemPrefabs.Length; i++){//加載的游戲物體存儲進(jìn)數(shù)組itemPrefabs[i] = Resources.Load<GameObject>(PrefabsPath + i);//是否加載完成、如果沒有該路徑if (!itemPrefabs[i]){Debug.Log("加載失敗、失敗路徑" + PrefabsPath + i);}} #endifspriteRenderer = GetComponent<SpriteRenderer>();//初始化格子狀態(tài)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;//動(dòng)畫播放Tween t = DOTween.To(() => spriteRenderer.color, tocolor => spriteRenderer.color = tocolor, new Color(1, 1, 1, 0.2f), 3f);//回調(diào)函數(shù)動(dòng)畫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(){//關(guān)閉渲染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//更新格子狀態(tài)public void UpdateGrid(){//可以建塔if (gridState.canBuild){spriteRenderer.enabled = true;//有道具 的時(shí)候if (gridState.hasItem){CreateItem();}}else{spriteRenderer.enabled = false;}}//創(chuàng)建物品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(){// //選中的時(shí)候?yàn)?UI return//#pragma warning disable CS0472 // 由于此類型的值永不等于 "null",該表達(dá)式的結(jié)果始終相同// if (EventSystem.current.IsPointerOverGameObject() == null)//#pragma warning restore CS0472 // 由于此類型的值永不等于 "null",該表達(dá)式的結(jié)果始終相同// {// return;// }Debug.Log("鼠標(biāo)點(diǎn)擊事件");gameControl.HandleGrid(this);}//建完塔之后的處理方法public void AfterBuild(){spriteRenderer.enabled = false;//塔的后續(xù)處理Debug.Log("隱藏");}//顯示格子public void ShowGird(){//當(dāng)前有無塔if (!hasTower){spriteRenderer.enabled = true;//顯示建塔列表towerListGo.transform.position = CorrectTowerListGoPosition();towerListGo.SetActive(true);}else{handleTowerCanvasGo.transform.position = transform.position;CorrectHandleTowerCanvasGoPosition();handleTowerCanvasGo.SetActive(true);//顯示攻擊范圍//TODO}}//隱藏上一個(gè)格子public void HideGrid(){//沒有塔的時(shí)候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(() =>{//關(guān)閉渲染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){//當(dāng)前塔在最左邊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//怪物路點(diǎn)private void OnMouseDown(){//玩家按左鍵的時(shí)候 、 怪物路點(diǎn)if (Input.GetKey(KeyCode.P)){//不能建塔gridState.canBuild = false;//打開渲染spriteRenderer.enabled = true;//回調(diào)、取非gridState.isMonsterPoint = !gridState.isMonsterPoint; //是怪物路點(diǎn)的時(shí)候if (gridState.isMonsterPoint){MapMaker.Instance.monsterPath.Add(gridIndex);//控制渲染spriteRenderer.sprite = monsterPathSprite;}else{//不是怪物路點(diǎn)的時(shí)候、刪除列表MapMaker.Instance.monsterPath.Remove(gridIndex);//改變格子渲染spriteRenderer.sprite = gridSprite;//可以建塔gridState.canBuild = true;}}else if(Input.GetKey(KeyCode.I)){//道具gridState.itemID++;//超出索引、當(dāng)前格子從持有道具轉(zhuǎn)換為沒有道具if (gridState.itemID == itemPrefabs.Length){gridState.itemID = -1;Destroy(currentItem);//是否持有道具gridState.hasItem = false;return;}if (currentItem == null){//產(chǎn)生道具CreateItem();}else{//本身掛載有道具Destroy(currentItem);//產(chǎn)生道具的方法CreateItem();}gridState.hasItem = true;}else if (!gridState.isMonsterPoint){//沒有鍵盤操作的時(shí)候且不是怪物路點(diǎn)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;}//更新格子狀態(tài)public void UpdateGrid(){//判斷格子狀態(tài)能否尖塔if (gridState.canBuild){spriteRenderer.sprite = gridSprite;//渲染打開spriteRenderer.enabled = true;//是否是道具if (gridState.hasItem){CreateItem();}}else{//格子是否是怪物路店點(diǎn)if (gridState.isMonsterPoint){spriteRenderer.sprite = monsterPathSprite;}else{//當(dāng)前格子點(diǎn)無法建塔spriteRenderer.enabled = false;}}} #endif} //========================== // - FileName: Level.cs // - Created: true. // - CreateTime: 2020/04/09 16:41:52 // - Email: 1670328571@qq.com // - Region: China WUHAN // - Description: 控制任務(wù)鏈疊加、賦值 //========================== using System.Collections; using System.Collections.Generic; using UnityEngine;public class Level {//當(dāng)前關(guān)卡波次怪物public int totalRound;//public Round[] roundList;//當(dāng)前的 roundpublic int currentRound;public Level(int roundNum, List<Round.RoundInfo> roundInfoList){totalRound = roundNum;roundList = new Round[totalRound];//具體內(nèi)容、for (int i = 0; i < totalRound; i++){roundList[i] = new Round(roundInfoList[i].mMonsterIDList, i, this);}//設(shè)置任務(wù)鏈for (int i = 0; i < totalRound; i++){//是否為最后一個(gè)元素if (i == totalRound - 1){break;}//設(shè)置任務(wù)roundList[i].SetNextRound(roundList[i + 1]);}}//控制者public void HandleRound(){//當(dāng)前回合大于等于 最后一關(guān)if (currentRound >= totalRound){//游戲勝利}else if (currentRound == totalRound-1){//最后一波怪 的 UI 、音樂}else{//普通波次roundList[currentRound].Handle(currentRound);}}//調(diào)用最后一回合的 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 {//需要存儲的信息//大關(guān)卡 IDpublic int bigLevelID;//小關(guān)卡 IDpublic int levelID;//所有格子狀態(tài)、避免使用二維數(shù)組public List<GridPoint.GridState> gridPoints;//怪物路徑點(diǎn)、使用索引存儲public List<GridPoint.GridIndex> monsterPath;//當(dāng)前關(guān)卡信息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: 地圖編輯器工具、游戲中作為地圖產(chǎn)生工具 //========================== using System.Collections; using System.Collections.Generic; using UnityEngine; using LitJson; using System.IO;public class MapMaker : MonoBehaviour {#if Tool//開關(guān)屬性、畫線開關(guān)public bool drawLine;//塔的添加點(diǎn)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]//當(dāng)前關(guān)數(shù)索引public int bigLevelID;[HideInInspector]public int LevelID;//地圖的全部格子對象public GridPoint[,] gridPoints;//行數(shù)public const int yRow = 8; //列數(shù)public const int xColumn = 12;[HideInInspector]//怪物路徑點(diǎn)具體位置public List<Vector3> monsterPathPos;//背景渲染private SpriteRenderer bgSR;//地圖的加載渲染private SpriteRenderer roadSR;[HideInInspector]//怪物路徑點(diǎn)、格子索引public List<GridPoint.GridIndex> monsterPath;//每一波次產(chǎn)生的怪物ID列表public List<Round.RoundInfo> roundInfoList;[HideInInspector]public Carrot carrot;private void Awake(){ #if Tool_instance = this;//InitMapMaker(); #endif}//初始化地圖public void InitMapMaker(){CalculateSize();//實(shí)例化數(shù)組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//設(shè)置屬性itemGo.transform.position = CorretPositon(x * gridWidth, y * gridHeight);itemGo.transform.SetParent(transform);//獲取格子點(diǎn)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++){//位置添加進(jìn)列表monsterPathPos.Add(gridPoints[monsterPath[i].xIndex,monsterPath[i].yIndex].transform.position); }//起始點(diǎn)與終止點(diǎn)GameObject startPointGo = GameControl.Instance.GetGameObjectResource("startPoint");//怪物點(diǎn)的第一個(gè)位置startPointGo.transform.position = monsterPathPos[0];startPointGo.transform.SetParent(transform);GameObject endPointGo = GameControl.Instance.GetGameObjectResource("Carrot");//怪物點(diǎn)的第一個(gè)位置endPointGo.transform.position = monsterPathPos[monsterPathPos.Count - 1];endPointGo.transform.SetParent(transform);carrot = endPointGo.GetComponent<Carrot>();} #endif//糾正預(yù)制件的起始位置public Vector3 CorretPositon(float x,float y){return new Vector3(x - mapWidth / 2 + gridWidth / 2, y- mapHeight / 2 + gridHeight / 2);}//計(jì)算地圖格子的寬高private void CalculateSize(){//左下角Vector3 leftDown = new Vector3(0, 0);//右上角Vector3 rightUp = new Vector3(1, 1);//視口坐標(biāo)轉(zhuǎn)世界坐標(biāo) 、 左下角的世界坐標(biāo)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){//計(jì)算格子的大小CalculateSize();//格子的顏色Gizmos.color = Color.green;//畫出行數(shù) 這里的值應(yīng)該是要等于行數(shù)的for (int y = 0; y <= yRow; y++){//起始位置Vector3 startPos = new Vector3(-mapWidth / 2, -mapHeight / 2 + y * gridHeight);//終點(diǎn)坐標(biāo)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//清除怪物路點(diǎn)public void ClearMonsterPath(){monsterPath.Clear();}//恢復(fù)地圖編輯默認(rèn)狀態(tài)public void RecoverTowerPoint(){//清除怪物路點(diǎn)ClearMonsterPath();for (int x = 0; x < xColumn; x++){for (int y = 0; y < yRow; y++){//初始化塔點(diǎn)gridPoints[x, y].InitGrid();}}}//初始化地圖public void InitMap(){//大小關(guān)卡 ID 置0 bigLevelID = 0;LevelID = 0;RecoverTowerPoint();//清除怪物路經(jīng)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++){//添加進(jìn)信息對象列表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]);}//產(chǎn)生怪物的 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、保存當(dāng)前關(guān)卡public void SaveLevelFileByJson(){LevelInfo levelInfoGo = CreateLevelInfoGo();//路徑string filePath = Application.dataPath + "/Resources/Json/Level/" + bigLevelID.ToString() + "_" + LevelID.ToString() + ".json";//對象轉(zhuǎn)換字符串string saveJsonStr = JsonMapper.ToJson(levelInfoGo); //文件流StreamWriter sw = new StreamWriter(filePath);//寫的內(nèi)容 sw.Write(saveJsonStr);//關(guān)閉文件流sw.Close();} #endif//讀取關(guān)卡文件、解析Josn 轉(zhuǎn)換為對象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();//關(guān)閉文件流sr.Close();//取得對象levelInfo = JsonMapper.ToObject<LevelInfo>(jsonStr);return levelInfo;}Debug.Log("文件加載失敗、失敗路徑"+filePath);return null;}//信息轉(zhuǎn)換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];//更新格子狀態(tài)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]);}//設(shè)置地圖的圖片切換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;//下一個(gè)對象protected Round mNextRound;//當(dāng)前關(guān)卡的編號protected int mRoundID;//Level 對象protected Level mlevel;public Round(int[] monsterIDList, int roundID, Level level){mlevel = level;roundInfo.mMonsterIDList = monsterIDList;mRoundID = roundID;}//下一個(gè)任務(wù)鏈public void SetNextRound(Round nextRound){mNextRound = nextRound;}//責(zé)任鏈的判定public void Handle(int roundID){//如果當(dāng)前回合并不是理想中 的 IDif (mRoundID < roundID){mNextRound.Handle(roundID);}else{//當(dāng)前任務(wù)鏈大于等于 ID 、產(chǎn)生怪物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: 存儲所有的關(guān)卡信息 //========================== using System.Collections; using System.Collections.Generic; using UnityEngine;public class Stage {//public int[] mTowerIDList;//具體長度public int mTowerIDListLength;//當(dāng)前關(guān)卡是否清除所有道具public bool mAllClear;//蘿卜狀態(tài)public int mCarrotState;//小關(guān)卡ID public int mLevelID;//大關(guān)卡IDpublic int mBigLevelID;//當(dāng)前關(guān)卡是否解鎖public bool unLocked;//當(dāng)前關(guān)卡是否為獎(jiǎng)勵(lì)、隱藏關(guān)卡public bool mIsRewardLevel;//當(dāng)前怪物波數(shù)public int mTotalRound;//使用構(gòu)造進(jìn)行賦值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;} }

總結(jié)

以上是生活随笔為你收集整理的Unity-地形编辑器-编辑器拓展功能类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。