113 lines
1.6 KiB
C#
113 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace BitStrap
|
|
{
|
|
public class SafeAction
|
|
{
|
|
private List<Action> actions = new List<Action>();
|
|
|
|
public void Register(Action a)
|
|
{
|
|
if (!actions.Contains(a))
|
|
{
|
|
actions.Add(a);
|
|
}
|
|
}
|
|
|
|
public void Unregister(Action a)
|
|
{
|
|
actions.Remove(a);
|
|
}
|
|
|
|
public void Call()
|
|
{
|
|
for (int i = 0; i < actions.Count; i++)
|
|
{
|
|
try
|
|
{
|
|
if (actions[i] != null)
|
|
{
|
|
actions[i]();
|
|
}
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.LogException(exception);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class SafeAction<T>
|
|
{
|
|
private List<Action<T>> actions = new List<Action<T>>();
|
|
|
|
public void Register(Action<T> a)
|
|
{
|
|
if (!actions.Contains(a))
|
|
{
|
|
actions.Add(a);
|
|
}
|
|
}
|
|
|
|
public void Unregister(Action<T> a)
|
|
{
|
|
actions.Remove(a);
|
|
}
|
|
|
|
public void Call(T p1)
|
|
{
|
|
for (int i = 0; i < actions.Count; i++)
|
|
{
|
|
try
|
|
{
|
|
if (actions[i] != null)
|
|
{
|
|
actions[i](p1);
|
|
}
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.LogException(exception);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class SafeAction<T1, T2>
|
|
{
|
|
private List<Action<T1, T2>> actions = new List<Action<T1, T2>>();
|
|
|
|
public void Register(Action<T1, T2> a)
|
|
{
|
|
if (!actions.Contains(a))
|
|
{
|
|
actions.Add(a);
|
|
}
|
|
}
|
|
|
|
public void Unregister(Action<T1, T2> a)
|
|
{
|
|
actions.Remove(a);
|
|
}
|
|
|
|
public void Call(T1 p1, T2 p2)
|
|
{
|
|
for (int i = 0; i < actions.Count; i++)
|
|
{
|
|
try
|
|
{
|
|
if (actions[i] != null)
|
|
{
|
|
actions[i](p1, p2);
|
|
}
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.LogException(exception);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|