123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- using System.IO;
- using System;
- using JamesCore;
- using System.Diagnostics;
- using James.Util;
- using UnityEngine.AddressableAssets;
- using Debug = UnityEngine.Debug;
- namespace JamesGame
- {
- [ExecuteInEditMode]
- public class BattleFieldSceneCreator : EditorWindow
- {
- private void OnFocus()
- {
- DataManager.Instance.InitData();
- GamePredata.Instance.InitData();
- }
- private void OnEnable()
- {
- Core.defaultRun();
- }
- private static GameObject editorTmpRoot;
- public const string EDITOR_TMP_NAME = "__EDITOR_TMp_root__";
- public static void AddDistanceSigns(int km)
- {
- // var gos = LevelBattleFieldLoader.LoadDistanceSigns(km);
- var distanceSigns = new GameObject("DistanceSigns");
- distanceSigns.transform.position = Vector3.zero;
- //var disSignTran = distanceSigns.transform;
- //disSignTran.SetParent(editorTmpRoot.transform);
- //
- // for (int i = 0; i < gos.Count; i++)
- LevelBattleFieldLoader.LoadDistanceSigns(km, (i, go) =>
- {
- var distance = (i + 1) * 20f + 10f;
- // var go = gos[i];
- var tran = go.transform;
- tran.SetParent(distanceSigns.transform);
- tran.localPosition = new Vector3(-5f, 0f, distance);
- tran.rotation = Quaternion.Euler(Vector3.zero);
- tran.localScale = Vector3.one;
- //
- var clone = Instantiate(go);
- clone.transform.SetParent(tran.parent);
- clone.transform.localPosition = new Vector3(5f, 0f, distance);
- });
- }
- public static void ClearScene()
- {
- var tmpRoot = GameObject.Find(EDITOR_TMP_NAME);
- if (tmpRoot != null)
- {
- DestroyImmediate(tmpRoot);
- editorTmpRoot = null;
- }
- }
- public static GameObject CreateEditorTmpRoot()
- {
- if (editorTmpRoot != null) return editorTmpRoot;
- var tmpRoot = GameObject.Find(EDITOR_TMP_NAME);
- if (tmpRoot != null)
- {
- editorTmpRoot = tmpRoot;
- return editorTmpRoot;
- }
- //
- tmpRoot = new GameObject(EDITOR_TMP_NAME);
- var tmpRootTran = tmpRoot.transform;
- tmpRootTran.position = Vector3.zero;
- tmpRootTran.rotation = Quaternion.Euler(Vector3.zero);
- tmpRootTran.localScale = Vector3.one;
- editorTmpRoot = tmpRoot;
- // Add peek camera
- var camGo = new GameObject("PeekCamera");
- var camTran = camGo.transform;
- camTran.SetParent(editorTmpRoot.transform);
- camTran.localPosition = new Vector3(0f, 5f, 0f);
- camTran.localRotation = Quaternion.Euler(Vector3.zero);
- camTran.localScale = Vector3.one;
- var cam = camGo.AddComponent<Camera>();
- cam.tag = "MainCamera";
- cam.fieldOfView = 50;
- // Clear original camera and light
- var oriCam = GameObject.Find("Main Camera");
- if (oriCam != null) DestroyImmediate(oriCam);
- var oriLight = GameObject.Find("Directional Light");
- if (oriLight != null) DestroyImmediate(oriLight);
- //
- // var adapter = Resources.Load("Prefabs/ARCHERY_ADAPTER");
- var adapter = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/LevelEditor/Prefabs/ARCHERY_ADAPTER.prefab");
- Instantiate(adapter, tmpRootTran);
- //
- // var global = Resources.Load("Prefabs/Global");
- var global = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/LevelEditor/Prefabs/Global.prefab");
- Instantiate(global, tmpRootTran);
- //加载UI主控制器
- // var uiMain = Resources.Load("Prefabs/UIMainController");
- var uiMain = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/LevelEditor/Prefabs/UIMainController.prefab");
- Instantiate(uiMain, tmpRootTran);
- //加载UI主控制器
- // var pool = Resources.Load("Prefabs/ObjectPool");
- var pool = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/LevelEditor/Prefabs/ObjectPool.prefab");
- Instantiate(pool, tmpRootTran);
- return editorTmpRoot;
- }
- [MenuItem("NeoGame/关卡编辑器", false)]
- public static void ShowDashboard()
- {
- EditorWindow.GetWindow<BattleFieldSceneCreator>();
- }
- [MenuItem("NeoGame/编译数据表")]
- public static void CompileGameConfigs()
- {
- string xlsPath = "../../Data";
- string batPath = Path.Combine(Application.dataPath, xlsPath);
- if (Application.platform == RuntimePlatform.OSXEditor)
- {
- ProcessCommand("/bin/bash", batPath, "export.sh", true);
- }
- else
- {
- ProcessCommand("export.bat", batPath, "", true);
- }
- GameDataConverter.WriteTableData("../Data/exports/TableData.bin", "Assets/StreamingAssets/ReadWritePath/Config/UserData.json");
- CreateZip(Application.dataPath, "StreamingAssets/ReadWritePath", "ReadWritePath.zip");
- AssetDatabase.Refresh();
- }
- [MenuItem("NeoGame/excel 转 Jsonpart 文件", false)]
- public static void Excel2Jsonfiles()
- {
- DataManager.Instance.InitData();
- GamePredata.Instance.InitData();
- ConfigEditor.Excel2Jsonparts();
- EditorUtility.DisplayDialog("Editor Message", "执行完毕", "OK", "");
- }
- [MenuItem("NeoGame/Jsonparts 转 excel 文件", false)]
- public static void Jsonparts2Excel()
- {
- ConfigEditor.Jsonparts2Excel();
- EditorUtility.DisplayDialog("Editor Message", "执行完毕", "OK", "");
- }
- /**
- * Draw GUI in editor mode
- */
- public const string TAB_TITLE = "Battle Editor";
- public BattleFieldSceneCreator()
- {
- this.titleContent = new GUIContent(TAB_TITLE);
- this.Reload();
- }
- static void CreateZip(string projectPath, string toZipPath, string zipName, string exclude = null)
- {
- string zipFolder = Path.Combine(projectPath, toZipPath);
- string zippTarget = Path.Combine(projectPath, "StreamingAssets/" + zipName);
- if (!Directory.Exists(zipFolder))
- return;
- if (File.Exists(zippTarget)) File.Delete(zippTarget);
- int CompressLevel = 9;
- ZipClass zc = new ZipClass();
- zc.ZipDirectory(zipFolder, zippTarget, CompressLevel, exclude);
- }
- //
- private static int brokenTargetGroupId = 0;
- private static int brokenChallengeDataId = 0;
- private static string targetResourceName = string.Empty;
- private static List<int> targetSearchGroupIds = new List<int>();
- //
- private static string toaddSceneName = string.Empty;
- //
- private static string tmplTargetGroupName = string.Empty;
- // Subeditor state
- private int subeditorState = 1;
- public const int BATTLE_FIELD_STATE_CODE = 1;
- public const int TARGET_DATA_STATE_CODE = 2;
- public const int AVATAR_DATA_STATE_CODE = 4;
- public const int WEAPON_DATA_STATE_CODE = 8;
- public const int ORIWEAPON_DATA_STATE_CODE = 16;
- public const int TARGET_TOOLKIT_STATE_CODE = 32;
- public const int TARGET_PATHFINDIND_STATE_CODE = 64;
- // Battle Field
- private int currBattleLevelId = 1;
- private void OnGUI()
- {
- GUILayout.BeginVertical();
- GUILayout.BeginHorizontal();
- //
- if (GUILayout.Button("重新载入"))
- {
- this.Reload();
- }
- GUILayout.EndHorizontal();
- //
- var battleFieldEditorExpanded = (subeditorState & BATTLE_FIELD_STATE_CODE) > 0;
- GUILayout.Space(10f);
- GUILayout.BeginHorizontal();
- if (GUILayout.Button(battleFieldEditorExpanded ? "-" : "+"))
- {
- subeditorState ^= BATTLE_FIELD_STATE_CODE;
- }
- GUILayout.Space(5f);
- GUILayout.Label("战场数据维护", EditorStyles.boldLabel);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- if (battleFieldEditorExpanded) this.DrawBattleFieldEditorGUI(ref currBattleLevelId);
- /**
- * 靶子数据维护
- */
- var targetDataEditorExpanded = (subeditorState & TARGET_DATA_STATE_CODE) > 0;
- GUILayout.Space(10f);
- GUILayout.BeginHorizontal();
- if (GUILayout.Button(targetDataEditorExpanded ? "-" : "+"))
- {
- subeditorState ^= TARGET_DATA_STATE_CODE;
- }
- GUILayout.Space(5f);
- GUILayout.Label("靶子数据维护", EditorStyles.boldLabel);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- if (targetDataEditorExpanded) this.DrawBattleTargetEditorGUI();
- /**
- * TO BE CONTINUE
- */
- GUILayout.FlexibleSpace();
- GUILayout.BeginHorizontal();
- GUILayout.FlexibleSpace();
- GUILayout.Label("TO BE CONTINUE", EditorStyles.boldLabel);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- //
- GUILayout.BeginHorizontal();
- if (GUILayout.Button("Add Distance Sign"))
- {
- AddDistanceSigns(130);
- }
- // Clear battle field scene
- if (GUILayout.Button("Clear Scene"))
- {
- ClearScene();
- }
- GUILayout.EndHorizontal();
- //
- GUILayout.EndVertical();
- }
- public void Reload()
- {
- this.ClearBattleFieldEditorDataCache();
- this.ClearBattleTargetEditorDataCache();
- ConfigEditor.ClearCacheData();
- }
- public void ChangeCurrBattleLevelId(int id)
- {
- this.currBattleLevelId = id;
- }
- private int testVar = 1;
- private static void ProcessCommand(string command, string workDir, string argument, bool isShell)
- {
- ProcessStartInfo start = new ProcessStartInfo(command);
- start.FileName = command;
- start.WorkingDirectory = workDir;
- start.Arguments = argument;
- start.CreateNoWindow = false;
- start.ErrorDialog = true;
- start.UseShellExecute = isShell;
- if (start.UseShellExecute)
- {
- start.RedirectStandardOutput = false;
- start.RedirectStandardError = false;
- start.RedirectStandardInput = false;
- }
- else
- {
- start.RedirectStandardOutput = true;
- start.RedirectStandardError = true;
- start.RedirectStandardInput = true;
- start.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
- start.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
- }
- Process p = Process.Start(start);
- if (p != null)
- {
- p.WaitForExit(100000);
- }
- if (!start.UseShellExecute)
- {
- PrintOutPut(p.StandardOutput);
- PrintOutPut(p.StandardError);
- }
- }
- private static void PrintOutPut(StreamReader reader)
- {
- string msg = reader.ReadToEnd();
- reader.Close();
- UnityEngine.Debug.Log(msg);
- }
- }
- }
|