public StringBufferPool() { for (int i = 0; i < pool.Length; i++) { pool[i] = new PoolItem(this, i); } }
/// <summary> /// Spawn a new pool item within range of player. /// </summary> void SpawnAvailableMobile() { // Player must be in range of location if (!playerInLocationRange) { return; } // Get a free mobile from pool int item = GetNextFreePoolItem(); if (item == -1) { return; } // Get closest point on navgrid to player position in world DFPosition playerWorldPos = new DFPosition(playerGPS.WorldX, playerGPS.WorldZ); DFPosition playerGridPos = cityNavigation.WorldToNavGridPosition(playerWorldPos); // Spawn mobile at a random position and schedule to be live DFPosition spawnPosition; if (cityNavigation.GetRandomSpawnPosition(playerGridPos, out spawnPosition, navGridSpawnRadius)) { PoolItem poolItem = populationPool[item]; // Setup spawn position DFPosition worldPosition = cityNavigation.NavGridToWorldPosition(spawnPosition); Vector3 scenePosition = cityNavigation.WorldToScenePosition(worldPosition); poolItem.motor.transform.position = scenePosition; GameObjectHelper.AlignBillboardToGround(poolItem.motor.gameObject, new Vector2(0, 2f)); // Schedule for enabling poolItem.active = true; poolItem.scheduleEnable = true; populationPool[item] = poolItem; } }
private PoolItem GetBestItem(IList <PoolItem> items, CombinatorialSemantics semantics, DistanceMeasure distanceMeasure) { double bestDistance = Double.MaxValue; PoolItem bestItem = null; var allSemantics = items.Where(item => item is ISemanticsHolder && ((ISemanticsHolder)item.Node).SemanticsEvaluated) .Select(item => ((ISemanticsHolder)item.Node).Semantics); foreach (var item in items) { var semanticsNode = item.Node as ISemanticsHolder; if (semanticsNode != null && semanticsNode.SemanticsEvaluated) { var distance = distanceMeasure(semantics, semanticsNode.Semantics, allSemantics); if (distance < bestDistance) { bestDistance = distance; bestItem = item; } } } return(bestItem); }
/// <summary> /// Agrega una textura al pool. /// Si no existe la crea. Sino reutiliza una existente. /// </summary> public Texture createTexture(Device d3dDevice, string filePath, Texture d3dTexture) { //Si no existe, crear textura if (!texturesPool.ContainsKey(filePath)) { var newItem = new PoolItem(); if (d3dTexture == null) { d3dTexture = TextureLoader.FromFile(d3dDevice, filePath); } newItem.Texture = d3dTexture; newItem.FilePath = filePath; newItem.References = 0; texturesPool.Add(filePath, newItem); } //aumentar las referencias a esta textura var item = texturesPool[filePath]; item.References++; return(item.Texture); }
public int DecreaseSize(int size) { int nDecrease = size; lock (this) { if (nDecrease <= 0) { return(0); } if (nDecrease > _listFreeIndex.Count) { nDecrease = _listFreeIndex.Count; } for (int i = 0; i < nDecrease; i++) { _listObjects.Remove(_listFreeIndex[i]); } _listFreeIndex.Clear(); _listUsingIndex.Clear(); foreach (DictionaryEntry de in _listObjects) { PoolItem pitem = (PoolItem)de.Value; if (pitem.Using) { _listUsingIndex.Add(pitem.InnerObjectHashcode); } else { _listFreeIndex.Add(pitem.InnerObjectHashcode); } } } _nCurrentSize -= nDecrease; return(nDecrease); }
public bool MoveNext() { if (version != pool.version) { throw new InvalidOperationException( "Object pool was modified, enumeration operation may not execute."); } if (index >= pool.Capacity) { current = new KeyValuePair <T, bool>(); return(false); } PoolItem item = pool.itemList[index]; current = new KeyValuePair <T, bool>(item.instance, item.used); index++; return(true); }
public static GameObject GetObject(string poolName, Vector3 position, Vector3 rotation, bool active = true) { PoolItem curPoolItem = FindPool(poolName); for (int i = 0; i < curPoolItem.pool.Count; i++) { if (!curPoolItem.pool[i].activeSelf) { if (active) { curPoolItem.pool[i].SetActive(true); } curPoolItem.pool[i].transform.position = position; curPoolItem.pool[i].transform.eulerAngles = rotation; return(curPoolItem.pool[i]); } } return(null); throw new System.Exception("Pool Out of range"); }
public void DestroyAll(bool destroyTemplate = true) { lock (syncObject) { if (itemList.Count == 0) { return; } RecycleAll(); for (int i = 0; i < itemList.Count; ++i) { PoolItem item = itemList[i]; if (item.instance != null) { item.poolItem?.OnDestroying(); Destroying?.Invoke(item.instance); DestroyImpl(item.instance); } } if (itemList != null) { itemList.Clear(); itemList.Capacity = 0; } if (destroyTemplate && Template != null) { DestroyImpl(Template); Template = null; } version++; residueCount = 0; } }
/// <summary> /// /// </summary> public void Dispose() { if (expireTimer != null) { expireTimer.Dispose(); } lock (syncRoot) { while (pool.Count != 0) { PoolItem result = pool.First(); pool.Remove(result); try { IDisposable dispose = result.Item as IDisposable; if (dispose != null) { dispose.Dispose(); } else { var wcfProxy = result.Item as ICommunicationObject; if (wcfProxy != null) { try { wcfProxy.Close(); } catch (CommunicationException) { wcfProxy.Abort(); } catch (TimeoutException) { wcfProxy.Abort(); } } } } catch (Exception ex) { Logger.Warn("Dispose PoolItem", ex); } } } }
/// <summary> /// 构造指定类型的对象池,主要给具体对象池使用。 /// </summary> /// <param name="type">对象的类型typeof</param> /// <param name="create_param">创建对象的参数</param> /// <param name="init_size">预创建的对象个数</param> /// <param name="capacity">预创建的对象池大小</param> public ObjectPool(Type type, System.Object create_param, int init_size, int capacity) { if (init_size < 0 || capacity < 1 || init_size > capacity) { throw (new Exception("Invalid parameter!")); } _nCapacity = capacity; _listObjects = new Hashtable(capacity); _listFreeIndex = new ArrayList(capacity); _listUsingIndex = new ArrayList(capacity); _typeObject = type; _objCreateParam = create_param; for (int i = 0; i < init_size; i++) { PoolItem pitem = new PoolItem(type, create_param); _listObjects.Add(pitem.InnerObjectHashcode, pitem); _listFreeIndex.Add(pitem.InnerObjectHashcode); } _nCurrentSize = _listObjects.Count; }
private GameObject GetFromPool(Type type, int value, string name) { for (int i = 0; i < Pool.Count; i++) { var item = Pool[i]; if (item.EnumType == type && item.EnumValue == value && item.GameObject.activeSelf == false) { item.GameObject.SetActive(true); return(item.GameObject); } } var poolItem = new PoolItem(); poolItem.EnumType = type; poolItem.EnumValue = value; poolItem.GameObject = Instantiate(type, value, name); Pool.Add(poolItem); return(poolItem.GameObject); }
public void AddItemToPool(PoolItem item) { Pool p = GetPool(item); p.pool.Add(item); item.transform.parent = p.parentObject; item.gameObject.SetActive(false); #region oldCode /* * for (int i = 0; i < pools.Count; i++) * { * if (pools[i].poolItem.Equals(item)) * { * pools[i].pool.Add(item); * item.transform.parent = transform; * item.gameObject.SetActive(false); * } * } */ #endregion }
private PoolItem Wrap(object key, object obj) { PoolItem item; int index = this.AllocIdentifier(); try { item = new PoolItem(index, key, obj, this.SlidingExpiration); } catch (Exception exception) { this.pemptyIndexs.Enqueue(index); throw exception; } lock (this.pindexer.SyncRoot) { this.pindexer[key] = index; } item.BeforeReleased += new CancelEventHandler(this.Item_OnBeforeReleased); item.AfterReleased += new EventHandler(this.Item_OnAfterReleased); this._checker.Add(item); return(item); }
// Constructor with expected number of objects and instance and destroy functions specified. public ObjectPool(int size, InstanceFunction cfunc, DestroyFunction dfunc) : this() { m_InstanceFxn = cfunc; m_DestroyFxn = dfunc; for (int i = 0; i < size; ++i) { PoolItem <T> newItem = new PoolItem <T>(); newItem.m_object = m_InstanceFxn(); if (newItem.m_object == null) { newItem.m_state = ItemLife.Null; ++m_NullObjects; } else { newItem.m_state = ItemLife.Ready; ++m_ReadyObjects; } m_objects.Add(newItem); } }
//Optimized version, using a pre-defined index instead of searching for one. public GameObject RequestInstantiate(int index, Vector3 pos, Quaternion rot, bool callStartImmediately = true) { if (pooledObjects[index].Count > 0 && pooledObjects[index].Count <= 250) { GameObject firstIndex = pooledObjects[index][0]; firstIndex.transform.parent = null; firstIndex.transform.position = pos; firstIndex.transform.rotation = rot; firstIndex.SetActive(true); PoolItem objPI = firstIndex.GetComponent <PoolItem>(); objPI.prefabIndex = index; if (callStartImmediately) { objPI.InstantiateStart(); } pooledObjects[index].RemoveAt(0); return(firstIndex); } else { GameObject newInstance = (GameObject)Instantiate(poolPrefabs[index], pos, rot); newInstance.name = poolPrefabs[index].name; PoolItem objPI = newInstance.GetComponent <PoolItem>(); objPI.prefabIndex = index; if (callStartImmediately) { objPI.InstantiateStart(); } return(newInstance); } }
public CachePool(int initCount = 0, int maxCount = 0, object[] initParams = null, ILogger logger = null) { if (logger == null) { logger = new DefaultLogger(ToString()); } mLogger = logger; if (maxCount != 0) { if (initCount > maxCount) { initCount = maxCount; mLogger.LogWarning("initCount > maxCount, 设置的初始个数超过最大个数,已经把初始个数重置为最大个数", "构造函数"); } mPool = new Stack <PoolItem <T> >(maxCount); mUsingList = new List <PoolItem <T> >(maxCount); } else { mPool = new Stack <PoolItem <T> >(); mUsingList = new List <PoolItem <T> >(); } mMaxCount = maxCount; mInitParams = initParams; mTmpInfo = new CacheItemInfo <T>(); for (int i = 0; i < initCount; i++) { PoolItem <T> item = NewItem(); mPool.Push(item); } }
/// <summary> /// Despawns all objects from the pool /// </summary> /// <param name="spawnPoolName"></param> public void DespawnAll(string spawnPoolName) { foreach (KeyValuePair <string, List <GameObject> > list in activeSpawns) { if (list.Key.Contains(spawnPoolName)) { for (int i = 0; i < list.Value.Count; i++) { Regex regex = new Regex("[^a-z]", RegexOptions.IgnoreCase); string prefabName = regex.Replace(list.Value[i].gameObject.name, @""); PoolItem item = prefabSpawns.Find(x => x.Prefab.name == prefabName); if (item.Reparent) { list.Value[i].gameObject.transform.parent = item.Parent; } list.Value[i].gameObject.SetActive(false); } break; } } }
// Start is called before the first frame update public void DeactivatePoolItem(GameObject removeObject) { if (poolItemList == null || removeObject == null) { return; } int count = poolItemList.Count; for (int i = 0; i < count; ++i) { PoolItem poolItem = poolItemList[i]; if (poolItem.gameobject == removeObject) { activeCount--; poolItem.isActive = false; poolItem.gameobject.SetActive(false); return; } } }
private void ExtendCapacity() { if (this.CurrentSize >= this.MaxPoolSize) { if (this.ForceRelease) { this.ForceFree(); } if (this.pemptyIndexs.Count == 0) { throw new PoolOverflowException("Pool is full."); } } else { int currentSize = this.CurrentSize; PoolItem[] itemArray = new PoolItem[this.Capacity]; for (int i = 0; i < itemArray.Length; i++) { this.pemptyIndexs.Enqueue(currentSize + i); } this.parrays[this.ArraySize] = itemArray; } }
public DialogViewBase TryGetDialogViewFromPool(string prefabPath, Transform parent) { int index = 0; var enumerator = this._pool.GetEnumerator(); while (enumerator.MoveNext()) { PoolItem poolItem = enumerator.Current; if (poolItem.prefabPath == prefabPath) { this._pool.RemoveAt(index); DialogViewBase view = poolItem.view; view.gameObject.SetActive(true); view.transform.SetParent(parent); return(view); } ++index; } return(null); }
public void Initialize(PoolingList cachedList = null) { if (initialized) { return; } tr = transform; PoolingList cachePL = (cachedList != null) ? cachedList : (PoolingList)Resources.Load("Static Prefabs/PoolingList", typeof(PoolingList)); poolPrefabs = cachePL.poolPrefabs; poolParticlesPrefabs = cachePL.poolParticles; pooledObjects = new List <GameObject> [poolPrefabs.Length]; pooledParticles = new ParticleManager[poolParticlesPrefabs.Length]; for (int i = 0; i < poolPrefabs.Length; i++) { pooledObjects[i] = new List <GameObject>(); GameObject initObj = (GameObject)Instantiate(poolPrefabs[i]); initObj.name = poolPrefabs[i].name; PoolItem objPI = initObj.GetComponent <PoolItem>(); objPI.prefabIndex = i; objPI.AddToPool(); } for (int j = 0; j < poolParticlesPrefabs.Length; j++) { ParticleManager pm = (ParticleManager)Instantiate(poolParticlesPrefabs[j]); pm.transform.parent = tr; pooledParticles[j] = pm; } initialized = true; }
/// <summary> /// Check if food production item is available. /// </summary> /// <param name="availableProducts">filter productions with list of products</param> /// <returns>true if food production item is available</returns> public bool HasTrap(params string[] availableProducts) { string[] foodProductions = new string[] { "item_trap", "item_snake_trap", "item_rat_trap", "item_knife" }; // look in order trap, snake trap, rat trap, knife foreach (string foodProduction in foodProductions) { PoolItem item = FindPoolItem(foodProduction); if (item != null) { // check if production is available foreach (string product in availableProducts) { // if available, then return current trap if (item.Type.Production.Produce.ID == product) { return(true); } } } } return(false); }
/// <summary> /// Hace Dispose de una textura del pool, pero solo si nadie mas la está utilizando. /// </summary> /// <returns>True si se hizo un Dispose físico</returns> public bool disposeTexture(string filePath) { if (texturesPool.ContainsKey(filePath)) { PoolItem item = texturesPool[filePath]; //Quitar una referencia a esta textura item.References--; //Si nadie mas referencia esta textura, eliminar realmente if (item.References <= 0) { //Dispose real de textura de DirectX if (item.Texture != null && !item.Texture.Disposed) { item.Texture.Dispose(); } //Quitar del pool texturesPool.Remove(filePath); return(true); } } return(false); }
/// <summary> /// Assemble the input sequences into the largest possible contigs. /// </summary> /// <remarks> /// The algorithm is: /// 1. initialize list of contigs to empty list. List of seqs is passed as argument. /// 2. compute pairwise overlap scores for each pair of input seqs (with reversal and /// complementation as appropriate). /// 3. choose best overlap score. the “merge items” (can be seqs or contigs) are the /// items with that score. If best score is less than threshold, assembly is finished. /// 4. merge the merge items into a single contig and remove them from their list(s) /// 5. compute the overlap between new item and all existing items /// 6. go to step 3 /// </remarks> /// <param name="inputSequences">The sequences to assemble.</param> /// <returns>Returns the OverlapDeNovoAssembly instance which contains list of /// contigs and list of unmerged sequences which are result of this assembly.</returns> public IDeNovoAssembly Assemble(IEnumerable <ISequence> inputSequences) { if (null == inputSequences) { throw new ArgumentNullException(Properties.Resource.ParameterNameInputSequences); } // Initializations if (inputSequences.Count() > 0) { _sequenceAlphabet = inputSequences.First().Alphabet; if (ConsensusResolver == null) { ConsensusResolver = new SimpleConsensusResolver(_sequenceAlphabet); } else { ConsensusResolver.SequenceAlphabet = _sequenceAlphabet; } } OverlapDeNovoAssembly sequenceAssembly = null; // numbering convention: every pool item (whether sequence or contig) // gets a fixed number. // sequence index = index into inputs (which we won't modify) // contig index = nSequences + index into contigs List <PoolItem> pool = new List <PoolItem>(); foreach (ISequence seq in inputSequences) { pool.Add(new PoolItem(seq)); } // put all the initial sequences into the pool, and generate the pair scores. // there are no contigs in the pool yet. // to save an iteration, we'll also find the best global score as we go. ItemScore globalBest = new ItemScore(-1, -1, false, false, 0, 0); int globalBestLargerIndex = -1; int unconsumedCount = inputSequences.Count(); // Compute alignment scores for all combinations between input sequences // Store these scores in the poolItem correspodning to each sequence for (int newSeq = 0; newSeq < pool.Count; ++newSeq) { PoolItem newItem = pool[newSeq]; for (int oldSeq = 0; oldSeq < newSeq; ++oldSeq) { PoolItem oldItem = pool[oldSeq]; ItemScore score = AlignSequence(oldItem.SequenceOrConsensus, newItem.SequenceOrConsensus, oldSeq, newSeq); newItem.Scores.Add(score); if (score.OverlapScore > globalBest.OverlapScore) { globalBest = new ItemScore(score); globalBestLargerIndex = newSeq; } } } // Merge sequence if best score is above threshold // and add new contig to pool if (globalBest.OverlapScore >= MergeThreshold) { if (Trace.Want(Trace.AssemblyDetails)) { ApplicationLog.WriteLine("Merging (overlap score {0}):", globalBest.OverlapScore); } PoolItem mergeItem1 = pool[globalBest.OtherItem]; PoolItem mergeItem2 = pool[globalBestLargerIndex]; Contig newContig = new Contig(); if (Trace.Want(Trace.AssemblyDetails)) { ApplicationLog.WriteLine( "new pool item {0} will merge old items {1} and {2}", pool.Count, globalBest.OtherItem, globalBestLargerIndex); } MergeLowerIndexedSequence(newContig, globalBest, mergeItem1.Sequence); MergeHigherIndexedSequence(newContig, globalBest, mergeItem2.Sequence); MakeConsensus(newContig); // Set ConsumedBy value and // free memory as these sequences are no longer used mergeItem1.ConsumedBy = pool.Count; mergeItem2.ConsumedBy = pool.Count; mergeItem1.FreeSequences(); mergeItem2.FreeSequences(); pool.Add(new PoolItem(newContig)); unconsumedCount--; while (unconsumedCount > 1) { // Compute scores for each unconsumed sequence with new contig globalBest = new ItemScore(-1, -1, false, false, 0, 0); globalBestLargerIndex = -1; int newSeq = pool.Count - 1; PoolItem newItem = pool[newSeq]; for (int oldSeq = 0; oldSeq < pool.Count - 1; ++oldSeq) { PoolItem oldItem = pool[oldSeq]; if (oldItem.ConsumedBy >= 0) { // already consumed - just add dummy score to maintain correct indices newItem.Scores.Add(new ItemScore()); } else { ItemScore score = AlignSequence(oldItem.SequenceOrConsensus, newItem.SequenceOrConsensus, oldSeq, newSeq); newItem.Scores.Add(score); } } // find best global score in the modified pool. globalBest = new ItemScore(-1, -1, false, false, 0, 0); globalBestLargerIndex = -1; for (int current = 0; current < pool.Count; ++current) { PoolItem curItem = pool[current]; if (curItem.ConsumedBy < 0) { for (int other = 0; other < current; ++other) { if (pool[other].ConsumedBy < 0) { ItemScore itemScore = curItem.Scores[other]; if (itemScore.OverlapScore > globalBest.OverlapScore) { globalBest = new ItemScore(itemScore); // copy the winner so far globalBestLargerIndex = current; } } } } } if (globalBest.OverlapScore >= MergeThreshold) { // Merge sequences / contigs if above threshold mergeItem1 = pool[globalBest.OtherItem]; mergeItem2 = pool[globalBestLargerIndex]; newContig = new Contig(); if (mergeItem1.IsContig) { if (Trace.Want(Trace.AssemblyDetails)) { ApplicationLog.WriteLine( "item {0} is a contig (reversed = {1}, complemented = {2}, offset = {3}", globalBest.OtherItem, globalBest.Reversed, globalBest.Complemented, globalBest.FirstOffset); } MergeLowerIndexedContig(newContig, globalBest, mergeItem1.Contig); } else { if (Trace.Want(Trace.AssemblyDetails)) { ApplicationLog.WriteLine( "item {0} is a sequence (reversed = {1}, complemented = {2}, offset = {3}", globalBest.OtherItem, globalBest.Reversed, globalBest.Complemented, globalBest.FirstOffset); } MergeLowerIndexedSequence(newContig, globalBest, mergeItem1.Sequence); } if (mergeItem2.IsContig) { if (Trace.Want(Trace.AssemblyDetails)) { ApplicationLog.WriteLine( "item {0} is a contig (offset = {1}", globalBestLargerIndex, globalBest.SecondOffset); } MergeHigherIndexedContig(newContig, globalBest, mergeItem2.Contig); } else { if (Trace.Want(Trace.AssemblyDetails)) { ApplicationLog.WriteLine( "item {0} is a sequence (offset = {1}", globalBestLargerIndex, globalBest.SecondOffset); } MergeHigherIndexedSequence(newContig, globalBest, mergeItem2.Sequence); } MakeConsensus(newContig); if (Trace.Want(Trace.AssemblyDetails)) { Dump(newContig); } // Set ConsumedBy value for these poolItems and // free memory as these sequences are no longer used mergeItem1.ConsumedBy = pool.Count; mergeItem2.ConsumedBy = pool.Count; mergeItem1.FreeSequences(); mergeItem2.FreeSequences(); pool.Add(new PoolItem(newContig)); unconsumedCount--; } else { // None of the alignment scores cross threshold // No more merges possible. So end iteration. break; } } } // no further qualifying merges, so we're done. // populate contigs and unmergedSequences sequenceAssembly = new OverlapDeNovoAssembly(); foreach (PoolItem curItem in pool) { if (curItem.ConsumedBy < 0) { if (curItem.IsContig) { sequenceAssembly.Contigs.Add(curItem.Contig); } else { sequenceAssembly.UnmergedSequences.Add(curItem.Sequence); } } } return(sequenceAssembly); }
internal void Recycle(string prefabName, PoolItem poolItem) { SpawnPoolDic[prefabName].Recycle(poolItem); }
public void Recycle(PoolItem poolItem) { poolItem.transform.parent = parentRoot; poolItemList.Add(poolItem); }
/// <summary> /// Agrega una textura al pool. /// Si no existe la crea. Sino reutiliza una existente. /// </summary> public Texture createTexture(Device d3dDevice, string filePath, Texture d3dTexture) { /*lock (syncRoot) No hace falta que este sincronizado*/ //Si no existe, crear textura if (!texturesPool.ContainsKey(filePath)) { PoolItem newItem = new PoolItem(); newItem.Texture = d3dTexture; newItem.FilePath = filePath; newItem.References = 0; texturesPool.Add(filePath, newItem); } //aumentar las referencias a esta textura PoolItem item = texturesPool[filePath]; item.References++; return item.Texture; }
/// <summary> /// Agrega una textura al pool. /// Si no existe la crea. Sino reutiliza una existente. /// </summary> public Texture createTexture(Device d3dDevice, string filePath, Texture d3dTexture) { //Si no existe, crear textura if (!texturesPool.ContainsKey(filePath)) { PoolItem newItem = new PoolItem(); if (d3dTexture == null) { d3dTexture = TextureLoader.FromFile(d3dDevice, filePath); } newItem.Texture = d3dTexture; newItem.FilePath = filePath; newItem.References = 0; texturesPool.Add(filePath, newItem); } //aumentar las referencias a esta textura PoolItem item = texturesPool[filePath]; item.References++; return item.Texture; }
private void SetScale(PoolItem poolItem) { var localScale = scale.RandomValue; poolItem.transform.localScale = new Vector3(localScale, localScale, 0f); }
public void Remove(PoolItem <T> poolItem) { _poolItems.Remove(poolItem); _totalWeight -= poolItem.Weight; }
public void SetUp() { _availableObjectsStorageMock = Mocks.Storage.GetNew(); _objectActionsMock = Mocks.ObjectActions.GetNewSuccessful(); _objectUtilizerMock = Mocks.ObjectUtilizer.GetNew(); _outPoolObject = null; _poolItem = new PoolItem<TestKey, TestResource>(_settings, _availableObjectsStorageMock.Object, _objectActionsMock.Object, _objectUtilizerMock.Object); }
/// <summary> /// Promote pending mobiles to live status and recycle out of range mobiles. /// </summary> void UpdateMobiles() { bool isDaytime = DaggerfallUnity.Instance.WorldTime.Now.IsDay; for (int i = 0; i < populationPool.Count; i++) { PoolItem poolItem = populationPool[i]; // Show pending mobiles when available if (poolItem.active && poolItem.scheduleEnable && AllowMobileActivationChange(ref poolItem) && isDaytime) { poolItem.npc.Motor.gameObject.SetActive(true); poolItem.scheduleEnable = false; poolItem.npc.RandomiseNPC(GetEntityRace()); poolItem.npc.Motor.InitMotor(); // Adjust billboard position for actual size Vector2 size = poolItem.npc.Billboard.GetBillboardSize(); if (Mathf.Abs(size.y - 2f) > 0.1f) { poolItem.npc.Billboard.transform.Translate(0, (size.y - 2f) * 0.52f, 0); } } // Get distance to player poolItem.distanceToPlayer = Vector3.Distance(playerGPS.transform.position, poolItem.npc.Motor.transform.position); // Mark for recycling if (poolItem.npc.Motor.SeekCount > 4 || poolItem.distanceToPlayer > recycleDistance || !isDaytime) { poolItem.scheduleRecycle = true; } // Recycle pending mobiles when available if (poolItem.active && poolItem.scheduleRecycle && AllowMobileActivationChange(ref poolItem)) { poolItem.npc.Motor.gameObject.SetActive(false); poolItem.active = false; poolItem.scheduleEnable = false; poolItem.scheduleRecycle = false; if (poolItem.npc.Billboard) { poolItem.npc.Billboard.transform.localPosition = Vector3.zero; } } populationPool[i] = poolItem; // Do not render active mobile until it has made at least 1 full tile move // This hides skating effect while unit aligning to navigation grid if (poolItem.active && poolItem.npc.Billboard) { MeshRenderer billboardRenderer = poolItem.npc.Billboard.GetComponent <MeshRenderer>(); if (billboardRenderer) { billboardRenderer.enabled = (poolItem.npc.Motor.MoveCount > 0) ? true : false; } } } }
public void ReturnItemToPool(PoolItem poolItem) { PoolContainer poolContainer = poolContainers.Find((x) => { return(x.IsPoolOf(poolItem.PoolName)); }); poolContainer.ReturnItemToPool(poolItem); }
public abstract void ReturnGeneric(PoolItem item);