private void CheckRegisteredComponent <T>(SubscribableBehaviour subscribableBehaviour, TaskCompletionSource <T> tcs) where T : SubscribableBehaviour { if (subscribableBehaviour is T behaviour) { tcs.SetResult(behaviour); } }
private void CheckComponentRegistered(SubscribableBehaviour subscribableBehaviour) { _awaitingRegister.TryGetValue(subscribableBehaviour.GetType(), out object tcsObject); if (tcsObject != null) { Type tcsType = typeof(TaskCompletionSource <>).MakeGenericType(subscribableBehaviour.GetType()); MethodInfo methodInfo = tcsType.GetMethod("SetResult"); methodInfo?.Invoke(tcsObject, new object[] { subscribableBehaviour }); _awaitingRegister.Remove(subscribableBehaviour.GetType()); } }
public void RegisterComponent(SubscribableBehaviour behaviour) { Debug.Log($"Registering {behaviour} in ComponentContainer {this}."); if (!_objectDictionary.ContainsKey(behaviour.GetType())) { _objectDictionary.Add(behaviour.GetType(), behaviour); behaviour.Destroyed += UnregisterComponent; ComponentRegistered?.Invoke(behaviour); } else { Debug.LogWarning($"Already registered {behaviour} in ComponentContainer {this}."); } }
public async Task CacheAndRegister(SubscribableBehaviour subscribableBehaviour) { await Cache(subscribableBehaviour); Ref.RegisterComponent(subscribableBehaviour); }
public void UnregisterComponent(SubscribableBehaviour unregisterBehaviour) { Debug.Log($"Unegistering {unregisterBehaviour} from ComponentContainer {this}."); _objectDictionary.Remove(unregisterBehaviour.GetType()); }