public void CanGetComponents() { entity.AddComponent <FakeComp>(); entity.AddComponent <FakeComp>(); var components = entity.GetComponents <FakeComp>().GetEnumerator(); components.MoveNext(); var fake1 = components.Current; components.MoveNext(); Assert.AreNotSame(fake1, components.Current); }
public void EntityGetComponents() { Engine engine = new Engine(); Entity entity = engine.CreateEntity(); TestComponent1 comp1 = new TestComponent1(); TestComponent2 comp2 = new TestComponent2(); entity.AddRawComponent(comp1); entity.AddRawComponent(comp2); Assert.IsTrue(entity.GetComponents().Contains(comp1)); Assert.IsTrue(entity.GetComponents().Contains(comp2)); }
void Update() { _entity.AddMyInt(0); _entity.RemoveMyInt(); _entity.GetComponents(); }
protected virtual void AddEntity(Group collection, Entity entity, int index, IComponent component) { MapPositionComponent mapPositionComponent = null; foreach (var c in entity.GetComponents()) { if (c.GetType() == typeof(MapPositionComponent)) { mapPositionComponent = (MapPositionComponent)c; } } if (mapPositionComponent != null) { if (lookup.ContainsKey(mapPositionComponent.Position) && lookup[mapPositionComponent.Position] == entity) { return; } if (lookup.ContainsKey(mapPositionComponent.Position) && lookup[mapPositionComponent.Position] != entity) { throw new Exception("the key " + mapPositionComponent + " is not unique. Present on entity: " + entity.creationIndex + " and entity: " + lookup[mapPositionComponent.Position].creationIndex); } entity.Retain(this); lookup[mapPositionComponent.Position] = entity; } }
static int GetComponents(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2) { Entity obj = LuaScriptMgr.GetNetObject <Entity>(L, 1); Type arg0 = LuaScriptMgr.GetTypeObject(L, 2); Component[] o = obj.GetComponents(arg0); LuaScriptMgr.PushArray(L, o); return(1); } else if (count == 3) { Entity obj = LuaScriptMgr.GetNetObject <Entity>(L, 1); Type arg0 = LuaScriptMgr.GetTypeObject(L, 2); List <Component> arg1 = LuaScriptMgr.GetNetObject <List <Component> >(L, 3); obj.GetComponents(arg0, arg1); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: Entity.GetComponents"); } return(0); }
void TickUpdate() { ComSat.Trace(this, "TickUpdate"); if (ComSat.EntityExists(target)) { destination = target.position; var radius = target.collisionRadius + entity.collisionRadius; if ((target.position - entity.position).sqrMagnitude < radius * radius) { var components = target.GetComponents(typeof(ISabotagable)); foreach (var c in components) { (c as ISabotagable).Sabotage(); } ComSat.DestroyEntity(entity, DestroyReason.HitTarget); } } if (moving) { if ((destination - entity.position).sqrMagnitude < sqrPositioningAccuracy) { // Close enough. moving = false; motor.Stop(); } else { motor.MoveTowards(destination); } } }
private static void CalcComponentsChangeInOneEntity(Entity currEntity, Entity prevEntity, List <ComponentChange> changes) { foreach (var currComponent in currEntity.GetComponents()) { var prevComponent = prevEntity.GetComponent(currComponent.GetType()); if (prevComponent == null && currComponent != null) { // Add component. var change = new ComponentChange(currEntity.Id, false, prevComponent, currComponent); changes.Add(change); } else { // Change component. var change = new ComponentChange(currEntity.Id, false, prevComponent, currComponent); if (!prevComponent.Equals(currComponent)) { changes.Add(change); } } } foreach (var prevComponent in prevEntity.GetComponents()) { if (currEntity.GetComponent(prevComponent.GetType()) != null) { continue; } // Remove components. var change = new ComponentChange(currEntity.Id, true, prevComponent, null); changes.Add(change); } }
public void AddsComponentAndReturnsItselfForComponent() { Entity target = EmptyEntity(); Assert.Equal(target, target.AddComponent(new FakeComponent1())); Assert.Single(target.GetComponents()); }
public void OnNewEntity(Entity entity) { if (entity.HasMask(ComponentTypes.COMPONENT_RENDER_TO_FRAME_BUFFER)) { var fList = entity.GetComponents(ComponentTypes.COMPONENT_RENDER_TO_FRAME_BUFFER); bool renderToMain = false; foreach (var fL in fList) { var f = fL as ComponentRenderToFrameBuffer; if (!frameBufferRenders.ContainsKey(f.BufferName)) { frameBufferRenders.Add(f.BufferName, new List <Entity>()); } frameBufferRenders[f.BufferName].Add(entity); renderToMain = f.RenderToMainBuffer; } if (!renderToMain) { return; } } if (entity.HasMask(MASK_3D) || entity.HasMask(MASK_TEXT)) { _entities.Add(entity); } }
public override void Run(Entity entity) { if (!(entity.HasComponent <Destination>() && entity.HasComponent <Actor>() && entity.GetComponent <Actor>().Energy >= 10)) { return; } var locationEntities = _em.GetAllEntitiesWithComponent <Location>() .Where(e => e.HasComponent <Actor>() || e.HasComponent <IsDoor>()); entity.GetComponent <Actor>().Energy -= 10; var allComponents = entity.GetComponents(); var current = entity.GetComponent <Location>(); var desired = entity.GetComponent <Destination>(); if (_map != null && desired != null && desired.X >= 0 && desired.X < _map.Width && desired.Y >= 0 && desired.Y < _map.Height) { var start = _map.GetCell(current.X, current.Y); var dest = _map.GetCell(desired.X, desired.Y); var path = _pathfinder.TryFindShortestPath(start, dest); _isClear = true; if (path != null && path.Length > 1) { var next = path.StepForward(); ResolveCollisions(entity, locationEntities, current, next); if (_isClear) { current.X = next.X; current.Y = next.Y; } } } }
public void Run() { for (int i = 0; i < n; i++) { _e.GetComponents(); } }
private void RefreshEntity(Entity entity) { EntityMasterComponent[] masters = entity.GetComponents <EntityMasterComponent>(); for (int i = masters.Length - 1; i >= 0; i--) { masters[i].Refresh(); } }
/// <summary> /// Remove an entity from the scene. /// </summary> /// <param name="entity">Die Entity, die entfernt werden soll.</param> public void Remove(Entity entity) { foreach (Component c in entity.GetComponents()) { c.OnRemove(); } Entities.Remove(entity); }
/// <summary> /// beräknar rörelsen som ändrar rörelsevektorn för att ta hänsyn till eventuella /// kollisioner som kommer att inträffa vid rörelse /// </summary> /// <returns><c>true</c> Om Rörelsen Blev Uträknad <c>false</c> Om Inte.</returns> /// <param name="rörelse"> Rörelse.</param> /// <param name="kollitionsResultat"> Kollitions Resultat.</param> public bool BeräknaRörelse(ref Vector2 rörelse, out CollisionResult kollitionsResultat) { kollitionsResultat = new CollisionResult(); // ingen kolliderare? Strunta i det och förflytta dig bara if (Entity.GetComponent <Collider>() == null || TriggerHjälpare == null) { return(false); } // 1. flytta alla icke-trigger Kollisioner och få närmaste kollision List <Collider> kolliders = Entity.GetComponents <Collider>(); for (int i = 0; i < kolliders.Count; i++) { Collider kollider = kolliders[i]; // hoppa över triggers för tillfället. //vi kommer tillbaka till de när vi förflyttar oss. if (kollider.IsTrigger) { continue; } // hämta allt som vi kan kollidera med vid den nya positionen RectangleF gränser = kollider.Bounds; gränser.X += rörelse.X; gränser.Y += rörelse.Y; Grannar = Physics.BoxcastBroadphaseExcludingSelf(kollider, ref gränser, kollider.CollidesWithLayers); foreach (Collider granne in Grannar) { // hoppa över triggers för tillfället. //vi kommer tillbaka till de när vi förflyttar oss. if (granne.IsTrigger) { continue; } if (kollider.CollidesWith(granne, rörelse, out CollisionResult InternKollitionsResultat)) { // vid träff. dra vi undan våran rörelse rörelse -= InternKollitionsResultat.MinimumTranslationVector; // Om vi träffar flera objekt, kolla bara med den första för att förenkla. if (InternKollitionsResultat.Collider != null) { kollitionsResultat = InternKollitionsResultat; } } } } ListPool <Collider> .Free(kolliders); return(kollitionsResultat.Collider != null); }
public EntityWrapper(GameController Poe, Entity entity) { gameController = Poe; internalEntity = entity; components = internalEntity.GetComponents(); Path = internalEntity.Path; cachedId = internalEntity.Id; LongId = internalEntity.LongId; }
void assertHasNotComponentA(Entity e) { var components = e.GetComponents(); components.Length.should_be(0); var indices = e.GetComponentIndices(); indices.Length.should_be(0); e.HasComponentA().should_be_false(); e.HasComponents(_indicesA).should_be_false(); e.HasAnyComponent(_indicesA).should_be_false(); }
/// <summary> /// caculates the movement modifying the motion vector to take into account any collisions that will /// occur when moving /// </summary> /// <returns><c>true</c>, if movement was calculated, <c>false</c> otherwise.</returns> /// <param name="motion">Motion.</param> /// <param name="collisionResult">Collision result.</param> public bool CalculateMovement(ref Vector2 motion, out CollisionResult collisionResult) { collisionResult = new CollisionResult(); // no collider? just move and forget about it if (Entity.GetComponent <Collider>() == null || _triggerHelper == null) { return(false); } // 1. move all non-trigger Colliders and get closest collision var colliders = Entity.GetComponents <Collider>(); for (var i = 0; i < colliders.Count; i++) { var collider = colliders[i]; // skip triggers for now. we will revisit them after we move. if (collider.IsTrigger) { continue; } // fetch anything that we might collide with at our new position var bounds = collider.Bounds; bounds.X += motion.X; bounds.Y += motion.Y; var neighbors = Physics.BoxcastBroadphaseExcludingSelf(collider, ref bounds, collider.CollidesWithLayers); foreach (var neighbor in neighbors) { // skip triggers for now. we will revisit them after we move. if (neighbor.IsTrigger) { continue; } if (collider.CollidesWith(neighbor, motion, out CollisionResult _InternalcollisionResult)) { // hit. back off our motion //motion -= _InternalcollisionResult.MinimumTranslationVector; // If we hit multiple objects, only take on the first for simplicity sake. if (_InternalcollisionResult.Collider != null) { collisionResult = _InternalcollisionResult; } } } } ListPool <Collider> .Free(colliders); return(collisionResult.Collider != null); }
public void RemovesAndReturnsComponentForExistentType() { Entity target = EmptyEntity(); var component = new FakeComponent1(); target.AddComponent(component); Assert.Equal(component, target.RemoveComponent <FakeComponent1>()); Assert.Empty(target.GetComponents()); }
/// <summary> /// Returns a string template for creating more entities with the same parameters. /// </summary> /// <param name="entity"></param> /// <returns></returns> public Dictionary <string, IComponent> GetEntityPrototype(Entity entity) { var components = entity.GetComponents(); var dict = new Dictionary <string, IComponent>(); foreach (var c in components) { dict.Add(c.GetType().Name, c); } return(dict); }
/// <summary> /// Get a body part by name. /// </summary> public Entity GetPartByName(string name) { foreach (BodyPart part in Entity.GetComponents <BodyPart>()) { if (part.Name == name) { return(part.Entity); } } return(null); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); Entity entity = target as Entity; if (entity == null) { return; } EditorGUILayout.LabelField(string.Concat("Entity: ", entity.gameObject.name)); EditorGUILayout.Space(); string[] tags = entity.GetTags(); EditorGUILayout.BeginHorizontal(); _currentTagAddString = EditorGUILayout.TextField("Add Tag: ", _currentTagAddString); if (GUILayout.Button("+", GUILayout.Width(30))) { entity.AddTag(_currentTagAddString); _currentTagAddString = string.Empty; EditorUtility.SetDirty(entity); } EditorGUILayout.EndHorizontal(); for (int i = 0; i < tags.Length; i++) { EditorGUILayout.BeginHorizontal(); GUIStyle s = new GUIStyle(GUI.skin.label); s.normal.textColor = new Color(0.5f, 0.3f, 0.6f); s.fontStyle = FontStyle.BoldAndItalic; GUILayout.Label(" * " + tags[i], s); s = new GUIStyle(GUI.skin.button); s.normal.textColor = Color.red; if (GUILayout.Button("x", s, GUILayout.Width(25))) { entity.RemoveTag(tags[i]); EditorUtility.SetDirty(entity); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Entity Components: "); EntityComponent[] entityComponents = entity.GetComponents <EntityComponent>(); for (int i = 0; i < entityComponents.Length; i++) { GUILayout.Label(" * " + entityComponents[i].GetType().Name + " (Script)", EditorStyles.boldLabel); } }
public void OnlyGetsComponentsThatExist() { Entity entity = new Entity(Guid.NewGuid()); var testString = new Component <string>("something"); entity.SetComponent <Component <string> >(testString); var result = entity.GetComponents <Component <string>, Component <int> >(); Assert.False(result.HasValue); }
/// <summary> /// Calculates the movement modifying the motion vector to take into account any collisions that will /// occur when moving. This version is modified to output through a given collection to show every /// collision that occured. /// </summary> /// <returns>The amount of collisions that occured.</returns> /// <param name="motion">Motion.</param> /// <param name="collisionResult">Collision result.</param> public int AdvancedCalculateMovement(ref Vector2 motion, ICollection <CollisionResult> collisionResults) { int Collisions = 0; // no collider? just move and forget about it if (Entity.GetComponent <Collider>() == null || _triggerHelper == null) { return(Collisions); } // 1. move all non-trigger Colliders and get closest collision var colliders = Entity.GetComponents <Collider>(); for (var i = 0; i < colliders.Count; i++) { var collider = colliders[i]; // skip triggers for now. we will revisit them after we move. if (collider.IsTrigger) { continue; } // fetch anything that we might collide with at our new position var bounds = collider.Bounds; bounds.X += motion.X; bounds.Y += motion.Y; var neighbors = Physics.BoxcastBroadphaseExcludingSelf(collider, ref bounds, collider.CollidesWithLayers); foreach (var neighbor in neighbors) { // skip triggers for now. we will revisit them after we move. if (neighbor.IsTrigger) { continue; } if (collider.CollidesWith(neighbor, motion, out CollisionResult _InternalcollisionResult)) { // hit. back off our motion motion -= _InternalcollisionResult.MinimumTranslationVector; collisionResults.Add(_InternalcollisionResult); Collisions++; } } } ListPool <Collider> .Free(colliders); return(Collisions); }
protected bool ArgumentIsEntityComponent(string argument, Entity targetEntity, out EntityComponent targetComponent) { targetComponent = null; foreach (EntityComponent entityComponent in targetEntity.GetComponents <EntityComponent>()) { if (entityComponent.GetCurrentIdentifier() != argument) { continue; } targetComponent = entityComponent; } return(targetComponent != null); }
private void DebugItem(Entity itemEntity) { ItemDebugLines = new List <string>(); LogMessage(itemEntity.Path, 0); var components = itemEntity.GetComponents(); var game = GameController.Game; ItemDebugLines.Add("Path: " + itemEntity.Path); ItemDebugLines.Add("Address: " + itemEntity.Address.ToString("x")); BaseItemType BIT = GameController.Files.BaseItemTypes.Translate(itemEntity.Path); if (BIT != null) { ItemDebugLines.Add("===== BaseItemTypeInfo: ======"); DebugProperty(typeof(BaseItemType), BIT, 1); ItemDebugLines.Add("=============================="); } foreach (var component in components) { ItemDebugLines.Add(""); Type compType = null; if (!PoeHUDComponents.TryGetValue(component.Key, out compType)) { ItemDebugLines.Add($"<{component.Key}> (Not implemented in PoeHUD)"); ItemDebugLines.Add($"{DIVIDER}Address: {component.Value.ToString("x")}"); continue; } ItemDebugLines.Add($"<{component.Key}>:"); object instance = Activator.CreateInstance(compType); var addrProp = compType.GetProperty("Address", setPropFlags); addrProp.SetValue(instance, component.Value); var gameProp = compType.GetProperty("Game", setPropFlags); gameProp.SetValue(instance, game); var mamoryProp = compType.GetProperty("M", setPropFlags); mamoryProp.SetValue(instance, Memory); DebugProperty(compType, instance, 1); } var path = Path.Combine(PluginDirectory, "_ItemDebugInfo.txt"); File.WriteAllText(path, string.Join(Environment.NewLine, ItemDebugLines.ToArray()).Replace(DIVIDER, "\t")); }
protected void AssertHasNotComponentA(Entity <ITestPool> e) { var components = e.GetComponents(); Assert.AreEqual(0, components.Length); var types = e.GetComponentsTypes(); Assert.AreEqual(0, types.Length); Assert.IsFalse(e.Has <TestComponentA>()); Assert.IsFalse(e.Has(typeof(TestComponentA))); Assert.IsFalse(e.HasAny(typeof(TestComponentA))); }
public Blueprint(string poolIdentifier, string name, Entity entity) { this.poolIdentifier = poolIdentifier; this.name = name; var allComponents = entity.GetComponents(); var componentIndices = entity.GetComponentIndices(); components = new ComponentBlueprint[allComponents.Length]; for (int i = 0, componentsLength = allComponents.Length; i < componentsLength; i++) { components[i] = new ComponentBlueprint(componentIndices[i], allComponents[i]); } }
private void DestroyEntity(ICommonSessionObjects sessionObjects, Entity entity) { foreach (var comp in entity.GetComponents()) { if (comp is IAssetComponent) { ((IAssetComponent)comp).Recycle(sessionObjects.AssetManager); } } if (sessionObjects.AssetManager != null) { sessionObjects.AssetManager.LoadCancel(entity); } }
public void GetsMultipleComponents() { Entity entity = new Entity(Guid.NewGuid()); var testString = new Component <string>("something"); var testInt = new Component <int>(4); entity.SetComponent <Component <string> >(testString); entity.SetComponent <Component <int> >(testInt); var result = entity.GetComponents <Component <string>, Component <int> >(); Assert.True(result.HasValue); Assert.Equal("something", result.Value.Item1); Assert.Equal((int)4, (int)result.Value.Item2); }
public override void Process(Entity entity) { var spawners = entity.GetComponents <BulletSpawnerComponent>(); foreach (BulletSpawnerComponent spawner in spawners) { spawner.Cooldown -= Time.DeltaTime; if (spawner.Cooldown <= 0) { spawner.Cooldown = 0.5f; CreateBullet(entity.Position.X, entity.Position.Y, spawner.polyPoints, entity, spawner.direction); } } }
void assertHasComponentA(Entity e, IComponent component = null) { if (component == null) { component = Component.A; } e.GetComponentA().should_be_same(component); var components = e.GetComponents(); components.Length.should_be(1); components.should_contain(component); var indices = e.GetComponentIndices(); indices.Length.should_be(1); indices.should_contain(CID.ComponentA); e.HasComponentA().should_be_true(); e.HasComponents(_indicesA).should_be_true(); e.HasAnyComponent(_indicesA).should_be_true(); }
public static void DrawComponents(Pool pool, Entity entity) { bool[] unfoldedComponents; if (!_poolToUnfoldedComponents.TryGetValue(pool, out unfoldedComponents)) { unfoldedComponents = new bool[pool.totalComponents]; for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } _poolToUnfoldedComponents.Add(pool, unfoldedComponents); } EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var componentNames = entity.poolMetaData.componentNames; var index = EditorGUILayout.Popup("Add Component", -1, componentNames); if (index >= 0) { var componentType = entity.poolMetaData.componentTypes[index]; var component = (IComponent)Activator.CreateInstance(componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); EntitasEditorLayout.BeginHorizontal(); { _componentNameSearchTerm = EditorGUILayout.TextField("Search", _componentNameSearchTerm); const string clearButtonControlName = "Clear Button"; GUI.SetNextControlName(clearButtonControlName); if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) { _componentNameSearchTerm = string.Empty; GUI.FocusControl(clearButtonControlName); } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (int i = 0; i < components.Length; i++) { DrawComponent(unfoldedComponents, entity, indices[i], components[i]); } } EntitasEditorLayout.EndVertical(); }
public static void DrawEntity(Pool pool, Entity entity) { var bgColor = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUILayout.Button("Destroy Entity")) { pool.DestroyEntity(entity); } GUI.backgroundColor = bgColor; bool[] unfoldedComponents; if (!_poolToUnfoldedComponents.TryGetValue(pool, out unfoldedComponents)) { unfoldedComponents = new bool[pool.totalComponents]; for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } _poolToUnfoldedComponents.Add(pool, unfoldedComponents); } EntitasEditorLayout.BeginVerticalBox(); { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EntitasEditorLayout.EndHorizontal(); EditorGUILayout.Space(); var componentNames = entity.poolMetaData.componentNames; var index = EditorGUILayout.Popup("Add Component", -1, componentNames); if (index >= 0) { var componentType = entity.poolMetaData.componentTypes[index]; var component = (IComponent)Activator.CreateInstance(componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); _componentNameSearchTerm = EditorGUILayout.TextField("Search", _componentNameSearchTerm); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (int i = 0; i < components.Length; i++) { DrawComponent(unfoldedComponents, entity, indices[i], components[i]); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Retained by (" + entity.retainCount + ")", EditorStyles.boldLabel); #if !ENTITAS_FAST_AND_UNSAFE EntitasEditorLayout.BeginVerticalBox(); { foreach (var owner in entity.owners.ToArray()) { EntitasEditorLayout.BeginHorizontal(); { EditorGUILayout.LabelField(owner.ToString()); if (GUILayout.Button("Release", GUILayout.Width(88), GUILayout.Height(14))) { entity.Release(owner); } EntitasEditorLayout.EndHorizontal(); } } } EntitasEditorLayout.EndVertical(); #endif } EntitasEditorLayout.EndVertical(); }