private void EntityGUI()
 {
     GUILayout.BeginHorizontal();
     GUILayout.Label("Entity:", GUILayout.Width(60));
     Entity = EditorGUILayout.ObjectField(Entity, typeof(ECS_Entity), true) as ECS_Entity;
     GUILayout.EndHorizontal();
 }
        protected override void OnEnable()
        {
            base.OnEnable();

            _components.Clear();
            _componentInfos.Clear();
            List <Type> types = ReflectionToolkit.GetTypesInRunTimeAssemblies((type) =>
            {
                return(type.IsSubclassOf(typeof(ECS_Component)) && !type.IsAbstract);
            });

            for (int i = 0; i < types.Count; i++)
            {
                _components.Add(types[i]);
                _componentInfos.Add(types[i], new ECS_ComponentInfo(types[i]));
            }

            _systems.Clear();
            _systemInfos.Clear();
            types = ReflectionToolkit.GetTypesInRunTimeAssemblies((type) =>
            {
                return(type.IsSubclassOf(typeof(ECS_System)) && !type.IsAbstract);
            });
            for (int i = 0; i < types.Count; i++)
            {
                _systems.Add(types[i]);
                _systemInfos.Add(types[i], new ECS_SystemInfo(types[i], _componentInfos));
            }

            Entity = null;
        }
Exemplo n.º 3
0
 /// <summary>
 /// 移除实体
 /// </summary>
 /// <param name="entity">实体</param>
 public void RemoveEntity(ECS_Entity entity)
 {
     if (Entities.ContainsKey(entity.ID))
     {
         Entities.Remove(entity.ID);
         SetDirty();
     }
 }
Exemplo n.º 4
0
        private void Awake()
        {
            Entity = GetComponent <ECS_Entity>();
            Entity.AppendComponent(this);

#if UNITY_EDITOR
            ComponentNameAttribute cna = GetType().GetCustomAttribute <ComponentNameAttribute>();
            Name = string.Format("{0} ({1})", cna != null ? cna.Name : "未命名", GetType().FullName);
#endif
        }
Exemplo n.º 5
0
        private static void MarkAsToEntity()
        {
            int index = 0;

            for (int i = 0; i < Selection.gameObjects.Length; i++)
            {
                ECS_Entity.CreateEntity(Selection.gameObjects[i]);
                index += 1;
            }
            Log.Info("已完成ECS实体标记 " + index + " 个!");
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public void AddEntity(ECS_Entity entity)
        {
            if (entity.ID == "")
            {
                Log.Warning(string.Format("ECS:发现ID为空的实体 [{0}],这是不被允许的!", entity.Name));
                return;
            }

            if (Entities.ContainsKey(entity.ID))
            {
                Log.Warning(string.Format("ECS:发现ID [{0}] 重复的实体 [{1}] 和 [{2}],这是不被允许的!", entity.ID, entity.Name, Entities[entity.ID].Name));
            }
            else
            {
                Entities.Add(entity.ID, entity);
                SetDirty();
            }
        }
        /// <summary>
        /// 创建新的实体
        /// </summary>
        /// <param name="target">实体依附的目标</param>
        /// <param name="entityName">实体名称</param>
        /// <returns>创建成功的实体</returns>
        public static ECS_Entity CreateEntity(GameObject target, string entityName = "Default")
        {
            if (target == null)
            {
                return(null);
            }

            ECS_Entity entity = target.GetComponent <ECS_Entity>();

            if (entity == null)
            {
                entity = target.AddComponent <ECS_Entity>();
            }
            entity.Name = entityName;
            if (entity.ID == "")
            {
                entity.GenerateID();
            }
            return(entity);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 移除实体
 /// </summary>
 /// <param name="entity">实体</param>
 internal void RemoveEntity(ECS_Entity entity)
 {
     _helper.RemoveEntity(entity);
 }
Exemplo n.º 9
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="entity">实体</param>
 internal void AddEntity(ECS_Entity entity)
 {
     _helper.AddEntity(entity);
 }