public void Unregister(IRegistryObject t)
        {
            if (t == null)
            {
                return;
            }

            if (!m_Objects.Remove(t.Id))
            {
                return;
            }

            m_UnregisteredObjects.Add(t);

            var type = t.GetType();
            HashSet <UTinyId> typeIds;

            if (m_IdsByType.TryGetValue(type, out typeIds))
            {
                if (typeIds.Remove(t.Id))
                {
                    UTinyEventDispatcher.Dispatch(UTinyRegistryEventType.Unregistered, t);
                }
                if (typeIds.Count == 0)
                {
                    m_IdsByType.Remove(type);
                }
            }
        }
        public void Register(IRegistryObject t)
        {
            Assert.IsNotNull(t);

            IRegistryObject oldObject;

            if (m_Objects.TryGetValue(t.Id, out oldObject))
            {
                if (oldObject == t)
                {
                    return;
                }
                Unregister(oldObject);
            }

            Assert.AreNotEqual(UTinyId.Empty, t.Id);

            m_Objects[t.Id] = t;
            var type = t.GetType();
            HashSet <UTinyId> typeIds;

            if (!m_IdsByType.TryGetValue(type, out typeIds))
            {
                m_IdsByType[type] = typeIds = new HashSet <UTinyId>();
            }

            SetSourceIdentifier(t);

            if (typeIds.Add(t.Id))
            {
                UTinyEventDispatcher.Dispatch(UTinyRegistryEventType.Registered, t);
            }
        }
        private static void HandleCoreTypeRegistered(UTinyRegistryEventType @event, IRegistryObject obj)
        {
            if (!(obj is UTinyType) || null == obj?.Registry)
            {
                return;
            }
            var type = (UTinyType)obj;

            UTinyEventDispatcher.AddListener <UTinyType.Reference, IEnumerable <UTinyEntity> >((UTinyType.Reference)type, ProcessDependency);
        }
        private void SetSourceIdentifier(IRegistryObject obj)
        {
            var identifier = SourceIdentifier;

            if (string.IsNullOrEmpty(identifier))
            {
                return;
            }
            HashSet <UTinyId> ids;

            if (!m_SourceIdentifierMap.TryGetValue(identifier, out ids))
            {
                ids = m_SourceIdentifierMap[identifier] = new HashSet <UTinyId>();
            }

            ids.Add(obj.Id);
        }
Example #5
0
        private static void HandleCoreTypeRegistered(UTinyRegistryEventType eventType, IRegistryObject obj)
        {
            if (!(obj is UTinyType) || null == obj.Registry)
            {
                return;
            }

            var type = obj as UTinyType;

            List <AttributeBinder> binders;

            if (!s_Lookup.TryGetValue(obj.Id, out binders))
            {
                return;
            }
            foreach (var binder in binders)
            {
                binder(obj.Registry, (UTinyType.Reference)type);
            }
        }
        private static void HandleGraphTypeRegistered(UTinyRegistryEventType eventType, IRegistryObject obj)
        {
            if (!(obj is UTinyType) || null == obj.Registry)
            {
                return;
            }

            var type     = (UTinyType)obj;
            var registry = obj.Registry;

            var cellGraphType = obj.Registry.FindByName <UTinyType>("CellGraph");

            if (null != cellGraphType && type.Id.Equals(cellGraphType.Id))
            {
                AddBindings(registry, (UTinyType.Reference)type, t => new CellGraphBindings(t));
                return;
            }

            var cellGraphNodeType = obj.Registry.FindByName <UTinyType>("CellGraphNode");

            if (null != cellGraphNodeType && type.Id.Equals(cellGraphNodeType.Id))
            {
                AddBindings(registry, (UTinyType.Reference)type, t => new CellGraphNodeBindings(t));
            }
        }