//------------------------------------------------- Factory Method ----------------------------------------------------// public static GameEventDelegate CreateDelegate(MonoBehaviour behaviour, string methodName, BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) { if (behaviour == null || string.IsNullOrEmpty(methodName)) { return(null); } var _type = behaviour.GetType(); if (_type == null) { return(null); } var _methodInfo = _type.GetMethod(methodName, flags, null, new[] { typeof(object) }, null); if (_methodInfo == null) { return(null); } var _method = (OnGameEventRaised)System.Delegate.CreateDelegate(typeof(OnGameEventRaised), behaviour, _methodInfo); if (_method == null) { return(null); } var _delegate = new GameEventDelegate(methodName); _delegate += _method; return(_delegate); }
public void Return(GameEventDelegate _event) { if (_event == null) { return; } _event.Clear(); inactive.Push(_event); }
public bool UnregisterMethod(OnGameEventRaised method) { if (method == null || invoker.IsEmpty) { return(false); } invoker -= method; if (verbose) { Debug.Log(string.Format("[{0}]: Method Unregistration Succesfull: [{1}]", name, method.Method.Name)); } return(true); }
//----------------------------------------------------- For Methods ---------------------------------------------------// public bool RegisterMethod(OnGameEventRaised method) { if (method == null) { return(false); } if (invoker == null) { invoker = new GameEventDelegate(); } invoker -= method; invoker += method; if (verbose) { Debug.Log(string.Format("[{0}]: Method Registration Succesfull: [{1}]", name, method.Method.Name)); } return(true); }
//=====================================================================================================================// //================================================== Private Methods ==================================================// //=====================================================================================================================// #region Private Methods /// <summary> /// Called OnValidate /// In EditMode caches method @name to be called at runtime (used as an alternative to Unity's SendMessage /// In PlayMode With the cached method @name, create a delegate method using reflection to fetche the corresponding method in the provided script /// </summary> /// <returns></returns> bool ValidateMethod() { if (action != ActionType.InvokeMethod) { return(false); } if (Application.isPlaying) { if (behaviour == null || ((MonoBehaviour)behaviour) == null) { return(false); } if (string.IsNullOrEmpty(_methodName)) { return(false); } methodDelegate = GameEventDelegate.CreateDelegate((MonoBehaviour)behaviour, _methodName); if (methodDelegate == null || methodDelegate.Count == 0) { return(false); } } else { if (behaviour == null) { _methodIdx = -1; _methodName = ""; return(false); } } return(true); }