89 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			89 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.IO; | |||
|  | using System.Text.RegularExpressions; | |||
|  | using UnityEngine; | |||
|  | using UnityEditor; | |||
|  | using UnityEditor.SceneManagement; | |||
|  | 
 | |||
|  | public class PathConfig | |||
|  | { | |||
|  |     public static readonly string ExcelPath = Application.dataPath + "/Excels/"; | |||
|  |     public static readonly string ExcelName = "LevelConfig.xlsx"; | |||
|  |     public static readonly string DataConfigPath = "Assets/Resources/Config/"; | |||
|  |     public static readonly string DataConfigName = "LevelConfig"; | |||
|  | } | |||
|  | 
 | |||
|  | public class DesignerTool : Editor | |||
|  | { | |||
|  |     //转ScriptableObject | |||
|  |     [MenuItem("策划工具/关卡导表")] | |||
|  |     public static void CreateItemAsset() { | |||
|  |         LevelConfig tLevelCfg = CreateInstance<LevelConfig>(); | |||
|  |         tLevelCfg.DataList = ExcelParser.CreateItemArrayWithExcel(PathConfig.ExcelPath + PathConfig.ExcelName); | |||
|  | 
 | |||
|  |         if(!Directory.Exists(PathConfig.DataConfigPath)) | |||
|  |         { | |||
|  |             Directory.CreateDirectory(PathConfig.DataConfigPath); | |||
|  |         } | |||
|  |   | |||
|  |         string tSavePath = string.Format("{0}{1}.asset", PathConfig.DataConfigPath, PathConfig.DataConfigName); | |||
|  |         AssetDatabase.CreateAsset(tLevelCfg, tSavePath); | |||
|  |         AssetDatabase.SaveAssets(); | |||
|  |          | |||
|  |         AssetDatabase.Refresh(); | |||
|  |     } | |||
|  | 
 | |||
|  |     [MenuItem("策划工具/运行游戏(手摆阵容)")] | |||
|  |     public static void PlayGame1() | |||
|  |     { | |||
|  |         GameConfig.Instance.IsAutoLevel = false; | |||
|  |         RealPlay(); | |||
|  |     } | |||
|  | 
 | |||
|  |     [MenuItem("策划工具/运行游戏(召唤次数)")] | |||
|  |     public static void PlayGame2() | |||
|  |     { | |||
|  |         GameConfig.Instance.IsAutoLevel = true; | |||
|  |         RealPlay(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private static void RealPlay() | |||
|  |     { | |||
|  |         GameConfig.Instance.IsDebug = true; | |||
|  |         AssetDatabase.SaveAssets(); | |||
|  |         AssetDatabase.Refresh(); | |||
|  | 
 | |||
|  |         if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) | |||
|  |         { | |||
|  |             EditorSceneManager.OpenScene("Assets/Scenes/Init.unity"); | |||
|  |         } | |||
|  | 
 | |||
|  |         if (!EditorApplication.isPlaying) | |||
|  |         { | |||
|  |             EditorApplication.isPlaying = true; | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     //转Json | |||
|  |     //[MenuItem("策划工具/关卡导Json")] | |||
|  |     //public static void CreateExcelJson() | |||
|  |     //{ | |||
|  |     //    LevelConfig tLevelCfg = CreateInstance<LevelConfig>(); | |||
|  |     //    tLevelCfg.DataList = ExcelParser.CreateItemArrayWithExcel(PathConfig.ExcelPath + PathConfig.ExcelName); | |||
|  | 
 | |||
|  |     //    string tFilePath = PathConfig.DataConfigPath + PathConfig.DataConfigName + ".json"; | |||
|  | 
 | |||
|  |     //    FileInfo tFile = new FileInfo(tFilePath); | |||
|  |     //    StreamWriter tSW = tFile.CreateText(); | |||
|  |     //    string tJson = JsonUtility.ToJson(tLevelCfg); | |||
|  | 
 | |||
|  |     //    Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})"); | |||
|  |     //    tJson = reg.Replace(tJson, delegate (Match m) { return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); }); | |||
|  |     //    tSW.WriteLine(tJson); | |||
|  | 
 | |||
|  |     //    tSW.Close(); | |||
|  |     //    tSW.Dispose(); | |||
|  | 
 | |||
|  |     //    AssetDatabase.Refresh(); | |||
|  |     //} | |||
|  | } |