コード例 #1
0
ファイル: Actor.cs プロジェクト: nozgames/com.noz.common
        private void RegisterHandlers(ActorComponent component)
        {
            if (component.info.handlers.Length == 0)
            {
                return;
            }

            if (handlers == null)
            {
                handlers = handlersPool.Get();
            }

            // Increase the list capacity if needed
            if (handlers.Capacity < handlers.Count + component.info.handlers.Length)
            {
                handlers.Capacity = handlers.Count + component.info.handlers.Length;
            }

            // Insert each handler
            foreach (var handler in component.info.handlers)
            {
                if (!handler.autoRegister)
                {
                    continue;
                }

                var temp = handler;
                temp.component = component;
                handlers.Insert(FindHandlerInsertionPoint(handler.priority), temp);
                OnCallbackRegistered(handler.eventType);
            }
        }
コード例 #2
0
ファイル: Actor.cs プロジェクト: nozgames/com.noz.common
        /// <summary>
        /// Unregister an actor component from the actor.  Generally this method
        /// is only used internally by ActorComponent to automatically unregister
        /// itself.
        /// </summary>
        /// <param name="component">Component to unregister</param>
        internal void UnregisterComponent(ActorComponent component)
        {
            if (handlers == null)
            {
                return;
            }

            // Remove all handlers from the registered handlers and record
            // all the the handlers that were unregistered.
            var unregistered = handlersPool.Get();

            for (int handlerIndex = handlers.Count - 1; handlerIndex >= 0; handlerIndex--)
            {
                if (handlers[handlerIndex].component == component)
                {
                    unregistered.Add(handlers[handlerIndex]);
                    handlers.RemoveAt(handlerIndex);
                }
            }

            // Send out an event for each unregistered callback
            foreach (var handler in unregistered)
            {
                OnCallbackUnregistered(handler.eventType);
            }
            unregistered.Clear();
            handlersPool.Release(unregistered);

            if (handlers.Count <= 0)
            {
                handlersPool.Release(handlers);
                handlers = null;
            }
        }
コード例 #3
0
ファイル: Actor.cs プロジェクト: nozgames/com.noz.common
        /// <summary>
        /// Register the given actor component with the actor by adding it to
        /// its components list.
        /// </summary>
        /// <param name="component">Component to register</param>
        internal void RegisterComponent(ActorComponent component)
        {
            if (null == components)
            {
                components = componentsPool.Get();
            }

            components.Add(component);

            RegisterHandlers(component);
        }