public void SetValue(IList array, int index) { if (array == null) { return; } if (array.Count > index) { var value = array[index]; if (value == null) { if (isUnityObject) { return; } else { value = array[index] = TypePoolManager.Create(elementType); } } PoolUtility.InitializeFields(value, setters); } }
protected PoolBase(object reference, Type type, Constructor constructor, Destructor destructor, int startSize, bool initialize) { PoolUtility.InitializeJanitor(); this.reference = reference; this.constructor = constructor ?? Construct; this.destructor = destructor ?? Destroy; this.startSize = startSize; Type = type; isPoolable = reference is IPoolable; hashedInstances = new HashSet <object>(); if (ApplicationUtility.IsMultiThreaded) { updater = new AsyncPoolUpdater(); } else { updater = new SyncPoolUpdater(); } if (initialize) { Initialize(); } }
protected void Initialize() { updater.Initializer = PoolUtility.GetPoolInitializer(reference); while (Size < startSize) { Enqueue(CreateInstance(), false); } }
public void SetValue(object instance) { if (instance == null) { return; } var array = (IList)field.GetValue(instance); if (array == null) { if (type.IsArray) { array = Array.CreateInstance(elementType, setters.Count); } else { array = (IList)Activator.CreateInstance(type); } field.SetValue(instance, array); } if (array.Count != setters.Count) { if (type.IsArray) { array = Array.CreateInstance(elementType, setters.Count); field.SetValue(instance, array); } else if (!array.IsFixedSize) { PoolUtility.Resize(array, elementType, setters.Count); } else { return; } } for (int i = 0; i < setters.Count; i++) { setters[i].SetValue(array, i); } }
public void SetValue(object instance) { if (instance == null) { return; } var value = field.GetValue(instance); if (value == null) { if (isUnityObject) { return; } else { field.SetValue(instance, value = TypePoolManager.Create(type)); } } PoolUtility.InitializeFields(value, setters); }
public void InitializeFields(object instance) { PoolUtility.InitializeFields(instance, setters); }
void OnDestroy() { PoolUtility.ClearAllPools(); }