Пример #1
0
        private void DoVisitComponent(SceneComponentContainer component)
        {
            VisitComponentMethod visitComponent;
            var compType = component.GetType();

            if (_visitors.Components.TryGetValue(compType, out visitComponent))
            {
                // Fast lane: we found a directly matching Visitor. Call it and leave.
                visitComponent(this, component);
            }
            else
            {
                // See if we find a matching Visitor up the inheritance hierarchy of the component's type
                var ancestorType = compType.BaseType;
                while (ancestorType != null)
                {
                    if (_visitors.Components.TryGetValue(ancestorType, out visitComponent))
                    {
                        // Found a handler. Register it for fast handling of future Visits of components with the same type!
                        _visitors.Components[compType] = visitComponent;
                        visitComponent(this, component);
                        return;
                    }
                    // one step up the inheritance hierarchy
                    ancestorType = ancestorType.BaseType;
                }
                // No matching Visitor among the ancestors. Add a dummy
                _visitors.Components[compType] = (th, comp) => { };
            }
        }
Пример #2
0
        private void DoVisitComponent(SceneComponentContainer component)
        {
            VisitComponentMethod visitComponent;

            if (_visitors.Components.TryGetValue(component.GetType(), out visitComponent))
            {
                visitComponent(this, component);
            }
        }
Пример #3
0
        private static void AddComponent(SceneNodeContainer snc, SceneComponentContainer scc)
        {
            if (scc == null || snc == null)
            {
                return;
            }

            if (snc.Components == null)
            {
                snc.Components = new List <SceneComponentContainer>();
            }
            snc.Components.Add(scc);
        }
Пример #4
0
        /// <summary>
        /// Adds the given component into this container's list of components.
        /// </summary>
        /// <param name="sncThis">This node.</param>
        /// <param name="scc">The component to add.</param>
        public static void AddComponent(this SceneNodeContainer sncThis, SceneComponentContainer scc)
        {
            if (scc == null || sncThis == null)
            {
                return;
            }

            if (sncThis.Components == null)
            {
                sncThis.Components = new List <SceneComponentContainer>();
            }
            sncThis.Components.Add(scc);
        }