public void AddComponent(ActorComponent component) { component.SetActor(this); _Components.Add(component); component.AddRef(this); if (component is SceneComponent) { RootComponent = (SceneComponent)component; } RegisterComponentName(component); }
public void RemoveComponent(ActorComponent component) { if (!_Components.Remove(component)) { return; } if (RootComponent == component) { RootComponent = null; } component.RemoveRef(this); UnregisterComponentName(component); }
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); } } }
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); } } }
public Actor(ActorComponent component) : this() { AddComponent(component); }