This commit is contained in:
VDH
2025-12-23 14:19:04 +07:00
parent dd476f0512
commit 76e66cafdb
14 changed files with 252 additions and 858 deletions
+24
View File
@@ -0,0 +1,24 @@
using UnityEditor;
using UnityEngine;
namespace BrewMonster
{
public static class ComponentDebugMenu
{
[MenuItem("CONTEXT/MonoBehaviour/Enable Debug")]
static void EnableDebug(MenuCommand command)
{
var comp = command.context as MonoBehaviour;
DebugRegistry.Enable(comp);
Debug.Log($"Debug enabled: {comp.name} ({comp.GetType().Name})");
}
[MenuItem("CONTEXT/MonoBehaviour/Disable Debug")]
static void DisableDebug(MenuCommand command)
{
var comp = command.context as MonoBehaviour;
DebugRegistry.Disable(comp);
Debug.Log($"Debug disabled: {comp.name} ({comp.GetType().Name})");
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b6b200e61208f0f4bb396ec3aa442feb
+56
View File
@@ -0,0 +1,56 @@
using UnityEditor;
using UnityEngine;
namespace BrewMonster
{
public static class DebugRegistryEditor
{
[MenuItem("Tools/Debug Registry/Clear All")]
private static void ClearAll()
{
DebugRegistry.Clear();
Debug.Log("DebugRegistry Cleared");
}
[MenuItem("GameObject/Enable Logging For This Component", true)]
private static bool ValidateEnableLogging()
{
return Selection.activeGameObject != null;
}
[MenuItem("GameObject/Enable Logging For This Component")]
private static void EnableLogging()
{
var go = Selection.activeGameObject;
if (go == null) return;
var comps = go.GetComponents<MonoBehaviour>();
Selection.objects = comps; // để hiển thị popup
EditorApplication.delayCall += () =>
{
foreach (var comp in comps)
DebugRegistry.Enable(comp);
Debug.Log($"Enabled logging for all components of {go.name}");
};
}
[MenuItem("GameObject/Disable Logging For This Component", true)]
private static bool ValidateDisableLogging()
{
return Selection.activeGameObject != null;
}
[MenuItem("GameObject/Disable Logging For This Component")]
private static void DisableLogging()
{
var go = Selection.activeGameObject;
foreach (var comp in go.GetComponents<MonoBehaviour>())
DebugRegistry.Disable(comp);
Debug.Log($"Disabled logging for all components of {go.name}");
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e6647e1ce7626a94194f2100e8500343
+23
View File
@@ -0,0 +1,23 @@
using UnityEditor;
using UnityEngine;
namespace BrewMonster
{
[CustomEditor(typeof(MonoBehaviour), true)]
public class DebuggableInspector : Editor
{
public override void OnInspectorGUI()
{
var targetMb = target as MonoBehaviour;
if (targetMb != null && DebugRegistry.IsEnabled(targetMb))
{
GUI.backgroundColor = Color.yellow;
EditorGUILayout.HelpBox("DEBUG ENABLED", MessageType.Info);
GUI.backgroundColor = Color.white;
}
DrawDefaultInspector();
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b1fca6a9b0c2bb3408095b0d47723f55
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using UnityEditor;
namespace BrewMonster
{
public static class DebugRegistry
{
private static readonly HashSet<object> targets = new HashSet<object>();
static DebugRegistry()
{
EditorApplication.playModeStateChanged += OnPlayModeChanged;
}
private static void OnPlayModeChanged(PlayModeStateChange state)
{
if (state == PlayModeStateChange.ExitingEditMode ||
state == PlayModeStateChange.EnteredPlayMode ||
state == PlayModeStateChange.EnteredEditMode)
{
Clear();
UnityEngine.Debug.Log("[DebugRegistry] Cleared");
}
}
public static void Enable(object o)
{
if (o == null) return;
targets.Add(o);
}
public static void Disable(object o)
{
if (o == null) return;
targets.Remove(o);
}
public static bool IsEnabled(object o)
{
return o != null && targets.Contains(o);
}
public static void Clear()
{
targets.Clear();
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f01401eab13bd2746b9d3ac316cfcbc0
+15 -10
View File
@@ -1,32 +1,37 @@
#define ENALBE_LOGGING
using UnityEngine;
namespace BrewMonster
{
public class BMLogger
{
public static void Log(string message)
{
#if ENALBE_LOGGING
#if ENALBE_LOGGING
Debug.Log(message);
#endif
#endif
}
public static void LogError(string message)
{
#if ENALBE_LOGGING
#if ENALBE_LOGGING
Debug.LogError(message);
#endif
#endif
}
public static void LogWarning(string message)
{
#if ENALBE_LOGGING
#if ENALBE_LOGGING
Debug.LogWarning(message);
#endif
#endif
}
public static void LogMono(object source, string message)
{
#if ENALBE_LOGGING
if (DebugRegistry.IsEnabled(source))
UnityEngine.Debug.LogError($"[{source}] {message}");
#endif
}
}
}
+7 -6
View File
@@ -668,15 +668,12 @@ public class CECNPC : CECObject
A3DVECTOR3 vDir = m_vServerPos - vCurPos;
float fDist = vDir.Normalize();
A3DVECTOR3 vPos = vDir * m_fMoveSpeed * deltaTime;
A3DVECTOR3 exPPos = vPos + EC_Utility.ToA3DVECTOR3(transform.position);
A3DVECTOR3 exPPos = vPos + vCurPos;
float fMoveDelta = Vector3.Magnitude(EC_Utility.ToVector3(exPPos) - EC_Utility.ToVector3(vCurPos));
BMLogger.LogMono(this, $"HoangDev: m_vServerPos:{m_vServerPos},vCurPos:{vCurPos},vDir:{vDir},fDist:{fDist},vPos:{vPos},fMoveDelta:{fMoveDelta}");
if (fMoveDelta >= fDist)
{
if (-2041570812 == m_NPCInfo.nid)
{
BMLogger.LogError($"HoangDev: m_vServerPos:{m_vServerPos},vCurPos:{vCurPos},vDir:{vDir},fDist:{fDist},vPos:{vPos},fMoveDelta:{fMoveDelta}");
}
// Already at destination
_characterController.enabled = false;
SetPos(EC_Utility.ToVector3(m_vServerPos));
@@ -685,7 +682,9 @@ public class CECNPC : CECObject
}
else
{
_characterController.Move(EC_Utility.ToVector3(vPos));
_characterController.enabled = false;
SetPos(EC_Utility.ToVector3(vPos));
_characterController.enabled = true;
FaceDirectionImmediate(EC_Utility.ToVector3(vPos));
}
}
@@ -1005,8 +1004,10 @@ public class CECNPC : CECObject
}
public void StopMoveTo(cmd_object_stop_move cmd)
{
BMLogger.LogMono(this,"CECNPC::StopMoveTo");
if (IsDead())
return;
BMLogger.LogMono(this, "CECNPC::StopMoveTo not dead");
int iMoveMode = cmd.move_mode & (int)GPMoveMode.GP_MOVE_MASK;
@@ -179,17 +179,7 @@ public class CECNPCModelDefaultPolicy
}
else
{
if (_npcVisual.isDebug)
{
BMLogger.LogError("CECNPCModelDefaultPolicy::PlayModelAction iAction :" + iAction);
BMLogger.LogError("GetActionName(iAction) :" + GetActionName(iAction));
}
result = _npcVisual.TryPlayAction(GetActionName(iAction), cECAttackEvent);
if (_npcVisual.isDebug)
{
BMLogger.LogError("result :" + result);
}
}
return result;
}
+11 -49
View File
@@ -15,45 +15,22 @@ public class NPCVisual : MonoBehaviour
private const FadeMode FadeMode = Animancer.FadeMode.FixedDuration;
public CECNPC.INFO GetNPCINFO => m_NPCInfo;
#if UNITY_EDITOR
public bool isDebug;
#endif
public bool TryPlayAction(string animationName, CECAttackEvent cECAttackEvent, bool isHit = false, bool bRestart = true)
{
#if UNITY_EDITOR
if (isDebug)
{
BMLogger.LogError("HoangDev: TryPlayAction: " + animationName);
}
BMLogger.LogMono(this, "HoangDev: TryPlayAction: " + animationName);
#endif
if (namedAnimancer == null) return false;
#if UNITY_EDITOR
if (isDebug)
{
BMLogger.LogError("HoangDev: namedAnimancer == null: " + animationName);
}
#endif
BMLogger.LogMono(this, "HoangDev: namedAnimancer == null: " + animationName);
if (namedAnimancer.IsPlaying(animationName)) return false;
#if UNITY_EDITOR
if (isDebug)
{
BMLogger.LogError("HoangDev: namedAnimancerIsPlaying == null1: " + animationName);
}
#endif
BMLogger.LogMono(this, "HoangDev: namedAnimancerIsPlaying == null1: " + animationName);
_currentState = namedAnimancer.TryPlay(animationName, fadeTime);
if (isHit)
{
_currentState.Events.OnEnd = () => SetHitOnEnd(cECAttackEvent);
}
#if UNITY_EDITOR
if (isDebug)
{
if (_currentState != null)
BMLogger.LogError("HoangDev: _currentState != null1: " + _currentState.Clip.name);
}
#endif
if (_currentState != null)
BMLogger.LogMono(this, "HoangDev: _currentState != null1: " + _currentState.Clip.name);
return _currentState != null;
}
private void SetHitOnEnd(CECAttackEvent cECAttackEvent)
@@ -74,24 +51,14 @@ public class NPCVisual : MonoBehaviour
}
private void OnClearComActFlagEvent(ClearComActFlagEvent @event)
{
#if UNITY_EDITOR
if (isDebug)
{
if (_currentState != null)
BMLogger.LogError("HoangDev: OnClearComActFlagEvent _currentState:" + _currentState.Clip.name);
}
#endif
if (_currentState != null)
BMLogger.LogError("HoangDev: OnClearComActFlagEvent _currentState:" + _currentState.Clip.name);
#if UNITY_EDITOR
if (isDebug)
foreach (var state in _animationQueue)
{
foreach (var state in _animationQueue)
{
BMLogger.LogError("HoangDev: OnClearComActFlagEvent state:" + state);
}
BMLogger.LogError("HoangDev: OnClearComActFlagEvent");
BMLogger.LogMono(this,"HoangDev: OnClearComActFlagEvent state:" + state);
}
#endif
BMLogger.LogMono(this,"HoangDev: OnClearComActFlagEvent");
_animationQueue.Clear();
}
@@ -125,12 +92,7 @@ public class NPCVisual : MonoBehaviour
animName1 = _animationQueue.Peek();
if (_currentState.NormalizedTime < 1f) return;
string animName = _animationQueue.Dequeue();
#if UNITY_EDITOR
if (isDebug)
{
BMLogger.LogError("HoangDev: PlayNext: " + animName);
}
#endif
BMLogger.LogMono(this,"HoangDev: PlayNext: " + animName);
_currentState = namedAnimancer.TryPlay(animName);
}
private void OnDestroy()
+1 -2
View File
@@ -584,7 +584,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
namedAnimancer: {fileID: 0}
isDebug: 0
animName1:
--- !u!143 &-2400324395862947468
CharacterController:
@@ -609,7 +608,7 @@ CharacterController:
m_SlopeLimit: 45
m_StepOffset: 0.3
m_SkinWidth: 0.08
m_MinMoveDistance: 0.001
m_MinMoveDistance: 0.00001
m_Center: {x: 0, y: 1, z: 0}
--- !u!136 &6956701954572561772
CapsuleCollider:
File diff suppressed because one or more lines are too long