/// <summary> /// Remove subscribers for the subscriber that left this region. /// </summary> /// <param name="sceneObject">A removed subscriber</param> private void RemoveSubscribersForSubscriber(ISceneObject sceneObject) { var subscribersToRemoveList = new List <ISceneObject>(); foreach (var subscriber in sceneObjects) { var subscriberArea = subscriber.GetGameObject().GetComponent <IInterestArea>(); var subscribedPublishers = subscriberArea?.GetSubscribedPublishers(); if (subscribedPublishers == null) { continue; } var hasSubscription = subscribedPublishers.Any(x => x.HasSubscription(sceneObject)); if (!hasSubscription) { subscribersToRemoveList.Add(subscriber); } } if (subscribersToRemoveList.Count <= 0) { return; } { var subscriberArea = sceneObject.GetGameObject().GetComponent <IInterestAreaEvents>(); subscriberArea.RemoveSubscribers(subscribersToRemoveList); } }
public ISceneObject AddSceneObject(ISceneObject sceneObject) { if (!sceneObjects.Add(sceneObject)) { Debug.LogWarning($"A scene object with a id #{sceneObject.Id} already exists in a scene."); return(null); } Debug.Log($"A new scene object: {sceneObject.GetGameObject().name}"); return(sceneObject); }
public void RemoveSceneObject(ISceneObject sceneObject) { if (!sceneObjects.Remove(sceneObject)) { Debug.LogWarning($"A scene object with id #{sceneObject.Id} does not exist in a scene."); return; } Debug.Log($"Removed scene object: {sceneObject.GetGameObject().name}"); RemoveSubscriptionFromPublishers(sceneObject); }
/// <summary> /// Add all subscribers for a new subscriber. /// </summary> /// <param name="sceneObject">A new subscriber</param> private void AddSubscribersForSubscriber(ISceneObject sceneObject) { var subscribers = GetSubscribersExcept(sceneObject.Id); if (subscribers.Length <= 0) { return; } { var subscriberArea = sceneObject.GetGameObject().GetComponent <IInterestAreaEvents>(); subscriberArea?.AddSubscribers(subscribers); } }
/// <summary> /// Remove subscribers for the subscriber that left from this region. /// </summary> private void RemoveAllSubscribersForSubscriber(ISceneObject sceneObject) { var subscriberArea = sceneObject.GetGameObject().GetComponent <IInterestAreaEvents>(); subscriberArea?.RemoveSubscribers(sceneObjects); }