Example #1
0
        /// <summary>
        /// 将一个组件手动添加到实体上
        /// </summary>
        public void AddComponet(YuoEntity entity, YuoComponent componet)
        {
            Type type = componet.Type;

            if (!components.ContainsKey(type))
            {
                components.Add(type, new List <YuoComponent>());
            }

            if (!components[type].Contains(componet))
            {
                components[type].Add(componet);
                foreach (var system in systemsOfComponent[type])
                {
                    if (system.AddComponent(entity))
                    {
                        if (system is IAwake)
                        {
                            system.RunType = SystemType.Awake;
                            system.m_Run(system.EntityCount - 1);
                        }
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// 移除实体
 /// </summary>
 /// <param name="entity"></param>
 public void UnRegisterEntity(YuoEntity entity)
 {
     if (_entities.ContainsKey(entity.EntityData.Id))
     {
         _entities.Remove(entity.EntityData.Id);
     }
 }
Example #3
0
 /// <summary>
 /// 初始化实体
 /// </summary>
 /// <param name="entity"></param>
 public void RegisterEntity(YuoEntity entity)
 {
     if (!_entities.ContainsKey(entity.EntityData.Id))
     {
         _entities.Add(entity.EntityData.Id, entity);
     }
     else
     {
         $"实体ID重复,请检查:{entity.EntityData.Id}".LogError();
     }
 }
Example #4
0
        public void SetComponet(YuoComponent componet1, YuoComponent componet2)
        {
            YuoEntity entity = componet1.Entity;

            components[componet1.Type].Remove(componet1);
            components[componet1.Type].Add(componet2);

            foreach (var system in systemsOfComponent[componet1.Type])
            {
                system.SetComponent(entity, componet1.Type, componet2);
            }

            RunSystemOfTag <ISwitchComponent>(componet2);
        }
Example #5
0
        public void RemoveComponet(YuoEntity entity, YuoComponent componet)
        {
            components[componet.Type].Remove(componet);
            foreach (var system in systemsOfComponent[componet.Type])
            {
                if (system is IDestroy)
                {
                    system.RunType = SystemType.Destroy;
                    system.m_Run(entity);
                }

                system.RemoveComponent(entity);
            }

            componet.Dispose();
        }
Example #6
0
        public void Awake()
        {
            _allSystem = new();
            if (Instance != null)
            {
                _dontInit = true;
                Destroy(gameObject);
                return;
            }

            _entities          = new();
            components         = new();
            systemsOfTag       = new();
            systemsOfComponent = new();

            Instance = this;

            DontDestroyOnLoad(gameObject);

            //系统初始化必须放在所有初始化之前
            Initialization();

            //基本核心组件挂载的实体
            Main = new YuoEntity(0);

            Main.EntityName = "核心组件";

            AddComponet(Main, IDGenerater.Instance);

            //添加一个场景实体
            var scene = new YuoEntity(IDGenerater.GetID(IDGenerater.IDType.Scene, 0));

            scene.EntityName = "默认场景";
            AllScenes.Add(scene);
            scene.AddComponent <SceneComponent>();
        }
Example #7
0
 public void Dispose()
 {
     Entity        = null;
     ConnectedType = null;
 }