mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-16 00:07:52 +08:00
add AddListener helper for IL2CPP, cleanup some unity extensions
This commit is contained in:
33
src/Helpers/EventHelper.cs
Normal file
33
src/Helpers/EventHelper.cs
Normal file
@ -0,0 +1,33 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace UnityExplorer.Helpers
|
||||
{
|
||||
// Possibly temporary, just so Il2Cpp can do the same style "AddListener" as Mono.
|
||||
// Just saves me having a preprocessor directive for every single AddListener.
|
||||
|
||||
public static class EventHelper
|
||||
{
|
||||
public static void AddListener(this UnityEvent action, Action listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T0, T1>(this UnityEvent<T0, T1> action, Action<T0, T1> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T0, T1, T2>(this UnityEvent<T0, T1, T2> action, Action<T0, T1, T2> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -18,12 +18,27 @@ namespace UnityExplorer.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
public static string ActiveSceneName
|
||||
public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = false)
|
||||
{
|
||||
get
|
||||
var unityObj = obj as Object;
|
||||
if (obj == null)
|
||||
{
|
||||
return UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
||||
if (!suppressWarning)
|
||||
ExplorerCore.LogWarning("The target instance is null!");
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (obj is Object)
|
||||
{
|
||||
if (!unityObj)
|
||||
{
|
||||
if (!suppressWarning)
|
||||
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string ToStringLong(this Vector3 vec)
|
||||
|
Reference in New Issue
Block a user