/// <summary> /// Initializes a new instance. /// </summary> protected Instance() { var type = GetType(); Destroyed = new Signal(this); // the destroyed event will be used by Signal, so it needs to be created first. Changed = new Signal <string>(this); ParentChanged = new Signal <Instance>(this); ChildAdded = new Signal <Instance>(this); ChildRemoved = new Signal <Instance>(this); AncestryChanged = new Signal <Instance, Instance>(this); DescendantAdded = new Signal <Instance>(this); DescendantRemoving = new Signal <Instance>(this); _waitForChildList = new Dictionary <string, List <LuaThread> >(); Children = new ChildrenCollection(); Name = type.Name; _archivable = true; IsDestroyed = false; if (this is ISingleton) { var oldId = _instanceId; _instanceId = type.Name.ToUpper(); // ReSharper disable once VirtualMemberCallInConstructor OnInstanceIdChanged(_instanceId, oldId); } else { InstanceId = InstanceId.Generate(); } DescendantAdded.Event += d => { Parent?.DescendantAdded.Fire(d); }; DescendantRemoving.Event += d => { Parent?.DescendantAdded.Fire(d); }; Game.InvokeInstanceAdded(this); }