Ejemplo n.º 1
0
    public static void InvokeBind(this MonoBehaviour target, object name, params object[] parameters)
    {
        if (target == null)
        {
            return;
        }
        target.BindMethods();
        Debug.Log($"Invoke Bind {name}");
        if (!_methods.ContainsKey(target))
        {
            Debug.Log($"{target} has no method bound to {name}()");
            return;
        }

        var targetMethods = _methods[target];
        var sn            = name.ToString().ToLower();

        if (targetMethods == null || !targetMethods.ContainsKey(sn))
        {
            Debug.Log($"{target} has no method bound to {name}()");
            return;
        }

        var methods = targetMethods[sn].ToArray();

        foreach (var method in methods)
        {
            try
            {
                method.Invoke(target, parameters);
            }
            catch (Exception e)
            {
                Debug.Log($"invoke bind method {name} -> {method.Name}() error :: {e.Message}");
            }
        }
    }