/// <summary> /// Finds the nearest entity that matches the tag. /// </summary> /// <param name="tag">Tag to filter.</param> /// <returns>The nearest entity that matches the tag, or null if none was found.</returns> public Entity FindNearest(EntityTags tag = EntityTags.Any, bool recursive = false) { Entity nearest = null; float nearestDistance = float.MaxValue; foreach (var entity in Awareness) { float distance = entity.DistanceTo(Owner.Owner); if (distance < nearestDistance) { if (entity.TagList.HasTag(tag)) { nearest = entity; nearestDistance = distance; } else if (recursive) { Entity found = FindInInventory(entity.Inventory, tag); if (found != null) { nearest = found; nearestDistance = distance; } } } } return(nearest); }
/// <summary> /// Fetch all active entities within a range that match a tag in this chunk /// </summary> /// <param name="entity">The entity to compare to</param> /// <param name="range">The maximum range</param> /// <param name="tag">The tag to match</param> /// <returns>An array of matching entities, or null if none were found</returns> public Entity[] GetAllEntitiesInRange(Entity entity, float range, EntityTags tag = EntityTags.Any) { if (TagDictionary.ContainsKey(tag)) { LinkedList <Entity> matches = TagDictionary[tag]; if (matches.Count > 0) { LinkedList <Entity> entitiesInRange = new LinkedList <Entity>(); foreach (var match in matches) { if (match == entity) { continue; } float distance = Vector2.Distance(match.transform.position, entity.transform.position); if (distance < range) { entitiesInRange.AddLast(match); } } if (entitiesInRange.Count > 0) { Entity[] returnArray = new Entity[entitiesInRange.Count]; entitiesInRange.CopyTo(returnArray, 0); return(returnArray); } } } return(null); }
/// <summary> /// Fetch the nearest entity to a position within a range that matches a tag in this chunk /// </summary> /// <param name="entity">The entity to compare to</param> /// <param name="range">The maximum range</param> /// <param name="tag">The tag to match</param> /// <returns>Nearest matching entity, or null if none were found</returns> public Entity GetNearestEntityInRange(Entity entity, float range, EntityTags tag = EntityTags.Any) { Entity nearestEntity = null; if (TagDictionary.ContainsKey(tag)) { LinkedList <Entity> matches = TagDictionary[tag]; float nearestDistance = range; foreach (var match in matches) { if (match == entity) { continue; } float distance = Vector2.Distance(match.transform.position, entity.transform.position); if (distance < nearestDistance) { nearestEntity = match; nearestDistance = distance; } } } return(nearestEntity); }
public bool HasTag(EntityTags tag) { if (tag == EntityTags.Any) { return(true); } return(Tags.Contains(tag)); }
private void DestroyEntitiesWithTag(EntityTag tag) { var gameObjects = GameObject.FindGameObjectsWithTag(EntityTags.ToString(tag)); for (var i = 0; i < gameObjects.Length; i++) { Destroy(gameObjects[i]); } }
public static bool HasEntityTagUpward(this GameObject go, EntityTags tagToCheck) { for (Transform g = go.transform; g != null; g = g.transform.parent) { if (g.gameObject.HasEntityTag(tagToCheck)) { return(true); } } return(false); }
/// <summary> /// Fetch all active entities that match a tag in this chunk /// </summary> /// <param name="tag">The tag to match</param> /// <returns>An array of matching entities, or null if none were found</returns> public Entity[] GetAllEntities(EntityTags tag = EntityTags.Any) { if (TagDictionary.ContainsKey(tag)) { LinkedList <Entity> matches = TagDictionary[tag]; if (matches.Count > 0) { Entity[] returnArray = new Entity[matches.Count]; matches.CopyTo(returnArray, 0); return(returnArray); } } return(null); }
/// <summary> /// Searches this inventory for an entity that has a certain tag. /// </summary> /// <param name="name">The tag to filter</param> /// <returns>The first stored stack that has the tag (may be null)</returns> public StackingModule Search(EntityTags tag) { foreach (var item in Storage) { if (item != null) { if (item.Owner.TagList.HasTag(tag)) { return(item); } } } return(null); }
/// <summary> /// Finds all entities that matches the tag. /// </summary> /// <param name="tag">Tag to filter.</param> /// <returns>A list of entities that match the tag, or an empty list if none were found.</returns> public List <Entity> FindAll(EntityTags tag = EntityTags.Any, bool recursive = false) { List <Entity> list = new List <Entity>(); foreach (var entity in Awareness) { if (entity.TagList.HasTag(tag)) { list.Add(entity); } if (recursive) { FindAllInInventory(entity.Inventory, list, tag); } } return(list); }
public override string ToString() { return(string.Join(",", new List <string> { s_statusesConverter.ConvertToString(Status).ToLowerInvariant().WithPrefixAndParentheses("status"), string.Join(",", SeverityLevel.Select(x => s_severityLevelsConverter.ConvertToString(x).ToLowerInvariant())).WithPrefixAndParentheses("severityLevel"), string.Join(",", ImpactLevel.Select(x => s_impactLevelsConverter.ConvertToString(x).ToLowerInvariant())).WithPrefixAndParentheses("impactLevel"), string.Join(",", RootCauseEntities).WithPrefixAndParentheses("rootCauseEntity"), string.Join(",", ManagementZoneIds).WithPrefixAndParentheses("managementZoneIds"), string.Join(",", ManagementZoneNames).WithPrefixAndParentheses("managementZones"), string.Join(",", ImpactedEntities).WithPrefixAndParentheses("impactedEntities"), string.Join(",", AffectedEntities).WithPrefixAndParentheses("affectedEntities"), string.Join(",", AffectedEntityTypes).WithPrefixAndParentheses("affectedEntityTypes"), string.Join(",", ProblemIds).WithPrefixAndParentheses("problemId"), string.Join(",", ProblemFilterIds).WithPrefixAndParentheses("problemFilterIds"), string.Join(",", ProblemFilterNames).WithPrefixAndParentheses("problemFilterNames"), string.Join(",", EntityTags.Select(kvp => $"{kvp.Key}:{kvp.Value}")).WithPrefixAndParentheses("entityTags"), string.Join(",", DisplayIds).WithPrefixAndParentheses("displayId") })); }
/// <summary> /// Finds the first entity that matches the tag. Priority is defined by the order the items were detected by the brain. /// </summary> /// <param name="tag">Tag to filter.</param> /// <param name="recursive">Whether to search recursively for childed entities.</param> /// <returns>The first entity that matches the tag, or null if none was found.</returns> public Entity Find(EntityTags tag = EntityTags.Any, bool recursive = false) { foreach (var entity in Awareness) { if (entity.TagList.HasTag(tag)) { return(entity); } if (recursive) { Entity found = FindInInventory(entity.Inventory, tag); if (found != null) { return(found); } } } return(null); }
private Entity FindInInventory(InventoryModule inventory, EntityTags tag) { if (inventory == null) { return(null); } foreach (var item in inventory.Storage.GetContents()) { if (item.Owner.TagList.HasTag(tag)) { return(item.Owner); } Entity found = FindInInventory(item.Owner.Inventory, tag); if (found != null) { return(found); } } return(null); }
private void ShowEntityComponents() { if (_entityNames.Length != _activeEntities.Count) { _entityNames = new string[_activeEntities.Count]; for (int i = 0; i < _activeEntities.Count; i++) { _entityNames[i] = _activeEntities[i].Name; } } _entityIndex = EditorGUILayout.Popup(_entityIndex, _entityNames); if (!_activeEntities.HasIndex(_entityIndex)) { EditorGUILayout.LabelField("No Entity " + _entityIndex); return; } var entity = _activeEntities[_entityIndex]; if (entity == null) { EditorGUILayout.LabelField("Null Entity " + _entityIndex); return; } EditorGUILayout.BeginVertical(); for (int i = 0; i < entity.Tags.Tags.Length; i++) { if (entity.Tags.Tags[i] > 0) { EditorGUILayout.LabelField("Tag " + EntityTags.GetNameAt(i)); } } foreach (var componentReference in entity.GetAllComponents()) { EditorGUILayout.BeginHorizontal(); System.Type type = componentReference.Array.ArrayType; EditorGUILayout.LabelField("Type: " + type.Name); var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public; var fields = type.GetFields(bindingFlags); System.Object instance = componentReference.Get(); List <object> fieldValues = null; if (instance != null) { fieldValues = fields.Select(field => field.GetValue(instance)).ToList(); } EditorGUILayout.BeginVertical(); for (int i = 0; i < fields.Length; i++) { var field = fields[i].FieldType.Name; field = field.Replace("PixelComrades.", ""); field = field.Replace("DungeonCrawler.", ""); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(field); EditorGUILayout.LabelField(fields[i].Name); if (instance == null || !fieldValues.HasIndex(i) || fieldValues[i] == null) { EditorGUILayout.EndHorizontal(); continue; } EditorGUILayout.LabelField(fieldValues[i].ToString()); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.LabelField("Stats"); var stats = entity.Get <StatsContainer>(); if (stats == null) { EditorGUILayout.LabelField("No Stats"); EditorGUILayout.EndVertical(); return; } for (int i = 0; i < stats.Count; i++) { EditorGUILayout.LabelField(stats[i].ToString()); } EditorGUILayout.EndVertical(); }
private void Awake() { _collider.radius = _detectData.radius; _objectTag = EntityTags.ToString(_tag); }
private void FindAllInInventory(InventoryModule inventory, List <Entity> list, EntityTags tag) { if (inventory == null) { return; } foreach (var item in inventory.Storage.GetContents()) { if (item.Owner.TagList.HasTag(tag)) { list.Add(item.Owner); } FindAllInInventory(item.Owner.Inventory, list, tag); } }
private void Awake() { _enemyTag = EntityTags.ToString(EntityTag.Enemy); }
public static bool HasNoEntityTag(this GameObject go, EntityTags tagToCheck) { return((go.EntityTags & (long)tagToCheck) == 0); }
private void OnAddElement(ReorderableList list) { EntityTags tag = EntityTags.Any; Target.Tags.Add(tag); }
/// <summary> /// Fetch the nearest entity to a position that matches a tag in this chunk /// </summary> /// <param name="entity">The entity to compare to</param> /// <param name="tag">The tag to match</param> /// <returns>Nearest matching entity, or null if none were found</returns> public Entity GetNearestEntity(Entity entity, EntityTags tag = EntityTags.Any) { return(GetNearestEntityInRange(entity, float.PositiveInfinity, tag)); }