using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif using System.Collections.Generic; using System.Text; public class RuntimeLogUtility : MonoBehaviour { private static string LS_Key_ForceAutoFight = "LS_Key_ForceAutoFight"; public static bool s_BattleLog = false; public static bool s_MoveLog = false; public static bool s_ForceOneEnemy = false; public static bool s_PerpetualAttack = true; public static bool s_UseKeyBoardCastSkill = false; public static bool s_LogMoveDistance = false; public static bool s_SkillEffectLog = false; public static bool s_ShowMapLine = false; public static bool s_forceAutoFight { get { #if UNITY_EDITOR return EditorPrefs.GetBool("LS_Key_ForceAutoFight", true); #else return true; #endif } set { #if UNITY_EDITOR EditorPrefs.SetBool("LS_Key_ForceAutoFight", value); #endif } } public static string s_LogPath; static readonly Dictionary s_LogDict = new Dictionary(); static readonly List s_LogList = new List(); public static bool s_HurtValueLog = false; public static void ClearLogs() { s_LogDict.Clear(); s_LogList.Clear(); } public static void AddLog_Blue(string info, uint objId = 0) { string _content; if (s_BattleLog) { _content = string.Format("{0}", info); string _strTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); Debug.Log(string.Format("[{0}] {1}", _strTime, _content)); } _content = string.Format("{0}", info); AddLog(_content, objId); } public static void AddLog_Green(string info, uint objId = 0) { string _content; if (s_BattleLog) { _content = string.Format("{0}", info); string _strTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); Debug.Log(string.Format("[{0}] {1}", _strTime, _content)); } _content = string.Format("{0}", info); AddLog(_content, objId); } public static void AddLog_Red(string info, uint objId = 0) { string _content; if (s_BattleLog) { _content = string.Format("{0}", info); string _strTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); Debug.Log(string.Format("[{0}] {1}", _strTime, _content)); } _content = string.Format("{0}", info); AddLog(_content, objId); } public static void AddLog_Black(string info, uint objId = 0) { if (s_BattleLog) { string _strTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); Debug.Log(string.Format("[{0}] {1}", _strTime, info)); } string _content = string.Format("{0}", info); AddLog(_content, objId); } public static void AddLog(string info, uint objId = 0) { string _strTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); string _content = string.Format("[{0}] {1}
", _strTime, info); s_LogList.Add(_content); if (objId == 0) { foreach (var _objId in s_LogDict.Keys) { s_LogDict[_objId].Append(_content); } } else { if (s_LogDict.ContainsKey(objId) == false) { s_LogDict.Add(objId, new StringBuilder()); } s_LogDict[objId].Append(_content); } //if (s_LogList.Count >= 10000) //{ // SaveNpcLog(); //} } public static void SaveNpcLog() { s_LogPath = Application.dataPath.Substring(0, 3) + "unit3D_Logs/"; if (System.IO.Directory.Exists(s_LogPath) == false) { System.IO.Directory.CreateDirectory(s_LogPath); } string _strTime = System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"); string _path = string.Empty; foreach (var _objId in s_LogDict.Keys) { _path = s_LogPath + _objId; if (System.IO.Directory.Exists(_path) == false) { System.IO.Directory.CreateDirectory(_path); } _path = string.Format(s_LogPath + "{0}/{1}.html", _objId, _strTime); using (System.IO.StreamWriter _writer = new System.IO.StreamWriter(_path)) { _writer.Write(s_LogDict[_objId].ToString()); } } s_LogDict.Clear(); _path = string.Format(s_LogPath + "Log_{0}.html", _strTime); StringBuilder _stringBuilder = new StringBuilder(); for (int i = 0; i < s_LogList.Count; ++i) { _stringBuilder.Append(s_LogList[i]); } using (System.IO.StreamWriter _writer = new System.IO.StreamWriter(_path)) { _writer.Write(_stringBuilder.ToString()); } s_LogList.Clear(); } } #if UNITY_EDITOR [CustomEditor(typeof(RuntimeLogUtility))] public class RuntimeLogUtilityEditor : Editor { private Vector3 _navChkPos; private int _npcID; public override void OnInspectorGUI() { GUILayout.Space(5); EditorGUILayout.LabelField("Log存储路径", RuntimeLogUtility.s_LogPath); if (GUILayout.Button("保存Log")) { RuntimeLogUtility.SaveNpcLog(); } if (GUILayout.Button("清空Log")) { RuntimeLogUtility.ClearLogs(); } RuntimeLogUtility.s_BattleLog = EditorGUILayout.Toggle("战斗过程的Log输出", RuntimeLogUtility.s_BattleLog); RuntimeLogUtility.s_MoveLog = EditorGUILayout.Toggle("移动过程的Log输出", RuntimeLogUtility.s_MoveLog); RuntimeLogUtility.s_ForceOneEnemy = EditorGUILayout.Toggle("强制只攻击一个目标对象", RuntimeLogUtility.s_ForceOneEnemy); RuntimeLogUtility.s_PerpetualAttack = EditorGUILayout.Toggle("执行攻击至死逻辑", RuntimeLogUtility.s_PerpetualAttack); RuntimeLogUtility.s_UseKeyBoardCastSkill = EditorGUILayout.Toggle("使用键盘释放技能", RuntimeLogUtility.s_UseKeyBoardCastSkill); RuntimeLogUtility.s_forceAutoFight = EditorGUILayout.Toggle("是否强制开启AI", RuntimeLogUtility.s_forceAutoFight); RuntimeLogUtility.s_SkillEffectLog = EditorGUILayout.Toggle("技能效果log输出", RuntimeLogUtility.s_SkillEffectLog); RuntimeLogUtility.s_LogMoveDistance = EditorGUILayout.Toggle("位移距离Log输出", RuntimeLogUtility.s_LogMoveDistance); RuntimeLogUtility.s_ShowMapLine = EditorGUILayout.Toggle("显示地图网格", RuntimeLogUtility.s_ShowMapLine); _navChkPos = EditorGUILayout.Vector3Field("检测点", _navChkPos); if (GUILayout.Button("检测")) { Vector3 _position = Vector3.zero; if (GActor.TryGetValidPos(_navChkPos, ref _position)) { Debug.Log("正常点........"); } else { Debug.Log("障碍点........"); } } _npcID = EditorGUILayout.IntField("npcID", _npcID); if (GUILayout.Button("酷酷酷")) { PlayerDatas.Instance.hero.Polymorph(!PlayerDatas.Instance.hero.IsPolyMorph, 0); } if (GUILayout.Button("直接重连")) { GameNetSystem.Instance.Reconnect(); } if (GUILayout.Button("GC.Collect()")) { System.GC.Collect(); } if (GUILayout.Button("Resources.UnloadUnusedAssets")) { Resources.UnloadUnusedAssets(); } if (GUILayout.Button("上马/下马")) { if (PlayerDatas.Instance.hero != null) { DTC0428_tagPlayerRideHorse.Send_tagPlayerRideHorse(PlayerDatas.Instance.hero.MovingState != E_MovingState.Ride); } } if (GUILayout.Button("采集")) { GA_Hero _hero = PlayerDatas.Instance.hero; if (_hero != null) { if (_hero.IsCollecting()) { _hero.Idle(); } else if (_hero.IsIdle()) { _hero.Collect(); } } } GUILayout.Space(10); EditorGUILayout.LabelField("# 玩家当前信息 #"); if (PlayerDatas.Instance.hero != null) { GA_Hero _hero = PlayerDatas.Instance.hero; if (_hero.SkillMgr.CurCastSkill != null) { int _curSkillID = _hero.SkillMgr.CurCastSkill.id; bool _isCompelete = _hero.SkillMgr.CurCastSkill.SkillCompelete; bool _isXuli = _hero.SkillMgr.CurCastSkill.SkillPreparing; string _content = string.Format("ID: {0}, 蓄力:{2}, 完成: {1}", _curSkillID, _isCompelete, _isXuli); EditorGUILayout.LabelField("技能信息", _content); } EditorGUILayout.TextField("队伍ID", _hero.ActorInfo.teamID.ToString()); EditorGUILayout.TextField("是否处于地图切换", GA_Hero.s_MapSwitching.ToString()); EditorGUILayout.TextField("当前身体状态", _hero.MovingState.ToString()); EditorGUILayout.TextField("当前行为状态", _hero.State.ToString()); EditorGUILayout.TextField("当前AI状态", _hero.aiHandler.currentType.ToString()); EditorGUILayout.TextField("是否死亡", _hero.ActorInfo.serverDie.ToString()); if (_hero.SelectTarget != null) { EditorGUILayout.TextField("当前选择目标", _hero.SelectTarget.ServerInstID.ToString()); } if (_hero.LockTarget != null) { EditorGUILayout.TextField("当前锁定目标", _hero.LockTarget.ServerInstID.ToString()); } for (MapArea.E_Type i = MapArea.E_Type.RebornSafe; i <= MapArea.E_Type.Boss; i = (MapArea.E_Type)((int)i << 1)) { bool _isIn = MapArea.IsInMapArea(_hero.CurMapArea, i); EditorGUILayout.Toggle(i.ToString(), _isIn); } } } } #endif