public void Remove <T>() where T : Component { var idx = ComponentTypeManager.GetIndexFor(typeof(T)); this.componentsToAdd.Remove(idx); this.componentIdxToRemove.Add(idx); }
public void Remove(Component component) { var idx = ComponentTypeManager.GetIndexFor(component.GetType()); this.componentsToAdd.Remove(idx); this.componentIdxToRemove.Add(idx); }
private void ComponentEnabled(Component component) { var idx = ComponentTypeManager.GetIndexFor(component.GetType()); this.componentIdxToDisable.Remove(idx); this.componentIdxToEnable.Add(idx); }
public T Add <T>(T component) where T : Component { var idx = ComponentTypeManager.GetIndexFor(component.GetType()); this.componentsToAdd.Add(idx, component); return(component); }
public void SetState(Entity entity, string stateName) { List <string> newState = this.States[stateName]; if (this.CurrentState == newState) { return; } foreach (string componentName in this.CurrentState) { if (newState.IndexOf(componentName) == -1) { entity.RemoveComponent(ComponentTypeManager.GetTypeFor(this.Components[componentName].GetType())); } } foreach (string componentName in newState) { if (this.CurrentState.IndexOf(componentName) == -1) { entity.AddComponent(this.Components[componentName]); } } this.CurrentState = newState; }
public void RemoveComponent <T>() where T : UnityEngine.Component { var c = _gameObject.GetComponent <T>(); GameObject.Destroy(c); this.ComponentBits.set(ComponentTypeManager.GetIndexFor(typeof(T)), false); _scene.EntityProcessors.onComponentRemoved(this); }
/// <summary>Initializes a new instance of the <see cref="HybridQueueSystemProcessing" /> class.</summary> /// <param name="requiredType">Type of the required.</param> /// <param name="otherTypes">The other types.</param> protected HybridQueueSystemProcessing(Type requiredType, params Type[] otherTypes) : base(requiredType, otherTypes) { this.queue = new Queue <Entity>(); this.compTypes = new List <ComponentType>(); foreach (Type type in this.Types) { this.compTypes.Add(ComponentTypeManager.GetTypeFor(type)); } }
public ComponentArray <T> GetComponentArray <T>() { var r = componentArrays[ComponentTypeManager.GetTypeIndex <T>()]; if (r == null) { throw new ArgumentException($"Entity not contains component of type {typeof(T)}"); } return((ComponentArray <T>)r); }
/// <summary> /// Creates a new EntitySystem instance associated with the provided types. /// </summary> /// <param name="types">Types to associate with the EntitySystem.</param> public EntitySystem(params Type[] types) : this() { int typeCount = types.Length; for (int i = 0; i < typeCount; ++i) { Type type = types[i]; ComponentType componentType = ComponentTypeManager.GetTypeFor(type); _typeFlags |= componentType.Bit; } }
public void TestInitializeComponentTypes() { FieldInfo field = typeof(ComponentTypeManager).GetField("ComponentTypes", BindingFlags.Static | BindingFlags.NonPublic); Assert.IsNotNull(field, "ComponentTypeManager.ComponentTypes field has not been found"); Assert.IsTrue(field.GetValue(null).GetType() == typeof(Dictionary <Type, ComponentType>), "ComponentTypes container is expected to be of type Dictionary<Type, ComponentType>"); // Debug.WriteLine("Resetting ComponentTypeManager.ComponentTypes..."); // field.SetValue(null, new Dictionary<Type, ComponentType>()); var componentTypes = (Dictionary <Type, ComponentType>)field.GetValue(null); Assert.IsNotNull(componentTypes, "Component Types dictionary must not be null"); // Assert.IsTrue(componentTypes.Count == 0, "Initial Component Types dictionary is expected to be empty."); // Debug.WriteLine("OK"); Debug.WriteLine("Initializing specific Component types..."); ComponentTypeManager.Initialize(new List <Type> { typeof(TestBaseComponent), typeof(TestDerivedComponent), typeof(TestHealthComponent), typeof(TestPowerComponent), typeof(TestPowerComponentPoolable), typeof(IComponent), // should be filtered out typeof(ComponentPoolable), // should be filtered out }); Debug.WriteLine("OK"); Assert.IsNotNull(componentTypes, "Initialized Component Types dictionary must not be null"); // NOTE: list of initialized types may change if you change existing Components var expectedTypes = new List <Type> { typeof(TestBaseComponent), typeof(TestDerivedComponent), typeof(TestHealthComponent), typeof(TestPowerComponent), typeof(TestPowerComponentPoolable) }; Debug.WriteLine("Checking initialized Component types..."); // Assert.AreEqual(expectedTypes.Count, componentTypes.Count, "Expected and actual Component Types count do not match."); foreach (var expectedType in expectedTypes) { Assert.IsTrue(componentTypes.ContainsKey(expectedType), "ComponentTypes is expected to contain {0}", expectedType); } Debug.WriteLine("OK"); }
public T AddComponent <T>() where T : UnityEngine.Component { var c = _gameObject.AddComponent <T>(); if (c is BaseMonoBehaviour) { object b = (object)c; ((BaseMonoBehaviour)b).Entity = this; } this.ComponentBits.set(ComponentTypeManager.GetIndexFor(typeof(T))); _scene.EntityProcessors.onComponentAdded(this); return(c); }
public static void Destroy(Entity entity) { foreach (var c in entity.GameObject.GetComponents(typeof(MonoBehaviour))) { //Debug.Log("Removed [" + entity.name + "] " + c.GetType().ToString()); if (c is Entity) { continue; } entity.ComponentBits.set(ComponentTypeManager.GetIndexFor(c.GetType()), false); entity.Scene.EntityProcessors.onComponentRemoved(entity); GameObject.Destroy(c); } GameObject.Destroy(entity.GameObject); }
public T Get <T>(bool withPending = true) where T : Component { var idx = ComponentTypeManager.GetIndexFor(typeof(T)); if (this.components.ContainsKey(idx)) { return((T)this.components[idx]); } if (withPending && this.componentsToAdd.ContainsKey(idx)) { return((T)this.componentsToAdd[idx]); } return(null); }
public virtual void Start() { pixelCamera = Camera.main.gameObject.AddComponent <PixelCamera>(); pixelCamera.DesignWidth = _designWidth; pixelCamera.DesignHeight = _designHeight; var guiCamera = GameObject.Find("GUI Camera"); if (guiCamera != null) { PixelCamera pixelCameraGUI = guiCamera.AddComponent <PixelCamera>(); pixelCameraGUI.DesignWidth = _designWidth; pixelCameraGUI.DesignHeight = _designHeight; } ComponentTypeManager.Initialize(); }
private void Validate() { if (entityMap.Count == 0) { throw new InvalidOperationException("No entities registered to scene"); } if (entityMap.CountEntities(e => e.ContainsComponent(ComponentTypeManager.GetKeyPart <CameraComponent>())) == 0) { LogEvent.Engine.Warning("No camera registered to scene"); } if (entityMap.CountEntities(e => e.ContainsComponent(ComponentTypeManager.GetKeyPart <PointLightComponent>())) == 0) { LogEvent.Engine.Warning("No light registered to scene"); } if (!entityMap.Validate()) { throw new InvalidOperationException("Entities are missing required components"); } }
public TComponent GetComponent <TComponent>() where TComponent : Component { return(GetComponent <TComponent>(ComponentTypeManager.GetKeyPart <TComponent>())); }
internal bool CommitChanges() { if (this.componentIdxToDisable.Count > 0) { foreach (var idx in this.componentIdxToDisable) { this.Bits.Set(idx, false); } } if (this.componentIdxToEnable.Count > 0) { if (!this.entity.Enabled) { this.componentIdxToEnable.Clear(); } foreach (var idx in this.componentIdxToEnable) { this.Bits.Set(idx, true); } } if (this.componentIdxToRemove.Count > 0) { foreach (var idx in this.componentIdxToRemove) { this.Bits.Set(idx, false); if (this.components.ContainsKey(idx)) { var component = this.components[idx]; component.Entity = null; component.ComponentEnabled -= this.ComponentEnabled; component.ComponentDisabled -= this.ComponentDisabled; this.components.Remove(idx); } } } if (this.componentsToAdd.Count > 0) { foreach (var component in this.componentsToAdd) { var idx = ComponentTypeManager.GetIndexFor(component.Value.GetType()); this.Bits.Set(idx, this.entity.Enabled && component.Value.Enabled); component.Value.Entity = this.entity; component.Value.ComponentEnabled += this.ComponentEnabled; component.Value.ComponentDisabled += this.ComponentDisabled; this.components.Add(idx, component.Value); } } var isSomethingChanged = this.componentIdxToRemove.Count > 0 || this.componentsToAdd.Count > 0 || this.componentIdxToDisable.Count > 0 || this.componentIdxToEnable.Count > 0; this.componentIdxToRemove.Clear(); this.componentsToAdd.Clear(); this.componentIdxToDisable.Clear(); this.componentIdxToEnable.Clear(); return(isSomethingChanged); }
public OptimizationSystem() : base(Selector.All(typeof(ModelComponent), typeof(ShaderComponent))) { tShader = ComponentTypeManager.GetType <ShaderComponent>(); tModel = ComponentTypeManager.GetType <ModelComponent>(); renderMapper = new RenderMapper(); }
public bool ContainsComponent <TComponent>() where TComponent : IComponent { return(ContainsComponent(ComponentTypeManager.GetKeyPart <TComponent>())); }
/// <summary> /// Gets a component of type T associated with the Entity. /// </summary> /// <typeparam name="T"><see cref="IComponent"/> type to get for the Entity.</typeparam> /// <returns>>An <see cref="IComponent"/> instance of the specified type if one is associated with the Entity, or null if not.</returns> public T GetComponent <T>() where T : IComponent { return((T)GetComponent(ComponentTypeManager.GetTypeFor <T>())); }
public ControllerComponent() : base(ComponentTypeManager.GetType <ControllerComponent>()) { }
public BloomComponent() : base(ComponentTypeManager.GetType <BloomComponent>()) { }
protected UpdateableSystemBase(Selector selector) : base(selector) { tUpdate = ComponentTypeManager.GetType <UpdateComponent>(); }
public UserInterfaceSystem() : base(Selector.All(typeof(UserInterfaceComponent))) { tUserInterface = ComponentTypeManager.GetType <UserInterfaceComponent>(); }
/// <summary> /// Creates a new ComponentMapper instance associated with the specified entity world. /// </summary> /// <param name="world">Entity world instance to associate with.</param> public ComponentMapper(IEntityWorld world) { _world = world; _componentType = ComponentTypeManager.GetTypeFor <T>(); }
public GlowComponent() : base(ComponentTypeManager.GetType <GlowComponent>()) { }
public bool TryGetComponent <TComponent>(out TComponent component) where TComponent : Component { return(Scene.EntityMap.TryGetEntityComponent(this, ComponentTypeManager.GetKeyPart <TComponent>(), out component)); }
public bool HasComponent <T>() { var typeId = ComponentTypeManager.GetTypeIndex <T>(); return(componentArrays.Length > typeId && componentArrays[typeId] != null); }