public override bool HandlePropertyValuesChanged(
            IReadOnlyList <IPropertyValueChange> changes, TEntity entity, IEntityGroup <TEntity> group)
        {
            if (base.HandlePropertyValuesChanged(changes, entity, group) ||
                !ContainsEntity(entity))
            {
                return(true);
            }

            foreach (var entityIndex in _changeListeners)
            {
                entityIndex.HandlePropertyValuesChanged(changes, entity, this);
            }

            if (_propertyValueChangedMessageNames != null)
            {
                foreach (var change in changes)
                {
                    if (_propertyValueChangedMessageNames.TryGetValue(change.ChangedPropertyName, out var messageName) &&
                        entity.HasComponent(change.ChangedComponent.ComponentId))
                    {
                        change.EnqueuePropertyValueChangedMessage <TEntity>(messageName, entity.Manager);
                    }
                }
            }

            return(false);
        }
示例#2
0
 /// <summary>
 /// 初始化隐藏实体完成事件的新实例。
 /// </summary>
 /// <param name="entityId">实体编号。</param>
 /// <param name="entityAssetName">实体资源名称。</param>
 /// <param name="entityGroup">实体所属的实体组。</param>
 /// <param name="userData">用户自定义数据。</param>
 public HideEntityCompleteEventArgs(int entityId, string entityAssetName, IEntityGroup entityGroup, object userData)
 {
     EntityId        = entityId;
     EntityAssetName = entityAssetName;
     EntityGroup     = entityGroup;
     UserData        = userData;
 }
示例#3
0
 public override IEntity CreateEntity(object entityInstance, IEntityGroup entityGroup, object userData)
 {
     GameObject gameObject = entityInstance as gameObject;
     Transform transform = gameObject.transform;
     transform.SetParent((MonoBehaviour)entityGroup.Helper).transform);
     return gameObject.GetOrAddComponent<Entity>();
 }
示例#4
0
        /// <summary>
        /// 实体初始化。
        /// </summary>
        /// <param name="entityId">实体编号。</param>
        /// <param name="entityGroup">实体所属的实体组。</param>
        /// <param name="isNewInstance">是否是新实例。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void OnInit(int entityId, IEntityGroup entityGroup, bool isNewInstance, object userData)
        {
            m_Id = entityId;
            if (isNewInstance)
            {
                m_EntityGroup = entityGroup;
            }
            else if (m_EntityGroup != entityGroup)
            {
                Log.Error("Entity group is inconsistent for non-new-instance entity.");
                return;
            }

            ShowEntityInfo showEntityInfo  = userData as ShowEntityInfo;
            Type           entityLogicType = showEntityInfo.EntityLogicType;

            if (entityLogicType == null)
            {
                Log.Error("Entity logic type is invalid.");
                return;
            }

            m_EntityLogic = gameObject.AddComponent(entityLogicType) as EntityLogic;
            if (m_EntityLogic == null)
            {
                Log.Error("Can not add entity logic.");
                return;
            }

            m_EntityLogic.OnInit(showEntityInfo.UserData);
        }
            public void HandleEntityRemoved(
                GameEntity entity, Component removedComponent, IEntityGroup <GameEntity> group)
            {
                Assert.Same(_testEntity, entity);
                Assert.Same(_group, group);

                GroupChangesDetected++;
            }
示例#6
0
        /// <summary>
        /// 实体初始化。
        /// </summary>
        /// <param name="entityId">实体编号。</param>
        /// <param name="entityAssetName">实体资源名称。</param>
        /// <param name="entityGroup">实体所属的实体组。</param>
        /// <param name="isNewInstance">是否是新实例。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void OnInit(int entityId, string entityAssetName, IEntityGroup entityGroup, bool isNewInstance, object userData)
        {
            m_Id = entityId;
            m_EntityAssetName = entityAssetName;
            if (isNewInstance)
            {
                m_EntityGroup = entityGroup;
            }
            else if (m_EntityGroup != entityGroup)
            {
                Log.Error("Entity group is inconsistent for non-new-instance entity.");
                return;
            }

            ShowEntityInfo showEntityInfo  = (ShowEntityInfo)userData;
            Type           entityLogicType = showEntityInfo.EntityLogicType;

            if (entityLogicType == null)
            {
                Log.Error("Entity logic type is invalid.");
                return;
            }

            if (m_EntityLogic != null)
            {
                if (m_EntityLogic.GetType() == entityLogicType)
                {
                    m_EntityLogic.enabled = true;
                    return;
                }

                Destroy(m_EntityLogic);
                m_EntityLogic = null;
            }

            m_EntityLogic = gameObject.GetComponent(entityLogicType) as EntityLogic;

            if (m_EntityLogic == null)
            {
                m_EntityLogic = gameObject.AddComponent(entityLogicType) as EntityLogic;
            }

            if (m_EntityLogic == null)
            {
                Log.Error("Entity '{0}' can not add entity logic.", entityAssetName);
                return;
            }

            try
            {
                m_EntityLogic.OnInit(showEntityInfo.UserData);
            }
            catch (Exception exception)
            {
                Log.Error("Entity '[{0}]{1}' OnInit with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
            }
        }
示例#7
0
        public override IEntityGroup GetEntities()
        {
            targetableEntities = EntityManager.Entities.Filter(typeof(TransformComponent));

            return EntityManager.Entities.Filter(new[]
            {
                typeof(TransformComponent),
                typeof(TargetBase)
            });
        }
 protected EntityIndexBase(
     string name,
     IEntityGroup <TEntity> group,
     IKeyValueGetter <TEntity, TKey> keyValueGetter)
 {
     Name           = name;
     KeyValueGetter = keyValueGetter;
     group.AddListener(this);
     Group = group;
 }
示例#9
0
        public override IEntityGroup GetEntities()
        {
            targetableEntities = EntityManager.Entities.Filter(typeof(TransformComponent));

            return(EntityManager.Entities.Filter(new[]
            {
                typeof(TransformComponent),
                typeof(TargetBase)
            }));
        }
        public override bool HandlePropertyValuesChanged(
            IReadOnlyList <IPropertyValueChange> changes, TEntity entity, IEntityGroup <TEntity> group)
        {
            if (base.HandlePropertyValuesChanged(changes, entity, group))
            {
                return(true);
            }

            Component componentUsed = null;

            for (var i = 0; i < changes.Count; i++)
            {
                var change = changes[i];
                if (_sortValueGetter.PropertyUsed(change.ChangedComponent.ComponentId, change.ChangedPropertyName))
                {
                    componentUsed = change.ChangedComponent;
                    break;
                }

                // The component might have been removed by the previous change listener
                if (!entity.HasComponent(change.ChangedComponent.ComponentId))
                {
                    return(true);
                }
            }

            if (componentUsed == null)
            {
                return(false);
            }

            if (!KeyValueGetter.TryGetKey(entity, new IPropertyValueChange[0], getOldValue: false, out var key))
            {
                return(true);
            }

            var entities = GetOrAddEntities(key);

            if (_sortValueGetter.TryGetKey(entity, changes, getOldValue: true, out var oldSortKey))
            {
                entities.Remove(oldSortKey);
            }

            if (_sortValueGetter.TryGetKey(entity, changes, getOldValue: false, out var newSortKey))
            {
                entities.Add(newSortKey, entity);
            }

            if (entities.Count == 0)
            {
                Index.Remove(key);
            }

            return(true);
        }
示例#11
0
        public IEntityGroup[] GetAllEntityGroups()
        {
            int index = 0;
            IEntityGroup[] results = new IEntityGroup[m_EntityGroups.Count];
            foreach (KeyValuePair<string, EntityGroup> entityGroup in m_EntityGroups)
            {
                results[index++] = entityGroup.Value;
            }

            return results;
        }
示例#12
0
        /// <summary>
        /// 获取所有实体组。
        /// </summary>
        /// <returns>所有实体组。</returns>
        public IEntityGroup[] GetAllEntityGroups()
        {
            int index = 0;

            IEntityGroup[] entityGroups = new IEntityGroup[m_EntityGroups.Count];
            foreach (EntityGroup entityGroup in m_EntityGroups.Values)
            {
                entityGroups[index++] = entityGroup;
            }

            return(entityGroups);
        }
示例#13
0
 public void HandleEntityRemoved(
     TEntity entity, Component removedComponent, IEntityGroup <TEntity> group)
 {
     if (KeyValueGetter.TryGetKey(
             entity,
             new IPropertyValueChange[] { new PropertyValueChange <object>(removedComponent) },
             getOldValue: false,
             out var keyValue))
     {
         TryRemoveEntity(keyValue, entity, removedComponent);
     }
 }
        /// <summary>
        /// 创建实体
        /// </summary>
        /// <param name="entityInstance">实体实例</param>
        /// <param name="entityGroup">实体所属的实体组</param>
        /// <param name="userData">用户自定义数据</param>
        /// <returns>实体</returns>
        public override IEntity CreateEntity(object entityInstance, IEntityGroup entityGroup, object userData)
        {
            GameObject gameObject = entityInstance as GameObject;

            if (gameObject == null)
            {
                Log.Error("[DefaultEntityHelper.CreateEntity] Entity instance is invalid.");
                return(null);
            }

            gameObject.transform.SetParent((entityGroup.Helper as MonoBehaviour).transform);
            return(gameObject.GetOrAddComponent <Entity>());
        }
            public void HandleEntityAdded(TEntity entity, Component addedComponent, IEntityGroup <TEntity> group)
            {
                if (_relationship.OrphanedEntities != null &&
                    _relationship.OrphanedEntities.TryGetValue(entity.Id, out var orphanedEntities))
                {
                    _relationship.OrphanedEntities.Remove(entity.Id);

                    foreach (var orphanedEntity in orphanedEntities)
                    {
                        _relationship.AddEntity(
                            entity.Id, orphanedEntity, changedComponent: null, entity);
                    }
                }
            }
示例#16
0
    public override IEntityGroup GetEntities()
    {
        quarkEntities = EntityManager.Entities.Filter(EntityGroups.Fermion).Filter(new Type[]
        {
            typeof(HexagonComponent),
        });
        electronEntities = EntityManager.Entities.Filter(EntityGroups.Fermion).Filter(new Type[]
        {
            typeof(TimeComponent),
            typeof(FollowContourComponent),
        });

        return EntityManager.Entities.Filter(typeof(AtomFactoryComponent));
    }
示例#17
0
        /// <summary>
        /// 实体初始化
        /// </summary>
        /// <param name="entityId">实体编号id</param>
        /// <param name="entityAssetName">实体资源名称</param>
        /// <param name="entityGroup">实体所属的实体组</param>
        /// <param name="isNewInstance">是否是新实例</param>
        /// <param name="userData">用户自定义数据</param>
        public void OnInit(int entityId, string entityAssetName, IEntityGroup entityGroup, bool isNewInstance, object userData)
        {
            Id = entityId;
            EntityAssetName = entityAssetName;
            if (isNewInstance)
            {
                EntityGroup = entityGroup;
            }
            else if (EntityGroup != entityGroup)
            {
                Log.Error("[Entity.OnInit] Entity group is inconsistent for non-new-instance entity.");
                return;
            }

            ShowEntityInfo showEntityInfo = userData as ShowEntityInfo;//EntityManager的ShowEntity函数传递进去的,最终又通过生命周期传递回来

            if (showEntityInfo == null || showEntityInfo.EntityLogicType == null)
            {
                Log.Error("[Entity.OnInit] Entity logic type is invalid.");
                return;
            }

            //修改控制逻辑
            if (Logic != null)
            {
                if (Logic.GetType() == showEntityInfo.EntityLogicType)
                {
                    Logic.enabled = true;   //直接启用
                    return;
                }

                Destroy(Logic);
                Logic = null;
            }

            if (!typeof(EntityLogic).IsAssignableFrom(showEntityInfo.EntityLogicType))
            {
                Log.Error("[Entity.OnInit] Type '{0}' is not assignable from EntityLogic.", showEntityInfo.EntityLogicType);
                return;
            }

            Logic = gameObject.AddComponent(showEntityInfo.EntityLogicType) as EntityLogic;
            if (Logic == null)
            {
                Log.Error("Entity '{0}' can not add entity logic.", entityAssetName);
                return;
            }
            Logic.OnInit(this, showEntityInfo.UserData);  //初始化
        }
示例#18
0
        /// <summary>
        /// 实体初始化。
        /// </summary>
        /// <param name="entityId">实体编号。</param>
        /// <param name="entityAssetName">实体资源名称。</param>
        /// <param name="entityGroup">实体所属的实体组。</param>
        /// <param name="isNewInstance">是否是新实例。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void OnInit(int entityId, string entityAssetName, IEntityGroup entityGroup, bool isNewInstance, object userData)
        {
            m_Id = entityId;
            m_EntityAssetName = entityAssetName;
            if (isNewInstance)
            {
                m_EntityGroup = entityGroup;
            }
            else if (m_EntityGroup != entityGroup)
            {
                Log.Error("Entity group is inconsistent for non-new-instance entity.");
                return;
            }

            //从显示实体信息中获取到实体逻辑的Type对象
            ShowEntityInfo showEntityInfo  = (ShowEntityInfo)userData;
            Type           entityLogicType = showEntityInfo.EntityLogicType;

            if (entityLogicType == null)
            {
                Log.Error("Entity logic type is invalid.");
                return;
            }

            if (m_EntityLogic != null)
            {
                if (m_EntityLogic.GetType() == entityLogicType)
                {
                    //已经添加了相同的实体逻辑脚本时,显示实体
                    m_EntityLogic.enabled = true;
                    return;
                }

                Destroy(m_EntityLogic);
                m_EntityLogic = null;
            }

            //为实体的GameObject添加实体逻辑脚本
            m_EntityLogic = gameObject.AddComponent(entityLogicType) as EntityLogic;
            if (m_EntityLogic == null)
            {
                Log.Error("Entity '{0}' can not add entity logic.", entityAssetName);
                return;
            }

            //新添加的实体逻辑脚本才会执行OnInit方法
            m_EntityLogic.OnInit(showEntityInfo.UserData);
        }
示例#19
0
 public EntityRelationship(string name,
                           IEntityGroup <TEntity> referencingGroup,
                           IEntityGroup <TEntity> referencedGroup,
                           IKeyValueGetter <TEntity, int> keyValueGetter,
                           Action <TEntity, TEntity, Component> handleReferencedDeleted,
                           bool referencedKeepAlive  = false,
                           bool referencingKeepAlive = false)
     : base(
         name,
         referencingGroup,
         referencedGroup,
         keyValueGetter,
         handleReferencedDeleted,
         referencedKeepAlive,
         referencingKeepAlive)
     => referencedGroup.AddListener(new ReferencedGroupListener(this));
            public bool HandlePropertyValueChanged <T>(
                string propertyName, T oldValue, T newValue, int componentId, Component component,
                GameEntity entity, IEntityGroup <GameEntity> group)
            {
                Assert.Same(_testEntity, entity);
                Assert.Equal(_testComponent.ComponentId, componentId);
                Assert.Same(_testComponent, component);
                Assert.Equal(nameof(EffectComponent.DurationAmount), propertyName);
                Assert.Null((string)(object)oldValue);
                Assert.Equal("10", (string)(object)newValue);
                Assert.Same(_group, group);

                GroupChangesDetected++;

                return(false);
            }
 protected EntityRelationshipBase(
     string name,
     IEntityGroup <TEntity> referencingGroup,
     IEntityGroup <TEntity> referencedGroup,
     IKeyValueGetter <TEntity, int> keyValueGetter,
     Action <TEntity, TEntity, Component> handleReferencedDeleted,
     bool referencedKeepAlive,
     bool referencingKeepAlive)
     : base(name, referencingGroup, keyValueGetter)
 {
     ReferencingGroup         = referencingGroup;
     ReferencedGroup          = referencedGroup;
     _handleReferencedDeleted = handleReferencedDeleted;
     _referencedKeepAlive     = referencedKeepAlive;
     _referencingKeepAlive    = referencingKeepAlive;
 }
示例#22
0
            public bool HandlePropertyValueChanged <T>(
                string propertyName, T oldValue, T newValue, int componentId, Component component,
                GameEntity entity, IEntityGroup <GameEntity> group)
            {
                Assert.Same(_testEntity, entity);
                Assert.Equal(_testComponent.ComponentId, componentId);
                Assert.Same(_testComponent, component);
                Assert.Equal(nameof(BeingComponent.ColdResistance), propertyName);
                Assert.Equal(0, (int)(object)oldValue);
                Assert.Equal(10, (int)(object)newValue);
                Assert.Same(_group, group);

                GroupChangesDetected++;

                return(false);
            }
            public bool HandlePropertyValuesChanged(
                IReadOnlyList <IPropertyValueChange> changes, GameEntity entity, IEntityGroup <GameEntity> group)
            {
                var change = (PropertyValueChange <Species>)changes[0];

                Assert.Same(_testEntity, entity);
                Assert.Equal(_testComponent.ComponentId, change.ChangedComponent?.ComponentId);
                Assert.Same(_testComponent, change.ChangedComponent);
                Assert.Equal(nameof(RaceComponent.Species), change.ChangedPropertyName);
                Assert.Equal(Species.Default, change.OldValue);
                Assert.Equal(Species.Dragon, change.NewValue);
                Assert.Same(_group, group);

                GroupChangesDetected++;

                return(false);
            }
            public bool HandlePropertyValuesChanged(
                IReadOnlyList <IPropertyValueChange> changes, GameEntity entity, IEntityGroup <GameEntity> group)
            {
                var change = (PropertyValueChange <string>)changes[0];

                Assert.Same(_testEntity, entity);
                Assert.Equal(_testComponent.ComponentId, change.ChangedComponent?.ComponentId);
                Assert.Same(_testComponent, change.ChangedComponent);
                Assert.Equal(nameof(EffectComponent.DurationAmount), change.ChangedPropertyName);
                Assert.Null(change.OldValue);
                Assert.Equal("10", change.NewValue);
                Assert.Same(_group, group);

                GroupChangesDetected++;

                return(false);
            }
示例#25
0
        /// <summary>
        /// 设置实体是否被加锁。
        /// </summary>
        /// <param name="entity">实体。</param>
        /// <param name="locked">实体是否被加锁。</param>
        public void SetEntityInstanceLocked(Entity entity, bool locked)
        {
            if (entity == null)
            {
                Log.Warning("Entity is invalid.");
                return;
            }

            IEntityGroup entityGroup = entity.EntityGroup;
            if (entityGroup == null)
            {
                Log.Warning("Entity group is invalid.");
                return;
            }

            entityGroup.SetEntityInstanceLocked(entity.gameObject, locked);
        }
示例#26
0
        /// <summary>
        /// 设置实体的优先级。
        /// </summary>
        /// <param name="entity">实体。</param>
        /// <param name="priority">实体优先级。</param>
        public void SetInstancePriority(Entity entity, int priority)
        {
            if (entity == null)
            {
                Log.Warning("Entity is invalid.");
                return;
            }

            IEntityGroup entityGroup = entity.EntityGroup;
            if (entityGroup == null)
            {
                Log.Warning("Entity group is invalid.");
                return;
            }

            entityGroup.SetEntityInstancePriority(entity.gameObject, priority);
        }
示例#27
0
            public bool HandlePropertyValuesChanged(
                IReadOnlyList <IPropertyValueChange> changes, GameEntity entity, IEntityGroup <GameEntity> group)
            {
                var change = (PropertyValueChange <int>)changes[0];

                Assert.Same(_testEntity, entity);
                Assert.Equal(_testComponent.ComponentId, change.ChangedComponent?.ComponentId);
                Assert.Same(_testComponent, change.ChangedComponent);
                Assert.Equal(nameof(BeingComponent.ColdResistance), change.ChangedPropertyName);
                Assert.Equal(0, change.OldValue);
                Assert.Equal(10, change.NewValue);
                Assert.Same(_group, group);

                GroupChangesDetected++;

                return(false);
            }
示例#28
0
文件: Entity.cs 项目: hafewa/LuckDial
        /// <summary>
        /// 实体初始化。
        /// </summary>
        /// <param name="entityId">实体编号。</param>
        /// <param name="entityAssetName">实体资源名称。</param>
        /// <param name="entityGroup">实体所属的实体组。</param>
        /// <param name="isNewInstance">是否是新实例。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void OnInit(int entityId, string entityAssetName, IEntityGroup entityGroup, bool isNewInstance, object userData)
        {
            m_Id = entityId;
            m_EntityAssetName = entityAssetName;
            if (isNewInstance)
            {
                m_EntityGroup = entityGroup;
            }
            else if (m_EntityGroup != entityGroup)
            {
                Log.Error("Entity group is inconsistent for non-new-instance entity.");
                return;
            }

            ShowEntityInfo showEntityInfo  = (ShowEntityInfo)userData;
            Type           entityLogicType = showEntityInfo.EntityLogicType;

            if (entityLogicType == null)
            {
                Log.Error("Entity logic type is invalid.");
                return;
            }

            if (m_EntityLogic != null)
            {
                if (m_EntityLogic.GetType() == entityLogicType)
                {
                    m_EntityLogic.enabled = true;
                    return;
                }

                Destroy(m_EntityLogic);
                m_EntityLogic = null;
            }

            m_EntityLogic = gameObject.AddComponent(entityLogicType) as EntityLogic;
            if (m_EntityLogic == null)
            {
                Log.Error("Can not add entity logic.");
                return;
            }

            m_EntityLogic.OnInit(showEntityInfo.UserData);
        }
示例#29
0
        IEntity GetClosest(IEntityGroup entities, Vector3 position)
        {
            float closestDisance = float.MaxValue;
            IEntity closestEntity = null;

            for (int i = 0; i < entities.Count; i++)
            {
                var entity = entities[i];
                var transform = entity.GetComponent<TransformComponent>().Transform;
                float distance = Vector3.Distance(transform.position, position);

                if (distance < closestDisance)
                {
                    closestDisance = distance;
                    closestEntity = entity;
                }
            }

            return closestEntity;
        }
示例#30
0
        public static IEntity GetFarthest(this IEntityGroup group, Vector3 position)
        {
            float   farthestDistance = 0f;
            IEntity farthestEntity   = null;

            for (int i = 0; i < group.Count; i++)
            {
                var   entity    = group[i];
                var   transform = entity.GetTransform();
                float distance  = Vector3.Distance(transform.position, position);

                if (distance > farthestDistance)
                {
                    farthestDistance = distance;
                    farthestEntity   = entity;
                }
            }

            return(farthestEntity);
        }
示例#31
0
        IEntity GetClosest(IEntityGroup entities, Vector3 position)
        {
            float   closestDisance = float.MaxValue;
            IEntity closestEntity  = null;

            for (int i = 0; i < entities.Count; i++)
            {
                var   entity    = entities[i];
                var   transform = entity.GetComponent <TransformComponent>().Transform;
                float distance  = Vector3.Distance(transform.position, position);

                if (distance < closestDisance)
                {
                    closestDisance = distance;
                    closestEntity  = entity;
                }
            }

            return(closestEntity);
        }
示例#32
0
        IEntity GetFarthest(IEntityGroup entities, Vector3 position)
        {
            float   farthestDistance = 0f;
            IEntity farthestEntity   = null;

            for (int i = 0; i < entities.Count; i++)
            {
                var   entity    = entities[i];
                var   transform = entity.GetComponent <TransformComponent>().Transform;
                float distance  = Vector3.Distance(transform.position, position);

                if (distance > farthestDistance)
                {
                    farthestDistance = distance;
                    farthestEntity   = entity;
                }
            }

            return(farthestEntity);
        }
示例#33
0
        public static IEntity GetClosest(this IEntityGroup group, Vector3 position)
        {
            float   closestDisance = float.MaxValue;
            IEntity closestEntity  = null;

            for (int i = 0; i < group.Count; i++)
            {
                var   entity    = group[i];
                var   transform = entity.GetTransform();
                float distance  = Vector3.Distance(transform.position, position);

                if (distance < closestDisance)
                {
                    closestDisance = distance;
                    closestEntity  = entity;
                }
            }

            return(closestEntity);
        }
示例#34
0
        public override void OnAdded()
        {
            base.OnAdded();

            targetables = entityManager.Entities.Filter(typeof(TransformComponent));
        }
示例#35
0
        IEntity GetFarthest(IEntityGroup entities, Vector3 position)
        {
            float farthestDistance = 0f;
            IEntity farthestEntity = null;

            for (int i = 0; i < entities.Count; i++)
            {
                var entity = entities[i];
                var transform = entity.GetComponent<TransformComponent>().Transform;
                float distance = Vector3.Distance(transform.position, position);

                if (distance > farthestDistance)
                {
                    farthestDistance = distance;
                    farthestEntity = entity;
                }
            }

            return farthestEntity;
        }
 public EntityMatchGroup(IEntityGroup parent, EntityMatches match)
 {
     this.parent = parent;
     this.match = match;
 }
示例#37
0
 Entity[] GetEntities(IEntityGroup ent)
 {
     if (Entities == null)
         return null;
     List<Entity> ents = new List<Entity>();
     foreach (Entity e in Entities)
         if (e.EntityData == ent)
             ents.Add(e);
     //System.Diagnostics.Debug.Assert(ents.Count <= 1, "Should not have more than 1 entity for each IEntityGroup");
     if (ents.Count > 0)
         return ents.ToArray();
     else return null;
 }
示例#38
0
 LabelBase[] GetLabels(IEntityGroup ent)
 {
     if (Entities == null)
         return null;
     List<LabelBase> ents = new List<LabelBase>();
     foreach (LabelBase e in Labels)
             ents.Add(e);
     //System.Diagnostics.Debug.Assert(ents.Count <= 1, "Should not have more than 1 entity for each IEntityGroup");
     if (ents.Count > 0)
         return ents.ToArray();
     else return null;
 }
示例#39
0
 private void RemoveEntities(IEntityGroup ent)
 {
     Entity[] ents = GetEntities(ent);
     if (ents != null)
         foreach (Entity e in ents)
             Entities.Remove(e);
         Labels.Remove(ent.devpDeptLabel);
 }
示例#40
0
        private void UpdateEntities(IEntityGroup ent)
        {
            Entity[] ents = GetEntities(ent);
            bool reselect = false;
            if (ents != null)
                foreach (Entity e in ents)
                {
                    reselect = e.Selected;
                    Entities.Remove(e);
                    //if (ent.devpDeptLabel != null)
                    Labels.Remove(ent.devpDeptLabel);
                    if (ent is NsNode)
                    {
                        if ((ent as NsNodes.NsNode).Label.Contains("Lifter") && ent.devpDeptLabel == null)
                            Labels.Clear();
                    }
                    else
                        continue;
                }

            Entity[] ee = ent.Entity;

            if(ee != null)
                foreach(Entity e in ee)
                    if (e != null)
                    {
                        Entities.Add(e);
                        e.Selected = reselect;
                        if(ent.devpDeptLabel != null)
                            Labels.Add(ent.devpDeptLabel);
                    }
        }