예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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);
            }
        }
예제 #5
0
        /// <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);
        }