private void InitializeTemplate(Type componentType) { if (_templateComponent == null) { ObserversList.Clear(); } if (_templateComponent != null) { if (componentType != _templateComponent.GetType()) { ObserversList.Clear(); } else { return; } } if (!typeof(EntryComponent).IsAssignableFrom(componentType)) { throw new ArgumentException("type must be a subclass of EntryComponent"); } _templateComponent = EntryComponent.CreateInstance(componentType); _templateComponent.Initialize(_holder); _templateComponent.OnEditModeModified += OnTemplateEditChanged_UpdateObservers; }
public void SetTemplate(EntryComponent template) { if (template == null) { throw new ArgumentNullException(); } ObserversList.Clear(); _templateComponent = template; _holder = template.Holder; _templateComponent.OnEditModeModified += OnTemplateEditChanged_UpdateObservers; }
public EntryComponent AddObserver() { //var instance = (EntryComponent)TemplateInstance.Clone(); //ObserversList.Add(instance); //return instance; var instance = (EntryComponent)TemplateInstance.Clone(); AssetsPath.CreateAsset(instance, AssetsPath.AssetName_ComponentsObservers); ObserversList.Add(instance); return(instance); }
//----------------------------------------------------------------- protected void OnTemplateEditChanged_UpdateObservers() //note: on edit changed.. component value is not taken into consideration { //note: can clear the _observersList, cause otherwise the _observersList elements are cloned from the template ObserversList.ForEach(x => { TemplateInstance.CloneTo(x); x.IsInEditMode = false; }); if (OnTemplateEditChanged != null) { OnTemplateEditChanged(); } }
public override void Notify() { if (isDamage || healthWasRaised) { foreach (var o in ObserversList.OfType <HealthManager>()) { o.UpdateObserver(this); } } if (Health.IsDead) { foreach (var o in ObserversList.OfType <GameManager>()) { o.UpdateObserver(this); } } }
public void ClearObservers() { ObserversList.ForEach(AssetsPath.DestroyAsset); ObserversList.Clear(); }
public void RemoveObserver(EntryComponent other) { AssetsPath.DestroyAsset(other); ObserversList.Remove(other); }
public void RemoveObserver(int index) { AssetsPath.DestroyAsset(ObserversList[index]); ObserversList.RemoveAt(index); }