private void Source_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (_updateSource == UpdateSourceType.NotUpdating) { try { _updateSource = UpdateSourceType.FromSource; switch (e.Action) { case NotifyCollectionChangedAction.Add: this.AddRange(e.NewItems); break; case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Remove: this.RemoveRange(e.OldItems); break; case NotifyCollectionChangedAction.Replace: this.RemoveRange(e.OldItems); this.AddRange(e.NewItems); break; case NotifyCollectionChangedAction.Reset: _aggregated.Clear(); _bridge.Clear(); AddRange(_source); break; } } finally { _updateSource = UpdateSourceType.NotUpdating; } } }
public void UnscribeEveryFrame(IUpdatable updatable, UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true) { var managerDescription = FindManagerDescription(_everyFrameUpdateList, sourceType, scaledTime); if (managerDescription != null) { managerDescription.updateManager.Unscribe(updatable); _everyFrameDirty = true; } }
void Aggregated_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (_updateSource == UpdateSourceType.NotUpdating) { try { _updateSource = UpdateSourceType.FromDest; switch (e.Action) { case NotifyCollectionChangedAction.Add: throw new ArgumentException("Can't add an item without an owner source"); case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Replace: throw new ArgumentException("Can't add an item without an owner source"); case NotifyCollectionChangedAction.Remove: foreach (T key in e.OldItems) { List <ObservableCollection <T> > sourceCollectionOwners; if (_itemToSourceCollectionOwners.TryGetValue(key, out sourceCollectionOwners)) { foreach (var collection in sourceCollectionOwners) { while (collection.Remove(key)) { ; } } _itemToSourceCollectionOwners.Remove(key); } } break; case NotifyCollectionChangedAction.Reset: if (this.Count > 0) { throw new ArgumentException("Can't add an item without an owner source"); } foreach (var collection in _sourceCollections) { collection.Clear(); } break; } } finally { _updateSource = UpdateSourceType.NotUpdating; } } }
public void UnscribeCountFrame(int count, IUpdatable updatable, UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true) { if (_countFrameUpdateLists.TryGetValue(count, out List <UpdateManagerDescription> updateList)) { var managerDescription = FindManagerDescription(updateList, sourceType, scaledTime); if (managerDescription != null) { managerDescription.updateManager.Unscribe(updatable); _countFrameDity = true; } } }
public void UnscribeTimed(float time, IUpdatable updatable, UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true) { if (_timedUpdateLists.TryGetValue(time, out List <UpdateManagerDescription> updateList)) { var managerDescription = FindManagerDescription(updateList, sourceType, scaledTime); if (managerDescription != null) { managerDescription.updateManager.Unscribe(updatable); _timedDirty = true; } } }
void Aggregated_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (_updateSource == UpdateSourceType.NotUpdating) { try { _updateSource = UpdateSourceType.FromDest; switch (e.Action) { case NotifyCollectionChangedAction.Add: throw new InvalidOperationException("Can't handle adding items aggregated value with no original value"); case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Replace: throw new InvalidOperationException("Can't handle adding items aggregated value with no original value"); case NotifyCollectionChangedAction.Remove: foreach (T key in e.OldItems) { if (_bridge.ContainsKey(key)) { foreach (K item in _bridge[key]) { _source.Remove(item); } _aggregated.Remove(key); _bridge.Remove(key); } } break; case NotifyCollectionChangedAction.Reset: _source.Clear(); if (_aggregated.Count > 0) { throw new InvalidOperationException("Can't handle adding items aggregated value with no original value"); } break; } } finally { _updateSource = UpdateSourceType.NotUpdating; } } }
public EveryFrameUpdateManager GetEveryFrameUpdateList(UpdateSourceType sourceType, bool scaledTime) { var managerDescription = FindManagerDescription(_everyFrameUpdateList, sourceType, scaledTime); if (managerDescription == null) { string scaledName = scaledTime ? "Scaled" : "Unscaled"; GameObject go = CreateUpdateSource(sourceType, $"EveryFrame_{scaledName}"); managerDescription = new UpdateManagerDescription { sourceType = sourceType, scaledTime = scaledTime, updateManager = go.GetComponent <UpdateManagerSourceBase>().InitForEveryFrame(scaledTime) }; _everyFrameUpdateList.Add(managerDescription); } return(managerDescription.updateManager as EveryFrameUpdateManager); }
void sourceCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (_updateSource == UpdateSourceType.NotUpdating) { try { _updateSource = UpdateSourceType.FromSource; switch (e.Action) { case NotifyCollectionChangedAction.Add: this.AddRange(e.NewItems, (ObservableCollection <T>)sender); break; case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Remove: this.RemoveRange(e.OldItems, (ObservableCollection <T>)sender); break; case NotifyCollectionChangedAction.Replace: this.RemoveRange(e.OldItems, (ObservableCollection <T>)sender); this.AddRange(e.NewItems, (ObservableCollection <T>)sender); break; case NotifyCollectionChangedAction.Reset: this.Clear(); _itemToSourceCollectionOwners.Clear(); foreach (var collection in _sourceCollections) { AddRange(collection, collection); } break; } } finally { _updateSource = UpdateSourceType.NotUpdating; } } }
private void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (_updateSource == UpdateSourceType.NotUpdating) { try { _updateSource = UpdateSourceType.FromSource; // Don't allow duplicates in list switch (e.Action) { case NotifyCollectionChangedAction.Add: AddRangeSourceToDest(e.NewItems); break; case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Remove: RemoveRangeSourceToDest(e.OldItems); break; case NotifyCollectionChangedAction.Replace: // Remove old items RemoveRangeSourceToDest(e.OldItems); // Add new items AddRangeSourceToDest(e.NewItems); break; case NotifyCollectionChangedAction.Reset: _deduplicated.Clear(); _itemCount.Clear(); AddRangeSourceToDest(_source); break; } } finally { _updateSource = UpdateSourceType.NotUpdating; } } }
public TimedUpdateManager GetTimedUpdateList(float time, UpdateSourceType sourceType, bool scaledTime) { if (!_timedUpdateLists.TryGetValue(time, out List <UpdateManagerDescription> updateList)) { updateList = new List <UpdateManagerDescription>(); _timedUpdateLists.Add(time, updateList); } var managerDescription = FindManagerDescription(_everyFrameUpdateList, sourceType, scaledTime); if (managerDescription == null) { string scaledName = scaledTime ? "Scaled" : "Unscaled"; GameObject go = CreateUpdateSource(sourceType, $"Timed_{scaledName}_{time}"); managerDescription = new UpdateManagerDescription { sourceType = sourceType, scaledTime = scaledTime, updateManager = go.GetComponent <UpdateManagerSourceBase>().InitForTimed(scaledTime, time) }; updateList.Add(managerDescription); } return(managerDescription.updateManager as TimedUpdateManager); }
GameObject CreateUpdateSource(UpdateSourceType sourceType, string name) { Type sourceTypeOf = null; switch (sourceType) { case UpdateSourceType.SimpleUpdate: sourceTypeOf = typeof(SimpleUpdateSource); break; case UpdateSourceType.FixedUpdate: sourceTypeOf = typeof(FixedUpdateSource); break; case UpdateSourceType.LateUpdate: sourceTypeOf = typeof(LateUpdateSource); break; } var go = new GameObject($"{sourceType}_{name}", sourceTypeOf); go.transform.SetParent(transform); return(go); }
public CountFrameUpdateManager GetCountFrameUpdateList(int count, UpdateSourceType sourceType, bool scaledTime) { if (!_countFrameUpdateLists.TryGetValue(count, out List <UpdateManagerDescription> updateList)) { updateList = new List <UpdateManagerDescription>(); _countFrameUpdateLists.Add(count, updateList); } var managerDescription = FindManagerDescription(_everyFrameUpdateList, sourceType, scaledTime); if (managerDescription == null) { string scaledName = scaledTime ? "Scaled" : "Unscaled"; GameObject go = CreateUpdateSource(sourceType, $"CountFrame_{scaledName}_{count}"); managerDescription = new UpdateManagerDescription { sourceType = sourceType, scaledTime = scaledTime, updateManager = go.GetComponent <UpdateManagerSourceBase>().InitForCountFrame(scaledTime, count) }; updateList.Add(managerDescription); } return(managerDescription.updateManager as CountFrameUpdateManager); }
// Update is called once per frame void Update() { if (simpleTest) { for (int i = 0; i < testSize; i++) { Instantiate(testSimplePrefab, transform, false); } simpleTest = false; } if (clearGos) { Clear(); clearGos = false; } if (subscribeKnownManager) { var newList = Create(); foreach (var obj in newList) { updateManagerSource.updateManager.Subscribe(obj); obj.unscribe = () => { updateManagerSource.updateManager.Unscribe(obj); }; } _objs.AddRange(newList); subscribeKnownManager = false; } if (subscribeEveryFrame) { var newList = Create(); UpdateSourceType buffSource = testSource; bool buffScaleTime = testScaleTime; foreach (var obj in newList) { GlobalUpdateManager.instance.SubscribeEveryFrame(obj, buffSource, buffScaleTime); obj.unscribe = () => { GlobalUpdateManager.instance.UnscribeEveryFrame(obj, buffSource, buffScaleTime); }; } _objs.AddRange(newList); subscribeEveryFrame = false; } if (subscribeTimed) { var newList = Create(); float buffTime = time; UpdateSourceType buffSource = testSource; bool buffScaleTime = testScaleTime; foreach (var obj in newList) { GlobalUpdateManager.instance.SubscribeTimed(buffTime, obj, buffSource, buffScaleTime); obj.unscribe = () => { GlobalUpdateManager.instance.UnscribeTimed(buffTime, obj, buffSource, buffScaleTime); }; } _objs.AddRange(newList); subscribeTimed = false; } if (subscribeCountFrame) { var newList = Create(); int buffCount = count; UpdateSourceType buffSource = testSource; bool buffScaleTime = testScaleTime; foreach (var obj in newList) { GlobalUpdateManager.instance.SubscribeCountFrame(buffCount, obj, buffSource, buffScaleTime); obj.unscribe = () => { GlobalUpdateManager.instance.UnscribeCountFrame(buffCount, obj, buffSource, buffScaleTime); }; } _objs.AddRange(newList); subscribeCountFrame = false; } }
UpdateManagerDescription FindManagerDescription(List <UpdateManagerDescription> list, UpdateSourceType sourceType, bool scaledTime) { return(list.Find((description) => { return (description.sourceType == sourceType) && (description.scaledTime == scaledTime); })); }
public void SubscribeEveryFrame(IUpdatable updatable, UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true) { GetEveryFrameUpdateList(sourceType, scaledTime).Subscribe(updatable); }
public void SubscribeCountFrame(int count, IUpdatable upadatable, UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true) { GetCountFrameUpdateList(count, sourceType, scaledTime).Subscribe(upadatable); }
public void SubscribeTimed(float time, IUpdatable updatable, UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true) { GetTimedUpdateList(time, sourceType, scaledTime).Subscribe(updatable); }