Esempio n. 1
0
 /// <summary>
 /// Add the system to this manager.
 /// </summary>
 /// <param name="system">The system to add.</param>
 /// <returns>This component system manager, for chaining.</returns>
 public IComponentSystemManager AddSystem(IComponentSystem system)
 {
     _systems.Add(system);
     _mapping.Remove(system.GetType());
     system.Manager = this;
     return(this);
 }
Esempio n. 2
0
        private T GetSubClassSystem <T>() where T : IService
        {
            IEnumerable <Type> subClases = null;
            IComponentSystem   retSystem = null;

            m_SubSystemCache.TryGetValue(typeof(T), out retSystem);
            if (retSystem == null)
            {
                subClases =
                    from assembly in s_Assembly.Where(a => !a.GlobalAssemblyCache)
                    from type in assembly.GetTypes()
                    where type.IsSubclassOf(typeof(T))
                    select type;
            }
            else
            {
                return(retSystem as T);
            }

            foreach (Type t in subClases)
            {
                if (m_Systems.TryGetValue(t.GUID, out retSystem))
                {
                    m_SubSystemCache.Add(typeof(T), retSystem);
                    return(retSystem as T);
                }
            }

            return(null);
        }
Esempio n. 3
0
 public void RegisterIComponentSystem(IComponentSystem service)
 {
     Guid guid = service.GetType().GUID;
     {
         IComponentSystem retService = null;
         if (!m_Systems.TryGetValue(guid, out retService))
         {
             m_Systems.Add(guid, service);
         }
     }
 }
Esempio n. 4
0
 public void RegisterComponentSystem <T>(T service) where T : IComponentSystem
 {
     Type t = typeof(T);
     //if (t.IsSealed)
     {
         IComponentSystem retService = null;
         if (!m_Systems.TryGetValue(t.GUID, out retService))
         {
             m_Systems.Add(typeof(T).GUID, service);
         }
     }
 }
Esempio n. 5
0
        public T GetComponentSystem <T>() where T : IComponentSystem
        {
            Type             serviceType = typeof(T);
            IComponentSystem system      = null;

            if (m_Systems.TryGetValue(serviceType.GUID, out system))
            {
                return(system as T);
            }
            else
            {
                return(GetSubClassSystem <T>());
            }
        }
        public virtual IEnumerable<IObservable<int>> Install(IComponentSystem componentSystem)
        {
            foreach (var item in Ctx.Data.Observables)
            {
                var node = item.Node;

                Ctx._("componentSystem.PropertyChanged<{0}, {1}>(_ => _.{2}Observable, (c, v) => {{ UpdateItem(c.EntityId); }})",
                    node.Name,
                    item.RelatedTypeName,
                    item.Name);
            }

            foreach (var item in SelectComponents)
            {
                Ctx._("{0} = componentSystem.RegisterComponent<{1}>()", item.Name + "Manager", item.Name);
                Ctx._("yield return {0}.CreatedObservable.Select(_=>_.EntityId);", item.Name + "Manager");
                Ctx._("yield return {0}.RemovedObservable.Select(_=>_.EntityId);", item.Name + "Manager");
            }

            yield break;
        }
Esempio n. 7
0
        public virtual IEnumerable <IObservable <int> > Install(IComponentSystem componentSystem)
        {
            foreach (var item in Ctx.Data.Observables)
            {
                var node = item.Node;

                Ctx._("componentSystem.PropertyChangedEvent<{0}, {1}>(_ => _.{2}Observable, (c, v) => {{ UpdateItem(c.EntityId); }})",
                      node.Name,
                      item.RelatedTypeName,
                      item.Name);
            }

            foreach (var item in SelectComponents)
            {
                Ctx._("{0} = componentSystem.RegisterComponent<{1}>()", item.Name + "Manager", item.Name);
                Ctx._("yield return {0}.CreatedObservable.Select(_=>_.EntityId);", item.Name + "Manager");
                Ctx._("yield return {0}.RemovedObservable.Select(_=>_.EntityId);", item.Name + "Manager");
            }

            yield break;
        }
Esempio n. 8
0
 /// <summary>
 /// This method is used to determine when to check that a group item is still valid. It should also initially store any component managers needed for matching.
 /// Ex. If a HealthComponent belongs to a PlayerGroup then it should return ComponentSystem.RegisterComponent'HealthComponent'.CreatedObservable.Select(p=>p.EntityId)
 /// </summary>
 /// <param name="ecsComponentService"></param>
 /// <returns></returns>
 public virtual IEnumerable <IObservable <int> > Install(IComponentSystem ecsComponentService)
 {
     yield break;
 }
Esempio n. 9
0
 public static IObservable <TComponentType> OnComponentDestroyed <TComponentType>(this IComponentSystem system) where TComponentType : class, IEcsComponent
 {
     return(system.RegisterComponent <TComponentType>().RemovedObservable);
 }
Esempio n. 10
0
 public IEnumerable <IObservable <int> > Install(IComponentSystem ecsComponentService)
 {
     ecsComponentService.ComponentCreatedObservable.Where(p => p is TInterface).Subscribe(OnNext);
     ecsComponentService.ComponentRemovedObservable.Where(p => p is TInterface).Subscribe(_ => RemoveItem(_));
     yield break;
 }
Esempio n. 11
0
 public IEnumerable <IObservable <int> > Install(IComponentSystem ecsComponentService)
 {
     ecsComponentService.ComponentCreatedObservable.Where(p => p.GetType().IsDefined(typeof(TAttributeType), true)).Subscribe(OnNext).DisposeWith(ecsComponentService);
     ecsComponentService.ComponentRemovedObservable.Where(p => p.GetType().IsDefined(typeof(TAttributeType), true)).Subscribe(_ => RemoveItem(_)).DisposeWith(ecsComponentService);
     yield break;
 }
Esempio n. 12
0
 public void RegisterSystem(IComponentSystem system)
 {
     system.CurrentEntityManager = this;
     systems.Add(system);
 }
Esempio n. 13
0
 /// <summary>
 /// Removes the system from this manager.
 /// </summary>
 /// <param name="system">The system to remove.</param>
 public void RemoveSystem(IComponentSystem system)
 {
     _systems.Remove(system);
     _mapping.Remove(system.GetType());
     system.Manager = null;
 }