예제 #1
0
        public void AddComponent(ActorComponent component)
        {
            component.SetActor(this);
            _Components.Add(component);
            component.AddRef(this);

            if (component is SceneComponent)
            {
                RootComponent = (SceneComponent)component;
            }

            RegisterComponentName(component);
        }
예제 #2
0
        public void RemoveComponent(ActorComponent component)
        {
            if (!_Components.Remove(component))
            {
                return;
            }

            if (RootComponent == component)
            {
                RootComponent = null;
            }

            component.RemoveRef(this);
            UnregisterComponentName(component);
        }
예제 #3
0
        internal void UnregisterComponentName(ActorComponent component, bool unregisterChilds = true)
        {
            if (!string.IsNullOrEmpty(component.Name))
            {
                List <ActorComponent> array;
                if (!ComponentNameHash.TryGetValue(component.Name, out array))
                {
                    return;
                }
                array.Remove(component);
            }

            if (unregisterChilds && component is SceneComponent sc)
            {
                foreach (var child in sc.Components)
                {
                    UnregisterComponentName(child);
                }
            }
        }
예제 #4
0
        internal void RegisterComponentName(ActorComponent component, bool registerChilds = true)
        {
            if (!string.IsNullOrEmpty(component.Name))
            {
                List <ActorComponent> array;
                if (!ComponentNameHash.TryGetValue(component.Name, out array))
                {
                    ComponentNameHash.TryAdd(component.Name, array = new List <ActorComponent>());
                }
                array.Add(component);
            }

            if (registerChilds && component is SceneComponent sc)
            {
                foreach (var child in sc.Components)
                {
                    RegisterComponentName(child);
                }
            }
        }
예제 #5
0
 public Actor(ActorComponent component) : this()
 {
     AddComponent(component);
 }