public void RegisterToBatchedUpdate(IBatchedUpdateHandler batchUpdateHandler, int batchInterval) { batchInterval = Mathf.Clamp(batchInterval, 1, int.MaxValue); // if : It doesn't have this Interface if (!BatchUpdateHandlerTracker.Contains(batchUpdateHandler)) { int instanceIndex = HasThisInstance(batchInterval); if (instanceIndex == -1) { BatchUpdateInstances.Add(new BatchUpdateInstance(batchInterval)); instanceIndex = BatchUpdateInstances.Count - 1; NumberOfInstances++; } int bucketIndex = BatchUpdateInstances[instanceIndex].AddToBucket(batchUpdateHandler); BatchUpdateHandlerTracker.Add( batchUpdateHandler, new UpdateInfo() { instanceIndex = instanceIndex, bucketIndex = bucketIndex } ); return; } //Debug.LogError(string.Format("{0} is already in registered in BatchUpdate", batchUpdateHandler)); }
private void OnSceneUnloaded(Scene scene) { int numberOfInstances = BatchUpdateInstances.Count; BatchUpdateHandlerTracker.Clear(); for (int i = 0; i < numberOfInstances; i++) { BatchUpdateInstances[i].Clear(); } }
private void StrightRemove() { while (_queueToRemove.Count > 0) { RemoveInfo _removeInfo = _queueToRemove.Dequeue(); if (BatchUpdateInstances[_removeInfo.updateInfo.instanceIndex].RemovedFromBucket( _removeInfo.batchedUpdateHandler, _removeInfo.updateInfo.bucketIndex)) { BucketClearerController(); InstancesClearerController(); BatchUpdateHandlerTracker.Remove(_removeInfo.batchedUpdateHandler); } else { //Debug.LogWarning(string.Format( // "Failed to remove for Interval({0}), Instance({1}), BucketIndex({2})", // BatchUpdateInstances[_removeInfo.updateInfo.instanceIndex].Interval, // _removeInfo.updateInfo.instanceIndex, // _removeInfo.updateInfo.bucketIndex)); } } }