Last active
November 6, 2021 18:25
-
-
Save giacomelli/28ee9438ad522985a9611c21312813bc to your computer and use it in GitHub Desktop.
UnityEvent Dump Log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.CompilerServices; | |
using System.Text; | |
using UnityEngine; | |
using UnityEngine.Events; | |
namespace Giacomelli.Framework | |
{ | |
public static class UnityEventExtensions | |
{ | |
[System.Diagnostics.Conditional("DEBUG")] | |
public static void Dump<TArgument>( | |
this UnityEvent<TArgument> instance, | |
string eventName, | |
[CallerFilePath] string filePath = null, | |
[CallerLineNumber] int lineNumber = 0, | |
[CallerMemberName] string memberName = null) | |
{ | |
var listenersCount = instance.GetPersistentEventCount(); | |
var msg = new StringBuilder(); | |
msg.AppendFormat($"[UNITY EVENT DUMP]\n"); | |
msg.AppendFormat($"{filePath} ({lineNumber}): {memberName}\n"); | |
msg.AppendFormat($"\t- Listeners: {listenersCount}\n"); | |
for (int i = 0; i < listenersCount; i++) | |
{ | |
msg.AppendFormat($"\t\t- Listener {i}: {instance.GetPersistentTarget(i)}.{instance.GetPersistentMethodName(i)}\n"); | |
} | |
Debug.Log(msg.ToString()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public UnityEvent<float> OnEnergyLost; | |
// ... | |
OnEnergyLost.Dump("OnEnergyLost"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment