public static bool Subscribe <Type>(this GameObject _this, IEventHandler <Type> handler) where Type : Subject <Type>, new() { if (_this != null) { UnitySubject nc = _this.GetComponent <UnitySubject>(); if (nc) { return(nc.Subscribe <Type>(handler)); } else { DebugUtil.LogWarning("[GameObject_UnitySubject] This game object does not have UnitySubject component. " + _this); return(false); } } else { DebugUtil.LogWarning("[GameObject_UnitySubject] The game object is null."); return(false); } }
public static Type Notification <Type>(this GameObject _this) where Type : Subject <Type>, new() { if (_this != null) { UnitySubject nc = _this.GetComponent <UnitySubject>(); if (nc) { Type ret = nc.Notification <Type>(); return(ret); } else { DebugUtil.LogWarning("[GameObject_UnitySubject] This game object does not have UnitySubject component. " + _this); } } else { DebugUtil.LogWarning("[GameObject_UnitySubject] The game object is null."); } // return a dummy instance as fallback, which should not happened under any circumstances, theoretically return(new Type()); }