Beispiel #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);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private void RemoveChildComponent(YuoComponent component)
 {
     if (component == null)
     {
         return;
     }
     ChildComponents.RemoveItem(component.Type, component);
 }
Beispiel #3
0
        /// <summary>
        /// 链接父组件,当执行子组件时也会调用父组件,用于组件继承
        /// </summary>
        public void Connect <T1>(YuoComponent child) where T1 : YuoComponent, new()
        {
            var type = typeof(T1);

            if (child == null || GetComponent <T1>() != null)
            {
                return;
            }
            child.ConnectedType = type;
            Components.Add(typeof(T1), child);
        }
Beispiel #4
0
 void AddChildComponent(Type type, YuoComponent component)
 {
     if (component == null)
     {
         return;
     }
     ChildComponents.AddItem(type, component);
     if (!Children.Contains(component.Entity))
     {
         Children.Add(component.Entity);
     }
 }
Beispiel #5
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);
        }
Beispiel #6
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();
        }