123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEditor;
- using System;
- using James.Util;
- using System.Text;
- namespace JamesGame
- {
- public static class BattleTargetEditor
- {
- public static void DrawBattleTargetEditorGUI(this BattleFieldSceneCreator battleEditor)
- {
- //
- if (targetDataChanged)
- {
- _targetResNames = null;
- _targetCtrlAnimNames = null;
- }
- if (currTargetDataId == -1)
- {
- if (targetDataIds.Length > 1)
- {
- currTargetDataId = targetDataIds[1];
- }
- else
- {
- currTargetDataId = targetDataIds[0];
- }
- }
- //
- GUILayout.BeginHorizontal();
- GUILayout.Label("ID:");
- var tmpTargetDataId = EditorGUILayout.IntPopup(currTargetDataId, targetDataStrIds, targetDataIds);
- if (!ConfigEditor.targetDataCfgs.ContainsKey(tmpTargetDataId))
- {
- tmpTargetDataId = targetDataIds[1];
- }
- if (tmpTargetDataId != currTargetDataId)
- {
- targetDataChanged = true;
- }
- currTargetDataId = tmpTargetDataId;
- var targetData = ConfigEditor.targetDataCfgs[currTargetDataId];
- if (targetDataChanged)
- {
- //
- if (targetData.ResourceName.IndexOf("#") > 0)
- {
- string[] targetExInfo = targetData.ResourceName.Split('#');
- if (targetExInfo.Length == 3)
- {
- targetIsObstacle = true;
- targetResNameIdx = IndexOfArray<string>(targetResNames, targetExInfo[0]);
- targetStateMachineIdx = IndexOfArray<string>(targetStateMachineNames, targetExInfo[1]);
- obstacleAnimType = (TargetExplodeFX.ObstacleAnimType)int.Parse(targetExInfo[2]);
- }
- else
- {
- DebugEx.Log("关卡编辑器中的障碍物的prefab名字解析出现问题");
- }
- }
- else
- {
- targetResNameIdx = IndexOfArray<string>(targetResNames, targetData.ResourceName);
- targetIsObstacle = false;
- targetStateMachineIdx = 0;
- obstacleAnimType = TargetExplodeFX.ObstacleAnimType.Once;
- }
- currTargetLift = targetData.Life;
- currTargetAttribute = (TargetAttribs)targetData.Attrib;
- //
- if (targetData.TargetPos.Count == 3)
- {
- currTargetPos = new Vector3(targetData.TargetPos[0], targetData.TargetPos[1], targetData.TargetPos[2]);
- }
- else
- {
- currTargetPos = Vector3.zero;
- }
- if (targetData.TargetRot.Count == 3)
- {
- currTargetRot = new Vector3(targetData.TargetRot[0], targetData.TargetRot[1], targetData.TargetRot[2]);
- }
- else
- {
- currTargetRot = Vector3.zero;
- }
- currTargetScale = targetData.Scale;
- //
- currTargetCtrlAnimIdx = IndexOfArray<string>(targetCtrlAnimNames, targetData.CtrlAniFileName);
- currTargetCtrlAnimDelay = targetData.CtrlAniStartDelay;
- currTargetCtrlAnimSpeed = targetData.CtrlAniSpeed;
- //
- currTargetHitAnimIdx = IndexOfArray<string>(targetCtrlAnimNames, targetData.Hit);
- currTargetDeathAnimIdx = IndexOfArray<string>(targetCtrlAnimNames, targetData.Death);
- //
- childTargetDataIds = string.IsNullOrEmpty(targetData.Child) ? "none" : targetData.Child;
- childContainerNodes = targetData.cNode;
- //
- targetDieAttribute = (TargetDieAttribs)targetData.DieRule;
- targetRebornId = targetData.ReID == 0 ? -1 : targetData.ReID;
- }
- GUILayout.FlexibleSpace();
- GUILayout.Label("筛选:");
- var tmpTargetDataIdFilter = EditorGUILayout.TextField(_targetDataIdFilter);
- if (_targetDataIdFilter != tmpTargetDataIdFilter)
- {
- _targetDataIds = null;
- }
- _targetDataIdFilter = tmpTargetDataIdFilter;
- GUILayout.EndHorizontal();
- GUIStyle style1 = new GUIStyle(GUI.skin.button);
- style1.normal.textColor = Color.black;
- GUIStyle style2 = new GUIStyle(GUI.skin.button);
- style2.normal.textColor = Color.white;
- GUILayout.BeginHorizontal();
- GUILayout.Label("ID分页:");
- if (GUILayout.Button("0-999条", pageNo == 0 ? style2 : style1))
- {
- pageNo = 0;
- }
- if (GUILayout.Button("1000-1999条", pageNo == 1 ? style2 : style1))
- {
- pageNo = 1;
- }
- if (GUILayout.Button("2000-2999条", pageNo == 2 ? style2 : style1))
- {
- pageNo = 2;
- }
- if (GUILayout.Button("3000-3999条", pageNo == 3 ? style2 : style1))
- {
- pageNo = 3;
- }
- _targetDataIds = null;
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("模型:");
- targetResNameIdx = EditorGUILayout.Popup(targetResNameIdx, targetResNames);
- if (GUILayout.Button("刷新"))
- {
- _targetResNames = null;
- }
- GUILayout.FlexibleSpace();
- GUILayout.Label("类型:");
- currTargetAttribute = (TargetAttribs)EditorGUILayout.EnumPopup(currTargetAttribute);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- EditorGUILayout.Space();
- GUILayout.BeginHorizontal();
- GUILayout.Label("血量HP:");
- currTargetLift = EditorGUILayout.IntField(currTargetLift);
- GUILayout.FlexibleSpace();
- targetIsObstacle = EditorGUILayout.Toggle("女战士系列:", targetIsObstacle);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- if (targetIsObstacle)
- {
- GUILayout.BeginHorizontal();
- GUILayout.Label("状态机:");
- targetStateMachineIdx = EditorGUILayout.Popup(targetStateMachineIdx, targetStateMachineNames);
- if (GUILayout.Button("刷新"))
- {
- _targetStateMachineNames = null;
- }
- GUILayout.FlexibleSpace();
- GUILayout.Label("循环类型:");
- obstacleAnimType = (TargetExplodeFX.ObstacleAnimType)EditorGUILayout.EnumPopup(obstacleAnimType);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- EditorGUILayout.Space();
- }
- GUILayout.BeginHorizontal();
- GUILayout.Label("位置:");
- currTargetPos = EditorGUILayout.Vector3Field(string.Empty, currTargetPos);
- GUILayout.FlexibleSpace();
- GUILayout.Label("缩放:");
- currTargetScale = EditorGUILayout.FloatField(currTargetScale);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("活动动画:");
- currTargetCtrlAnimIdx = EditorGUILayout.Popup(currTargetCtrlAnimIdx, targetCtrlAnimNames);
- GUILayout.FlexibleSpace();
- GUILayout.Label("延迟播放:");
- currTargetCtrlAnimDelay = EditorGUILayout.FloatField(currTargetCtrlAnimDelay);
- GUILayout.FlexibleSpace();
- GUILayout.Label("播放速度:");
- currTargetCtrlAnimSpeed = EditorGUILayout.FloatField(currTargetCtrlAnimSpeed);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("击中动画:");
- currTargetHitAnimIdx = EditorGUILayout.Popup(currTargetHitAnimIdx, targetCtrlAnimNames);
- GUILayout.FlexibleSpace();
- GUILayout.Label("死亡动画:");
- currTargetDeathAnimIdx = EditorGUILayout.Popup(currTargetDeathAnimIdx, targetCtrlAnimNames);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("子靶子:");
- childTargetDataIds = EditorGUILayout.TextField(childTargetDataIds);
- GUILayout.FlexibleSpace();
- GUILayout.Label("挂点:");
- childContainerNodes = EditorGUILayout.TextField(childContainerNodes);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("重生方式:");
- targetDieAttribute = (TargetDieAttribs)EditorGUILayout.EnumPopup(targetDieAttribute);
- GUILayout.FlexibleSpace();
- GUILayout.Label("重生ID:");
- targetRebornId = EditorGUILayout.IntPopup(targetRebornId, targetDataStrIds, targetDataIds);
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- targetDataChanged = false;
- GUILayout.BeginHorizontal();
- if (GUILayout.Button("保存"))
- {
- //
- if (targetIsObstacle)
- {
- targetData.ResourceName = string.Format("{0}#{1}#{2}", targetResNames[targetResNameIdx], targetStateMachineNames[targetStateMachineIdx], (int)obstacleAnimType);
- DebugEx.Log("targetData.ResourceName =" + targetData.ResourceName);
- }
- else
- {
- targetData.ResourceName = targetResNames[targetResNameIdx];
- }
- targetData.Attrib = (int)currTargetAttribute;
- targetData.TargetPos = new List<float> { currTargetPos.x, currTargetPos.y, currTargetPos.z };
- targetData.TargetRot = new List<float> { currTargetRot.x, currTargetRot.y, currTargetRot.z };
- targetData.Scale = currTargetScale;
- if (currTargetCtrlAnimIdx < 0)
- {
- targetData.CtrlAniFileName = string.Empty;
- }
- else
- {
- targetData.CtrlAniFileName = targetCtrlAnimNames[currTargetCtrlAnimIdx];
- }
- targetData.CtrlAniStartDelay = currTargetCtrlAnimDelay;
- targetData.CtrlAniSpeed = currTargetCtrlAnimSpeed;
- if (currTargetHitAnimIdx < 0)
- {
- targetData.Hit = string.Empty;
- }
- else
- {
- targetData.Hit = targetCtrlAnimNames[currTargetHitAnimIdx];
- }
- if (currTargetDeathAnimIdx < 0)
- {
- targetData.Death = string.Empty;
- }
- else
- {
- targetData.Death = targetCtrlAnimNames[currTargetDeathAnimIdx];
- }
- targetData.Child = childTargetDataIds.Trim();
- targetData.cNode = childContainerNodes;
- targetData.DieRule = (int)targetDieAttribute;
- targetData.ReID = targetRebornId == -1 ? 0 : targetRebornId;
- targetData.Life = currTargetLift;
- ConfigEditor.SaveTargetData2ExcelAndJson();
-
- battleEditor.Reload();
- BattleFieldSceneCreator.CompileGameConfigs();
- DataManager.Instance.InitData();
- }
- GUILayout.EndHorizontal();
- GUILayout.Space(10f);
- GUILayout.BeginHorizontal();
- GUILayout.Label("ID");
- newTargetDataId = EditorGUILayout.IntField(newTargetDataId);
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("新增"))
- {
- if (newTargetDataId <= 0)
- {
- foreach (var targetDataId in ConfigEditor.targetDataCfgs.Keys)
- {
- if (targetDataId > newTargetDataId) newTargetDataId = targetDataId;
- }
- newTargetDataId++;
- }
- if (newTargetDataId < 0 || ConfigEditor.targetDataCfgs.ContainsKey(newTargetDataId))
- {
- Debug.LogError("Error, new target data id: " + newTargetDataId.ToString());
- }
- else
- {
- var newTargetData = new TargetDataDefine
- {
- ID = newTargetDataId,
- ResourceName = targetResNames[0],
- Life = currTargetLift,
- CtrlAniFileName = "none",
- Attrib = 0,
- CtrlAniStartDelay = 0f,
- Child = "none",
- cNode = "none",
- Material = 0,
- Hit = "none",
- Death = "none",
- CtrlAniSpeed = 1f,
- Scale = 1f,
- DieRule = (int)TargetDieAttribs.Do_Nothing,
- ReID = 0,
- TargetPos = new List<float> { 0f, 0f, 0f },
- TargetRot = new List<float> { 0f, 0f, 0f },
- };
- ConfigEditor.targetDataCfgs.Add(newTargetData.ID, newTargetData);
- targetDataChanged = true;
- currTargetDataId = newTargetData.ID;
- }
- }
- GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- if (GUILayout.Button("删除"))
- {
- if (ConfigEditor.targetDataCfgs.ContainsKey(currTargetDataId))
- {
- ConfigEditor.targetDataCfgs.Remove(currTargetDataId);
- Debug.Log("Remove target data successfully. ID:" + currTargetDataId);
-
- targetDataChanged = true;
- _targetDataIds = null;
- if (targetDataIds.Length > 1)
- {
- currTargetDataId = targetDataIds[1];
- }
- else
- {
- currTargetDataId = targetDataIds[0];
- }
- }
- }
- GUILayout.EndHorizontal();
- }
- public static void ClearBattleTargetEditorDataCache(this BattleFieldSceneCreator battleEditor)
- {
- _targetDataIds = null;
- _targetResNames = null;
- _targetCtrlAnimNames = null;
- _targetStateMachineNames = null;
- }
- public static char PATH_DELIMITER
- {
- get
- {
- return Application.platform == RuntimePlatform.WindowsEditor ? '\\' : '/';
- }
- }
- public static int IndexOfArray<T>(T[] arr, T target) where T : IComparable
- {
- for (var i = 0; i < arr.Length; i++)
- {
- if (arr[i].Equals(target)) return i;
- }
- return -1;
- }
- /**
- * Data
- */
- private static bool targetDataChanged = true;
- private static int currTargetDataId = -1;
- private static TargetAttribs currTargetAttribute = TargetAttribs.ExistAlways;
- private static TargetExplodeFX.ObstacleAnimType obstacleAnimType = TargetExplodeFX.ObstacleAnimType.Once;
- private static Vector3 currTargetPos;
- private static Vector3 currTargetRot;
- private static float currTargetScale = 1f;
- private static int currTargetCtrlAnimIdx = 0;
- private static float currTargetCtrlAnimDelay = 0f;
- private static float currTargetCtrlAnimSpeed = 1f;
- private static int currTargetLift = 1;
- private static bool targetIsObstacle = false;
- private static int currTargetHitAnimIdx = 0;
- private static int currTargetDeathAnimIdx = 0;
- private static int newTargetDataId = -1;
- //
- private static string childTargetDataIds = "none";
- private static string childContainerNodes;
- //
- //皇冠相关的子靶子
- private static string crownTargetDataIds = "none";
- //皇冠靶子挂点
- private static string crownTargetNodes;
- private static float crownTargetScale;
- private static string crownTargetParentName;
- //
- private static TargetDieAttribs targetDieAttribute = TargetDieAttribs.Do_Nothing;
- private static int targetRebornId = -1;
- // Target Data Ids
- private static int pageNo = 0;
- private static string _targetDataIdFilter = string.Empty;
- private static string[] targetDataStrIds;
- private static int[] _targetDataIds;
- private static int[] targetDataIds
- {
- get
- {
- if (_targetDataIds == null)
- {
- int i = 0;
- var ints = new Stack<int>();
- var strs = new Stack<string>();
- foreach (var kv in ConfigEditor.targetDataCfgs)
- {
- if (kv.Key < 10000) continue;
- var strInt = kv.Key.ToString();
- if (!strInt.StartsWith(_targetDataIdFilter, StringComparison.Ordinal))
- {
- continue;
- }
- if (i / 1000 == pageNo)
- {
- ints.Push(kv.Key);
- strs.Push(strInt);
- }
- i++;
- }
- ints.Push(-1);
- strs.Push("none");
- targetDataStrIds = strs.ToArray();
- _targetDataIds = ints.ToArray();
- ints.Clear();
- strs.Clear();
- ints = null;
- strs = null;
- }
- return _targetDataIds;
- }
- }
- public static int[] GetTargetDataIds(this BattleFieldSceneCreator battleEditor)
- {
- return targetDataIds;
- }
- public static string[] GetTargetDataStrIds(this BattleFieldSceneCreator battleEditor)
- {
- return targetDataStrIds;
- }
- // Target Resource Name
- private static int targetResNameIdx = 0;
- private static string[] _targetResNames;
- private static string[] targetResNames
- {
- get
- {
- if (_targetResNames == null)
- {
- var paths = Directory.GetFiles(Path.Combine(Application.dataPath, "Resources/Prefabs/Targets"), "*.prefab");
- var list = new List<string>();
- foreach (var path in paths)
- {
- list.Add(path.Substring(path.LastIndexOf(PATH_DELIMITER) + 1).Replace(".prefab", ""));
- }
- _targetResNames = list.ToArray();
- list.Clear();
- list = null;
- }
- return _targetResNames;
- }
- }
- // Target Ctrl Anim
- private static string[] _targetCtrlAnimNames;
- private static string[] targetCtrlAnimNames
- {
- get
- {
- if (_targetCtrlAnimNames == null)
- {
- var paths = Directory.GetFiles(Path.Combine(Application.dataPath, "Resources/Prefabs/AnimationClips"), "*.anim");
- var list = new List<string> { "none" };
- foreach (var path in paths)
- {
- list.Add(path.Substring(path.LastIndexOf(PATH_DELIMITER) + 1).Replace(".anim", ""));
- }
- _targetCtrlAnimNames = list.ToArray();
- list.Clear();
- list = null;
- }
- return _targetCtrlAnimNames;
- }
- }
- // Target stateMachine overrideController
- private static int targetStateMachineIdx = 0;
- private static string[] _targetStateMachineNames;
- private static string[] targetStateMachineNames
- {
- get
- {
- if (_targetStateMachineNames == null)
- {
- var paths = Directory.GetFiles(Path.Combine(Application.dataPath, "ShootGame/Resources/Animators"), "*.overrideController");
- var list = new List<string> { "none" };
- foreach (var path in paths)
- {
- list.Add(path.Substring(path.LastIndexOf(PATH_DELIMITER) + 1).Replace(".overrideController", ""));
- }
- _targetStateMachineNames = list.ToArray();
- list.Clear();
- list = null;
- }
- return _targetStateMachineNames;
- }
- }
- }
- }
|