internal static IEnumerable <MethodInfo> Find <T>(PlayMonoBehaviour host) where T : Attribute { return(host.GetType().GetMethods() .Where(m => m.GetCustomAttributes(typeof(T), false).Length > 0) .ToArray()); }
internal static void RegisterBehaviour <T>(PlayMonoBehaviour behaviour, IDictionary <string, IList <PlayMonoBehaviour> > methodBehaviours) where T : Attribute { var methods = Play.Find <T>(behaviour); methods.Every(m => { if (methodBehaviours.ContainsKey(m.Name)) { var behaviours = methodBehaviours[m.Name]; if (behaviours == null) { behaviours = new List <PlayMonoBehaviour>(); } behaviours.Add(behaviour); } else { methodBehaviours.Add(m.Name, new List <PlayMonoBehaviour>() { behaviour }); } }); }
public static void UnregisterBehaviour(PlayMonoBehaviour behaviour) { if (!Behaviours.Contains(behaviour)) { return; } Behaviours.Remove(behaviour); UnregisterBehaviour(behaviour, EventBehaviours); UnregisterBehaviour(behaviour, RPCBehaviours); }
/// <summary> /// register message noticitication. /// </summary> /// <param name="behaviour">PlayMonoBehaviour instance</param> public static void RegisterBehaviour(PlayMonoBehaviour behaviour) { if (Behaviours.Contains(behaviour)) { return; } Behaviours.Add(behaviour); RegisterBehaviour <PlayEventAttribute>(behaviour, EventBehaviours); RegisterBehaviour <PlayRPCAttribute>(behaviour, RPCBehaviours); }
internal static void UnregisterBehaviour(PlayMonoBehaviour behaviour, IDictionary <string, IList <PlayMonoBehaviour> > methodBehaviours) { var methodBehaviourListCollection = methodBehaviours.Values; methodBehaviourListCollection.Every(behaviours => { if (behaviours.Contains(behaviour)) { behaviours.Remove(behaviour); } }); }
internal static MethodInfo Find(PlayMonoBehaviour host, string methodName, Type[] parameterTypes) { return(host.GetType().GetMethod(methodName, parameterTypes)); }
internal static MethodInfo Find <T>(PlayMonoBehaviour host, string methodName) where T : Attribute { return(host.GetType().GetMethods() .Where(m => m.GetCustomAttributes(typeof(T), false).Length > 0 && m.Name == methodName).FirstOrDefault()); }