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;
                }
            }
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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;
                }
            }
        }
Ejemplo n.º 4
0
 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;
         }
     }
 }
Ejemplo n.º 5
0
 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;
         }
     }
 }
Ejemplo n.º 6
0
        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;
                }
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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;
                }
            }
        }
Ejemplo n.º 9
0
        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;
                }
            }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
    // 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;
        }
    }
Ejemplo n.º 14
0
 UpdateManagerDescription FindManagerDescription(List <UpdateManagerDescription> list, UpdateSourceType sourceType, bool scaledTime)
 {
     return(list.Find((description) =>
     {
         return (description.sourceType == sourceType) && (description.scaledTime == scaledTime);
     }));
 }
Ejemplo n.º 15
0
 public void SubscribeEveryFrame(IUpdatable updatable, UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true)
 {
     GetEveryFrameUpdateList(sourceType, scaledTime).Subscribe(updatable);
 }
Ejemplo n.º 16
0
 public void SubscribeCountFrame(int count, IUpdatable upadatable,
                                 UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true)
 {
     GetCountFrameUpdateList(count, sourceType, scaledTime).Subscribe(upadatable);
 }
Ejemplo n.º 17
0
 public void SubscribeTimed(float time, IUpdatable updatable,
                            UpdateSourceType sourceType = UpdateSourceType.SimpleUpdate, bool scaledTime = true)
 {
     GetTimedUpdateList(time, sourceType, scaledTime).Subscribe(updatable);
 }