using NAK.AvatarScaleMod.Components; namespace NAK.AvatarScaleMod.AvatarScaling; public static class AvatarScaleEvents { #region Local Avatar Scaling Events /// /// Invoked when the local avatar's height changes for any reason. /// public static readonly AvatarScaleEvent OnLocalAvatarHeightChanged = new(); /// /// Invoked when the local avatar's animated height changes. /// public static readonly AvatarScaleEvent OnLocalAvatarAnimatedHeightChanged = new(); /// /// Invoked when the local avatar's target height changes. /// public static readonly AvatarScaleEvent OnLocalAvatarTargetHeightChanged = new(); /// /// Invoked when the local avatar's height is reset. /// public static readonly AvatarScaleEvent OnLocalAvatarHeightReset = new(); #endregion #region Avatar Scaling Events /// /// Invoked when a remote avatar's height changes. /// public static readonly AvatarScaleEvent OnRemoteAvatarHeightChanged = new(); /// /// Invoked when a remote avatar's height is reset. /// public static readonly AvatarScaleEvent OnRemoteAvatarHeightReset = new(); #endregion #region Event Classes public class AvatarScaleEvent { private Action _listener = arg => { }; public void AddListener(Action listener) => _listener += listener; public void RemoveListener(Action listener) => _listener -= listener; public void Invoke(T arg) { var invokeList = _listener.GetInvocationList(); foreach (Delegate method in invokeList) { if (method is not Action action) continue; try { action(arg); } catch (Exception e) { AvatarScaleMod.Logger.Error($"Unable to invoke listener, an exception was thrown and not handled: {e}."); } } } } public class AvatarScaleEvent { private Action _listener = (arg1, arg2) => { }; public void AddListener(Action listener) => _listener += listener; public void RemoveListener(Action listener) => _listener -= listener; public void Invoke(T1 arg1, T2 arg2) { var invokeList = _listener.GetInvocationList(); foreach (Delegate method in invokeList) { if (method is not Action action) continue; try { action(arg1, arg2); } catch (Exception e) { AvatarScaleMod.Logger.Error($"Unable to invoke listener, an exception was thrown and not handled: {e}."); } } } } #endregion }