From 732d8ef6c48e5b9e7ff01fc61511b27ea8300b85 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 30 Jan 2024 11:39:44 +0700 Subject: [PATCH 01/35] Format code --- Assets/Environment/Scripts/Grid.cs | 69 ++++++++------- Assets/Environment/Scripts/Slot.cs | 13 +-- .../AddressableGameObjectPoolSample1.cs | 67 +++++++-------- .../AddressableGameObjectPoolSample2.cs | 2 +- .../AddressablePoolBehaviourSample1.cs | 36 ++++---- .../Scripts/CustomAddressGameObjectPool.cs | 12 +-- Assets/PoolSample/Demo.cs | 2 +- .../Scripts/CustomGameObjectPool.cs | 30 +------ .../Scripts/GameObjectPoolSample.cs | 85 +++++++------------ .../Pools/AssetRefGameObjectPool.cs | 4 +- .../Prefabs/AddressGameObjectPrefab.cs | 19 ++--- .../Foundation/Prefabs/AddressPrefab{T}.cs | 6 +- .../Prefabs/AssetRefGameObjectPrefab.cs | 19 ++--- .../Common/Interfaces/IReturnable{T}.cs | 2 +- .../Foundation/Common/SharedPool.cs | 20 +---- .../Common/UnityObjectPrefab.cs | 2 +- .../Common/UnityObjectPrepooler.cs | 10 +-- .../Pools/ScriptablePool{T}.cs | 6 +- .../System.Collections.Generic/HashSetPool.cs | 17 +--- .../UnityPoolBehaviour{T,TPrefab,TPool}.cs | 4 +- .../UnityPools/Common/Interfaces/IPrefab.cs | 2 +- .../Common/Interfaces/IPrefab{T}.cs | 3 +- .../Interfaces/IPrepooler{T,TPrefab,TPool}.cs | 6 +- .../UnityPools/Pools/GameObjectPool.cs | 18 ++-- .../Pools/GameObjectPool{TPrefab}.cs | 41 +++------ .../UnityPools/Pools/UnityPool{T,TPrefab}.cs | 24 ++---- .../UnityPools/Prefabs/GameObjectPrefab.cs | 15 +--- .../Prefabs/UnityPrefab{T,TSource}.cs | 30 +++---- .../UnityPrepooler{T,TPrefab,TPool}.cs | 27 +++--- 29 files changed, 214 insertions(+), 377 deletions(-) diff --git a/Assets/Environment/Scripts/Grid.cs b/Assets/Environment/Scripts/Grid.cs index e9e6f55..750bb9b 100644 --- a/Assets/Environment/Scripts/Grid.cs +++ b/Assets/Environment/Scripts/Grid.cs @@ -6,7 +6,7 @@ namespace Sample.Environment { public class Grid { - private List _slots = new List(); + private readonly List _slots = new (); public Grid(int width, int height) { @@ -28,25 +28,17 @@ public Grid(int width, int height, bool odd) if (x % 2 == 0) continue; } - else - { - if (x % 2 != 0) - continue; - } - + else if (x % 2 != 0) + continue; for (int y = -height; y < height; y++) { if (odd) { if (y % 2 == 0) continue; - } - else - { - if (y % 2 != 0) - continue; - } - + } + else if (y % 2 != 0) + continue; _slots.Add(new Slot(new Vector3(x, 0, y), false)); } } @@ -56,31 +48,44 @@ public Slot GetAvailableSlot() { for (int i = 0; i < this._slots.Count; i++) { - if (!this._slots[i].isOccupied) - { - var newSlot = this._slots[i]; - newSlot.isOccupied = true; - this._slots[i] = newSlot; - return this._slots[i]; - } + if (this._slots[i].isOccupied) + continue; + var newSlot = this._slots[i]; + newSlot.isOccupied = true; + this._slots[i] = newSlot; + return this._slots[i]; } - - throw new Exception("No available slot"); + + return default; + } + + public bool TryGetAvailableSlot(out Slot slot) + { + for (int i = 0; i < this._slots.Count; i++) + { + if (this._slots[i].isOccupied) + continue; + var newSlot = this._slots[i]; + newSlot.isOccupied = true; + this._slots[i] = newSlot; + slot = this._slots[i]; + return true; + } + slot = default; + return false; } - public Slot FreeSlot(Vector3 position) + public void FreeSlot(Vector3 position) { foreach (var slot in this._slots) { - if (slot.position == position) - { - var newSlot = slot; - newSlot.isOccupied = false; - this._slots[this._slots.IndexOf(slot)] = newSlot; - return slot; - } + if (slot.position != position) + continue; + var newSlot = slot; + newSlot.isOccupied = false; + this._slots[this._slots.IndexOf(slot)] = newSlot; + return; } - throw new Exception("No available slot"); } } diff --git a/Assets/Environment/Scripts/Slot.cs b/Assets/Environment/Scripts/Slot.cs index 82452d7..56d6b3d 100644 --- a/Assets/Environment/Scripts/Slot.cs +++ b/Assets/Environment/Scripts/Slot.cs @@ -4,23 +4,14 @@ namespace Sample.Environment { public struct Slot { + public Vector3 position; public bool isOccupied; - + public Slot(Vector3 position, bool isOccupied) { this.position = position; this.isOccupied = isOccupied; } - - public void Occupy() - { - isOccupied = true; - } - - public void Free() - { - isOccupied = false; - } } } \ No newline at end of file diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs index 7f73555..82652e4 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs @@ -1,4 +1,3 @@ -using System; using Cysharp.Threading.Tasks; using UnityEngine; using ZBase.Collections.Pooled.Generic; @@ -11,9 +10,8 @@ namespace Pooling.Sample public class AddressableGameObjectPoolSample1 : MonoBehaviour { private const string K_CHARACTER01_KEY = "Character_AddressPool_P01"; - - private Grid _grid = new Grid(20, 15, true); - private List _spawned = new List(); + private Grid _grid = new(20, 15, true); + private List _spawned = new(); private void Start() { var pool = SharedPool.Of(); @@ -23,35 +21,6 @@ private void Start() }; } - private async void OnGUI() - { - if (GUI.Button(new Rect(10, 10, 150, 50), "Spawn")) - { - for (int i = 0; i < 100; i++) - { - Spawn().Forget(); - } - Debug.Log("Spawn 100 item from the AddressableGameObject pool"); - } - - if (GUI.Button(new Rect(10, 70, 150, 50), "Spawn Disposable Item")) - { - await SpawnDisposableItems(); - Debug.Log("Item automatically returned to pool when context is disposed"); - } - - if (GUI.Button(new Rect(10, 130, 150, 50), "Return")) - { - Return(); - Debug.Log("Return all item to the pool"); - } - - if (GUI.Button(new Rect(10, 190, 150, 50), "Release All")) - { - ReleaseAll(); - Debug.Log("Release all item from the pool"); - } - } private async UniTask Spawn() { @@ -90,9 +59,37 @@ private void ReleaseAll() _spawned.Clear(); } - private void OnDisable() + private void OnDisable()=> ReleaseAll(); + + + private async void OnGUI() { - ReleaseAll(); + if (GUI.Button(new Rect(10, 10, 150, 50), "Spawn")) + { + for (int i = 0; i < 100; i++) + { + Spawn().Forget(); + } + Debug.Log("Spawn 100 item from the AddressableGameObject pool"); + } + + if (GUI.Button(new Rect(10, 70, 150, 50), "Spawn Disposable Item")) + { + await SpawnDisposableItems(); + Debug.Log("Item automatically returned to pool when context is disposed"); + } + + if (GUI.Button(new Rect(10, 130, 150, 50), "Return")) + { + Return(); + Debug.Log("Return all item to the pool"); + } + + if (GUI.Button(new Rect(10, 190, 150, 50), "Release All")) + { + ReleaseAll(); + Debug.Log("Release all item from the pool"); + } } } } \ No newline at end of file diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs index 9030d7d..98f017f 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs @@ -19,7 +19,7 @@ private void Start() pool.Prefab = new AddressGameObjectPrefab { Source = K_CHARACTER02_KEY, Parent = transform, - PrepoolAmount = 100 + PrePoolAmount = 100 }; pool.Prepool().Forget(); } diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs index 8ed1181..e61b89d 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs @@ -1,8 +1,6 @@ -using System; using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; -using UnityEngine.Serialization; using ZBase.Collections.Pooled.Generic; using ZBase.Foundation.Pooling; @@ -25,30 +23,13 @@ public class AddressablePoolBehaviourSample1 : MonoBehaviour { [SerializeField] private AddressableColliderPoolBehaviour pool; - private readonly List _units = new List(); + private readonly List _units = new(); - private async void Start() - { - await this.pool.Prepool(gameObject.GetCancellationTokenOnDestroy()); - } - - private async void OnGUI() - { - if(GUI.Button(new Rect(0, 0, 150, 50), "Rent All")) - { - await Rent(gameObject.GetCancellationTokenOnDestroy()); - } - - if (GUI.Button(new Rect(0, 100, 150, 50), "Return All")) - { - this.pool.Return(this._units); - } - } + private async void Start() => await this.pool.Prepool(destroyCancellationToken); // ReSharper disable Unity.PerformanceAnalysis private async UniTask Rent(CancellationToken cancelToken = default) { - //fill units in range (-30,0,-15) to (30,0,15) sequentially, each unit is 1x1x1 for (int x = -20; x < 20; x++) { if(x % 2 == 0) @@ -64,5 +45,18 @@ private async UniTask Rent(CancellationToken cancelToken = default) } } } + + private async void OnGUI() + { + if(GUI.Button(new Rect(0, 0, 150, 50), "Rent All")) + { + await Rent(gameObject.GetCancellationTokenOnDestroy()); + } + + if (GUI.Button(new Rect(0, 100, 150, 50), "Return All")) + { + this.pool.Return(this._units); + } + } } } \ No newline at end of file diff --git a/Assets/PoolSample/AddressablePools/Scripts/CustomAddressGameObjectPool.cs b/Assets/PoolSample/AddressablePools/Scripts/CustomAddressGameObjectPool.cs index 33fcfde..55033a6 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/CustomAddressGameObjectPool.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/CustomAddressGameObjectPool.cs @@ -8,35 +8,35 @@ namespace Pooling.Sample { public class CustomAddressGameObjectPool : AddressGameObjectPool { - private readonly UnityPrepooler _prepooler; + private readonly UnityPrePool _prePool; public CustomAddressGameObjectPool() : base() { - _prepooler = new UnityPrepooler(); + this._prePool = new UnityPrePool(); } public CustomAddressGameObjectPool(AddressGameObjectPrefab prefab) : base(prefab) { - _prepooler = new UnityPrepooler(); + this._prePool = new UnityPrePool(); } public CustomAddressGameObjectPool(UniqueQueue queue) : base(queue) { - _prepooler = new UnityPrepooler(); + this._prePool = new UnityPrePool(); } public CustomAddressGameObjectPool(UniqueQueue queue, AddressGameObjectPrefab prefab) : base(queue, prefab) { - _prepooler = new UnityPrepooler(); + this._prePool = new UnityPrePool(); } public async UniTask Prepool() { - await _prepooler.Prepool(Prefab, this, Prefab.Parent); + await this._prePool.PrePool(Prefab, this, Prefab.Parent); } } } \ No newline at end of file diff --git a/Assets/PoolSample/Demo.cs b/Assets/PoolSample/Demo.cs index c06a236..9d2f9ac 100644 --- a/Assets/PoolSample/Demo.cs +++ b/Assets/PoolSample/Demo.cs @@ -59,7 +59,7 @@ async void Start() Debug.Log(foo.Name); var gameObjectPrefab = new GameObjectPrefab() { - Parent = this.transform, PrepoolAmount = 40, Source = this.prefab + Parent = this.transform, PrePoolAmount = 40, Source = this.prefab }; _gameObjectPool = new GameObjectPool(gameObjectPrefab); diff --git a/Assets/PoolSample/GameObjectPools/Scripts/CustomGameObjectPool.cs b/Assets/PoolSample/GameObjectPools/Scripts/CustomGameObjectPool.cs index a2067ef..870c93d 100644 --- a/Assets/PoolSample/GameObjectPools/Scripts/CustomGameObjectPool.cs +++ b/Assets/PoolSample/GameObjectPools/Scripts/CustomGameObjectPool.cs @@ -1,6 +1,5 @@ -using System.Runtime.CompilerServices; +using Cysharp.Threading.Tasks; using UnityEngine; -using ZBase.Foundation.Pooling; using ZBase.Foundation.Pooling.UnityPools; namespace Pooling.Sample @@ -10,31 +9,8 @@ namespace Pooling.Sample /// public class CustomGameObjectPool : GameObjectPool { - private readonly UnityPrepooler _prepooler; - - public CustomGameObjectPool() : base() - { - _prepooler = new UnityPrepooler(); - } - - public CustomGameObjectPool(GameObjectPrefab prefab) : base(prefab) - { - _prepooler = new UnityPrepooler(); - } - - public CustomGameObjectPool(UniqueQueue queue) : base(queue) - { - _prepooler = new UnityPrepooler(); - } - - public CustomGameObjectPool(UniqueQueue queue, GameObjectPrefab prefab) : base(queue, prefab) - { - _prepooler = new UnityPrepooler(); - } + private readonly UnityPrePool _prePool = new(); - public void Prepool() - { - _prepooler.Prepool(Prefab, this, Prefab.Parent); - } + public void PrePool() => this._prePool.PrePool(Prefab, this, Prefab.Parent).Forget(); } } \ No newline at end of file diff --git a/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs b/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs index 307b0ea..33955a9 100644 --- a/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs +++ b/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs @@ -1,4 +1,3 @@ -using Cysharp.Threading.Tasks; using UnityEngine; using ZBase.Collections.Pooled.Generic; using ZBase.Foundation.Pooling; @@ -13,38 +12,24 @@ public class GameObjectPoolSample : MonoBehaviour public Transform poolParent2; public GameObject prefab1; public GameObject prefab2; + //you can access the spawned objects in your own list - public List myGameObjects = new List(); - + public List myGameObjects = new(); + //Manage lifetime of the pool yourself (in this case, the pool4 will not be registered in the SharedPool) public GameObjectPool pool4; - public List pool4Objects = new List(); + public List pool4Objects = new(); - private Grid _grid = new Grid(20, 15, true); - private async UniTaskVoid Start() - { - /* - //GameObjectPool do not have implementation of Prepool - var pool1 = new GameObjectPool(); - pool1.Prefab = new GameObjectPrefab() {Parent = poolParent1, Source = this.prefab1}; - var item = await pool1.Rent(); - item.transform.position = this._grid.GetAvailableSlot().position; - */ + private readonly Grid _grid = new(20, 15, true); - /* - //Create a new CustomGameObjectPool and prepool 10 objects - //This pool is not registered in the SharedPool, so you can't get it later using SharedPool.Of() - var pool = new CustomGameObjectPool(); - pool.Prefab = new GameObjectPrefab() {Parent = poolParent1, PrepoolAmount = 10, Source = this.prefab2}; - pool.Prepool(); - */ - //Create a new CustomGameObjectPool and prepool 10 objects - //This pool will be automatically registered in the SharedPool, so you can globally get it later using SharedPool.Of() + private void Start() + { var pool2 = SharedPool.Of(); - pool2.Prefab = new GameObjectPrefab() {Parent = poolParent1, PrepoolAmount = 10, Source = this.prefab1}; - pool2.Prepool(); - - pool4 = new GameObjectPool(new GameObjectPrefab(){Parent = poolParent2, PrepoolAmount = 100, Source = this.prefab2}); + pool2.Prefab = new GameObjectPrefab { Parent = poolParent1, PrePoolAmount = 10, Source = this.prefab1 }; + pool2.PrePool(); + pool4 = new GameObjectPool(new GameObjectPrefab { + Parent = poolParent2, PrePoolAmount = 100, Source = this.prefab2 + }); } private async void OnGUI() @@ -66,51 +51,43 @@ private async void OnGUI() if (GUI.Button(new Rect(0, 100, 300, 50), "Despawn in SharedPool")) { var pool = SharedPool.Of(); - //despawn first 7 objects - for (int i = 0; i < 50; i++) + for (int i = myGameObjects.Count - 1; i >= 0; i++) { var go = this.myGameObjects[i]; pool.Return(go); this._grid.FreeSlot(go.transform.position); } - - /* - you can despawn all the list: pool.Return(this.myGameObjects); - */ } - + if (GUI.Button(new Rect(0, 200, 150, 50), "Spawn in Pool 4")) { for (int i = 0; i < 100; i++) { + if (!this._grid.TryGetAvailableSlot(out var slot)) + continue; var go = await this.pool4.Rent(); - go.transform.position = this._grid.GetAvailableSlot().position; + go.transform.position = slot.position; go.SetActive(true); this.pool4Objects.Add(go); } - Debug.Log("Rent 100 game objects in Pool 4"); - Debug.Log("There is " + this.pool4.Count() + " objects in Pool 4"); } - - if (GUI.Button(new Rect(0, 300, 150, 50), "Despawn in Pool 4")) + + if (!GUI.Button(new Rect(0, 300, 150, 50), "Despawn in Pool 4")) + return; + + //return random 50 times in pool4, may some objects will be returned multiple times + for (int i = 0; i < 50; i++) { - //return random 50 times in pool4, may some objects will be returned multiple times - for (int i = 0; i < 50; i++) - { - var go = this.pool4Objects[UnityEngine.Random.Range(0, this.pool4Objects.Count)]; - this.pool4.Return(go); - this._grid.FreeSlot(go.transform.position); - } - Debug.Log("Return random 50 times game objects in Pool 4"); - Debug.Log("There is " + this.pool4.Count() + " objects in Pool 4"); + var index = Random.Range(0, this.pool4Objects.Count); + if (this.pool4Objects.Count <= index) + continue; + var go = this.pool4Objects[index]; + this.pool4.Return(go); + this._grid.FreeSlot(go.transform.position); + this.pool4Objects.RemoveAt(index); } - } - private void OnDestroy() - { - //manually dispose the pool4 - this.pool4.Dispose(); - } + private void OnDestroy() => this.pool4.Dispose(); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs index 2d93cf9..d330e1d 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs @@ -6,11 +6,9 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AssetRefGameObjectPool - : GameObjectPool + public class AssetRefGameObjectPool : GameObjectPool { public AssetRefGameObjectPool() - : base() { } public AssetRefGameObjectPool(AssetRefGameObjectPrefab prefab) diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs index 6a7793f..a39aa20 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs @@ -8,22 +8,13 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AddressGameObjectPrefab - : AddressPrefab + public class AddressGameObjectPrefab : AddressPrefab { protected override async UniTask Instantiate( - string source - , Transform parent - , CancellationToken cancelToken - ) + string source, Transform parent, CancellationToken cancelToken = default) { - AsyncOperationHandle handle; - - if (parent) - handle = Addressables.InstantiateAsync(source, parent); - else - handle = Addressables.InstantiateAsync(source); - + AsyncOperationHandle handle = + parent ? Addressables.InstantiateAsync(source, parent) : Addressables.InstantiateAsync(source); return await handle.WithCancellation(cancelToken); } @@ -33,4 +24,4 @@ public override void Release(GameObject instance) Addressables.ReleaseInstance(instance); } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressPrefab{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressPrefab{T}.cs index 09f4521..86bd866 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressPrefab{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressPrefab{T}.cs @@ -4,9 +4,7 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public abstract class AddressPrefab - : UnityPrefab - where T : UnityEngine.Object + public abstract class AddressPrefab : UnityPrefab where T : UnityEngine.Object { } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs index 394e6a0..5146873 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs @@ -8,22 +8,13 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AssetRefGameObjectPrefab - : AssetRefPrefab + public class AssetRefGameObjectPrefab : AssetRefPrefab { protected override async UniTask Instantiate( - AssetReferenceGameObject source - , Transform parent - , CancellationToken cancelToken - ) + AssetReferenceGameObject source, Transform parent, CancellationToken cancelToken = default) { - AsyncOperationHandle handle; - - if (parent) - handle = source.InstantiateAsync(parent, true); - else - handle = source.InstantiateAsync(); - + AsyncOperationHandle handle = + parent ? source.InstantiateAsync(parent, true) : source.InstantiateAsync(); return await handle.WithCancellation(cancelToken); } @@ -33,4 +24,4 @@ public override void Release(GameObject instance) Source.ReleaseInstance(instance); } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/Interfaces/IReturnable{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/Interfaces/IReturnable{T}.cs index 4bcd506..6ee3b0c 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/Interfaces/IReturnable{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/Interfaces/IReturnable{T}.cs @@ -1,6 +1,6 @@ namespace ZBase.Foundation.Pooling { - public interface IReturnable + public interface IReturnable { void Return(T instance); } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/SharedPool.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/SharedPool.cs index c139761..7ddbe13 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/SharedPool.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/SharedPool.cs @@ -6,26 +6,14 @@ namespace ZBase.Foundation.Pooling public static class SharedPool { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T Of() where T : IPool, IShareable, new() - => SharedInstance.Instance; + public static T Of() where T : IPool, IShareable, new() => SharedInstance.Instance; private static class SharedInstance where T : IPool, IShareable, new() { - private static T s_instance; - - public static T Instance => s_instance; - - static SharedInstance() - { - Init(); - } - - /// + public static T Instance { get; private set; } + static SharedInstance() => Init(); [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] - static void Init() - { - s_instance = new T(); - } + static void Init() => Instance = new T(); } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrefab.cs index e354b95..10a7814 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrefab.cs @@ -28,7 +28,7 @@ public ScriptableSource Source set => _source = value; } - public int PrepoolAmount + public int PrePoolAmount { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _prepoolAmount; diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrepooler.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrepooler.cs index 0cbcafc..450b8bf 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrepooler.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Common/UnityObjectPrepooler.cs @@ -5,13 +5,13 @@ namespace ZBase.Foundation.Pooling.ScriptablePools { - public struct UnityObjectPrepooler - : IPrepooler > { - public async UniTask Prepool( + public async UniTask PrePool( UnityObjectPrefab prefab , IReturnable pool , Transform defaultParent @@ -24,13 +24,13 @@ UnityObjectPrefab prefab if (pool == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pool); - if (prefab.PrepoolAmount <= 0) + if (prefab.PrePoolAmount <= 0) return; if (prefab.Parent == false && defaultParent) prefab.Parent = defaultParent; - for (int i = 0, count = prefab.PrepoolAmount; i < count; i++) + for (int i = 0, count = prefab.PrePoolAmount; i < count; i++) { var instance = await prefab.Instantiate(cancelToken); pool.Return(instance); diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Pools/ScriptablePool{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Pools/ScriptablePool{T}.cs index 24e9e13..55c3f75 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Pools/ScriptablePool{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/ScriptablePools/Pools/ScriptablePool{T}.cs @@ -17,8 +17,8 @@ public class ScriptablePool [SerializeField] private bool _prepoolOnStart = false; - private readonly UnityObjectPool _pool = new UnityObjectPool(); - private readonly UnityObjectPrepooler _prepooler = default; + private readonly UnityObjectPool _pool = new(); + private readonly UnityObjectPrePool _prePool = default; public bool PrepoolOnStart { @@ -57,7 +57,7 @@ public void Return(T instance) [MethodImpl(MethodImplOptions.AggressiveInlining)] public async UniTask Prepool(CancellationToken cancelToken) - => await _prepooler.Prepool(_prefab, _pool, Parent, cancelToken); + => await this._prePool.PrePool(_prefab, _pool, Parent, cancelToken); public void ReleaseInstances(int keep, Action onReleased = null) { diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/System.Collections.Generic/HashSetPool.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/System.Collections.Generic/HashSetPool.cs index 303f08b..ae76633 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/System.Collections.Generic/HashSetPool.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/System.Collections.Generic/HashSetPool.cs @@ -3,20 +3,9 @@ namespace System.Collections.Generic.Pooling { - public class HashSetPool - : Pool - , DefaultConstructorInstantiator>> + public sealed class HashSetPool : Pool, DefaultConstructorInstantiator>> { - public HashSetPool() - : base() - { } - - public HashSetPool(UniqueQueue> queue) - : base(queue) - { } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected override void ReturnPreprocess(HashSet instance) - => instance.Clear(); + protected override void ReturnPreprocess(HashSet instance) => instance.Clear(); } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Behaviours/UnityPoolBehaviour{T,TPrefab,TPool}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Behaviours/UnityPoolBehaviour{T,TPrefab,TPool}.cs index 69d97f5..05d575f 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Behaviours/UnityPoolBehaviour{T,TPrefab,TPool}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Behaviours/UnityPoolBehaviour{T,TPrefab,TPool}.cs @@ -23,7 +23,7 @@ public bool PrepoolOnStart set => _prepoolOnStart = value; } - private readonly UnityPrepooler _prepooler = default; + private readonly UnityPrePool _prePool = default; protected void Awake() { @@ -46,7 +46,7 @@ protected async UniTask Start() [MethodImpl(MethodImplOptions.AggressiveInlining)] public async UniTask Prepool(CancellationToken cancelToken) - => await _prepooler.Prepool(Pool.Prefab, Pool, this.transform, cancelToken); + => await this._prePool.PrePool(Pool.Prefab, Pool, this.transform, cancelToken); protected virtual void OnAwake() { } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab.cs index f0c28e2..3c97cca 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab.cs @@ -2,6 +2,6 @@ { public interface IPrefab { - int PrepoolAmount { get; set; } + int PrePoolAmount { get; set; } } } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab{T}.cs index d115ae0..e54f0c8 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrefab{T}.cs @@ -1,7 +1,6 @@ namespace ZBase.Foundation.Pooling.UnityPools { - public interface IPrefab - : IPrefab, IAsyncInstantiable, IReleasable, IHasParent + public interface IPrefab : IPrefab, IAsyncInstantiable, IReleasable, IHasParent { } } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrepooler{T,TPrefab,TPool}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrepooler{T,TPrefab,TPool}.cs index 2983538..95c01dc 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrepooler{T,TPrefab,TPool}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Common/Interfaces/IPrepooler{T,TPrefab,TPool}.cs @@ -4,11 +4,9 @@ namespace ZBase.Foundation.Pooling.UnityPools { - public interface IPrepooler - where TPrefab : IPrefab - where TPool : IReturnable + public interface IPrePool where TPrefab : IPrefab where TPool : IReturnable { - UniTask Prepool( + UniTask PrePool( TPrefab prefab , TPool pool , Transform defaultParent diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool.cs index 9f79c7f..c1dd54e 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool.cs @@ -4,23 +4,15 @@ namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] - public class GameObjectPool - : GameObjectPool + public class GameObjectPool : GameObjectPool { - public GameObjectPool() - : base() - { } + public GameObjectPool() { } - public GameObjectPool(GameObjectPrefab prefab) - : base(prefab) - { } + public GameObjectPool(GameObjectPrefab prefab) : base(prefab) { } - public GameObjectPool(UniqueQueue queue) - : base(queue) - { } + public GameObjectPool(UniqueQueue queue): base(queue){ } - public GameObjectPool(UniqueQueue queue, GameObjectPrefab prefab) - : base(queue, prefab) + public GameObjectPool(UniqueQueue queue, GameObjectPrefab prefab): base(queue, prefab) { } } } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs index 5db022c..96d7fd8 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs @@ -5,49 +5,34 @@ namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] - public class GameObjectPool - : UnityPool - where TPrefab : IPrefab + public class GameObjectPool : UnityPool where TPrefab : IPrefab { - [SerializeField] - private bool _dontApplyPrefabParentOnReturn; + [SerializeField] private bool _dontApplyPrefabParentOnReturn; public GameObjectPool() - : base() - { } - - public GameObjectPool(TPrefab prefab) - : base(prefab) - { } + { + } - public GameObjectPool(UniqueQueue queue) - : base(queue) - { } + public GameObjectPool(TPrefab prefab) : base(prefab) + { + } - public GameObjectPool(UniqueQueue queue, TPrefab prefab) - : base(queue, prefab) - { } + public GameObjectPool(UniqueQueue queue) : base(queue) + { + } - public bool DontApplyPrefabParentOnReturn + public GameObjectPool(UniqueQueue queue, TPrefab prefab) : base(queue, prefab) { - get => _dontApplyPrefabParentOnReturn; - set => _dontApplyPrefabParentOnReturn = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override void ReturnPreprocess(GameObject instance) { - if (instance == false) - { + if (!instance) return; - } - instance.SetActive(false); - if (_dontApplyPrefabParentOnReturn == false && Prefab != null) - { instance.transform.SetParent(Prefab.Parent); - } } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs index 439ff5f..1d9b905 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs @@ -8,19 +8,14 @@ namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] public class UnityPool - : IUnityPool, IShareable, IDisposable - where T : UnityEngine.Object - where TPrefab : IPrefab + : IUnityPool, IShareable, IDisposable where T : UnityEngine.Object where TPrefab : IPrefab { private readonly UniqueQueue _queue; [SerializeField] private TPrefab _prefab; - public UnityPool() - { - _queue = new UniqueQueue(); - } + public UnityPool() => _queue = new UniqueQueue(); public UnityPool(TPrefab prefab) { @@ -29,9 +24,7 @@ public UnityPool(TPrefab prefab) } public UnityPool(UniqueQueue queue) - { - _queue = queue ?? throw new ArgumentNullException(nameof(queue)); - } + => _queue = queue ?? throw new ArgumentNullException(nameof(queue)); public UnityPool(UniqueQueue queue, TPrefab prefab) { @@ -51,10 +44,7 @@ public TPrefab Prefab [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => _queue.Count; - public void Dispose() - { - _queue.Dispose(); - } + public void Dispose() => _queue.Dispose(); /// public void ReleaseInstances(int keep, Action onReleased = null) @@ -70,16 +60,14 @@ public void ReleaseInstances(int keep, Action onReleased = null) else if (_prefab != null) _prefab.Release(instance); } - countRemove--; } } public async UniTask Rent() { - if (_queue.TryDequeue(out var _, out var instance)) + if (_queue.TryDequeue(out _, out var instance)) return instance; - return await _prefab.Instantiate(); } @@ -87,7 +75,6 @@ public async UniTask Rent(CancellationToken cancelToken) { if (_queue.TryDequeue(out var _, out var instance)) return instance; - return await _prefab.Instantiate(cancelToken); } @@ -95,7 +82,6 @@ public void Return(T instance) { if (instance == false) return; - ReturnPreprocess(instance); _queue.TryEnqueue(instance.GetInstanceID(), instance); } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs index 0810064..83329fc 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs @@ -9,18 +9,11 @@ namespace ZBase.Foundation.Pooling.UnityPools public class GameObjectPrefab : UnityPrefab { protected override async UniTask Instantiate( - GameObject source - , Transform parent - , CancellationToken cancelToken - ) + GameObject source, Transform parent, CancellationToken cancelToken = default) { - GameObject instance; - - if (parent) - instance = UnityEngine.Object.Instantiate(Source, parent, true); - else - instance = UnityEngine.Object.Instantiate(Source); - + GameObject instance = parent + ? UnityEngine.Object.Instantiate(this.Source, parent, true) + : UnityEngine.Object.Instantiate(this.Source); return await UniTask.FromResult(instance); } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs index eb7b92f..6bcfd70 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using Cysharp.Threading.Tasks; using UnityEngine; +using UnityEngine.Serialization; namespace ZBase.Foundation.Pooling.UnityPools { @@ -11,20 +12,14 @@ public abstract class UnityPrefab : IPrefab where T : class { - [SerializeField] - private TSource _source; - - [SerializeField] - private Transform _parent; - - [SerializeField] - private int _prepoolAmount; + [SerializeField] private TSource _source; + [SerializeField] private Transform _parent; + [SerializeField] private int _prePoolAmount; public TSource Source { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] set => _source = value; } @@ -33,25 +28,22 @@ public Transform Parent { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _parent; - [MethodImpl(MethodImplOptions.AggressiveInlining)] set => _parent = value; } - public int PrepoolAmount + public int PrePoolAmount { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _prepoolAmount; - + get => this._prePoolAmount; [MethodImpl(MethodImplOptions.AggressiveInlining)] - set => _prepoolAmount = value; + set => this._prePoolAmount = value; } public async UniTask Instantiate() { if (_source is null) throw new NullReferenceException(nameof(Source)); - return await Instantiate(Source, Parent); } @@ -59,17 +51,15 @@ public async UniTask Instantiate(CancellationToken cancelToken) { if (_source is null) throw new NullReferenceException(nameof(Source)); - return await Instantiate(Source, Parent, cancelToken); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected abstract UniTask Instantiate( - TSource source + TSource source , Transform parent - , CancellationToken cancelToken = default) - ; + , CancellationToken cancelToken = default); public abstract void Release(T instance); } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prepoolers/UnityPrepooler{T,TPrefab,TPool}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prepoolers/UnityPrepooler{T,TPrefab,TPool}.cs index 0f06315..5045152 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prepoolers/UnityPrepooler{T,TPrefab,TPool}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prepoolers/UnityPrepooler{T,TPrefab,TPool}.cs @@ -4,36 +4,35 @@ namespace ZBase.Foundation.Pooling.UnityPools { - public struct UnityPrepooler - : IPrepooler - where T : UnityEngine.Object - where TPrefab : IPrefab - where TPool : IReturnable + public struct UnityPrePool + : IPrePool where T : Object where TPrefab : IPrefab where TPool : IReturnable { - public async UniTask Prepool( - TPrefab prefab - , TPool pool - , Transform defaultParent - , CancellationToken cancelToken = default - ) + public readonly async UniTask PrePool( + TPrefab prefab , TPool pool , Transform defaultParent , CancellationToken cancelToken = default ) { if (prefab == null) + { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.prefab); + return; + } if (pool == null) + { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pool); + return; + } - if (prefab.PrepoolAmount <= 0) + if (prefab.PrePoolAmount <= 0) return; if (prefab.Parent == false && defaultParent) prefab.Parent = defaultParent; - for (int i = 0, count = prefab.PrepoolAmount; i < count; i++) + for (int i = 0; i < prefab.PrePoolAmount; i++) { var instance = await prefab.Instantiate(cancelToken); pool.Return(instance); } } } -} +} \ No newline at end of file From 825032a857b90ffc417ff1a577d112f0ccc44941 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Wed, 31 Jan 2024 18:01:12 +0700 Subject: [PATCH 02/35] Lazy Pool --- Assets/Environment/Scripts/Grid.cs | 2 +- .../AddressGameObjectPool_1.unity | 24 +++++- .../AddressableGameObjectPoolSample1.cs | 32 ++++---- .../AddressableGameObjectPoolSample2.cs | 2 +- .../AddressablePoolBehaviourSample2.cs | 31 +++---- Assets/PoolSample/Pooling.Sample.asmdef | 3 +- .../Universal Render Pipeline Asset.asset | 43 +++++++++- ...ersal Render Pipeline Asset_Renderer.asset | 6 +- ...niversalRenderPipelineGlobalSettings.asset | 16 +++- .../ZBase.Foundation.Pooling/ItemPooling.meta | 3 + .../ItemPooling/Foundation.meta | 3 + .../ItemPooling/Foundation/Pools.meta | 3 + .../Pools/AssetRefGameObjectItemPool.cs | 30 +++++++ .../Pools/AssetRefGameObjectItemPool.cs.meta | 3 + .../ItemPooling/GlobalPools.meta | 3 + .../GlobalAssetRefGameObjectPool.cs | 45 +++++++++++ .../GlobalAssetRefGameObjectPool.cs.meta | 3 + .../ItemPooling/ItemPooling.asmdef | 30 +++++++ .../ItemPooling/ItemPooling.asmdef.meta | 3 + .../ItemPooling/Items.meta | 3 + .../Items/AssetRefGameObjectPoolItem.cs | 10 +++ .../Items/AssetRefGameObjectPoolItem.cs.meta | 3 + .../ItemPooling/Items/PoolItem.cs | 26 ++++++ .../ItemPooling/Items/PoolItem.cs.meta | 3 + .../AssetRefGameObjectPoolBehaviour.cs | 6 +- .../Foundation/Pools/AddressGameObjectPool.cs | 25 +++--- .../Pools/AddressGameObjectPool{TPrefab}.cs | 28 +++---- .../Pools/AssetRefComponentPool{T}.cs | 26 +++--- .../Pools/AssetRefGameObjectPool.cs | 21 ++--- .../Prefabs/AddressGameObjectPrefab.cs | 3 +- .../Prefabs/AssetRefComponentPrefab{T}.cs | 22 ++--- .../Prefabs/AssetRefPrefab{T,TAssetRef}.cs | 4 +- .../Common/UniqueQueue{TKey,TValue}.cs | 20 ++--- .../Foundation/Common/UniqueQueue{T}.cs | 3 +- .../Pools/ComponentPool{T,TPrefab}.cs | 15 +--- .../Pools/GameObjectPool{TPrefab}.cs | 1 + .../UnityPools/Pools/UnityPool{T,TPrefab}.cs | 35 +++++--- Packages/manifest.json | 14 ++-- Packages/packages-lock.json | 81 ++++++++++++------- 39 files changed, 435 insertions(+), 199 deletions(-) create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Items.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs.meta create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs create mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs.meta diff --git a/Assets/Environment/Scripts/Grid.cs b/Assets/Environment/Scripts/Grid.cs index 750bb9b..b075ba8 100644 --- a/Assets/Environment/Scripts/Grid.cs +++ b/Assets/Environment/Scripts/Grid.cs @@ -86,7 +86,7 @@ public void FreeSlot(Vector3 position) this._slots[this._slots.IndexOf(slot)] = newSlot; return; } - throw new Exception("No available slot"); + Debug .LogError($"Slot at position {position} not found"); } } } \ No newline at end of file diff --git a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity index dbcb81f..e196d88 100644 --- a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity +++ b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity @@ -104,7 +104,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +117,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -128,6 +128,7 @@ PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: + serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: - target: {fileID: 5685908662808553381, guid: bc0a642a3d8c4485fa3e2c739a4cf9c8, type: 3} @@ -179,6 +180,9 @@ PrefabInstance: value: Env objectReference: {fileID: 0} m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: bc0a642a3d8c4485fa3e2c739a4cf9c8, type: 3} --- !u!1 &1962524535 GameObject: @@ -204,13 +208,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1962524535} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1962524537 MonoBehaviour: @@ -224,3 +228,17 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cdb23546d86448568402c2d071ea936d, type: 3} m_Name: m_EditorClassIdentifier: + _prefab: + _source: + m_AssetGUID: 1c14710c0d49c480497e5be810eb4fc4 + m_SubObjectName: + m_SubObjectType: + m_EditorAssetChanged: 0 + _parent: {fileID: 0} + _prePoolAmount: 0 +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: + - {fileID: 572524172} + - {fileID: 1962524536} diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs index 82652e4..cc58023 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs @@ -9,23 +9,14 @@ namespace Pooling.Sample { public class AddressableGameObjectPoolSample1 : MonoBehaviour { - private const string K_CHARACTER01_KEY = "Character_AddressPool_P01"; - private Grid _grid = new(20, 15, true); - private List _spawned = new(); - private void Start() - { - var pool = SharedPool.Of(); - pool.Prefab = new AddressGameObjectPrefab { - Source = K_CHARACTER01_KEY, - Parent = transform - }; - } - + [SerializeField]private AssetRefGameObjectPrefab _prefab; + private readonly Grid _grid = new(20, 15, true); + private readonly List _spawned = new(); private async UniTask Spawn() { - var pool = SharedPool.Of(); - var go = await pool.Rent(); + var pool = SharedPool.Of(); + var go = await pool.Rent(_prefab); go.transform.position = _grid.GetAvailableSlot().position; go.SetActive(true); _spawned.Add(go); @@ -33,12 +24,17 @@ private async UniTask Spawn() private void Return() { - var pool = SharedPool.Of(); + var pool = SharedPool.Of(); foreach (var go in _spawned) - { pool.Return(go); - this._grid.FreeSlot(go.transform.position); - } + FreeSlot(); + _spawned.Clear(); + } + + private void FreeSlot() + { + foreach (var go in _spawned) + _grid.FreeSlot(go.transform.position); } private async UniTask SpawnDisposableItems() diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs index 98f017f..9f2b57a 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs @@ -12,7 +12,7 @@ public class AddressableGameObjectPoolSample2 : MonoBehaviour private const string K_CHARACTER02_KEY = "Character_AddressPool_P02"; private Grid _grid = new Grid(20, 15, true); - private List _spawned = new List(); + private List _spawned = new (); private void Start() { var pool = SharedPool.Of(); diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample2.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample2.cs index c94979a..03990d7 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample2.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample2.cs @@ -24,8 +24,8 @@ public class AddressablePoolBehaviourSample2 : MonoBehaviour { [SerializeField] private AssetRefGameObjectPoolBehaviour pool; - private List _spawned = new List(); - private List _slots = new List(); + private readonly List _spawned = new(); + private readonly List _slots = new(); private void Start() { @@ -45,12 +45,8 @@ private void Start() private async void OnGUI() { if(GUI.Button(new Rect(10, 10, 150, 50), "Spawn 100")) - { for (int i = 0; i < 100; i++) - { await Spawn(); - } - } if(GUI.Button(new Rect(10, 70, 150, 50), "Despawn 10")) { @@ -59,9 +55,7 @@ private async void OnGUI() } if(GUI.Button(new Rect(10, 130, 150, 50), "Release Keep 10")) - { Release(); - } } private async UniTask Spawn() @@ -74,23 +68,18 @@ private async UniTask Spawn() private void Despawn(ref int count) { - //despawn count last spawned active for (int i = this._spawned.Count - 1; i >= 0; i--) { - if(this._spawned[i].activeSelf) - { - this.pool.Return(this._spawned[i]); - count--; - if(count == 0) - break; - } + if (!this._spawned[i].activeSelf) + continue; + this.pool.Return(this._spawned[i]); + count--; + if(count == 0) + break; } } - - private void Release() - { - this.pool.ReleaseInstances(10); - } + + private void Release() => this.pool.ReleaseInstances(10); private void OnDestroy() { diff --git a/Assets/PoolSample/Pooling.Sample.asmdef b/Assets/PoolSample/Pooling.Sample.asmdef index c1c120b..3c5cd14 100644 --- a/Assets/PoolSample/Pooling.Sample.asmdef +++ b/Assets/PoolSample/Pooling.Sample.asmdef @@ -11,7 +11,8 @@ "ZBase.Collections.Pooled", "ZBase.Foundation.Pooling", "ZBase.Foundation.Pooling.Addressables", - "Sample.Environment" + "Sample.Environment", + "ItemPooling" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Render/Universal Render Pipeline Asset.asset b/Assets/Render/Universal Render Pipeline Asset.asset index 82c4377..2c58e9b 100644 --- a/Assets/Render/Universal Render Pipeline Asset.asset +++ b/Assets/Render/Universal Render Pipeline Asset.asset @@ -12,8 +12,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bf2edee5c58d82540a51f03df9d42094, type: 3} m_Name: Universal Render Pipeline Asset m_EditorClassIdentifier: - k_AssetVersion: 9 - k_AssetPreviousVersion: 9 + k_AssetVersion: 11 + k_AssetPreviousVersion: 11 m_RendererType: 1 m_RendererData: {fileID: 0} m_RendererDataList: @@ -23,13 +23,16 @@ MonoBehaviour: m_RequireOpaqueTexture: 0 m_OpaqueDownsampling: 1 m_SupportsTerrainHoles: 1 - m_StoreActionsOptimization: 0 m_SupportsHDR: 1 + m_HDRColorBufferPrecision: 0 m_MSAA: 8 m_RenderScale: 1 m_UpscalingFilter: 0 m_FsrOverrideSharpness: 0 m_FsrSharpness: 0.92 + m_EnableLODCrossFade: 1 + m_LODCrossFadeDitheringType: 1 + m_ShEvalMode: 0 m_MainLightRenderingMode: 1 m_MainLightShadowsSupported: 1 m_MainLightShadowmapResolution: 2048 @@ -54,22 +57,54 @@ MonoBehaviour: m_SoftShadowsSupported: 0 m_ConservativeEnclosingSphere: 1 m_NumIterationsEnclosingSphere: 64 + m_SoftShadowQuality: 2 m_AdditionalLightsCookieResolution: 2048 m_AdditionalLightsCookieFormat: 3 m_UseSRPBatcher: 1 m_SupportsDynamicBatching: 0 m_MixedLightingSupported: 1 + m_SupportsLightCookies: 1 m_SupportsLightLayers: 0 m_DebugLevel: 0 + m_StoreActionsOptimization: 0 + m_EnableRenderGraph: 0 m_UseAdaptivePerformance: 1 m_ColorGradingMode: 0 m_ColorGradingLutSize: 32 m_UseFastSRGBLinearConversion: 0 + m_SupportDataDrivenLensFlare: 1 m_ShadowType: 1 m_LocalShadowsSupported: 0 m_LocalShadowsAtlasResolution: 256 m_MaxPixelLights: 0 m_ShadowAtlasResolution: 256 - m_ShaderVariantLogLevel: 0 m_VolumeFrameworkUpdateMode: 0 + m_Textures: + blueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3} + bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3} + m_PrefilteringModeMainLightShadows: 1 + m_PrefilteringModeAdditionalLight: 4 + m_PrefilteringModeAdditionalLightShadows: 1 + m_PrefilterXRKeywords: 0 + m_PrefilteringModeForwardPlus: 1 + m_PrefilteringModeDeferredRendering: 1 + m_PrefilteringModeScreenSpaceOcclusion: 1 + m_PrefilterDebugKeywords: 0 + m_PrefilterWriteRenderingLayers: 0 + m_PrefilterHDROutput: 0 + m_PrefilterSSAODepthNormals: 0 + m_PrefilterSSAOSourceDepthLow: 0 + m_PrefilterSSAOSourceDepthMedium: 0 + m_PrefilterSSAOSourceDepthHigh: 0 + m_PrefilterSSAOInterleaved: 0 + m_PrefilterSSAOBlueNoise: 0 + m_PrefilterSSAOSampleCountLow: 0 + m_PrefilterSSAOSampleCountMedium: 0 + m_PrefilterSSAOSampleCountHigh: 0 + m_PrefilterDBufferMRT1: 0 + m_PrefilterDBufferMRT2: 0 + m_PrefilterDBufferMRT3: 0 + m_PrefilterScreenCoord: 0 + m_PrefilterNativeRenderPass: 0 + m_ShaderVariantLogLevel: 0 m_ShadowCascades: 0 diff --git a/Assets/Render/Universal Render Pipeline Asset_Renderer.asset b/Assets/Render/Universal Render Pipeline Asset_Renderer.asset index 1a4c991..791a29e 100644 --- a/Assets/Render/Universal Render Pipeline Asset_Renderer.asset +++ b/Assets/Render/Universal Render Pipeline Asset_Renderer.asset @@ -14,6 +14,7 @@ MonoBehaviour: m_EditorClassIdentifier: debugShaders: debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7, type: 3} + hdrDebugViewPS: {fileID: 4800000, guid: 573620ae32aec764abd4d728906d2587, type: 3} m_RendererFeatures: [] m_RendererFeatureMap: m_UseNativeRenderPass: 0 @@ -26,11 +27,14 @@ MonoBehaviour: samplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3} stencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3} fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3} + fallbackLoadingPS: {fileID: 4800000, guid: 7f888aff2ac86494babad1c2c5daeee2, type: 3} materialErrorPS: {fileID: 4800000, guid: 5fd9a8feb75a4b5894c241777f519d4e, type: 3} coreBlitPS: {fileID: 4800000, guid: 93446b5c5339d4f00b85c159e1159b7c, type: 3} coreBlitColorAndDepthPS: {fileID: 4800000, guid: d104b2fc1ca6445babb8e90b0758136b, type: 3} + blitHDROverlay: {fileID: 4800000, guid: a89bee29cffa951418fc1e2da94d1959, type: 3} cameraMotionVector: {fileID: 4800000, guid: c56b7e0d4c7cb484e959caeeedae9bbf, type: 3} objectMotionVector: {fileID: 4800000, guid: 7b3ede40266cd49a395def176e1bc486, type: 3} + dataDrivenLensFlare: {fileID: 4800000, guid: 6cda457ac28612740adb23da5d39ea92, type: 3} m_AssetVersion: 2 m_OpaqueLayerMask: serializedVersion: 2 @@ -50,6 +54,4 @@ MonoBehaviour: m_DepthPrimingMode: 0 m_CopyDepthMode: 0 m_AccurateGbufferNormals: 0 - m_ClusteredRendering: 0 - m_TileSize: 32 m_IntermediateTextureMode: 1 diff --git a/Assets/Render/UniversalRenderPipelineGlobalSettings.asset b/Assets/Render/UniversalRenderPipelineGlobalSettings.asset index a996a2e..98f0dfd 100644 --- a/Assets/Render/UniversalRenderPipelineGlobalSettings.asset +++ b/Assets/Render/UniversalRenderPipelineGlobalSettings.asset @@ -12,7 +12,17 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2ec995e51a6e251468d2a3fd8a686257, type: 3} m_Name: UniversalRenderPipelineGlobalSettings m_EditorClassIdentifier: - k_AssetVersion: 2 + k_AssetVersion: 3 + m_RenderingLayerNames: + - Light Layer default + - Light Layer 1 + - Light Layer 2 + - Light Layer 3 + - Light Layer 4 + - Light Layer 5 + - Light Layer 6 + - Light Layer 7 + m_ValidRenderingLayers: 255 lightLayerName0: Light Layer default lightLayerName1: Light Layer 1 lightLayerName2: Light Layer 2 @@ -24,4 +34,8 @@ MonoBehaviour: m_StripDebugVariants: 1 m_StripUnusedPostProcessingVariants: 0 m_StripUnusedVariants: 1 + m_StripUnusedLODCrossFadeVariants: 1 + m_StripScreenCoordOverrideVariants: 1 supportRuntimeDebugDisplay: 0 + m_ShaderVariantLogLevel: 0 + m_ExportShaderVariants: 1 diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling.meta new file mode 100644 index 0000000..887d59b --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3e5d04ffff9a43d3a45bc183454a025c +timeCreated: 1706689866 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation.meta new file mode 100644 index 0000000..f612fdb --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a6fcca5fb5444205b3a29ef26b1f5368 +timeCreated: 1706691037 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools.meta new file mode 100644 index 0000000..375468b --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3de7c7c0d5d64b5e9d10192e688ffc02 +timeCreated: 1706691056 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs new file mode 100644 index 0000000..f787a65 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs @@ -0,0 +1,30 @@ +using System; +using UnityEngine; +using ZBase.Foundation.Pooling.AddressableAssets; +using ZBase.Foundation.Pooling.AddressableAssets.Items; + +namespace ZBase.Foundation.Pooling.ItemPooling +{ + public class AssetRefGameObjectItemPool : AssetRefGameObjectPool + { + internal event Action OnReturn; + + public AssetRefGameObjectItemPool(AssetRefGameObjectPrefab prefab) : base(prefab) + { + } + + protected override void ProcessNewInstance(GameObject instance) + { + base.ProcessNewInstance(instance); + if (!instance.TryGetComponent(out var poolItem)) + poolItem = instance.AddComponent(); + poolItem.SetUp(this, instance, Prefab); + } + + protected override void ReturnPreprocess(GameObject instance) + { + base.ReturnPreprocess(instance); + OnReturn?.Invoke(instance); + } + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta new file mode 100644 index 0000000..19a554b --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d551af5f51a2477d98e29c8d09eb95d8 +timeCreated: 1706691066 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools.meta new file mode 100644 index 0000000..4d732ea --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ffeb1638715845adaf4bb3261298e4b2 +timeCreated: 1706694323 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs new file mode 100644 index 0000000..eb733ab --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using Cysharp.Threading.Tasks; +using UnityEngine; +using ZBase.Foundation.Pooling.ItemPooling; + +namespace ZBase.Foundation.Pooling.AddressableAssets +{ + public class GlobalAssetRefGameObjectPool : IPool, IShareable + { + private readonly Dictionary _pools = new(); + + private readonly Dictionary _prefabToAssetReference = new(); + + public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) + { + if (!_pools.TryGetValue(gameObjectReference, out var pool)) + { + pool = new AssetRefGameObjectItemPool(gameObjectReference); + pool.OnReturn += OnReturnToPool; + this._pools.Add(gameObjectReference, pool); + } + GameObject item = await pool.Rent(); + _prefabToAssetReference.Add(item, gameObjectReference); + return item; + } + + public void Return(GameObject gameObject) + { + if(!gameObject) + return; + if (_prefabToAssetReference.TryGetValue(gameObject, out var assetReference)) + Return(assetReference, gameObject); + else + Debug.LogError($"GameObject {gameObject.name} is not registered in the pool"); + } + + public void Return(AssetRefGameObjectPrefab gameObjectReference, GameObject gameObject) + { + if (_pools.TryGetValue(gameObjectReference, out var pool)) + pool.Return(gameObject); + } + + private void OnReturnToPool(GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta new file mode 100644 index 0000000..10af81a --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9ad6533b2f29433fa6ea93b117498d66 +timeCreated: 1706689315 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef b/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef new file mode 100644 index 0000000..034a76b --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef @@ -0,0 +1,30 @@ +{ + "name": "ItemPooling", + "rootNamespace": "ZBase.Foundation.Pooling.ItemPooling", + "references": [ + "UniTask", + "UniTask.Addressables", + "Unity.Addressables", + "Unity.ResourceManager", + "ZBase.Collections.Pooled", + "ZBase.Foundation.Pooling", + "ZBase.Foundation.Pooling.Addressables" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [ + "ZBASE_FOUNDATION_POOLING_ADDRESSABLES" + ], + "versionDefines": [ + { + "name": "com.unity.addressables", + "expression": "", + "define": "ZBASE_FOUNDATION_POOLING_ADDRESSABLES" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef.meta new file mode 100644 index 0000000..2ae0f44 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1dd4b175824f4ea2928e751802e11a74 +timeCreated: 1706691178 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items.meta new file mode 100644 index 0000000..0c269b9 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bf77127ed4474e0d8bbf4854cac716ab +timeCreated: 1706691451 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs new file mode 100644 index 0000000..be591da --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs @@ -0,0 +1,10 @@ +using UnityEngine; +using ZBase.Foundation.Pooling.UnityPools; +using Object = UnityEngine.Object; + +namespace ZBase.Foundation.Pooling.AddressableAssets.Items +{ + public class AssetRefGameObjectPoolItem : PoolItem + { + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs.meta new file mode 100644 index 0000000..743e2e4 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 03493b6a82c244069e0431cf41601291 +timeCreated: 1706695936 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs new file mode 100644 index 0000000..88145dd --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs @@ -0,0 +1,26 @@ +using UnityEngine; +using ZBase.Foundation.Pooling.UnityPools; +using Object = UnityEngine.Object; + +namespace ZBase.Foundation.Pooling.AddressableAssets.Items +{ + public class PoolItem : MonoBehaviour where T : Object where TPrefab : IPrefab + { + private T _instance; + private TPrefab _prefab; + private UnityPool _pool; + + public void SetUp(UnityPool pool, T instance, TPrefab prefab) + { + _instance = instance; + _pool = pool; + _prefab = prefab; + } + + private void OnDestroy() + { + _pool.RemoveItem(_instance); + _prefab.Release(_instance); + } + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs.meta b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs.meta new file mode 100644 index 0000000..6a37029 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ae2b5ebcb0b54c60b5f24757dee4cc8d +timeCreated: 1706691481 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Behaviours/AssetRefGameObjectPoolBehaviour.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Behaviours/AssetRefGameObjectPoolBehaviour.cs index 37fe144..0694246 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Behaviours/AssetRefGameObjectPoolBehaviour.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Behaviours/AssetRefGameObjectPoolBehaviour.cs @@ -3,11 +3,7 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { - public class AssetRefGameObjectPoolBehaviour - : UnityPoolBehaviour< - GameObject - , AssetRefGameObjectPrefab - , AssetRefGameObjectPool + public class AssetRefGameObjectPoolBehaviour : UnityPoolBehaviour< GameObject , AssetRefGameObjectPrefab , AssetRefGameObjectPool > { } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool.cs index 1c8663a..63850ac 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool.cs @@ -5,23 +5,24 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AddressGameObjectPool - : AddressGameObjectPool + public class AddressGameObjectPool : AddressGameObjectPool { public AddressGameObjectPool() - : base() - { } + { + } public AddressGameObjectPool(AddressGameObjectPrefab prefab) : base(prefab) - { } + { + } - public AddressGameObjectPool(UniqueQueue queue) - : base(queue) - { } + public AddressGameObjectPool(UniqueQueue queue) : base(queue) + { + } - public AddressGameObjectPool(UniqueQueue queue, AddressGameObjectPrefab prefab) - : base(queue, prefab) - { } + public AddressGameObjectPool(UniqueQueue queue, AddressGameObjectPrefab prefab) : base(queue, + prefab) + { + } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool{TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool{TPrefab}.cs index d39e19d..0a5d3e6 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool{TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AddressGameObjectPool{TPrefab}.cs @@ -6,24 +6,22 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AddressGameObjectPool - : GameObjectPool - where TPrefab : AddressGameObjectPrefab + public class AddressGameObjectPool : GameObjectPool where TPrefab : AddressGameObjectPrefab { public AddressGameObjectPool() - : base() - { } + { + } - public AddressGameObjectPool(TPrefab prefab) - : base(prefab) - { } + public AddressGameObjectPool(TPrefab prefab) : base(prefab) + { + } - public AddressGameObjectPool(UniqueQueue queue) - : base(queue) - { } + public AddressGameObjectPool(UniqueQueue queue) : base(queue) + { + } - public AddressGameObjectPool(UniqueQueue queue, TPrefab prefab) - : base(queue, prefab) - { } + public AddressGameObjectPool(UniqueQueue queue, TPrefab prefab) : base(queue, prefab) + { + } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefComponentPool{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefComponentPool{T}.cs index 1cf7aa8..8ac4bf5 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefComponentPool{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefComponentPool{T}.cs @@ -1,29 +1,27 @@ using System; using UnityEngine; -using ZBase.Foundation.Pooling; using ZBase.Foundation.Pooling.UnityPools; namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AssetRefComponentPool - : ComponentPool> - where T : Component + public class AssetRefComponentPool : ComponentPool> where T : Component { public AssetRefComponentPool() - : base() - { } + { + } - public AssetRefComponentPool(AssetRefComponentPrefab prefab) - : base(prefab) - { } + public AssetRefComponentPool(AssetRefComponentPrefab prefab) : base(prefab) + { + } - public AssetRefComponentPool(UniqueQueue queue) - : base(queue) - { } + public AssetRefComponentPool(UniqueQueue queue) : base(queue) + { + } public AssetRefComponentPool(UniqueQueue queue, AssetRefComponentPrefab prefab) : base(queue, prefab) - { } + { + } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs index d330e1d..a82a9e3 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Pools/AssetRefGameObjectPool.cs @@ -1,6 +1,5 @@ using System; using UnityEngine; -using ZBase.Foundation.Pooling; using ZBase.Foundation.Pooling.UnityPools; namespace ZBase.Foundation.Pooling.AddressableAssets @@ -9,18 +8,20 @@ namespace ZBase.Foundation.Pooling.AddressableAssets public class AssetRefGameObjectPool : GameObjectPool { public AssetRefGameObjectPool() - { } + { + } - public AssetRefGameObjectPool(AssetRefGameObjectPrefab prefab) - : base(prefab) - { } + public AssetRefGameObjectPool(AssetRefGameObjectPrefab prefab) : base(prefab) + { + } - public AssetRefGameObjectPool(UniqueQueue queue) - : base(queue) - { } + public AssetRefGameObjectPool(UniqueQueue queue) : base(queue) + { + } public AssetRefGameObjectPool(UniqueQueue queue, AssetRefGameObjectPrefab prefab) : base(queue, prefab) - { } + { + } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs index a39aa20..a244cfe 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AddressGameObjectPrefab.cs @@ -13,8 +13,7 @@ public class AddressGameObjectPrefab : AddressPrefab protected override async UniTask Instantiate( string source, Transform parent, CancellationToken cancelToken = default) { - AsyncOperationHandle handle = - parent ? Addressables.InstantiateAsync(source, parent) : Addressables.InstantiateAsync(source); + var handle = parent ? Addressables.InstantiateAsync(source, parent) : Addressables.InstantiateAsync(source); return await handle.WithCancellation(cancelToken); } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefComponentPrefab{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefComponentPrefab{T}.cs index d640b5e..ba03c7c 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefComponentPrefab{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefComponentPrefab{T}.cs @@ -8,25 +8,15 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AssetRefComponentPrefab - : AssetRefPrefab + public class AssetRefComponentPrefab : AssetRefPrefab where T : Component { - protected override async UniTask Instantiate( - AssetReferenceGameObject source - , Transform parent - , CancellationToken cancelToken = default - ) + protected override async UniTask Instantiate(AssetReferenceGameObject source, Transform parent, + CancellationToken cancelToken = default) { - AsyncOperationHandle handle; - - if (parent) - handle = source.InstantiateAsync(parent, true); - else - handle = source.InstantiateAsync(); - + AsyncOperationHandle handle = + parent ? source.InstantiateAsync(parent, true) : source.InstantiateAsync(); var gameObject = await handle.WithCancellation(cancelToken); - return gameObject.GetComponent(); } @@ -36,4 +26,4 @@ public override void Release(T instance) Source.ReleaseInstance(instance.gameObject); } } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs index fc415d2..724c9c9 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs @@ -6,9 +6,7 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] public abstract class AssetRefPrefab - : UnityPrefab - where T : UnityEngine.Object - where TAssetRef : AssetReference + : UnityPrefab where T : UnityEngine.Object where TAssetRef : AssetReference { } } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs index 2b6082c..32a4b4e 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs @@ -38,27 +38,23 @@ public bool TryEnqueue(TKey key, TValue value) { if (key is null || value is null) return false; - - if (_unique.ContainsKey(key)) + if (!this._unique.TryAdd(key, value)) return false; - - _unique.Add(key, value); _queue.Enqueue(key); return true; } - public bool TryDequeue(out TKey key, out TValue value) + public bool TryDequeue(out TValue value) { - if (_queue.TryDequeue(out key) && _unique.TryGetValue(key, out value)) - { - _unique.Remove(key); - return true; - } - value = default; + while (_queue.Count > 0) + if (_queue.TryDequeue(out var key) && this._unique.Remove(key, out value) && value != null) + return true; return false; } + public void Remove(TKey key) => this._unique.Remove(key, out _); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TKey key) => _unique.ContainsKey(key); @@ -67,4 +63,4 @@ public bool Contains(TKey key) public bool Contains(in KVPair item) => _unique.ContainsKey(item.Key); } -} +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{T}.cs index 4be7ffd..9532014 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{T}.cs @@ -9,7 +9,6 @@ public bool TryEnqueue(T item) => TryEnqueue(item, item); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool TryDequeue(out T item) - => TryDequeue(out var _, out item); + public bool TryDequeue(out T item) => base.TryDequeue(out item); } } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/ComponentPool{T,TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/ComponentPool{T,TPrefab}.cs index 4861d66..7bdb31d 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/ComponentPool{T,TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/ComponentPool{T,TPrefab}.cs @@ -5,28 +5,21 @@ namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] - public class ComponentPool - : UnityPool - where T : UnityEngine.Component - where TPrefab : IPrefab + public class ComponentPool : UnityPool where T : Component where TPrefab : IPrefab { [SerializeField] private bool _dontApplyPrefabParentOnReturn; public ComponentPool() - : base() { } - public ComponentPool(TPrefab prefab) - : base(prefab) + public ComponentPool(TPrefab prefab) : base(prefab) { } - public ComponentPool(UniqueQueue queue) - : base(queue) + public ComponentPool(UniqueQueue queue) : base(queue) { } - public ComponentPool(UniqueQueue queue, TPrefab prefab) - : base(queue, prefab) + public ComponentPool(UniqueQueue queue, TPrefab prefab) : base(queue, prefab) { } public bool DontApplyPrefabParentOnReturn diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs index 96d7fd8..2dc2744 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs @@ -24,6 +24,7 @@ public GameObjectPool(UniqueQueue queue) : base(queue) public GameObjectPool(UniqueQueue queue, TPrefab prefab) : base(queue, prefab) { } + [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override void ReturnPreprocess(GameObject instance) diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs index 1d9b905..69c7850 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs @@ -12,8 +12,7 @@ public class UnityPool { private readonly UniqueQueue _queue; - [SerializeField] - private TPrefab _prefab; + [SerializeField] private TPrefab _prefab; public UnityPool() => _queue = new UniqueQueue(); @@ -23,8 +22,7 @@ public UnityPool(TPrefab prefab) _prefab = prefab ?? throw new ArgumentNullException(nameof(prefab)); } - public UnityPool(UniqueQueue queue) - => _queue = queue ?? throw new ArgumentNullException(nameof(queue)); + public UnityPool(UniqueQueue queue) => _queue = queue ?? throw new ArgumentNullException(nameof(queue)); public UnityPool(UniqueQueue queue, TPrefab prefab) { @@ -53,40 +51,55 @@ public void ReleaseInstances(int keep, Action onReleased = null) while (countRemove > 0) { - if (_queue.TryDequeue(out var _, out var instance)) + if (_queue.TryDequeue(out var instance)) { if (onReleased != null) onReleased(instance); else if (_prefab != null) _prefab.Release(instance); } + countRemove--; } } public async UniTask Rent() { - if (_queue.TryDequeue(out _, out var instance)) + if (_queue.TryDequeue(out var instance)) return instance; - return await _prefab.Instantiate(); + instance = await _prefab.Instantiate(); + ProcessNewInstance(instance); + return instance; } public async UniTask Rent(CancellationToken cancelToken) { - if (_queue.TryDequeue(out var _, out var instance)) + if (_queue.TryDequeue(out var instance)) return instance; - return await _prefab.Instantiate(cancelToken); + instance = await _prefab.Instantiate(cancelToken); + ProcessNewInstance(instance); + return instance; } + protected virtual void ProcessNewInstance(T instance) { } + public void Return(T instance) { - if (instance == false) + if (!instance) return; ReturnPreprocess(instance); _queue.TryEnqueue(instance.GetInstanceID(), instance); } + + public void RemoveItem(T instance) + { + if (!instance) + return; + ReturnPreprocess(instance); + _queue.Remove(instance.GetInstanceID()); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected virtual void ReturnPreprocess(T instance) { } } -} +} \ No newline at end of file diff --git a/Packages/manifest.json b/Packages/manifest.json index 2032235..43534fc 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,14 +1,16 @@ { "dependencies": { - "com.cysharp.unitask": "2.3.3", - "com.unity.addressables": "1.19.19", - "com.unity.ide.rider": "3.0.18", - "com.unity.ide.visualstudio": "2.0.16", + "com.cysharp.unitask": "2.5.3", + "com.unity.addressables": "1.21.12", + "com.unity.ai.navigation": "1.1.4", + "com.unity.ide.rider": "3.0.24", + "com.unity.ide.visualstudio": "2.0.18", "com.unity.ide.vscode": "1.2.5", - "com.unity.render-pipelines.universal": "12.1.8", + "com.unity.render-pipelines.universal": "14.0.8", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", - "com.unity.timeline": "1.6.4", + "com.unity.timeline": "1.7.5", + "com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.6", "com.unity.ugui": "1.0.0", "com.zbase.collections.pooled": "2.8.1", "org.nuget.system.runtime.compilerservices.unsafe": "6.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index f3cb63f..5d4d5f6 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,18 +1,18 @@ { "dependencies": { "com.cysharp.unitask": { - "version": "2.3.3", + "version": "2.5.3", "depth": 0, "source": "registry", "dependencies": {}, "url": "https://package.openupm.com" }, "com.unity.addressables": { - "version": "1.19.19", + "version": "1.21.12", "depth": 0, "source": "registry", "dependencies": { - "com.unity.scriptablebuildpipeline": "1.19.6", + "com.unity.scriptablebuildpipeline": "1.21.5", "com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.imageconversion": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0", @@ -21,8 +21,17 @@ }, "url": "https://packages.unity.com" }, + "com.unity.ai.navigation": { + "version": "1.1.4", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.modules.ai": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.burst": { - "version": "1.8.2", + "version": "1.8.7", "depth": 1, "source": "registry", "dependencies": { @@ -38,7 +47,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "3.0.18", + "version": "3.0.24", "depth": 0, "source": "registry", "dependencies": { @@ -47,7 +56,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.16", + "version": "2.0.18", "depth": 0, "source": "registry", "dependencies": { @@ -70,49 +79,66 @@ "url": "https://packages.unity.com" }, "com.unity.render-pipelines.core": { - "version": "12.1.8", + "version": "14.0.8", "depth": 1, "source": "builtin", "dependencies": { "com.unity.ugui": "1.0.0", "com.unity.modules.physics": "1.0.0", + "com.unity.modules.terrain": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0" } }, "com.unity.render-pipelines.universal": { - "version": "12.1.8", + "version": "14.0.8", "depth": 0, "source": "builtin", "dependencies": { "com.unity.mathematics": "1.2.1", - "com.unity.burst": "1.8.2", - "com.unity.render-pipelines.core": "12.1.8", - "com.unity.shadergraph": "12.1.8" + "com.unity.burst": "1.8.4", + "com.unity.render-pipelines.core": "14.0.8", + "com.unity.shadergraph": "14.0.8" } }, "com.unity.scriptablebuildpipeline": { - "version": "1.20.1", + "version": "1.21.5", "depth": 1, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.searcher": { - "version": "4.9.1", + "version": "4.9.2", "depth": 2, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.shadergraph": { - "version": "12.1.8", + "version": "14.0.8", "depth": 1, "source": "builtin", "dependencies": { - "com.unity.render-pipelines.core": "12.1.8", - "com.unity.searcher": "4.9.1" + "com.unity.render-pipelines.core": "14.0.8", + "com.unity.searcher": "4.9.2" } }, + "com.unity.sysroot": { + "version": "2.0.7", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.sysroot.linux-x86_64": { + "version": "2.0.6", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.sysroot": "2.0.7" + }, + "url": "https://packages.unity.com" + }, "com.unity.test-framework": { "version": "1.1.33", "depth": 0, @@ -134,7 +160,7 @@ "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.6.4", + "version": "1.7.5", "depth": 0, "source": "registry", "dependencies": { @@ -145,6 +171,16 @@ }, "url": "https://packages.unity.com" }, + "com.unity.toolchain.win-x86_64-linux-x86_64": { + "version": "2.0.6", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.sysroot": "2.0.7", + "com.unity.sysroot.linux-x86_64": "2.0.6" + }, + "url": "https://packages.unity.com" + }, "com.unity.ugui": { "version": "1.0.0", "depth": 0, @@ -311,17 +347,6 @@ "version": "1.0.0", "depth": 0, "source": "builtin", - "dependencies": { - "com.unity.modules.ui": "1.0.0", - "com.unity.modules.imgui": "1.0.0", - "com.unity.modules.jsonserialize": "1.0.0", - "com.unity.modules.uielementsnative": "1.0.0" - } - }, - "com.unity.modules.uielementsnative": { - "version": "1.0.0", - "depth": 1, - "source": "builtin", "dependencies": { "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0", From 341c3af98aee8ab47c39f2b89700439404ce9f2e Mon Sep 17 00:00:00 2001 From: DuyCa Date: Wed, 31 Jan 2024 18:08:59 +0700 Subject: [PATCH 03/35] Null Check --- .../ItemPooling/Items/AssetRefGameObjectPoolItem.cs | 2 -- .../ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs index be591da..ae24574 100644 --- a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs @@ -1,6 +1,4 @@ using UnityEngine; -using ZBase.Foundation.Pooling.UnityPools; -using Object = UnityEngine.Object; namespace ZBase.Foundation.Pooling.AddressableAssets.Items { diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs index 88145dd..e19d5c0 100644 --- a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs @@ -19,8 +19,8 @@ public void SetUp(UnityPool pool, T instance, TPrefab prefab) private void OnDestroy() { - _pool.RemoveItem(_instance); - _prefab.Release(_instance); + _pool?.RemoveItem(_instance); + _prefab?.Release(_instance); } } } \ No newline at end of file From e1dd9d8aa7f41f76df79d0283acb859deb735cb0 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 15:12:48 +0700 Subject: [PATCH 04/35] Add Auto Destroy + GameObject Pool --- .../AddressGameObjectPool_1.unity | 4 +- .../Prefabs/Character_AddressPool_P01.prefab | 165 ++++++++++-------- .../AddressablePools/Prefabs/Empt.prefab | 47 +++++ .../AddressablePools/Prefabs/Empt.prefab.meta | 7 + .../AddressableGameObjectPoolSample1.cs | 64 ++----- .../AddressableGameObjectPoolSample2.cs | 8 +- .../Prefabs/Character_P01.prefab | 155 ++++++++-------- ...emPooling.meta => GameObjectLazyPool.meta} | 0 .../Foundation.meta | 0 .../Foundation/Pools.meta | 0 .../Pools/AssetRefGameObjectItemPool.cs | 9 +- .../Pools/AssetRefGameObjectItemPool.cs.meta | 0 .../Foundation/Pools/GameObjectItemPool.cs | 28 +++ .../Pools/GameObjectItemPool.cs.meta | 3 + .../GameObjectLazyPool.asmdef} | 0 .../GameObjectLazyPool.asmdef.meta} | 0 .../GlobalPools.meta | 0 .../GlobalPools/Extensions.meta | 3 + .../GlobalAssetRefGameObjectPool.cs | 24 ++- .../GlobalAssetRefGameObjectPool.cs.meta | 0 .../GlobalPools/GlobalGameObjectPool.cs | 51 ++++++ .../GlobalPools/GlobalGameObjectPool.cs.meta | 3 + .../Items.meta | 0 .../Items/AssetRefGameObjectPoolItem.cs | 8 + .../Items/AssetRefGameObjectPoolItem.cs.meta | 0 .../Items/GameObjectPoolItem.cs | 7 + .../Items/GameObjectPoolItem.cs.meta | 3 + .../GameObjectLazyPool/Items/PoolItem.cs | 51 ++++++ .../Items/PoolItem.cs.meta | 0 .../Items/PoolItemAutoDeSpawnSetUp.cs | 10 ++ .../Items/PoolItemAutoDeSpawnSetUp.cs.meta | 3 + .../Items/AssetRefGameObjectPoolItem.cs | 8 - .../ItemPooling/Items/PoolItem.cs | 26 --- .../Prefabs/AssetRefPrefab{T,TAssetRef}.cs | 3 +- .../UnityPools/Pools/UnityPool{T,TPrefab}.cs | 1 - .../UnityPools/Prefabs/ComponentPrefab{T}.cs | 3 +- .../Prefabs/UnityPrefab{T,TSource}.cs | 5 +- 37 files changed, 447 insertions(+), 252 deletions(-) create mode 100644 Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab create mode 100644 Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta rename Packages/ZBase.Foundation.Pooling/{ItemPooling.meta => GameObjectLazyPool.meta} (100%) rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/Foundation.meta (100%) rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/Foundation/Pools.meta (100%) rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/Foundation/Pools/AssetRefGameObjectItemPool.cs (70%) rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta (100%) create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs.meta rename Packages/ZBase.Foundation.Pooling/{ItemPooling/ItemPooling.asmdef => GameObjectLazyPool/GameObjectLazyPool.asmdef} (100%) rename Packages/ZBase.Foundation.Pooling/{ItemPooling/ItemPooling.asmdef.meta => GameObjectLazyPool/GameObjectLazyPool.asmdef.meta} (100%) rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/GlobalPools.meta (100%) create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions.meta rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/GlobalPools/GlobalAssetRefGameObjectPool.cs (56%) rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta (100%) create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs.meta rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/Items.meta (100%) create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/Items/AssetRefGameObjectPoolItem.cs.meta (100%) create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs.meta create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs rename Packages/ZBase.Foundation.Pooling/{ItemPooling => GameObjectLazyPool}/Items/PoolItem.cs.meta (100%) create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs.meta delete mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs delete mode 100644 Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs diff --git a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity index e196d88..722f6b4 100644 --- a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity +++ b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity @@ -230,12 +230,14 @@ MonoBehaviour: m_EditorClassIdentifier: _prefab: _source: - m_AssetGUID: 1c14710c0d49c480497e5be810eb4fc4 + m_AssetGUID: d313163ceba02498b974cf73b0605e8a m_SubObjectName: m_SubObjectType: m_EditorAssetChanged: 0 _parent: {fileID: 0} _prePoolAmount: 0 + _spawnRadius: 20 + _spawnCount: 100 --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/PoolSample/AddressablePools/Prefabs/Character_AddressPool_P01.prefab b/Assets/PoolSample/AddressablePools/Prefabs/Character_AddressPool_P01.prefab index bf96fe0..f0f2c1b 100644 --- a/Assets/PoolSample/AddressablePools/Prefabs/Character_AddressPool_P01.prefab +++ b/Assets/PoolSample/AddressablePools/Prefabs/Character_AddressPool_P01.prefab @@ -24,13 +24,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 138330896580303601} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1206049215986293514} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &1876880627608008340 SkinnedMeshRenderer: @@ -163,13 +163,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 226250982463271441} + serializedVersion: 2 m_LocalRotation: {x: 2.3129124e-18, y: -0.7257409, z: -2.3129124e-18, w: 0.6879682} m_LocalPosition: {x: -0.2914453, y: 8.946976e-13, z: -2.131628e-15} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 8531396079878343762} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &287753642208092652 GameObject: @@ -194,6 +194,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 287753642208092652} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.09367575, w: 0.9956028} m_LocalPosition: {x: -0.28033707, y: 4.973799e-16, z: -9.895423e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -201,7 +202,6 @@ Transform: m_Children: - {fileID: 7109230986068702383} m_Father: {fileID: 2327371354313371515} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &455465716626962545 GameObject: @@ -226,6 +226,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 455465716626962545} + serializedVersion: 2 m_LocalRotation: {x: 0.20964532, y: -0.0013932837, z: 0.97775495, w: -0.0064980704} m_LocalPosition: {x: -0.12041652, y: 0.0049800063, z: 0.08191209} m_LocalScale: {x: 1, y: 1, z: 1} @@ -233,7 +234,6 @@ Transform: m_Children: - {fileID: 6784831572693372801} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &488199171439605489 GameObject: @@ -258,6 +258,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 488199171439605489} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.0670836, w: 0.99774736} m_LocalPosition: {x: -0.30618182, y: -6.0396133e-16, z: 8.413475e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -273,7 +274,6 @@ Transform: - {fileID: 1716483456479881960} - {fileID: 5426280670556242380} m_Father: {fileID: 863968998202755581} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &698436440287394580 GameObject: @@ -298,13 +298,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 698436440287394580} + serializedVersion: 2 m_LocalRotation: {x: -0.018653171, y: -0.018653171, z: 0.7068607, w: 0.7068607} m_LocalPosition: {x: -0.018659646, y: 0.0832196, z: -0.0010736184} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 8082933049513224970} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &714991354291320810 GameObject: @@ -329,6 +329,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 714991354291320810} + serializedVersion: 2 m_LocalRotation: {x: 2.2397977e-18, y: 5.568265e-17, z: -0.10232073, w: 0.99475145} m_LocalPosition: {x: -0.14028804, y: 0.0061973166, z: 2.2516412e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -337,7 +338,6 @@ Transform: - {fileID: 8280717662683578009} - {fileID: 2824468195007885066} m_Father: {fileID: 3021292840473646586} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &859208988865393670 GameObject: @@ -362,6 +362,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 859208988865393670} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0.43467525, z: -0, w: 0.9005873} m_LocalPosition: {x: -0.21829395, y: -7.105427e-17, z: 1.4210854e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -369,7 +370,6 @@ Transform: m_Children: - {fileID: 7033026291598922017} m_Father: {fileID: 7153945816541528113} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1050784358429973911 GameObject: @@ -394,13 +394,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1050784358429973911} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.27836862, y: -0.14700456, z: 0.0005698343} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7538635978781088124} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1114744663058868659 GameObject: @@ -425,6 +425,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1114744663058868659} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -432,7 +433,6 @@ Transform: m_Children: - {fileID: 3021292840473646586} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1141075905393938299 GameObject: @@ -457,13 +457,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1141075905393938299} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.24130988, y: 0.13323241, z: -0.0005894659} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7538635978781088124} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1504218546410239170 GameObject: @@ -488,6 +488,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1504218546410239170} + serializedVersion: 2 m_LocalRotation: {x: -1.3548951e-16, y: 4.5886806e-17, z: -0.08148055, w: 0.99667495} m_LocalPosition: {x: -0.14891407, y: 1.2434498e-16, z: 4.8846454e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -497,7 +498,6 @@ Transform: - {fileID: 7554977265215205441} - {fileID: 863968998202755581} m_Father: {fileID: 2824468195007885066} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1549371409795741819 GameObject: @@ -522,6 +522,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1549371409795741819} + serializedVersion: 2 m_LocalRotation: {x: 1.00992795e-29, y: 2.648741e-28, z: 0.03987671, w: 0.99920464} m_LocalPosition: {x: 0.35891908, y: 1.5543122e-17, z: 1.4210854e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -529,7 +530,6 @@ Transform: m_Children: - {fileID: 7538635978781088124} m_Father: {fileID: 7478584122703587002} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1627694566779018130 GameObject: @@ -554,6 +554,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1627694566779018130} + serializedVersion: 2 m_LocalRotation: {x: -0.05363183, y: 0.00061813387, z: 0.022184182, w: 0.99831414} m_LocalPosition: {x: 0.25370672, y: -0.010923628, z: 0.0016361566} m_LocalScale: {x: 1, y: 1, z: 1} @@ -561,7 +562,6 @@ Transform: m_Children: - {fileID: 668438987156427820} m_Father: {fileID: 2272526423318546737} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1679905956533328033 GameObject: @@ -586,13 +586,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1679905956533328033} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.27837098, y: 0.14700453, z: -0.00056984223} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1812620905285711470} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1802479053495865607 GameObject: @@ -617,13 +617,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1802479053495865607} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.06756819, w: 0.99771464} m_LocalPosition: {x: -0.30677703, y: 0.011362112, z: -3.952184e-17} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7109230986068702383} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1929923597870699303 GameObject: @@ -648,6 +648,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1929923597870699303} + serializedVersion: 2 m_LocalRotation: {x: 0.08801344, y: 0.7016079, z: 0.08801344, w: 0.7016079} m_LocalPosition: {x: -3.0999767e-32, y: -0.0007635658, z: 0.46243998} m_LocalScale: {x: 1, y: 1, z: 1} @@ -658,7 +659,6 @@ Transform: - {fileID: 2272526423318546737} - {fileID: 921109918825724116} m_Father: {fileID: 750084520247354679} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2032261819383484458 GameObject: @@ -683,13 +683,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2032261819383484458} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.28746313, z: -0, w: 0.95779175} m_LocalPosition: {x: -0.35610884, y: 2.8398991e-31, z: -1.4210854e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6145952056201830785} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2507900356367636727 GameObject: @@ -714,6 +714,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2507900356367636727} + serializedVersion: 2 m_LocalRotation: {x: -0.031930987, y: 0.077209614, z: 0.98761743, w: 0.13278146} m_LocalPosition: {x: 0.022657752, y: -0.0018067972, z: 0.17085} m_LocalScale: {x: 1, y: 1, z: 1} @@ -721,7 +722,6 @@ Transform: m_Children: - {fileID: 420675736411534631} m_Father: {fileID: 3021292840473646586} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2532881563549839027 GameObject: @@ -746,13 +746,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2532881563549839027} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.11008295, y: -0.009449474, z: 0.0006042766} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1812620905285711470} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2643011505494255503 GameObject: @@ -777,6 +777,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2643011505494255503} + serializedVersion: 2 m_LocalRotation: {x: -0.0013932837, y: -0.20964532, z: 0.0064980704, w: 0.97775495} m_LocalPosition: {x: -0.120417975, y: 0.0049800063, z: -0.081912056} m_LocalScale: {x: 1, y: 1, z: 1} @@ -784,7 +785,6 @@ Transform: m_Children: - {fileID: 283173838363886958} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2713646055767526605 GameObject: @@ -809,13 +809,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2713646055767526605} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.5431475, z: -0, w: 0.8396373} m_LocalPosition: {x: -0.67569554, y: -2.8865798e-17, z: -5.684342e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6670808628360169920} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2843460156077627762 GameObject: @@ -840,6 +840,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2843460156077627762} + serializedVersion: 2 m_LocalRotation: {x: 0.07721848, y: 0.0319301, z: -0.13278173, w: 0.9876167} m_LocalPosition: {x: 0.022657402, y: -0.0018067064, z: -0.17085041} m_LocalScale: {x: 1, y: 1, z: 1} @@ -847,7 +848,6 @@ Transform: m_Children: - {fileID: 5975660448523642792} m_Father: {fileID: 3021292840473646586} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3420775065772691144 GameObject: @@ -872,6 +872,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3420775065772691144} + serializedVersion: 2 m_LocalRotation: {x: 1.485756e-30, y: 5.747986e-29, z: 0.03987671, w: 0.99920464} m_LocalPosition: {x: -0.35891947, y: -6.661338e-18, z: -4.2632563e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -879,7 +880,6 @@ Transform: m_Children: - {fileID: 1812620905285711470} m_Father: {fileID: 1205495623789889750} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3583981249486399142 GameObject: @@ -905,13 +905,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3583981249486399142} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 8073424196381629842} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &567454439128644213 SkinnedMeshRenderer: @@ -1044,6 +1044,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3603544498873252484} + serializedVersion: 2 m_LocalRotation: {x: 0.72198325, y: 0.03173624, z: 0.67331934, w: -0.15612186} m_LocalPosition: {x: -0.06351176, y: 0.030065548, z: 0.20842399} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1051,7 +1052,6 @@ Transform: m_Children: - {fileID: 7478584122703587002} m_Father: {fileID: 7896211863139388261} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3630709394180804763 GameObject: @@ -1076,6 +1076,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3630709394180804763} + serializedVersion: 2 m_LocalRotation: {x: 0.47399396, y: 5.5526276e-16, z: 0.88052815, w: -1.0314995e-15} m_LocalPosition: {x: 0.06945347, y: 0.0049800063, z: 0.235986} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1083,7 +1084,6 @@ Transform: m_Children: - {fileID: 5737231255890581570} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3803429104794297356 GameObject: @@ -1108,6 +1108,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3803429104794297356} + serializedVersion: 2 m_LocalRotation: {x: -0.019583104, y: -0.014337628, z: -0.016081654, w: 0.9995761} m_LocalPosition: {x: 0.15340362, y: 0.01794422, z: -0.0011433699} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1115,7 +1116,6 @@ Transform: m_Children: - {fileID: 3945426546291992806} m_Father: {fileID: 5975660448523642792} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4115995605409072671 GameObject: @@ -1140,6 +1140,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4115995605409072671} + serializedVersion: 2 m_LocalRotation: {x: -0.3024084, y: 0.95317847, z: 6.7676127e-16, w: -2.7212164e-16} m_LocalPosition: {x: -0.030352466, y: 0.25417748, z: 2.7145378e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1147,7 +1148,6 @@ Transform: m_Children: - {fileID: 2187775998403471798} m_Father: {fileID: 3021292840473646586} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4268021608341189657 GameObject: @@ -1160,6 +1160,7 @@ GameObject: - component: {fileID: 3490535618095509155} - component: {fileID: 4033649509468943910} - component: {fileID: 903822165} + - component: {fileID: 7039333522338043405} m_Layer: 0 m_Name: Character_AddressPool_P01 m_TagString: Untagged @@ -1174,6 +1175,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4268021608341189657} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1188,7 +1190,6 @@ Transform: - {fileID: 750084520247354679} - {fileID: 8073424196381629842} m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!95 &4033649509468943910 Animator: @@ -1210,6 +1211,7 @@ Animator: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 + m_WriteDefaultValuesOnDisable: 0 --- !u!65 &903822165 BoxCollider: m_ObjectHideFlags: 0 @@ -1218,11 +1220,32 @@ BoxCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4268021608341189657} m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 m_IsTrigger: 0 + m_ProvidesContacts: 0 m_Enabled: 1 - serializedVersion: 2 + serializedVersion: 3 m_Size: {x: 1, y: 1.6, z: 1} m_Center: {x: 0, y: 0.8, z: 0} +--- !u!114 &7039333522338043405 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4268021608341189657} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3ccfd0da2bab4198bf7a2413d826a967, type: 3} + m_Name: + m_EditorClassIdentifier: + _lifeTime: 2 --- !u!1 &4283619346492918992 GameObject: m_ObjectHideFlags: 0 @@ -1246,6 +1269,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4283619346492918992} + serializedVersion: 2 m_LocalRotation: {x: -0.05363183, y: 0.00061813387, z: 0.022184182, w: 0.99831414} m_LocalPosition: {x: -0.25370672, y: 0.010923714, z: -0.0016354381} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1253,7 +1277,6 @@ Transform: m_Children: - {fileID: 8082933049513224970} m_Father: {fileID: 921109918825724116} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4424136353415040355 GameObject: @@ -1278,13 +1301,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4424136353415040355} + serializedVersion: 2 m_LocalRotation: {x: -0, y: -0.7071068, z: 0, w: 0.7071068} m_LocalPosition: {x: 0.16025886, y: 0.020835321, z: 1.5729948e-18} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2882362028944447721} - m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4639378322033702546 GameObject: @@ -1309,6 +1332,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4639378322033702546} + serializedVersion: 2 m_LocalRotation: {x: -0.7056592, y: 0.014749782, z: -0.0129053835, w: 0.7082804} m_LocalPosition: {x: 0.40930742, y: 4.440892e-18, z: -7.1054274e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1319,7 +1343,6 @@ Transform: - {fileID: 5892047406499915741} - {fileID: 2434394716824458521} m_Father: {fileID: 7195090757511394589} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4692713380248173046 GameObject: @@ -1344,6 +1367,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4692713380248173046} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1351,7 +1375,6 @@ Transform: m_Children: - {fileID: 228228637039729191} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4701507429529918184 GameObject: @@ -1376,6 +1399,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4701507429529918184} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0.43467525, z: -0, w: 0.9005873} m_LocalPosition: {x: 0.21829534, y: -0.0000002822668, z: -0.0000019725908} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1383,7 +1407,6 @@ Transform: m_Children: - {fileID: 7500284451345412696} m_Father: {fileID: 80097259736002229} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4718454532800291202 GameObject: @@ -1408,6 +1431,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4718454532800291202} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1415,7 +1439,6 @@ Transform: m_Children: - {fileID: 2201632628865876993} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4817060318934790676 GameObject: @@ -1441,13 +1464,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4817060318934790676} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6500139712878797334} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &1310368571816120189 SkinnedMeshRenderer: @@ -1580,6 +1603,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5083488943237554619} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1587,7 +1611,6 @@ Transform: m_Children: - {fileID: 6526375789445201083} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5111183543478305989 GameObject: @@ -1612,13 +1635,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5111183543478305989} + serializedVersion: 2 m_LocalRotation: {x: 0.5415089, y: 0.45471767, z: 0.5415089, w: -0.45471767} m_LocalPosition: {x: -0.1039998, y: -0.006094659, z: -1.09662166e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6711860330090213021} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5159717039236245029 GameObject: @@ -1643,6 +1666,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5159717039236245029} + serializedVersion: 2 m_LocalRotation: {x: -0.7056592, y: 0.014749782, z: -0.0129053835, w: 0.7082804} m_LocalPosition: {x: -0.40930396, y: -2.842171e-16, z: 2.2737367e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1653,7 +1677,6 @@ Transform: - {fileID: 8554790566202856765} - {fileID: 1167101034371147920} m_Father: {fileID: 3173945538790593745} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5233688159518383750 GameObject: @@ -1678,6 +1701,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5233688159518383750} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1685,7 +1709,6 @@ Transform: m_Children: - {fileID: 5271289200934064066} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5269846092593865583 GameObject: @@ -1711,13 +1734,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5269846092593865583} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 4515168733536942268} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &1145621938648953583 SkinnedMeshRenderer: @@ -1850,6 +1873,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5587478901108345050} + serializedVersion: 2 m_LocalRotation: {x: 0.0015542243, y: 0.022218248, z: -0.11379966, w: 0.993254} m_LocalPosition: {x: -0.1541595, y: -2.664535e-16, z: -2.131628e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1857,7 +1881,6 @@ Transform: m_Children: - {fileID: 3173945538790593745} m_Father: {fileID: 4462894962888916735} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5590637880744520908 GameObject: @@ -1883,13 +1906,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5590637880744520908} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7977154252773851303} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &3691570734654701062 SkinnedMeshRenderer: @@ -2022,13 +2045,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5707481856367446099} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.13957767, y: -0.0022430373, z: 0.00047288262} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1812620905285711470} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5764652118192804511 GameObject: @@ -2053,6 +2076,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5764652118192804511} + serializedVersion: 2 m_LocalRotation: {x: 0.0015542243, y: 0.022218248, z: -0.11379966, w: 0.993254} m_LocalPosition: {x: 0.15415917, y: 0.00000004352324, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2060,7 +2084,6 @@ Transform: m_Children: - {fileID: 7195090757511394589} m_Father: {fileID: 7554977265215205441} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5788336186966367919 GameObject: @@ -2085,6 +2108,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5788336186966367919} + serializedVersion: 2 m_LocalRotation: {x: 6.142407e-17, y: 1.655707e-16, z: -0.0765332, w: 0.99706703} m_LocalPosition: {x: -0.15357347, y: -3.6637358e-17, z: 4.178964e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2092,7 +2116,6 @@ Transform: m_Children: - {fileID: 7896211863139388261} m_Father: {fileID: 3343182092621812688} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6066855096617392838 GameObject: @@ -2117,6 +2140,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6066855096617392838} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2124,7 +2148,6 @@ Transform: m_Children: - {fileID: 119567693795888709} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6170896697531000994 GameObject: @@ -2149,6 +2172,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6170896697531000994} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.47399396, z: -0, w: 0.88052815} m_LocalPosition: {x: 0.06945152, y: 0.0049800063, z: -0.2359865} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2156,7 +2180,6 @@ Transform: m_Children: - {fileID: 5617441830511941826} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6446345808013169856 GameObject: @@ -2181,6 +2204,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6446345808013169856} + serializedVersion: 2 m_LocalRotation: {x: 0.03173624, y: -0.72198325, z: 0.15612186, w: 0.67331934} m_LocalPosition: {x: -0.063511945, y: 0.030065516, z: -0.20842351} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2188,7 +2212,6 @@ Transform: m_Children: - {fileID: 1205495623789889750} m_Father: {fileID: 7896211863139388261} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6744019224384860890 GameObject: @@ -2213,13 +2236,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6744019224384860890} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.5431475, z: -0, w: 0.8396373} m_LocalPosition: {x: 0.67569244, y: 0.000000046456332, z: 0.000001032785} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6719809345154168994} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6808674702210550146 GameObject: @@ -2245,13 +2268,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6808674702210550146} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6142648240148854792} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &8032734649195767439 SkinnedMeshRenderer: @@ -2384,13 +2407,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6922517017255397821} + serializedVersion: 2 m_LocalRotation: {x: 0.004463791, y: -0.7070927, z: 0.004463791, w: 0.7070927} m_LocalPosition: {x: -0.6819025, y: -0.00860988, z: 7.8409694e-17} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 4909785548142953856} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7063172531990631227 GameObject: @@ -2415,13 +2438,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7063172531990631227} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.13957906, y: 0.0022421728, z: -0.00047287406} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7538635978781088124} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7149982063308821801 GameObject: @@ -2446,13 +2469,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7149982063308821801} + serializedVersion: 2 m_LocalRotation: {x: 2.3129124e-18, y: -0.7257409, z: -2.3129124e-18, w: 0.6879682} m_LocalPosition: {x: 0.29144114, y: 0.00000043365793, z: -0.00000014326524} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2926320213317427512} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7684779052209821285 GameObject: @@ -2477,6 +2500,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7684779052209821285} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2484,7 +2508,6 @@ Transform: m_Children: - {fileID: 7719620923427115511} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7754637199560309470 GameObject: @@ -2509,6 +2532,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7754637199560309470} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2516,7 +2540,6 @@ Transform: m_Children: - {fileID: 5937915795577801586} m_Father: {fileID: 3490535618095509155} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7762759151279305076 GameObject: @@ -2541,6 +2564,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7762759151279305076} + serializedVersion: 2 m_LocalRotation: {x: -2.7535306e-17, y: -3.897205e-18, z: 0.20162798, w: 0.9794622} m_LocalPosition: {x: -0.20905116, y: 1.7763567e-16, z: 1.0606601e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2548,7 +2572,6 @@ Transform: m_Children: - {fileID: 2882362028944447721} m_Father: {fileID: 7896211863139388261} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7794991725766163678 GameObject: @@ -2573,6 +2596,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7794991725766163678} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.006312754, w: 0.9999801} m_LocalPosition: {x: -0.18918252, y: 0.0049800063, z: 1.1443254e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2580,7 +2604,6 @@ Transform: m_Children: - {fileID: 1155972674449271357} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7910800774690219132 GameObject: @@ -2605,13 +2628,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7910800774690219132} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.110078454, y: 0.009448838, z: -0.0006042899} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7538635978781088124} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7992483945061454146 GameObject: @@ -2636,6 +2659,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7992483945061454146} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0.76580924, w: 0.6430679} m_LocalPosition: {x: 0.11468992, y: -0.11381889, z: -1.1558126e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2643,7 +2667,6 @@ Transform: m_Children: - {fileID: 4425924654405568705} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8091743642228453956 GameObject: @@ -2668,6 +2691,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8091743642228453956} + serializedVersion: 2 m_LocalRotation: {x: 0.40998435, y: 0.019879602, z: 0.9108058, w: -0.044163775} m_LocalPosition: {x: -0.016146528, y: 0.0049800063, z: 0.207973} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2675,7 +2699,6 @@ Transform: m_Children: - {fileID: 2926320213317427512} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8199562350594480232 GameObject: @@ -2701,13 +2724,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8199562350594480232} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 8759273347186801075} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &7846209212776854146 SkinnedMeshRenderer: @@ -2840,6 +2863,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8204447360954277264} + serializedVersion: 2 m_LocalRotation: {x: -0.019574154, y: -0.01433758, z: -0.016081778, w: 0.9995763} m_LocalPosition: {x: -0.15340334, y: -0.017944258, z: 0.001143231} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2847,7 +2871,6 @@ Transform: m_Children: - {fileID: 5000632246707600923} m_Father: {fileID: 420675736411534631} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8366429916056520271 GameObject: @@ -2872,13 +2895,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8366429916056520271} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.28746313, z: -0, w: 0.95779175} m_LocalPosition: {x: 0.35611197, y: 3.100587e-17, z: -0.0000042392044} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1716483456479881960} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8452615318620168085 GameObject: @@ -2903,13 +2926,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8452615318620168085} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.24131815, y: -0.13323142, z: 0.0005894331} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1812620905285711470} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8457796172106953154 GameObject: @@ -2934,13 +2957,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8457796172106953154} + serializedVersion: 2 m_LocalRotation: {x: -0.015762473, y: -0.7069311, z: -0.015762473, w: 0.7069311} m_LocalPosition: {x: 0.004094967, y: -0.27914742, z: -2.8367557e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3343182092621812688} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8794922878653033462 GameObject: @@ -2965,6 +2988,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8794922878653033462} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.09853762, w: 0.99513334} m_LocalPosition: {x: -0.30899003, y: 7.105427e-17, z: -7.424184e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2972,7 +2996,6 @@ Transform: m_Children: - {fileID: 3480807667522060672} m_Father: {fileID: 2187775998403471798} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &9020965509426264544 GameObject: @@ -2997,13 +3020,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9020965509426264544} + serializedVersion: 2 m_LocalRotation: {x: -0.018653171, y: -0.018653171, z: 0.7068607, w: 0.7068607} m_LocalPosition: {x: 0.018659662, y: -0.08321956, z: 0.0010733596} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 668438987156427820} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &9037692245517675030 GameObject: @@ -3028,6 +3051,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9037692245517675030} + serializedVersion: 2 m_LocalRotation: {x: 0.019879602, y: -0.40998435, z: 0.044163775, w: 0.9108058} m_LocalPosition: {x: -0.016145382, y: 0.0049800063, z: -0.20797296} m_LocalScale: {x: 1, y: 1, z: 1} @@ -3035,5 +3059,4 @@ Transform: m_Children: - {fileID: 8531396079878343762} m_Father: {fileID: 2882362028944447721} - m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab b/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab new file mode 100644 index 0000000..6fdf478 --- /dev/null +++ b/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2523104297209005010 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3821941267034635079} + - component: {fileID: -7625971595942420386} + m_Layer: 0 + m_Name: Empt + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3821941267034635079 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2523104297209005010} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &-7625971595942420386 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2523104297209005010} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3ccfd0da2bab4198bf7a2413d826a967, type: 3} + m_Name: + m_EditorClassIdentifier: + _lifeTime: 2 diff --git a/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta b/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta new file mode 100644 index 0000000..b627252 --- /dev/null +++ b/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5c4c0ac3f2694a44b8f014a328729ec1 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs index cc58023..af1a575 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs @@ -3,21 +3,23 @@ using ZBase.Collections.Pooled.Generic; using ZBase.Foundation.Pooling; using ZBase.Foundation.Pooling.AddressableAssets; -using Grid = Sample.Environment.Grid; +using ZBase.Foundation.Pooling.GameObject.LazyPool; namespace Pooling.Sample { public class AddressableGameObjectPoolSample1 : MonoBehaviour { - [SerializeField]private AssetRefGameObjectPrefab _prefab; - private readonly Grid _grid = new(20, 15, true); + [SerializeField] private AssetRefGameObjectPrefab _prefab; + [SerializeField] private float _spawnRadius = 20f; + [SerializeField] private int _spawnCount = 20; private readonly List _spawned = new(); - + private async UniTask Spawn() { var pool = SharedPool.Of(); var go = await pool.Rent(_prefab); - go.transform.position = _grid.GetAvailableSlot().position; + var pos = Random.insideUnitCircle * _spawnRadius; + go.transform.position = new Vector3 { x = pos.x, y = 0, z = pos.y }; go.SetActive(true); _spawned.Add(go); } @@ -27,65 +29,29 @@ private void Return() var pool = SharedPool.Of(); foreach (var go in _spawned) pool.Return(go); - FreeSlot(); _spawned.Clear(); } - private void FreeSlot() - { - foreach (var go in _spawned) - _grid.FreeSlot(go.transform.position); - } - - private async UniTask SpawnDisposableItems() - { - var pool = SharedPool.Of(); - var context = pool.DisposableContext(); - using var go = await context.Rent(); - go.Instance.transform.position = _grid.GetAvailableSlot().position; - go.Instance.SetActive(true); - _spawned.Add(go.Instance); - await UniTask.Delay(1500); - } - private void ReleaseAll() { - var pool = SharedPool.Of(); + foreach (var go in _spawned) + go.SetActive(false); + var pool = SharedPool.Of(); pool.ReleaseInstances(0); _spawned.Clear(); } - - private void OnDisable()=> ReleaseAll(); - - - private async void OnGUI() + + private void OnDisable() => ReleaseAll(); + + private void OnGUI() { if (GUI.Button(new Rect(10, 10, 150, 50), "Spawn")) - { - for (int i = 0; i < 100; i++) - { + for (int i = 0; i < _spawnCount; i++) Spawn().Forget(); - } - Debug.Log("Spawn 100 item from the AddressableGameObject pool"); - } - - if (GUI.Button(new Rect(10, 70, 150, 50), "Spawn Disposable Item")) - { - await SpawnDisposableItems(); - Debug.Log("Item automatically returned to pool when context is disposed"); - } - if (GUI.Button(new Rect(10, 130, 150, 50), "Return")) - { Return(); - Debug.Log("Return all item to the pool"); - } - if (GUI.Button(new Rect(10, 190, 150, 50), "Release All")) - { ReleaseAll(); - Debug.Log("Release all item from the pool"); - } } } } \ No newline at end of file diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs index 9f2b57a..46e0ecf 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs @@ -56,7 +56,7 @@ private async void OnGUI() private async UniTask Spawn() { - var pool = SharedPool.Of(); + var pool = SharedPool.Of(); var go = await pool.Rent(); go.transform.position = _grid.GetAvailableSlot().position; go.SetActive(true); @@ -65,7 +65,7 @@ private async UniTask Spawn() private void Return() { - var pool = SharedPool.Of(); + var pool = SharedPool.Of(); foreach (var go in _spawned) { pool.Return(go); @@ -75,7 +75,7 @@ private void Return() private async UniTask SpawnDisposableItems() { - var pool = SharedPool.Of(); + var pool = SharedPool.Of(); var context = pool.DisposableContext(); using var go = await context.Rent(); go.Instance.transform.position = _grid.GetAvailableSlot().position; @@ -86,7 +86,7 @@ private async UniTask SpawnDisposableItems() private void ReleaseAll() { - var pool = SharedPool.Of(); + var pool = SharedPool.Of(); pool.ReleaseInstances(0); _spawned.Clear(); } diff --git a/Assets/PoolSample/ScriptablePools/Prefabs/Character_P01.prefab b/Assets/PoolSample/ScriptablePools/Prefabs/Character_P01.prefab index 1659a7e..dac7c12 100644 --- a/Assets/PoolSample/ScriptablePools/Prefabs/Character_P01.prefab +++ b/Assets/PoolSample/ScriptablePools/Prefabs/Character_P01.prefab @@ -23,6 +23,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 87579466245271997} + serializedVersion: 2 m_LocalRotation: {x: 0.019879602, y: -0.40998435, z: 0.044163775, w: 0.9108058} m_LocalPosition: {x: -0.016145382, y: 0.0049800063, z: -0.20797296} m_LocalScale: {x: 1, y: 1, z: 1} @@ -30,7 +31,6 @@ Transform: m_Children: - {fileID: 738286535971428345} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &102343006776975947 GameObject: @@ -55,13 +55,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 102343006776975947} + serializedVersion: 2 m_LocalRotation: {x: -0.018653171, y: -0.018653171, z: 0.7068607, w: 0.7068607} m_LocalPosition: {x: 0.018659662, y: -0.08321956, z: 0.0010733596} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 8439100899513847687} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &456737110537875549 GameObject: @@ -86,6 +86,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 456737110537875549} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.09853762, w: 0.99513334} m_LocalPosition: {x: -0.30899003, y: 7.105427e-17, z: -7.424184e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -93,7 +94,6 @@ Transform: m_Children: - {fileID: 5482323410964126251} m_Father: {fileID: 7063890055000896029} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &594747381485460964 GameObject: @@ -118,13 +118,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 594747381485460964} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.28746313, z: -0, w: 0.95779175} m_LocalPosition: {x: 0.35611197, y: 3.100587e-17, z: -0.0000042392044} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7748826485428433219} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &654931664071918654 GameObject: @@ -149,13 +149,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 654931664071918654} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.24131815, y: -0.13323142, z: 0.0005894331} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7312941058919804357} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &665214393656486505 GameObject: @@ -180,13 +180,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 665214393656486505} + serializedVersion: 2 m_LocalRotation: {x: -0.015762473, y: -0.7069311, z: -0.015762473, w: 0.7069311} m_LocalPosition: {x: 0.004094967, y: -0.27914742, z: -2.8367557e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 5926225148148664443} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &869429754410150383 GameObject: @@ -211,6 +211,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 869429754410150383} + serializedVersion: 2 m_LocalRotation: {x: 0.40998435, y: 0.019879602, z: 0.9108058, w: -0.044163775} m_LocalPosition: {x: -0.016146528, y: 0.0049800063, z: 0.207973} m_LocalScale: {x: 1, y: 1, z: 1} @@ -218,7 +219,6 @@ Transform: m_Children: - {fileID: 6108869574807812755} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &974885687907763771 GameObject: @@ -243,6 +243,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 974885687907763771} + serializedVersion: 2 m_LocalRotation: {x: -0.019574154, y: -0.01433758, z: -0.016081778, w: 0.9995763} m_LocalPosition: {x: -0.15340334, y: -0.017944258, z: 0.001143231} m_LocalScale: {x: 1, y: 1, z: 1} @@ -250,7 +251,6 @@ Transform: m_Children: - {fileID: 4124910992819119536} m_Father: {fileID: 8758932156336025228} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &977776698513753027 GameObject: @@ -276,13 +276,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 977776698513753027} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 420031629014426136} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &1204754186042796329 SkinnedMeshRenderer: @@ -415,6 +415,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1186187869344917365} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.006312754, w: 0.9999801} m_LocalPosition: {x: -0.18918252, y: 0.0049800063, z: 1.1443254e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -422,7 +423,6 @@ Transform: m_Children: - {fileID: 7805203505397084566} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1266566330199539671 GameObject: @@ -447,13 +447,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1266566330199539671} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.110078454, y: 0.009448838, z: -0.0006042899} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1496863322693239511} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1346701583620917993 GameObject: @@ -478,6 +478,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1346701583620917993} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0.76580924, w: 0.6430679} m_LocalPosition: {x: 0.11468992, y: -0.11381889, z: -1.1558126e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -485,7 +486,6 @@ Transform: m_Children: - {fileID: 4699360250324849514} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1656939751193480654 GameObject: @@ -510,6 +510,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1656939751193480654} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -517,7 +518,6 @@ Transform: m_Children: - {fileID: 1691922366214638172} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1712899803133419893 GameObject: @@ -542,6 +542,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1712899803133419893} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -549,7 +550,6 @@ Transform: m_Children: - {fileID: 3331756410027397337} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1720846097131416287 GameObject: @@ -574,6 +574,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1720846097131416287} + serializedVersion: 2 m_LocalRotation: {x: -2.7535306e-17, y: -3.897205e-18, z: 0.20162798, w: 0.9794622} m_LocalPosition: {x: -0.20905116, y: 1.7763567e-16, z: 1.0606601e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -581,7 +582,6 @@ Transform: m_Children: - {fileID: 6078527746324431682} m_Father: {fileID: 1283397127760695502} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2038662461075362326 GameObject: @@ -606,13 +606,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2038662461075362326} + serializedVersion: 2 m_LocalRotation: {x: 0.004463791, y: -0.7070927, z: 0.004463791, w: 0.7070927} m_LocalPosition: {x: -0.6819025, y: -0.00860988, z: 7.8409694e-17} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 4069142763321466411} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2188219209632303248 GameObject: @@ -637,13 +637,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2188219209632303248} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.13957906, y: 0.0022421728, z: -0.00047287406} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1496863322693239511} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2261553530829999746 GameObject: @@ -668,13 +668,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2261553530829999746} + serializedVersion: 2 m_LocalRotation: {x: 2.3129124e-18, y: -0.7257409, z: -2.3129124e-18, w: 0.6879682} m_LocalPosition: {x: 0.29144114, y: 0.00000043365793, z: -0.00000014326524} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6108869574807812755} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2435569958190950769 GameObject: @@ -699,13 +699,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2435569958190950769} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.5431475, z: -0, w: 0.8396373} m_LocalPosition: {x: 0.67569244, y: 0.000000046456332, z: 0.000001032785} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2385499082292159241} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2460713244427948585 GameObject: @@ -731,13 +731,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2460713244427948585} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2982616874506314659} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &1378507907859086628 SkinnedMeshRenderer: @@ -870,6 +870,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2678926418829430635} + serializedVersion: 2 m_LocalRotation: {x: 0.03173624, y: -0.72198325, z: 0.15612186, w: 0.67331934} m_LocalPosition: {x: -0.063511945, y: 0.030065516, z: -0.20842351} m_LocalScale: {x: 1, y: 1, z: 1} @@ -877,7 +878,6 @@ Transform: m_Children: - {fileID: 7845754180672164733} m_Father: {fileID: 1283397127760695502} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2912347542243836269 GameObject: @@ -902,6 +902,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2912347542243836269} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -909,7 +910,6 @@ Transform: m_Children: - {fileID: 9075802281208305134} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3024200014160179977 GameObject: @@ -934,6 +934,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3024200014160179977} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.47399396, z: -0, w: 0.88052815} m_LocalPosition: {x: 0.06945152, y: 0.0049800063, z: -0.2359865} m_LocalScale: {x: 1, y: 1, z: 1} @@ -941,7 +942,6 @@ Transform: m_Children: - {fileID: 3579897352336261993} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3174823477700166916 GameObject: @@ -966,6 +966,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3174823477700166916} + serializedVersion: 2 m_LocalRotation: {x: 6.142407e-17, y: 1.655707e-16, z: -0.0765332, w: 0.99706703} m_LocalPosition: {x: -0.15357347, y: -3.6637358e-17, z: 4.178964e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -973,7 +974,6 @@ Transform: m_Children: - {fileID: 1283397127760695502} m_Father: {fileID: 5926225148148664443} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3196245902660274484 GameObject: @@ -998,6 +998,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3196245902660274484} + serializedVersion: 2 m_LocalRotation: {x: 0.0015542243, y: 0.022218248, z: -0.11379966, w: 0.993254} m_LocalPosition: {x: 0.15415917, y: 0.00000004352324, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1005,7 +1006,6 @@ Transform: m_Children: - {fileID: 2270210955174571702} m_Father: {fileID: 1478266937938357226} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3588981539407820647 GameObject: @@ -1031,13 +1031,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3588981539407820647} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1364586009460595468} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &5719686150480389549 SkinnedMeshRenderer: @@ -1170,6 +1170,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3589868412656243569} + serializedVersion: 2 m_LocalRotation: {x: 0.0015542243, y: 0.022218248, z: -0.11379966, w: 0.993254} m_LocalPosition: {x: -0.1541595, y: -2.664535e-16, z: -2.131628e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1177,7 +1178,6 @@ Transform: m_Children: - {fileID: 5789217477003333498} m_Father: {fileID: 4734430458834019668} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3706036688498988024 GameObject: @@ -1202,13 +1202,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3706036688498988024} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.13957767, y: -0.0022430373, z: 0.00047288262} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7312941058919804357} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3817569925875762477 GameObject: @@ -1233,6 +1233,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3817569925875762477} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1240,7 +1241,6 @@ Transform: m_Children: - {fileID: 3853974761597031529} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3853164971416451268 GameObject: @@ -1266,13 +1266,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3853164971416451268} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 4824034921282773783} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &8339928928853977412 SkinnedMeshRenderer: @@ -1405,13 +1405,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4230536342340116334} + serializedVersion: 2 m_LocalRotation: {x: 0.5415089, y: 0.45471767, z: 0.5415089, w: -0.45471767} m_LocalPosition: {x: -0.1039998, y: -0.006094659, z: -1.09662166e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2413403082384274742} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4239961458664028688 GameObject: @@ -1436,6 +1436,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4239961458664028688} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1443,7 +1444,6 @@ Transform: m_Children: - {fileID: 2794809067659323152} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4305880457951329678 GameObject: @@ -1468,6 +1468,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4305880457951329678} + serializedVersion: 2 m_LocalRotation: {x: -0.7056592, y: 0.014749782, z: -0.0129053835, w: 0.7082804} m_LocalPosition: {x: -0.40930396, y: -2.842171e-16, z: 2.2737367e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1478,7 +1479,6 @@ Transform: - {fileID: 784691246771375766} - {fileID: 7811792676116116283} m_Father: {fileID: 5789217477003333498} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4339519752159341881 GameObject: @@ -1503,6 +1503,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4339519752159341881} + serializedVersion: 2 m_LocalRotation: {x: -0.7056592, y: 0.014749782, z: -0.0129053835, w: 0.7082804} m_LocalPosition: {x: 0.40930742, y: 4.440892e-18, z: -7.1054274e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1513,7 +1514,6 @@ Transform: - {fileID: 3287541827770039414} - {fileID: 6742949812747898546} m_Father: {fileID: 2270210955174571702} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4404557115531491881 GameObject: @@ -1538,6 +1538,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4404557115531491881} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1545,7 +1546,6 @@ Transform: m_Children: - {fileID: 7122078940071272362} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4414844631148323421 GameObject: @@ -1570,6 +1570,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4414844631148323421} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1577,7 +1578,6 @@ Transform: m_Children: - {fileID: 9183302009042485644} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4423779623539917123 GameObject: @@ -1602,6 +1602,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4423779623539917123} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0.43467525, z: -0, w: 0.9005873} m_LocalPosition: {x: 0.21829534, y: -0.0000002822668, z: -0.0000019725908} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1609,7 +1610,6 @@ Transform: m_Children: - {fileID: 1462874664368663027} m_Father: {fileID: 9027430480726930718} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4504394502470117823 GameObject: @@ -1635,13 +1635,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4504394502470117823} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2769241637506005437} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &7959036452802090198 SkinnedMeshRenderer: @@ -1774,13 +1774,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4701406902020134600} + serializedVersion: 2 m_LocalRotation: {x: -0, y: -0.7071068, z: 0, w: 0.7071068} m_LocalPosition: {x: 0.16025886, y: 0.020835321, z: 1.5729948e-18} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6078527746324431682} - m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &4991540948030905780 GameObject: @@ -1805,6 +1805,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4991540948030905780} + serializedVersion: 2 m_LocalRotation: {x: -0.3024084, y: 0.95317847, z: 6.7676127e-16, w: -2.7212164e-16} m_LocalPosition: {x: -0.030352466, y: 0.25417748, z: 2.7145378e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1812,7 +1813,6 @@ Transform: m_Children: - {fileID: 7063890055000896029} m_Father: {fileID: 6176328368197471825} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5127639685006055291 GameObject: @@ -1837,6 +1837,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5127639685006055291} + serializedVersion: 2 m_LocalRotation: {x: -0.05363183, y: 0.00061813387, z: 0.022184182, w: 0.99831414} m_LocalPosition: {x: -0.25370672, y: 0.010923714, z: -0.0016354381} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1844,7 +1845,6 @@ Transform: m_Children: - {fileID: 898231667641610401} m_Father: {fileID: 8111828103614620543} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5143250635345817522 GameObject: @@ -1856,6 +1856,7 @@ GameObject: m_Component: - component: {fileID: 5488673670398653704} - component: {fileID: 5449662185156111757} + - component: {fileID: -8585594812908407642} m_Layer: 0 m_Name: Character_P01 m_TagString: Untagged @@ -1870,6 +1871,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5143250635345817522} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1.5, y: 1.5, z: 1.5} @@ -1884,7 +1886,6 @@ Transform: - {fileID: 8517333686487891612} - {fileID: 887737656511170105} m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!95 &5449662185156111757 Animator: @@ -1906,6 +1907,20 @@ Animator: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 + m_WriteDefaultValuesOnDisable: 0 +--- !u!114 &-8585594812908407642 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5143250635345817522} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3ccfd0da2bab4198bf7a2413d826a967, type: 3} + m_Name: + m_EditorClassIdentifier: + _lifeTime: 2 --- !u!1 &5229539704271912871 GameObject: m_ObjectHideFlags: 0 @@ -1929,6 +1944,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5229539704271912871} + serializedVersion: 2 m_LocalRotation: {x: -0.019583104, y: -0.014337628, z: -0.016081654, w: 0.9995761} m_LocalPosition: {x: 0.15340362, y: 0.01794422, z: -0.0011433699} m_LocalScale: {x: 1, y: 1, z: 1} @@ -1936,7 +1952,6 @@ Transform: m_Children: - {fileID: 5376040885117629261} m_Father: {fileID: 3366088592808131587} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5613644357447253261 GameObject: @@ -1962,13 +1977,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5613644357447253261} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 887737656511170105} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &8915844096056353246 SkinnedMeshRenderer: @@ -2101,6 +2116,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5636728604099005232} + serializedVersion: 2 m_LocalRotation: {x: 0.47399396, y: 5.5526276e-16, z: 0.88052815, w: -1.0314995e-15} m_LocalPosition: {x: 0.06945347, y: 0.0049800063, z: 0.235986} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2108,7 +2124,6 @@ Transform: m_Children: - {fileID: 3730613643346740201} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5645592642720882991 GameObject: @@ -2133,6 +2148,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5645592642720882991} + serializedVersion: 2 m_LocalRotation: {x: 0.72198325, y: 0.03173624, z: 0.67331934, w: -0.15612186} m_LocalPosition: {x: -0.06351176, y: 0.030065548, z: 0.20842399} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2140,7 +2156,6 @@ Transform: m_Children: - {fileID: 1986708226969140497} m_Father: {fileID: 1283397127760695502} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &5990483450429035875 GameObject: @@ -2165,6 +2180,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5990483450429035875} + serializedVersion: 2 m_LocalRotation: {x: 1.485756e-30, y: 5.747986e-29, z: 0.03987671, w: 0.99920464} m_LocalPosition: {x: -0.35891947, y: -6.661338e-18, z: -4.2632563e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2172,7 +2188,6 @@ Transform: m_Children: - {fileID: 7312941058919804357} m_Father: {fileID: 7845754180672164733} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6410501128257649700 GameObject: @@ -2197,6 +2212,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6410501128257649700} + serializedVersion: 2 m_LocalRotation: {x: -0.0013932837, y: -0.20964532, z: 0.0064980704, w: 0.97775495} m_LocalPosition: {x: -0.120417975, y: 0.0049800063, z: -0.081912056} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2204,7 +2220,6 @@ Transform: m_Children: - {fileID: 9202394604179414725} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6481733797294446438 GameObject: @@ -2229,13 +2244,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6481733797294446438} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.5431475, z: -0, w: 0.8396373} m_LocalPosition: {x: -0.67569554, y: -2.8865798e-17, z: -5.684342e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2362148052469027435} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6570347010630812377 GameObject: @@ -2260,6 +2275,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6570347010630812377} + serializedVersion: 2 m_LocalRotation: {x: 0.07721848, y: 0.0319301, z: -0.13278173, w: 0.9876167} m_LocalPosition: {x: 0.022657402, y: -0.0018067064, z: -0.17085041} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2267,7 +2283,6 @@ Transform: m_Children: - {fileID: 3366088592808131587} m_Father: {fileID: 6176328368197471825} - m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6815822208755467100 GameObject: @@ -2292,6 +2307,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6815822208755467100} + serializedVersion: 2 m_LocalRotation: {x: -0.031930987, y: 0.077209614, z: 0.98761743, w: 0.13278146} m_LocalPosition: {x: 0.022657752, y: -0.0018067972, z: 0.17085} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2299,7 +2315,6 @@ Transform: m_Children: - {fileID: 8758932156336025228} m_Father: {fileID: 6176328368197471825} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6880913526979753240 GameObject: @@ -2324,13 +2339,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6880913526979753240} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.11008295, y: -0.009449474, z: 0.0006042766} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7312941058919804357} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6948908413824387969 GameObject: @@ -2355,13 +2370,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6948908413824387969} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0.28746313, z: -0, w: 0.95779175} m_LocalPosition: {x: -0.35610884, y: 2.8398991e-31, z: -1.4210854e-16} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2959356354339617322} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7302799138544732844 GameObject: @@ -2386,13 +2401,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7302799138544732844} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.06756819, w: 0.99771464} m_LocalPosition: {x: -0.30677703, y: 0.011362112, z: -3.952184e-17} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2229985312042118916} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7391259593930885260 GameObject: @@ -2417,6 +2432,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7391259593930885260} + serializedVersion: 2 m_LocalRotation: {x: 0.08801344, y: 0.7016079, z: 0.08801344, w: 0.7016079} m_LocalPosition: {x: -3.0999767e-32, y: -0.0007635658, z: 0.46243998} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2427,7 +2443,6 @@ Transform: - {fileID: 7193043019390489242} - {fileID: 8111828103614620543} m_Father: {fileID: 8517333686487891612} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7546765193722654569 GameObject: @@ -2452,6 +2467,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7546765193722654569} + serializedVersion: 2 m_LocalRotation: {x: -1.3548951e-16, y: 4.5886806e-17, z: -0.08148055, w: 0.99667495} m_LocalPosition: {x: -0.14891407, y: 1.2434498e-16, z: 4.8846454e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2461,7 +2477,6 @@ Transform: - {fileID: 1478266937938357226} - {fileID: 8621612622155584086} m_Father: {fileID: 6587067380640101537} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7627700492663890896 GameObject: @@ -2486,6 +2501,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7627700492663890896} + serializedVersion: 2 m_LocalRotation: {x: 1.00992795e-29, y: 2.648741e-28, z: 0.03987671, w: 0.99920464} m_LocalPosition: {x: 0.35891908, y: 1.5543122e-17, z: 1.4210854e-16} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2493,7 +2509,6 @@ Transform: m_Children: - {fileID: 1496863322693239511} m_Father: {fileID: 1986708226969140497} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7696031279786655801 GameObject: @@ -2518,6 +2533,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7696031279786655801} + serializedVersion: 2 m_LocalRotation: {x: -0.05363183, y: 0.00061813387, z: 0.022184182, w: 0.99831414} m_LocalPosition: {x: 0.25370672, y: -0.010923628, z: 0.0016361566} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2525,7 +2541,6 @@ Transform: m_Children: - {fileID: 8439100899513847687} m_Father: {fileID: 7193043019390489242} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7713339776856982282 GameObject: @@ -2550,13 +2565,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7713339776856982282} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: -0.27837098, y: 0.14700453, z: -0.00056984223} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7312941058919804357} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8272640787805210172 GameObject: @@ -2581,13 +2596,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8272640787805210172} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.27836862, y: -0.14700456, z: 0.0005698343} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1496863322693239511} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8296525948743463448 GameObject: @@ -2612,6 +2627,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8296525948743463448} + serializedVersion: 2 m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2619,7 +2635,6 @@ Transform: m_Children: - {fileID: 6176328368197471825} m_Father: {fileID: 5488673670398653704} - m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8326762379355067600 GameObject: @@ -2644,13 +2659,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8326762379355067600} + serializedVersion: 2 m_LocalRotation: {x: 0.70580983, y: -0.0022091598, z: 0.0003184791, w: 0.7083978} m_LocalPosition: {x: 0.24130988, y: 0.13323241, z: -0.0005894659} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1496863322693239511} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8482346146269408321 GameObject: @@ -2675,6 +2690,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8482346146269408321} + serializedVersion: 2 m_LocalRotation: {x: 2.2397977e-18, y: 5.568265e-17, z: -0.10232073, w: 0.99475145} m_LocalPosition: {x: -0.14028804, y: 0.0061973166, z: 2.2516412e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2683,7 +2699,6 @@ Transform: - {fileID: 1058474480227476786} - {fileID: 6587067380640101537} m_Father: {fileID: 6176328368197471825} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8496647645266993343 GameObject: @@ -2708,13 +2723,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8496647645266993343} + serializedVersion: 2 m_LocalRotation: {x: -0.018653171, y: -0.018653171, z: 0.7068607, w: 0.7068607} m_LocalPosition: {x: -0.018659646, y: 0.0832196, z: -0.0010736184} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 898231667641610401} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8626634349840445357 GameObject: @@ -2739,6 +2754,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8626634349840445357} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0.43467525, z: -0, w: 0.9005873} m_LocalPosition: {x: -0.21829395, y: -7.105427e-17, z: 1.4210854e-15} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2746,7 +2762,6 @@ Transform: m_Children: - {fileID: 2144034615767353994} m_Father: {fileID: 2241838139369937818} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8793651686068708314 GameObject: @@ -2771,6 +2786,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8793651686068708314} + serializedVersion: 2 m_LocalRotation: {x: 0.20964532, y: -0.0013932837, z: 0.97775495, w: -0.0064980704} m_LocalPosition: {x: -0.12041652, y: 0.0049800063, z: 0.08191209} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2778,7 +2794,6 @@ Transform: m_Children: - {fileID: 2482574556682163242} m_Father: {fileID: 6078527746324431682} - m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8835251813235354970 GameObject: @@ -2803,6 +2818,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8835251813235354970} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.0670836, w: 0.99774736} m_LocalPosition: {x: -0.30618182, y: -6.0396133e-16, z: 8.413475e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -2818,7 +2834,6 @@ Transform: - {fileID: 7748826485428433219} - {fileID: 3969208101077916263} m_Father: {fileID: 8621612622155584086} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &9056742210991128922 GameObject: @@ -2844,13 +2859,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9056742210991128922} + serializedVersion: 2 m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7847468916615446689} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!137 &7374491305410030911 SkinnedMeshRenderer: @@ -2983,13 +2998,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9185300519223470522} + serializedVersion: 2 m_LocalRotation: {x: 2.3129124e-18, y: -0.7257409, z: -2.3129124e-18, w: 0.6879682} m_LocalPosition: {x: -0.2914453, y: 8.946976e-13, z: -2.131628e-15} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 738286535971428345} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &9197826329153354311 GameObject: @@ -3014,6 +3029,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9197826329153354311} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: -0.09367575, w: 0.9956028} m_LocalPosition: {x: -0.28033707, y: 4.973799e-16, z: -9.895423e-17} m_LocalScale: {x: 1, y: 1, z: 1} @@ -3021,5 +3037,4 @@ Transform: m_Children: - {fileID: 2229985312042118916} m_Father: {fileID: 6635785579605554384} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool.meta diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation.meta diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools.meta diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs similarity index 70% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs index f787a65..dd68e7a 100644 --- a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs @@ -1,19 +1,18 @@ using System; using UnityEngine; using ZBase.Foundation.Pooling.AddressableAssets; -using ZBase.Foundation.Pooling.AddressableAssets.Items; -namespace ZBase.Foundation.Pooling.ItemPooling +namespace ZBase.Foundation.Pooling.GameObject.LazyPool { public class AssetRefGameObjectItemPool : AssetRefGameObjectPool { - internal event Action OnReturn; + internal event Action OnReturn; public AssetRefGameObjectItemPool(AssetRefGameObjectPrefab prefab) : base(prefab) { } - protected override void ProcessNewInstance(GameObject instance) + protected override void ProcessNewInstance(UnityEngine.GameObject instance) { base.ProcessNewInstance(instance); if (!instance.TryGetComponent(out var poolItem)) @@ -21,7 +20,7 @@ protected override void ProcessNewInstance(GameObject instance) poolItem.SetUp(this, instance, Prefab); } - protected override void ReturnPreprocess(GameObject instance) + protected override void ReturnPreprocess(UnityEngine.GameObject instance) { base.ReturnPreprocess(instance); OnReturn?.Invoke(instance); diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs.meta diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs new file mode 100644 index 0000000..9f169e3 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs @@ -0,0 +1,28 @@ +using System; +using ZBase.Foundation.Pooling.UnityPools; + +namespace ZBase.Foundation.Pooling.GameObject.LazyPool +{ + public sealed class GameObjectItemPool : GameObjectPool + { + internal event Action OnReturn; + + public GameObjectItemPool(GameObjectPrefab prefab) : base(prefab) + { + } + + protected override void ProcessNewInstance(UnityEngine.GameObject instance) + { + base.ProcessNewInstance(instance); + if (!instance.TryGetComponent(out var poolItem)) + poolItem = instance.AddComponent(); + poolItem.SetUp(this, instance, Prefab); + } + + protected override void ReturnPreprocess(UnityEngine.GameObject instance) + { + base.ReturnPreprocess(instance); + OnReturn?.Invoke(instance); + } + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs.meta new file mode 100644 index 0000000..6ff1e69 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ae9ef4c7867a4109b97f6921f55dae8d +timeCreated: 1706771153 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GameObjectLazyPool.asmdef similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GameObjectLazyPool.asmdef diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GameObjectLazyPool.asmdef.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/ItemPooling.asmdef.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GameObjectLazyPool.asmdef.meta diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools.meta diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions.meta new file mode 100644 index 0000000..6280da2 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8ffdeaa9adba41399df445ca4e9cf0cf +timeCreated: 1706773425 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs similarity index 56% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index eb733ab..1ca9881 100644 --- a/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -1,17 +1,17 @@ using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; -using ZBase.Foundation.Pooling.ItemPooling; +using ZBase.Foundation.Pooling.AddressableAssets; -namespace ZBase.Foundation.Pooling.AddressableAssets +namespace ZBase.Foundation.Pooling.GameObject.LazyPool { public class GlobalAssetRefGameObjectPool : IPool, IShareable { private readonly Dictionary _pools = new(); - private readonly Dictionary _prefabToAssetReference = new(); + private readonly Dictionary _prefabToAssetReference = new(); - public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) + public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) { if (!_pools.TryGetValue(gameObjectReference, out var pool)) { @@ -19,27 +19,33 @@ public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReferen pool.OnReturn += OnReturnToPool; this._pools.Add(gameObjectReference, pool); } - GameObject item = await pool.Rent(); + UnityEngine.GameObject item = await pool.Rent(); _prefabToAssetReference.Add(item, gameObjectReference); return item; } - public void Return(GameObject gameObject) + public void Return(UnityEngine.GameObject gameObject) { if(!gameObject) return; if (_prefabToAssetReference.TryGetValue(gameObject, out var assetReference)) Return(assetReference, gameObject); else - Debug.LogError($"GameObject {gameObject.name} is not registered in the pool"); + Debug.LogError($"GameObject {gameObject.name} is not registered in the pool or was already returned."); } - public void Return(AssetRefGameObjectPrefab gameObjectReference, GameObject gameObject) + public void Return(AssetRefGameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) { if (_pools.TryGetValue(gameObjectReference, out var pool)) pool.Return(gameObject); } + + public void ReleaseInstances(int keep, System.Action onReleased = null) + { + foreach (var pool in _pools.Values) + pool.ReleaseInstances(keep, onReleased); + } - private void OnReturnToPool(GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); + private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs.meta diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs new file mode 100644 index 0000000..c15c9b3 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using Cysharp.Threading.Tasks; +using UnityEngine; +using ZBase.Foundation.Pooling.UnityPools; + +namespace ZBase.Foundation.Pooling.GameObject.LazyPool +{ + public class GlobalGameObjectPool : IPool, IShareable + { + private readonly Dictionary _pools = new(); + + private readonly Dictionary _prefabToAssetReference = new(); + + public async UniTask Rent(GameObjectPrefab gameObjectReference) + { + if (!_pools.TryGetValue(gameObjectReference, out var pool)) + { + pool = new GameObjectItemPool(gameObjectReference); + pool.OnReturn += OnReturnToPool; + this._pools.Add(gameObjectReference, pool); + } + UnityEngine.GameObject item = await pool.Rent(); + _prefabToAssetReference.Add(item, gameObjectReference); + return item; + } + + public void Return(UnityEngine.GameObject gameObject) + { + if(!gameObject) + return; + if (_prefabToAssetReference.TryGetValue(gameObject, out var assetReference)) + Return(assetReference, gameObject); + else + Debug.LogError($"GameObject {gameObject.name} is not registered in the pool or was already returned."); + } + + public void Return(GameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) + { + if (_pools.TryGetValue(gameObjectReference, out var pool)) + pool.Return(gameObject); + } + + public void ReleaseInstances(int keep, System.Action onReleased = null) + { + foreach (var pool in _pools.Values) + pool.ReleaseInstances(keep, onReleased); + } + + private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs.meta new file mode 100644 index 0000000..b55c660 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0f2065ce9fcb408daed7dc486453f99a +timeCreated: 1706771113 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/Items.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items.meta diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs new file mode 100644 index 0000000..cf6e700 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs @@ -0,0 +1,8 @@ +using ZBase.Foundation.Pooling.AddressableAssets; + +namespace ZBase.Foundation.Pooling.GameObject.LazyPool +{ + public class AssetRefGameObjectPoolItem : PoolItem + { + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs.meta diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs new file mode 100644 index 0000000..84d5a4c --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs @@ -0,0 +1,7 @@ +using ZBase.Foundation.Pooling.UnityPools; +namespace ZBase.Foundation.Pooling.GameObject.LazyPool +{ + public class GameObjectPoolItem : PoolItem + { + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs.meta new file mode 100644 index 0000000..fb28cc7 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2498a09f8bdf432e9b248f3f14dec53d +timeCreated: 1706770559 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs new file mode 100644 index 0000000..e4ee43a --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs @@ -0,0 +1,51 @@ +using System; +using Cysharp.Threading.Tasks; +using UnityEngine; +using ZBase.Foundation.Pooling.UnityPools; +using Object = UnityEngine.Object; + +namespace ZBase.Foundation.Pooling.GameObject.LazyPool +{ + public class PoolItem : MonoBehaviour where T : Object where TPrefab : IPrefab + { + private float _lifeTime; + private T _instance; + private TPrefab _prefab; + private UnityPool _pool; + + private void Awake() + { + var setUp = GetComponent(); + if (setUp != null) + _lifeTime = setUp.LifeTime; + } + + private void OnEnable() + { + if (_lifeTime <= 0) + return; + StartDeSpawn().Forget(); + } + + private async UniTask StartDeSpawn() + { + if (_lifeTime <= 0) + return; + await UniTask.Delay(TimeSpan.FromSeconds(_lifeTime), cancellationToken: this.GetCancellationTokenOnDestroy()); + _pool?.Return(_instance); + } + + public void SetUp(UnityPool pool, T instance, TPrefab prefab) + { + _instance = instance; + _pool = pool; + _prefab = prefab; + } + + private void OnDestroy() + { + _pool?.RemoveItem(_instance); + _prefab?.Release(_instance); + } + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs.meta similarity index 100% rename from Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs.meta rename to Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs.meta diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs new file mode 100644 index 0000000..af4bdc5 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +namespace ZBase.Foundation.Pooling.GameObject.LazyPool +{ + public class PoolItemAutoDeSpawnSetUp : MonoBehaviour + { + [SerializeField] private float _lifeTime; + public float LifeTime => _lifeTime; + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs.meta new file mode 100644 index 0000000..a3efd47 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3ccfd0da2bab4198bf7a2413d826a967 +timeCreated: 1706772086 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs deleted file mode 100644 index ae24574..0000000 --- a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/AssetRefGameObjectPoolItem.cs +++ /dev/null @@ -1,8 +0,0 @@ -using UnityEngine; - -namespace ZBase.Foundation.Pooling.AddressableAssets.Items -{ - public class AssetRefGameObjectPoolItem : PoolItem - { - } -} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs deleted file mode 100644 index e19d5c0..0000000 --- a/Packages/ZBase.Foundation.Pooling/ItemPooling/Items/PoolItem.cs +++ /dev/null @@ -1,26 +0,0 @@ -using UnityEngine; -using ZBase.Foundation.Pooling.UnityPools; -using Object = UnityEngine.Object; - -namespace ZBase.Foundation.Pooling.AddressableAssets.Items -{ - public class PoolItem : MonoBehaviour where T : Object where TPrefab : IPrefab - { - private T _instance; - private TPrefab _prefab; - private UnityPool _pool; - - public void SetUp(UnityPool pool, T instance, TPrefab prefab) - { - _instance = instance; - _pool = pool; - _prefab = prefab; - } - - private void OnDestroy() - { - _pool?.RemoveItem(_instance); - _prefab?.Release(_instance); - } - } -} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs index 724c9c9..45bc0fa 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefPrefab{T,TAssetRef}.cs @@ -5,8 +5,7 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public abstract class AssetRefPrefab - : UnityPrefab where T : UnityEngine.Object where TAssetRef : AssetReference + public abstract class AssetRefPrefab : UnityPrefab where T : UnityEngine.Object where TAssetRef : AssetReference { } } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs index 69c7850..1c7fe4d 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs @@ -48,7 +48,6 @@ public TPrefab Prefab public void ReleaseInstances(int keep, Action onReleased = null) { var countRemove = _queue.Count - keep; - while (countRemove > 0) { if (_queue.TryDequeue(out var instance)) diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/ComponentPrefab{T}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/ComponentPrefab{T}.cs index 56aafa3..a7fde5a 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/ComponentPrefab{T}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/ComponentPrefab{T}.cs @@ -6,8 +6,7 @@ namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] - public class ComponentPrefab : UnityPrefab - where T : UnityEngine.Component + public class ComponentPrefab : UnityPrefab where T : Component { protected override async UniTask Instantiate( T source diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs index 6bcfd70..bbccddd 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/UnityPrefab{T,TSource}.cs @@ -3,14 +3,11 @@ using System.Runtime.CompilerServices; using Cysharp.Threading.Tasks; using UnityEngine; -using UnityEngine.Serialization; namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] - public abstract class UnityPrefab - : IPrefab - where T : class + public abstract class UnityPrefab : IPrefab where T : class { [SerializeField] private TSource _source; [SerializeField] private Transform _parent; From cfe4fda7f93c0979b10c455f6133c91248cc0883 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 15:17:47 +0700 Subject: [PATCH 05/35] Lazy pool --- .../Extensions/LazyAssetRefGameObjectPool.cs | 23 +++++++++++++++++++ .../LazyAssetRefGameObjectPool.cs.meta | 3 +++ .../Extensions/LazyGameObjectPool.cs | 23 +++++++++++++++++++ .../Extensions/LazyGameObjectPool.cs.meta | 3 +++ 4 files changed, 52 insertions(+) create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs.meta create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs create mode 100644 Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs.meta diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs new file mode 100644 index 0000000..8997760 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs @@ -0,0 +1,23 @@ +using Cysharp.Threading.Tasks; +using ZBase.Foundation.Pooling.AddressableAssets; + +namespace ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions +{ + + public static class LazyAssetRefGameObjectPool + { + private static GlobalAssetRefGameObjectPool GlobalGameObjectPool => SharedPool.Of(); + + public static async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) + => await GlobalGameObjectPool.Rent(gameObjectReference); + + public static void Return(UnityEngine.GameObject gameObject) + => GlobalGameObjectPool.Return(gameObject); + + public static void Return(AssetRefGameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) + => GlobalGameObjectPool.Return(gameObjectReference, gameObject); + + public static void ReleaseInstances(int keep, System.Action onReleased = null) + => GlobalGameObjectPool.ReleaseInstances(keep, onReleased); + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs.meta new file mode 100644 index 0000000..6d55e58 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 159ae9755d504cff866d1b3e1a168b7a +timeCreated: 1706775414 \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs new file mode 100644 index 0000000..a65ffdb --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs @@ -0,0 +1,23 @@ +using Cysharp.Threading.Tasks; +using ZBase.Foundation.Pooling.UnityPools; + +namespace ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions +{ + + public static class LazyGameObjectPool + { + private static GlobalGameObjectPool GlobalGameObjectPool => SharedPool.Of(); + + public static async UniTask Rent(GameObjectPrefab gameObjectReference) + => await GlobalGameObjectPool.Rent(gameObjectReference); + + public static void Return(UnityEngine.GameObject gameObject) + => GlobalGameObjectPool.Return(gameObject); + + public static void Return(GameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) + => GlobalGameObjectPool.Return(gameObjectReference, gameObject); + + public static void ReleaseInstances(int keep, System.Action onReleased = null) + => GlobalGameObjectPool.ReleaseInstances(keep, onReleased); + } +} \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs.meta b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs.meta new file mode 100644 index 0000000..e56cf43 --- /dev/null +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2ecbf73f63cf4edfa28cac9edb131a77 +timeCreated: 1706775264 \ No newline at end of file From 19cfab989c50a485cba917c40f108e2abdf0fc57 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 16:07:29 +0700 Subject: [PATCH 06/35] Update AddressableGameObjectPoolSample1.cs --- .../Scripts/AddressableGameObjectPoolSample1.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs index af1a575..929ea71 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs @@ -1,5 +1,6 @@ using Cysharp.Threading.Tasks; using UnityEngine; +using UnityEngine.AddressableAssets; using ZBase.Collections.Pooled.Generic; using ZBase.Foundation.Pooling; using ZBase.Foundation.Pooling.AddressableAssets; @@ -9,6 +10,7 @@ namespace Pooling.Sample { public class AddressableGameObjectPoolSample1 : MonoBehaviour { + [SerializeField] private AssetReference _sceneRef; [SerializeField] private AssetRefGameObjectPrefab _prefab; [SerializeField] private float _spawnRadius = 20f; [SerializeField] private int _spawnCount = 20; @@ -41,17 +43,19 @@ private void ReleaseAll() _spawned.Clear(); } - private void OnDisable() => ReleaseAll(); - private void OnGUI() { if (GUI.Button(new Rect(10, 10, 150, 50), "Spawn")) for (int i = 0; i < _spawnCount; i++) Spawn().Forget(); - if (GUI.Button(new Rect(10, 130, 150, 50), "Return")) + if (GUI.Button(new Rect(10, 70, 150, 50), "Return")) Return(); - if (GUI.Button(new Rect(10, 190, 150, 50), "Release All")) + if (GUI.Button(new Rect(10, 130, 150, 50), "Release All")) ReleaseAll(); + if (GUI.Button(new Rect(10, 190, 150, 50), "SwitchScene")) + { + Addressables.LoadSceneAsync(_sceneRef); + } } } } \ No newline at end of file From c345fb11904ad3e5ac57ec4378d1da5f910db3ad Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 16:07:36 +0700 Subject: [PATCH 07/35] Update AddressGameObjectPool_1.unity --- .../AddressablePools/AddressGameObjectPool_1.unity | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity index 722f6b4..ec81581 100644 --- a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity +++ b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity @@ -228,6 +228,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cdb23546d86448568402c2d071ea936d, type: 3} m_Name: m_EditorClassIdentifier: + _sceneRef: + m_AssetGUID: d0d1d00d6013742259b0519a178bae7e + m_SubObjectName: + m_SubObjectType: + m_EditorAssetChanged: 0 _prefab: _source: m_AssetGUID: d313163ceba02498b974cf73b0605e8a From d820ab3b6a0ce00afc844239fbf63ebb0194f12f Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 16:07:44 +0700 Subject: [PATCH 08/35] remove --- .../AddressablePools/Prefabs/Empt.prefab | 47 ------------------- .../AddressablePools/Prefabs/Empt.prefab.meta | 7 --- 2 files changed, 54 deletions(-) delete mode 100644 Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab delete mode 100644 Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta diff --git a/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab b/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab deleted file mode 100644 index 6fdf478..0000000 --- a/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab +++ /dev/null @@ -1,47 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &2523104297209005010 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 3821941267034635079} - - component: {fileID: -7625971595942420386} - m_Layer: 0 - m_Name: Empt - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &3821941267034635079 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2523104297209005010} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &-7625971595942420386 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2523104297209005010} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3ccfd0da2bab4198bf7a2413d826a967, type: 3} - m_Name: - m_EditorClassIdentifier: - _lifeTime: 2 diff --git a/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta b/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta deleted file mode 100644 index b627252..0000000 --- a/Assets/PoolSample/AddressablePools/Prefabs/Empt.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 5c4c0ac3f2694a44b8f014a328729ec1 -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 3c084903b1106e825c7b2c5dd73bd34460e2a586 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 16:18:08 +0700 Subject: [PATCH 09/35] Update package.json --- Packages/ZBase.Foundation.Pooling/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index 26ad728..5849412 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,7 +1,7 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.1", + "version": "2.3.2", "unity": "2021.3", "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", "dependencies": { From 04709ae3a72ff227d037e9248e6222fa75d1f6fe Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 17:08:52 +0700 Subject: [PATCH 10/35] Update GlobalGameObjectPool.cs --- .../GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index c15c9b3..51e7c23 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; using ZBase.Foundation.Pooling.UnityPools; @@ -15,6 +16,8 @@ public class GlobalGameObjectPool : IPool, IShareable { if (!_pools.TryGetValue(gameObjectReference, out var pool)) { + if (gameObjectReference.Source.transform.root != null) + throw new Exception($"Non Prefab not supported {gameObjectReference.Source.name}"); pool = new GameObjectItemPool(gameObjectReference); pool.OnReturn += OnReturnToPool; this._pools.Add(gameObjectReference, pool); From f0bc099a34c70140c769a20a61962fd588de52dd Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 18:26:07 +0700 Subject: [PATCH 11/35] Update AssetRefGameObjectPrefab.cs --- .../Foundation/Prefabs/AssetRefGameObjectPrefab.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs index 5146873..335fb04 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; @@ -8,7 +9,8 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AssetRefGameObjectPrefab : AssetRefPrefab + public class AssetRefGameObjectPrefab : AssetRefPrefab, + IEquatable, IEqualityComparer { protected override async UniTask Instantiate( AssetReferenceGameObject source, Transform parent, CancellationToken cancelToken = default) @@ -23,5 +25,12 @@ public override void Release(GameObject instance) if (instance && Source != null) Source.ReleaseInstance(instance); } + + public bool Equals(AssetRefGameObjectPrefab other) => other != null && this.Source.Equals(other.Source); + + public bool Equals(AssetRefGameObjectPrefab x, AssetRefGameObjectPrefab y) + => x != null && y != null && x.Source.Equals(y.Source); + + public int GetHashCode(AssetRefGameObjectPrefab obj) => obj.Source.GetHashCode(); } } \ No newline at end of file From 21112ca833d67d5974282463deb167e639161070 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 18:27:06 +0700 Subject: [PATCH 12/35] Update GameObjectPrefab.cs --- .../UnityPools/Prefabs/GameObjectPrefab.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs index 83329fc..94fe225 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; @@ -6,7 +7,8 @@ namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] - public class GameObjectPrefab : UnityPrefab + public class GameObjectPrefab : UnityPrefab, IEquatable, + IEqualityComparer { protected override async UniTask Instantiate( GameObject source, Transform parent, CancellationToken cancelToken = default) @@ -22,5 +24,12 @@ public override void Release(GameObject instance) if (instance) UnityEngine.Object.Destroy(instance); } + + public bool Equals(GameObjectPrefab other) => other != null && this.Source.Equals(other.Source); + + public bool Equals(GameObjectPrefab x, GameObjectPrefab y) + => x != null && y != null && x.Source.Equals(y.Source); + + public int GetHashCode(GameObjectPrefab obj) => obj.Source.GetHashCode(); } } \ No newline at end of file From b2dcb9eaff89f27ef0f90bf60a0e6426f1f26c45 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 18:29:01 +0700 Subject: [PATCH 13/35] Update package.json --- Packages/ZBase.Foundation.Pooling/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index 5849412..caad892 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,7 +1,7 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.2", + "version": "2.3.3", "unity": "2021.3", "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", "dependencies": { From d3ebc7e73d631ac906bc914477947d459ac37312 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 18:39:08 +0700 Subject: [PATCH 14/35] Update GlobalAssetRefGameObjectPool.cs --- .../GlobalAssetRefGameObjectPool.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index 1ca9881..4545ecf 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; +using UnityEngine.AddressableAssets; using ZBase.Foundation.Pooling.AddressableAssets; namespace ZBase.Foundation.Pooling.GameObject.LazyPool @@ -11,6 +12,25 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable private readonly Dictionary _prefabToAssetReference = new(); + private readonly Dictionary _poolKeyCache = new(); + + public async UniTask Rent(AssetReferenceGameObject gameObjectReference) + { + if(!_poolKeyCache.TryGetValue(gameObjectReference, out var key)) + _poolKeyCache.Add(gameObjectReference, key = new AssetRefGameObjectPrefab { + Source = gameObjectReference, + }); + if (!_pools.TryGetValue(key, out var pool)) + { + pool = new AssetRefGameObjectItemPool(key); + pool.OnReturn += OnReturnToPool; + this._pools.Add(key, pool); + } + UnityEngine.GameObject item = await pool.Rent(); + _prefabToAssetReference.Add(item, key); + return item; + } + public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) { if (!_pools.TryGetValue(gameObjectReference, out var pool)) @@ -46,6 +66,12 @@ public void ReleaseInstances(int keep, System.Action onR pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); + private void OnReturnToPool(UnityEngine.GameObject gameObject) + { + if(!this._prefabToAssetReference.Remove(gameObject, out var assetReference)) + return; + if(_poolKeyCache.ContainsKey(assetReference.Source)) + _poolKeyCache.Remove(assetReference.Source); + } } } \ No newline at end of file From 170a9066113fae390fe98639392284174ff41956 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 18:42:59 +0700 Subject: [PATCH 15/35] Update --- .../GlobalAssetRefGameObjectPool.cs | 10 +-------- .../GlobalPools/GlobalGameObjectPool.cs | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index 4545ecf..e0cc067 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -20,15 +20,7 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable _poolKeyCache.Add(gameObjectReference, key = new AssetRefGameObjectPrefab { Source = gameObjectReference, }); - if (!_pools.TryGetValue(key, out var pool)) - { - pool = new AssetRefGameObjectItemPool(key); - pool.OnReturn += OnReturnToPool; - this._pools.Add(key, pool); - } - UnityEngine.GameObject item = await pool.Rent(); - _prefabToAssetReference.Add(item, key); - return item; + return await Rent(key); } public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index 51e7c23..5ea2075 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -11,7 +11,16 @@ public class GlobalGameObjectPool : IPool, IShareable private readonly Dictionary _pools = new(); private readonly Dictionary _prefabToAssetReference = new(); - + private readonly Dictionary _poolKeyCache = new(); + + public async UniTask Rent(UnityEngine.GameObject gameObjectReference) + { + if (!_poolKeyCache.TryGetValue(gameObjectReference, out var key)) + this._poolKeyCache.Add(gameObjectReference, key = new GameObjectPrefab { + Source = gameObjectReference + }); + return await Rent(key); + } public async UniTask Rent(GameObjectPrefab gameObjectReference) { if (!_pools.TryGetValue(gameObjectReference, out var pool)) @@ -43,12 +52,18 @@ public void Return(GameObjectPrefab gameObjectReference, UnityEngine.GameObject pool.Return(gameObject); } - public void ReleaseInstances(int keep, System.Action onReleased = null) + public void ReleaseInstances(int keep, Action onReleased = null) { foreach (var pool in _pools.Values) pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); + private void OnReturnToPool(UnityEngine.GameObject gameObject) + { + if(!this._prefabToAssetReference.Remove(gameObject, out var assetReference)) + return; + if(_poolKeyCache.ContainsKey(assetReference.Source)) + _poolKeyCache.Remove(assetReference.Source); + } } } \ No newline at end of file From ee5cf30061b29a75d3fef6da9000013cf3b88186 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Thu, 1 Feb 2024 18:54:47 +0700 Subject: [PATCH 16/35] ffff --- .../Extensions/LazyAssetRefGameObjectPool.cs | 4 ++++ .../Extensions/LazyGameObjectPool.cs | 3 +++ .../GlobalPools/GlobalAssetRefGameObjectPool.cs | 17 +++++++++++++---- .../GlobalPools/GlobalGameObjectPool.cs | 1 - 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs index 8997760..5f8a4e0 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs @@ -1,4 +1,5 @@ using Cysharp.Threading.Tasks; +using UnityEngine.AddressableAssets; using ZBase.Foundation.Pooling.AddressableAssets; namespace ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions @@ -8,6 +9,9 @@ public static class LazyAssetRefGameObjectPool { private static GlobalAssetRefGameObjectPool GlobalGameObjectPool => SharedPool.Of(); + public static async UniTask Rent(AssetReferenceGameObject gameObjectReference) + => await GlobalGameObjectPool.Rent(gameObjectReference); + public static async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs index a65ffdb..0f128ca 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs @@ -8,6 +8,9 @@ public static class LazyGameObjectPool { private static GlobalGameObjectPool GlobalGameObjectPool => SharedPool.Of(); + public static async UniTask Rent(UnityEngine.GameObject gameObjectReference) + => await GlobalGameObjectPool.Rent(gameObjectReference); + public static async UniTask Rent(GameObjectPrefab gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index e0cc067..fc82125 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -16,10 +16,14 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable public async UniTask Rent(AssetReferenceGameObject gameObjectReference) { - if(!_poolKeyCache.TryGetValue(gameObjectReference, out var key)) + if (!_poolKeyCache.TryGetValue(gameObjectReference, out var key)) + { _poolKeyCache.Add(gameObjectReference, key = new AssetRefGameObjectPrefab { Source = gameObjectReference, }); + Debug.LogError( $"add key"); + } + return await Rent(key); } @@ -62,8 +66,13 @@ private void OnReturnToPool(UnityEngine.GameObject gameObject) { if(!this._prefabToAssetReference.Remove(gameObject, out var assetReference)) return; - if(_poolKeyCache.ContainsKey(assetReference.Source)) - _poolKeyCache.Remove(assetReference.Source); - } + if (!this._pools.TryGetValue(assetReference, out var pool) || pool.Count() != 0) + return; + + this._pools.Remove(assetReference); + pool.OnReturn -= OnReturnToPool; + if(this._poolKeyCache.ContainsKey(assetReference.Source)) + this._poolKeyCache.Remove(assetReference.Source); + } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index 5ea2075..0cbeea5 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -9,7 +9,6 @@ namespace ZBase.Foundation.Pooling.GameObject.LazyPool public class GlobalGameObjectPool : IPool, IShareable { private readonly Dictionary _pools = new(); - private readonly Dictionary _prefabToAssetReference = new(); private readonly Dictionary _poolKeyCache = new(); From 001821c366000b46c209d2ae364d8dfd9e1948a2 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Fri, 2 Feb 2024 10:31:33 +0700 Subject: [PATCH 17/35] Fix load by assetRef --- .../AddressableGameObjectPoolSample1.cs | 52 ++++++++++++------- .../AddressableGameObjectPoolSample2.cs | 5 +- .../Extensions/LazyAssetRefGameObjectPool.cs | 3 +- .../GlobalAssetRefGameObjectPool.cs | 42 +++++++-------- .../GlobalPools/GlobalGameObjectPool.cs | 8 +-- .../Prefabs/AssetRefGameObjectPrefab.cs | 11 +--- .../UnityPools/Prefabs/GameObjectPrefab.cs | 10 +--- 7 files changed, 58 insertions(+), 73 deletions(-) diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs index 929ea71..2b54c41 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs @@ -2,35 +2,44 @@ using UnityEngine; using UnityEngine.AddressableAssets; using ZBase.Collections.Pooled.Generic; -using ZBase.Foundation.Pooling; using ZBase.Foundation.Pooling.AddressableAssets; -using ZBase.Foundation.Pooling.GameObject.LazyPool; +using ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions; namespace Pooling.Sample { public class AddressableGameObjectPoolSample1 : MonoBehaviour { - [SerializeField] private AssetReference _sceneRef; [SerializeField] private AssetRefGameObjectPrefab _prefab; - [SerializeField] private float _spawnRadius = 20f; - [SerializeField] private int _spawnCount = 20; - private readonly List _spawned = new(); + [SerializeField] private AssetReferenceGameObject _assetReferenceGameObject; + + private GameObject _item; private async UniTask Spawn() { - var pool = SharedPool.Of(); - var go = await pool.Rent(_prefab); + _item = await LazyAssetRefGameObjectPool.Rent(_prefab); + _item.SetActive(true); var pos = Random.insideUnitCircle * _spawnRadius; - go.transform.position = new Vector3 { x = pos.x, y = 0, z = pos.y }; - go.SetActive(true); - _spawned.Add(go); - } + _item.transform.position = new Vector3 {x = pos.x, y = 0, z = pos.y}; + _spawned.Add(_item); + } + private async UniTask SpawnByRef() + { + _item = await LazyAssetRefGameObjectPool.Rent(_assetReferenceGameObject); + _item.SetActive(true); + var pos = Random.insideUnitCircle * _spawnRadius; + _item.transform.position = new Vector3 {x = pos.x, y = 0, z = pos.y}; + _spawned.Add(_item); + } + + private void DeSpawn() => LazyAssetRefGameObjectPool.Return(_item); private void Return() { - var pool = SharedPool.Of(); foreach (var go in _spawned) - pool.Return(go); + { + go.SetActive(false); + LazyAssetRefGameObjectPool.Return(go); + } _spawned.Clear(); } @@ -38,8 +47,7 @@ private void ReleaseAll() { foreach (var go in _spawned) go.SetActive(false); - var pool = SharedPool.Of(); - pool.ReleaseInstances(0); + LazyAssetRefGameObjectPool.ReleaseInstances(0); _spawned.Clear(); } @@ -52,10 +60,14 @@ private void OnGUI() Return(); if (GUI.Button(new Rect(10, 130, 150, 50), "Release All")) ReleaseAll(); - if (GUI.Button(new Rect(10, 190, 150, 50), "SwitchScene")) - { - Addressables.LoadSceneAsync(_sceneRef); - } + if (!GUI.Button(new Rect(10, 190, 150, 50), "Load By AssetRef")) + return; + for (int i = 0; i < this._spawnCount; i++) + SpawnByRef().Forget(); } + [SerializeField] private AssetReference _sceneRef; + [SerializeField] private float _spawnRadius = 20f; + [SerializeField] private int _spawnCount = 20; + private readonly List _spawned = new(); } } \ No newline at end of file diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs index 46e0ecf..2dfc6f2 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample2.cs @@ -13,7 +13,7 @@ public class AddressableGameObjectPoolSample2 : MonoBehaviour private Grid _grid = new Grid(20, 15, true); private List _spawned = new (); - private void Start() + private async UniTask OnStart() { var pool = SharedPool.Of(); pool.Prefab = new AddressGameObjectPrefab { @@ -21,13 +21,14 @@ private void Start() Parent = transform, PrePoolAmount = 100 }; - pool.Prepool().Forget(); + await pool.Prepool(); } private async void OnGUI() { if (GUI.Button(new Rect(10, 10, 150, 50), "Spawn")) { + await OnStart(); for (int i = 0; i < 100; i++) { Spawn().Forget(); diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs index 5f8a4e0..baa2a23 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs @@ -1,4 +1,5 @@ using Cysharp.Threading.Tasks; +using UnityEngine; using UnityEngine.AddressableAssets; using ZBase.Foundation.Pooling.AddressableAssets; @@ -11,7 +12,7 @@ public static class LazyAssetRefGameObjectPool public static async UniTask Rent(AssetReferenceGameObject gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); - + public static async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index fc82125..bbf043a 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.AddressableAssets; @@ -8,22 +9,18 @@ namespace ZBase.Foundation.Pooling.GameObject.LazyPool { public class GlobalAssetRefGameObjectPool : IPool, IShareable { - private readonly Dictionary _pools = new(); - + private readonly Dictionary _pools = + new(new AssetRefGameObjectPrefabEqualityComparer()); + private readonly Dictionary _prefabToAssetReference = new(); private readonly Dictionary _poolKeyCache = new(); - + public async UniTask Rent(AssetReferenceGameObject gameObjectReference) { if (!_poolKeyCache.TryGetValue(gameObjectReference, out var key)) - { - _poolKeyCache.Add(gameObjectReference, key = new AssetRefGameObjectPrefab { - Source = gameObjectReference, - }); - Debug.LogError( $"add key"); - } - + _poolKeyCache.Add(gameObjectReference, + key = new AssetRefGameObjectPrefab { Source = gameObjectReference, }); return await Rent(key); } @@ -39,40 +36,37 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable _prefabToAssetReference.Add(item, gameObjectReference); return item; } - + public void Return(UnityEngine.GameObject gameObject) { - if(!gameObject) + if (!gameObject) return; if (_prefabToAssetReference.TryGetValue(gameObject, out var assetReference)) Return(assetReference, gameObject); else Debug.LogError($"GameObject {gameObject.name} is not registered in the pool or was already returned."); } - + public void Return(AssetRefGameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) { if (_pools.TryGetValue(gameObjectReference, out var pool)) pool.Return(gameObject); } - + public void ReleaseInstances(int keep, System.Action onReleased = null) { foreach (var pool in _pools.Values) pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) - { - if(!this._prefabToAssetReference.Remove(gameObject, out var assetReference)) - return; - if (!this._pools.TryGetValue(assetReference, out var pool) || pool.Count() != 0) - return; + private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); - this._pools.Remove(assetReference); - pool.OnReturn -= OnReturnToPool; - if(this._poolKeyCache.ContainsKey(assetReference.Source)) - this._poolKeyCache.Remove(assetReference.Source); + private class AssetRefGameObjectPrefabEqualityComparer : IEqualityComparer + { + public bool Equals([NotNull] AssetRefGameObjectPrefab x, [NotNull] AssetRefGameObjectPrefab y) + => y is { Source: not null } && x is { Source: not null } && + x.Source.AssetGUID.Equals(y.Source.AssetGUID); + public int GetHashCode(AssetRefGameObjectPrefab obj) => obj.Source.AssetGUID.GetHashCode(); } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index 0cbeea5..50620c8 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -57,12 +57,6 @@ public void ReleaseInstances(int keep, Action onReleased pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) - { - if(!this._prefabToAssetReference.Remove(gameObject, out var assetReference)) - return; - if(_poolKeyCache.ContainsKey(assetReference.Source)) - _poolKeyCache.Remove(assetReference.Source); - } + private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs index 335fb04..5146873 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling.Addressables/Foundation/Prefabs/AssetRefGameObjectPrefab.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; @@ -9,8 +8,7 @@ namespace ZBase.Foundation.Pooling.AddressableAssets { [Serializable] - public class AssetRefGameObjectPrefab : AssetRefPrefab, - IEquatable, IEqualityComparer + public class AssetRefGameObjectPrefab : AssetRefPrefab { protected override async UniTask Instantiate( AssetReferenceGameObject source, Transform parent, CancellationToken cancelToken = default) @@ -25,12 +23,5 @@ public override void Release(GameObject instance) if (instance && Source != null) Source.ReleaseInstance(instance); } - - public bool Equals(AssetRefGameObjectPrefab other) => other != null && this.Source.Equals(other.Source); - - public bool Equals(AssetRefGameObjectPrefab x, AssetRefGameObjectPrefab y) - => x != null && y != null && x.Source.Equals(y.Source); - - public int GetHashCode(AssetRefGameObjectPrefab obj) => obj.Source.GetHashCode(); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs index 94fe225..8bbf73f 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Prefabs/GameObjectPrefab.cs @@ -7,8 +7,7 @@ namespace ZBase.Foundation.Pooling.UnityPools { [Serializable] - public class GameObjectPrefab : UnityPrefab, IEquatable, - IEqualityComparer + public class GameObjectPrefab : UnityPrefab { protected override async UniTask Instantiate( GameObject source, Transform parent, CancellationToken cancelToken = default) @@ -24,12 +23,5 @@ public override void Release(GameObject instance) if (instance) UnityEngine.Object.Destroy(instance); } - - public bool Equals(GameObjectPrefab other) => other != null && this.Source.Equals(other.Source); - - public bool Equals(GameObjectPrefab x, GameObjectPrefab y) - => x != null && y != null && x.Source.Equals(y.Source); - - public int GetHashCode(GameObjectPrefab obj) => obj.Source.GetHashCode(); } } \ No newline at end of file From 2e736c60e2ae26ce80857f560eaa739985d8b4e9 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Fri, 2 Feb 2024 10:50:22 +0700 Subject: [PATCH 18/35] Using InstanceID to prevent memory leak --- .../AddressableGameObjectPoolSample1.cs | 1 + .../GameObjectPools/GameObjectPool.unity | 38 +++--- .../Scripts/GameObjectPoolSample.cs | 111 ++++++------------ .../GlobalAssetRefGameObjectPool.cs | 8 +- .../GlobalPools/GlobalGameObjectPool.cs | 45 ++++--- 5 files changed, 93 insertions(+), 110 deletions(-) diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs index 2b54c41..01c4991 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs @@ -22,6 +22,7 @@ private async UniTask Spawn() _item.transform.position = new Vector3 {x = pos.x, y = 0, z = pos.y}; _spawned.Add(_item); } + private async UniTask SpawnByRef() { _item = await LazyAssetRefGameObjectPool.Rent(_assetReferenceGameObject); diff --git a/Assets/PoolSample/GameObjectPools/GameObjectPool.unity b/Assets/PoolSample/GameObjectPools/GameObjectPool.unity index e3eb2f7..c3f8416 100644 --- a/Assets/PoolSample/GameObjectPools/GameObjectPool.unity +++ b/Assets/PoolSample/GameObjectPools/GameObjectPool.unity @@ -104,7 +104,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +117,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -146,13 +146,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 780156842} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1076946245} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1076946244 GameObject: @@ -178,6 +178,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1076946244} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -186,7 +187,6 @@ Transform: - {fileID: 1263221993} - {fileID: 780156843} m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1076946246 MonoBehaviour: @@ -200,16 +200,13 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e9eaf35d17ab4b978cb9ce80e6d1355a, type: 3} m_Name: m_EditorClassIdentifier: - poolParent1: {fileID: 1263221993} - poolParent2: {fileID: 780156843} - prefab1: {fileID: 5535647646396653931, guid: 1dacc378b7a85e64696e56ce8d0ce8a7, type: 3} + prefab1: + _source: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + _parent: {fileID: 0} + _prePoolAmount: 0 prefab2: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - pool4: - _prefab: - _source: {fileID: 0} - _parent: {fileID: 0} - _prepoolAmount: 0 - _dontApplyPrefabParentOnReturn: 0 + _spawnRadius: 20 + _spawnCount: 20 --- !u!1 &1252375770 GameObject: m_ObjectHideFlags: 0 @@ -270,13 +267,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1252375770} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1263221992 GameObject: @@ -301,19 +298,20 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1263221992} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1076946245} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1838171512 PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: + serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: - target: {fileID: 5685908662808553381, guid: bc0a642a3d8c4485fa3e2c739a4cf9c8, type: 3} @@ -365,4 +363,14 @@ PrefabInstance: value: Env objectReference: {fileID: 0} m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: bc0a642a3d8c4485fa3e2c739a4cf9c8, type: 3} +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: + - {fileID: 1076946245} + - {fileID: 1252375773} + - {fileID: 1838171512} diff --git a/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs b/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs index 33955a9..a67bb13 100644 --- a/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs +++ b/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs @@ -1,93 +1,56 @@ +using Cysharp.Threading.Tasks; using UnityEngine; using ZBase.Collections.Pooled.Generic; -using ZBase.Foundation.Pooling; +using ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions; using ZBase.Foundation.Pooling.UnityPools; -using Grid = Sample.Environment.Grid; namespace Pooling.Sample { public class GameObjectPoolSample : MonoBehaviour { - public Transform poolParent1; - public Transform poolParent2; - public GameObject prefab1; + public GameObjectPrefab prefab1; public GameObject prefab2; - - //you can access the spawned objects in your own list - public List myGameObjects = new(); - - //Manage lifetime of the pool yourself (in this case, the pool4 will not be registered in the SharedPool) - public GameObjectPool pool4; - public List pool4Objects = new(); - - private readonly Grid _grid = new(20, 15, true); - - private void Start() + + private async UniTask Spawn() { - var pool2 = SharedPool.Of(); - pool2.Prefab = new GameObjectPrefab { Parent = poolParent1, PrePoolAmount = 10, Source = this.prefab1 }; - pool2.PrePool(); - pool4 = new GameObjectPool(new GameObjectPrefab { - Parent = poolParent2, PrePoolAmount = 100, Source = this.prefab2 - }); - } - - private async void OnGUI() + var item = await LazyGameObjectPool.Rent(prefab1); + item.SetActive(true); + var pos = Random.insideUnitCircle * _spawnRadius; + item.transform.position = new Vector3 {x = pos.x, y = 0, z = pos.y}; + _spawned.Add(item); + } + + private async UniTask SpawnByPrefab() { - //manually get the CustomGameObjectPool then rent and spawn some objects - if (GUI.Button(new Rect(0, 0, 300, 50), "Spawn in Shared Pool")) - { - var pool = SharedPool.Of(); - for (int i = 0; i < 50; i++) - { - var go = await pool.Rent(); - go.transform.position = this._grid.GetAvailableSlot().position; - go.SetActive(true); - this.myGameObjects.Add(go); - } - } + var item = await LazyGameObjectPool.Rent(prefab2); + item.SetActive(true); + var pos = Random.insideUnitCircle * _spawnRadius; + item.transform.position = new Vector3 {x = pos.x, y = 0, z = pos.y}; + _spawned.Add(item); + } - //manually get the CustomGameObjectPool then return and despawn some objects - if (GUI.Button(new Rect(0, 100, 300, 50), "Despawn in SharedPool")) - { - var pool = SharedPool.Of(); - for (int i = myGameObjects.Count - 1; i >= 0; i++) - { - var go = this.myGameObjects[i]; - pool.Return(go); - this._grid.FreeSlot(go.transform.position); - } - } - - if (GUI.Button(new Rect(0, 200, 150, 50), "Spawn in Pool 4")) - { - for (int i = 0; i < 100; i++) - { - if (!this._grid.TryGetAvailableSlot(out var slot)) - continue; - var go = await this.pool4.Rent(); - go.transform.position = slot.position; - go.SetActive(true); - this.pool4Objects.Add(go); - } - } - if (!GUI.Button(new Rect(0, 300, 150, 50), "Despawn in Pool 4")) + private void OnGUI() + { + //manually get the CustomGameObjectPool then rent and spawn some objects + if (GUI.Button(new Rect(0, 0, 150, 50), "Spawn")) + for (int i = 0; i < _spawnCount; i++) + Spawn().Forget(); + if (GUI.Button(new Rect(0, 60, 150, 50), "Spawn By Prefab")) + for (int i = 0; i < this._spawnCount; i++) + SpawnByPrefab().Forget(); + if (!GUI.Button(new Rect(0, 120, 150, 50), "DeSpawn All")) return; - - //return random 50 times in pool4, may some objects will be returned multiple times - for (int i = 0; i < 50; i++) + foreach (var go in _spawned) { - var index = Random.Range(0, this.pool4Objects.Count); - if (this.pool4Objects.Count <= index) - continue; - var go = this.pool4Objects[index]; - this.pool4.Return(go); - this._grid.FreeSlot(go.transform.position); - this.pool4Objects.RemoveAt(index); + go.SetActive(false); + LazyGameObjectPool.Return(go); } + _spawned.Clear(); } - - private void OnDestroy() => this.pool4.Dispose(); + + [SerializeField] private float _spawnRadius = 20f; + [SerializeField] private int _spawnCount = 20; + private readonly List _spawned = new(); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index bbf043a..45868d5 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -12,7 +12,7 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable private readonly Dictionary _pools = new(new AssetRefGameObjectPrefabEqualityComparer()); - private readonly Dictionary _prefabToAssetReference = new(); + private readonly Dictionary _prefabToAssetReference = new(); private readonly Dictionary _poolKeyCache = new(); @@ -33,7 +33,7 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable this._pools.Add(gameObjectReference, pool); } UnityEngine.GameObject item = await pool.Rent(); - _prefabToAssetReference.Add(item, gameObjectReference); + _prefabToAssetReference.Add(item.GetInstanceID(), gameObjectReference); return item; } @@ -41,7 +41,7 @@ public void Return(UnityEngine.GameObject gameObject) { if (!gameObject) return; - if (_prefabToAssetReference.TryGetValue(gameObject, out var assetReference)) + if (_prefabToAssetReference.TryGetValue(gameObject.GetInstanceID(), out var assetReference)) Return(assetReference, gameObject); else Debug.LogError($"GameObject {gameObject.name} is not registered in the pool or was already returned."); @@ -59,7 +59,7 @@ public void ReleaseInstances(int keep, System.Action onR pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); + private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject.GetInstanceID()); private class AssetRefGameObjectPrefabEqualityComparer : IEqualityComparer { diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index 50620c8..dc49736 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -8,55 +8,66 @@ namespace ZBase.Foundation.Pooling.GameObject.LazyPool { public class GlobalGameObjectPool : IPool, IShareable { - private readonly Dictionary _pools = new(); - private readonly Dictionary _prefabToAssetReference = new(); - private readonly Dictionary _poolKeyCache = new(); - + private readonly Dictionary _pools = + new(new GameObjectPrefabEqualityComparer()); + + private readonly Dictionary _prefabToAssetReference = new(); + private readonly Dictionary _poolKeyCache = new(); + public async UniTask Rent(UnityEngine.GameObject gameObjectReference) { - if (!_poolKeyCache.TryGetValue(gameObjectReference, out var key)) - this._poolKeyCache.Add(gameObjectReference, key = new GameObjectPrefab { - Source = gameObjectReference - }); + var hash = gameObjectReference.GetInstanceID(); + if (!_poolKeyCache.TryGetValue(hash, out var key)) + this._poolKeyCache.Add(hash, key = new GameObjectPrefab { Source = gameObjectReference }); return await Rent(key); } + public async UniTask Rent(GameObjectPrefab gameObjectReference) { if (!_pools.TryGetValue(gameObjectReference, out var pool)) { - if (gameObjectReference.Source.transform.root != null) + if (gameObjectReference.Source.transform.root != gameObjectReference.Source.transform) throw new Exception($"Non Prefab not supported {gameObjectReference.Source.name}"); pool = new GameObjectItemPool(gameObjectReference); pool.OnReturn += OnReturnToPool; this._pools.Add(gameObjectReference, pool); } + UnityEngine.GameObject item = await pool.Rent(); - _prefabToAssetReference.Add(item, gameObjectReference); + _prefabToAssetReference.Add(item.GetInstanceID(), gameObjectReference); return item; } - + public void Return(UnityEngine.GameObject gameObject) { - if(!gameObject) + if (!gameObject) return; - if (_prefabToAssetReference.TryGetValue(gameObject, out var assetReference)) + if (_prefabToAssetReference.TryGetValue(gameObject.GetInstanceID(), out var assetReference)) Return(assetReference, gameObject); else - Debug.LogError($"GameObject {gameObject.name} is not registered in the pool or was already returned."); + Debug.LogWarning($"GameObject {gameObject.name} is not registered in the pool or was already returned."); } - + public void Return(GameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) { if (_pools.TryGetValue(gameObjectReference, out var pool)) pool.Return(gameObject); } - + public void ReleaseInstances(int keep, Action onReleased = null) { foreach (var pool in _pools.Values) pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject); + private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject.GetInstanceID()); + + private class GameObjectPrefabEqualityComparer : IEqualityComparer + { + public bool Equals(GameObjectPrefab x, GameObjectPrefab y) => + y != null && y.Source != null && x != null && x.Source != null && + x.Source.GetInstanceID() == y.Source.GetInstanceID(); + public int GetHashCode(GameObjectPrefab obj) => obj.Source.GetInstanceID(); + } } } \ No newline at end of file From 2b45ea1960feba6dd679039c85fb8dca8533fb0c Mon Sep 17 00:00:00 2001 From: DuyCa Date: Fri, 2 Feb 2024 10:55:16 +0700 Subject: [PATCH 19/35] Update GlobalGameObjectPool.cs --- .../GlobalPools/GlobalGameObjectPool.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index dc49736..35ba248 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -8,9 +8,7 @@ namespace ZBase.Foundation.Pooling.GameObject.LazyPool { public class GlobalGameObjectPool : IPool, IShareable { - private readonly Dictionary _pools = - new(new GameObjectPrefabEqualityComparer()); - + private readonly Dictionary _pools = new(); private readonly Dictionary _prefabToAssetReference = new(); private readonly Dictionary _poolKeyCache = new(); @@ -24,13 +22,14 @@ public class GlobalGameObjectPool : IPool, IShareable public async UniTask Rent(GameObjectPrefab gameObjectReference) { - if (!_pools.TryGetValue(gameObjectReference, out var pool)) + var instanceID = gameObjectReference.Source.GetInstanceID(); + if (!_pools.TryGetValue(instanceID, out var pool)) { if (gameObjectReference.Source.transform.root != gameObjectReference.Source.transform) throw new Exception($"Non Prefab not supported {gameObjectReference.Source.name}"); pool = new GameObjectItemPool(gameObjectReference); pool.OnReturn += OnReturnToPool; - this._pools.Add(gameObjectReference, pool); + this._pools.Add(instanceID, pool); } UnityEngine.GameObject item = await pool.Rent(); @@ -50,7 +49,7 @@ public void Return(UnityEngine.GameObject gameObject) public void Return(GameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) { - if (_pools.TryGetValue(gameObjectReference, out var pool)) + if (_pools.TryGetValue(gameObjectReference.Source.GetInstanceID(), out var pool)) pool.Return(gameObject); } @@ -61,13 +60,5 @@ public void ReleaseInstances(int keep, Action onReleased } private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject.GetInstanceID()); - - private class GameObjectPrefabEqualityComparer : IEqualityComparer - { - public bool Equals(GameObjectPrefab x, GameObjectPrefab y) => - y != null && y.Source != null && x != null && x.Source != null && - x.Source.GetInstanceID() == y.Source.GetInstanceID(); - public int GetHashCode(GameObjectPrefab obj) => obj.Source.GetInstanceID(); - } } } \ No newline at end of file From 95c952fb0ec8cac3c788fbf1ecef5329f12b6ebc Mon Sep 17 00:00:00 2001 From: DuyCa Date: Fri, 2 Feb 2024 11:10:08 +0700 Subject: [PATCH 20/35] Dispose OnLoad for Enter Play mode --- .../GameObjectPools/GameObjectPool.unity | 65 ++++++++++++++++++- .../Extensions/LazyAssetRefGameObjectPool.cs | 3 + .../Extensions/LazyGameObjectPool.cs | 8 ++- .../GlobalAssetRefGameObjectPool.cs | 9 +++ .../GlobalPools/GlobalGameObjectPool.cs | 11 +++- 5 files changed, 91 insertions(+), 5 deletions(-) diff --git a/Assets/PoolSample/GameObjectPools/GameObjectPool.unity b/Assets/PoolSample/GameObjectPools/GameObjectPool.unity index c3f8416..4d45015 100644 --- a/Assets/PoolSample/GameObjectPools/GameObjectPool.unity +++ b/Assets/PoolSample/GameObjectPools/GameObjectPool.unity @@ -204,7 +204,7 @@ MonoBehaviour: _source: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} _parent: {fileID: 0} _prePoolAmount: 0 - prefab2: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + prefab2: {fileID: 2113338613} _spawnRadius: 20 _spawnCount: 20 --- !u!1 &1252375770 @@ -367,6 +367,68 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: bc0a642a3d8c4485fa3e2c739a4cf9c8, type: 3} +--- !u!1001 &2113338612 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_Name + value: P01x + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} +--- !u!1 &2113338613 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + m_PrefabInstance: {fileID: 2113338612} + m_PrefabAsset: {fileID: 0} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -374,3 +436,4 @@ SceneRoots: - {fileID: 1076946245} - {fileID: 1252375773} - {fileID: 1838171512} + - {fileID: 2113338612} diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs index baa2a23..097d27f 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs @@ -24,5 +24,8 @@ public static void Return(AssetRefGameObjectPrefab gameObjectReference, UnityEng public static void ReleaseInstances(int keep, System.Action onReleased = null) => GlobalGameObjectPool.ReleaseInstances(keep, onReleased); + + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] + private static void Dispose() => GlobalGameObjectPool.Dispose(); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs index 0f128ca..82b2e1b 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs @@ -1,4 +1,5 @@ using Cysharp.Threading.Tasks; +using UnityEngine; using ZBase.Foundation.Pooling.UnityPools; namespace ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions @@ -7,13 +8,11 @@ namespace ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions public static class LazyGameObjectPool { private static GlobalGameObjectPool GlobalGameObjectPool => SharedPool.Of(); - + public static async UniTask Rent(UnityEngine.GameObject gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); - public static async UniTask Rent(GameObjectPrefab gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); - public static void Return(UnityEngine.GameObject gameObject) => GlobalGameObjectPool.Return(gameObject); @@ -22,5 +21,8 @@ public static void Return(GameObjectPrefab gameObjectReference, UnityEngine.Game public static void ReleaseInstances(int keep, System.Action onReleased = null) => GlobalGameObjectPool.ReleaseInstances(keep, onReleased); + + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] + private static void Dispose() => GlobalGameObjectPool.Dispose(); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index 45868d5..7f0e003 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -68,5 +68,14 @@ public bool Equals([NotNull] AssetRefGameObjectPrefab x, [NotNull] AssetRefGameO x.Source.AssetGUID.Equals(y.Source.AssetGUID); public int GetHashCode(AssetRefGameObjectPrefab obj) => obj.Source.AssetGUID.GetHashCode(); } + + public void Dispose() + { + foreach (var pool in _pools.Values) + pool.Dispose(); + _pools.Clear(); + _prefabToAssetReference.Clear(); + _poolKeyCache.Clear(); + } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index 35ba248..d8c7413 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -25,7 +25,7 @@ public class GlobalGameObjectPool : IPool, IShareable var instanceID = gameObjectReference.Source.GetInstanceID(); if (!_pools.TryGetValue(instanceID, out var pool)) { - if (gameObjectReference.Source.transform.root != gameObjectReference.Source.transform) + if (gameObjectReference.Source.scene.IsValid()) throw new Exception($"Non Prefab not supported {gameObjectReference.Source.name}"); pool = new GameObjectItemPool(gameObjectReference); pool.OnReturn += OnReturnToPool; @@ -60,5 +60,14 @@ public void ReleaseInstances(int keep, Action onReleased } private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject.GetInstanceID()); + + public void Dispose() + { + foreach (var pool in _pools.Values) + pool.Dispose(); + _pools.Clear(); + _prefabToAssetReference.Clear(); + _poolKeyCache.Clear(); + } } } \ No newline at end of file From 0abaa6bbc5da7970f2c306995928738b3e47c4dc Mon Sep 17 00:00:00 2001 From: DuyCa Date: Fri, 2 Feb 2024 11:11:20 +0700 Subject: [PATCH 21/35] Update package.json --- Packages/ZBase.Foundation.Pooling/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index caad892..85ce5ba 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,7 +1,7 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.3", + "version": "2.3.4", "unity": "2021.3", "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", "dependencies": { From 7335da3c4d48f8bff383ec8791435023eee67e17 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Fri, 2 Feb 2024 11:13:41 +0700 Subject: [PATCH 22/35] Update package.json --- Packages/ZBase.Foundation.Pooling/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index 85ce5ba..04beb3e 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,7 +1,7 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.4", + "version": "2.3.5", "unity": "2021.3", "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", "dependencies": { From bbd13565e7fb007d257ee57b69e4010067353f7b Mon Sep 17 00:00:00 2001 From: DuyCa Date: Mon, 5 Feb 2024 10:04:33 +0700 Subject: [PATCH 23/35] PoolGameObject Self Clear on Empty --- .../Pools/AssetRefGameObjectItemPool.cs | 8 +-- .../Foundation/Pools/GameObjectItemPool.cs | 29 ++++++--- .../Extensions/LazyAssetRefGameObjectPool.cs | 12 ++-- .../Extensions/LazyGameObjectPool.cs | 12 ++-- .../GlobalAssetRefGameObjectPool.cs | 44 ++++++------- .../GlobalPools/GlobalGameObjectPool.cs | 62 ++++++++++++++----- .../Items/AssetRefGameObjectPoolItem.cs | 2 +- .../Items/GameObjectPoolItem.cs | 15 ++++- .../GameObjectLazyPool/Items/PoolItem.cs | 4 +- .../Items/PoolItemAutoDeSpawnSetUp.cs | 2 +- .../ZBase.Foundation.Pooling/package.json | 2 +- 11 files changed, 124 insertions(+), 68 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs index dd68e7a..bbf8b4b 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs @@ -2,17 +2,17 @@ using UnityEngine; using ZBase.Foundation.Pooling.AddressableAssets; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public class AssetRefGameObjectItemPool : AssetRefGameObjectPool { - internal event Action OnReturn; + internal event Action OnReturn; public AssetRefGameObjectItemPool(AssetRefGameObjectPrefab prefab) : base(prefab) { } - protected override void ProcessNewInstance(UnityEngine.GameObject instance) + protected override void ProcessNewInstance(GameObject instance) { base.ProcessNewInstance(instance); if (!instance.TryGetComponent(out var poolItem)) @@ -20,7 +20,7 @@ protected override void ProcessNewInstance(UnityEngine.GameObject instance) poolItem.SetUp(this, instance, Prefab); } - protected override void ReturnPreprocess(UnityEngine.GameObject instance) + protected override void ReturnPreprocess(GameObject instance) { base.ReturnPreprocess(instance); OnReturn?.Invoke(instance); diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs index 9f169e3..5d6dd00 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs @@ -1,25 +1,38 @@ using System; +using System.Collections.Generic; +using UnityEngine; using ZBase.Foundation.Pooling.UnityPools; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public sealed class GameObjectItemPool : GameObjectPool { - internal event Action OnReturn; - - public GameObjectItemPool(GameObjectPrefab prefab) : base(prefab) - { - } + internal event Action OnReturn; + internal event Action OnPoolEmpty; + private readonly List _poolItems = new(); + + internal int ID { get; } + + public GameObjectItemPool(GameObjectPrefab prefab) : base(prefab) => ID = Prefab.Source.GetInstanceID(); - protected override void ProcessNewInstance(UnityEngine.GameObject instance) + protected override void ProcessNewInstance(GameObject instance) { base.ProcessNewInstance(instance); if (!instance.TryGetComponent(out var poolItem)) poolItem = instance.AddComponent(); poolItem.SetUp(this, instance, Prefab); + poolItem.OnItemDestroy += OnItemDestroy; + this._poolItems.Add(instance.GetInstanceID()); } - protected override void ReturnPreprocess(UnityEngine.GameObject instance) + private void OnItemDestroy(GameObject instance) + { + this._poolItems.Remove(instance.GetInstanceID()); + if(this._poolItems.Count == 0) + OnPoolEmpty?.Invoke(this); + } + + protected override void ReturnPreprocess(GameObject instance) { base.ReturnPreprocess(instance); OnReturn?.Invoke(instance); diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs index 097d27f..d58a88c 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs @@ -3,26 +3,26 @@ using UnityEngine.AddressableAssets; using ZBase.Foundation.Pooling.AddressableAssets; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool.Extensions { public static class LazyAssetRefGameObjectPool { private static GlobalAssetRefGameObjectPool GlobalGameObjectPool => SharedPool.Of(); - public static async UniTask Rent(AssetReferenceGameObject gameObjectReference) + public static async UniTask Rent(AssetReferenceGameObject gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); - public static async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) + public static async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); - public static void Return(UnityEngine.GameObject gameObject) + public static void Return(GameObject gameObject) => GlobalGameObjectPool.Return(gameObject); - public static void Return(AssetRefGameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) + public static void Return(AssetRefGameObjectPrefab gameObjectReference, GameObject gameObject) => GlobalGameObjectPool.Return(gameObjectReference, gameObject); - public static void ReleaseInstances(int keep, System.Action onReleased = null) + public static void ReleaseInstances(int keep, System.Action onReleased = null) => GlobalGameObjectPool.ReleaseInstances(keep, onReleased); [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs index 82b2e1b..5eee4fc 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyGameObjectPool.cs @@ -2,24 +2,24 @@ using UnityEngine; using ZBase.Foundation.Pooling.UnityPools; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool.Extensions { public static class LazyGameObjectPool { private static GlobalGameObjectPool GlobalGameObjectPool => SharedPool.Of(); - public static async UniTask Rent(UnityEngine.GameObject gameObjectReference) + public static async UniTask Rent(GameObject gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); - public static async UniTask Rent(GameObjectPrefab gameObjectReference) + public static async UniTask Rent(GameObjectPrefab gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); - public static void Return(UnityEngine.GameObject gameObject) + public static void Return(GameObject gameObject) => GlobalGameObjectPool.Return(gameObject); - public static void Return(GameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) + public static void Return(GameObjectPrefab gameObjectReference, GameObject gameObject) => GlobalGameObjectPool.Return(gameObjectReference, gameObject); - public static void ReleaseInstances(int keep, System.Action onReleased = null) + public static void ReleaseInstances(int keep, System.Action onReleased = null) => GlobalGameObjectPool.ReleaseInstances(keep, onReleased); [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index 7f0e003..481434a 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -5,18 +5,18 @@ using UnityEngine.AddressableAssets; using ZBase.Foundation.Pooling.AddressableAssets; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public class GlobalAssetRefGameObjectPool : IPool, IShareable { private readonly Dictionary _pools = new(new AssetRefGameObjectPrefabEqualityComparer()); - private readonly Dictionary _prefabToAssetReference = new(); + private readonly Dictionary _dicTrackingInstancePools = new(); private readonly Dictionary _poolKeyCache = new(); - public async UniTask Rent(AssetReferenceGameObject gameObjectReference) + public async UniTask Rent(AssetReferenceGameObject gameObjectReference) { if (!_poolKeyCache.TryGetValue(gameObjectReference, out var key)) _poolKeyCache.Add(gameObjectReference, @@ -24,7 +24,7 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable return await Rent(key); } - public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) + public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReference) { if (!_pools.TryGetValue(gameObjectReference, out var pool)) { @@ -32,50 +32,50 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable pool.OnReturn += OnReturnToPool; this._pools.Add(gameObjectReference, pool); } - UnityEngine.GameObject item = await pool.Rent(); - _prefabToAssetReference.Add(item.GetInstanceID(), gameObjectReference); + GameObject item = await pool.Rent(); + _dicTrackingInstancePools.Add(item.GetInstanceID(), pool); return item; } - public void Return(UnityEngine.GameObject gameObject) + public void Return(GameObject gameObject) { if (!gameObject) return; - if (_prefabToAssetReference.TryGetValue(gameObject.GetInstanceID(), out var assetReference)) - Return(assetReference, gameObject); + if (_dicTrackingInstancePools.TryGetValue(gameObject.GetInstanceID(), out var pool)) + pool.Return(gameObject); else - Debug.LogError($"GameObject {gameObject.name} is not registered in the pool or was already returned."); + Debug.LogWarning($"GameObject {gameObject.name} is not registered in the pool or was already returned."); } - public void Return(AssetRefGameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) + public void Return(AssetRefGameObjectPrefab gameObjectReference, GameObject gameObject) { if (_pools.TryGetValue(gameObjectReference, out var pool)) pool.Return(gameObject); } - public void ReleaseInstances(int keep, System.Action onReleased = null) + public void ReleaseInstances(int keep, System.Action onReleased = null) { foreach (var pool in _pools.Values) pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject.GetInstanceID()); + private void OnReturnToPool(GameObject gameObject) => _dicTrackingInstancePools.Remove(gameObject.GetInstanceID()); - private class AssetRefGameObjectPrefabEqualityComparer : IEqualityComparer - { - public bool Equals([NotNull] AssetRefGameObjectPrefab x, [NotNull] AssetRefGameObjectPrefab y) - => y is { Source: not null } && x is { Source: not null } && - x.Source.AssetGUID.Equals(y.Source.AssetGUID); - public int GetHashCode(AssetRefGameObjectPrefab obj) => obj.Source.AssetGUID.GetHashCode(); - } - public void Dispose() { foreach (var pool in _pools.Values) pool.Dispose(); _pools.Clear(); - _prefabToAssetReference.Clear(); + _dicTrackingInstancePools.Clear(); _poolKeyCache.Clear(); } + + private class AssetRefGameObjectPrefabEqualityComparer : IEqualityComparer + { + public bool Equals([NotNull] AssetRefGameObjectPrefab x, [NotNull] AssetRefGameObjectPrefab y) + => y is { Source: not null } && x is { Source: not null } && + x.Source.AssetGUID.Equals(y.Source.AssetGUID); + public int GetHashCode(AssetRefGameObjectPrefab obj) => obj.Source.AssetGUID.GetHashCode(); + } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index d8c7413..4128777 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -4,15 +4,15 @@ using UnityEngine; using ZBase.Foundation.Pooling.UnityPools; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public class GlobalGameObjectPool : IPool, IShareable { private readonly Dictionary _pools = new(); - private readonly Dictionary _prefabToAssetReference = new(); + private readonly Dictionary _dicTrackingInstancePools = new(); private readonly Dictionary _poolKeyCache = new(); - public async UniTask Rent(UnityEngine.GameObject gameObjectReference) + public async UniTask Rent(GameObject gameObjectReference) { var hash = gameObjectReference.GetInstanceID(); if (!_poolKeyCache.TryGetValue(hash, out var key)) @@ -20,7 +20,7 @@ public class GlobalGameObjectPool : IPool, IShareable return await Rent(key); } - public async UniTask Rent(GameObjectPrefab gameObjectReference) + public async UniTask Rent(GameObjectPrefab gameObjectReference) { var instanceID = gameObjectReference.Source.GetInstanceID(); if (!_pools.TryGetValue(instanceID, out var pool)) @@ -29,44 +29,78 @@ public class GlobalGameObjectPool : IPool, IShareable throw new Exception($"Non Prefab not supported {gameObjectReference.Source.name}"); pool = new GameObjectItemPool(gameObjectReference); pool.OnReturn += OnReturnToPool; + pool.OnPoolEmpty += OnPoolEmpty; this._pools.Add(instanceID, pool); } - UnityEngine.GameObject item = await pool.Rent(); - _prefabToAssetReference.Add(item.GetInstanceID(), gameObjectReference); + GameObject item = await pool.Rent(); + this._dicTrackingInstancePools.Add(item.GetInstanceID(), pool); return item; } - public void Return(UnityEngine.GameObject gameObject) + public void Return(GameObject gameObject) { if (!gameObject) return; - if (_prefabToAssetReference.TryGetValue(gameObject.GetInstanceID(), out var assetReference)) - Return(assetReference, gameObject); + if (this._dicTrackingInstancePools.TryGetValue(gameObject.GetInstanceID(), out var pool)) + pool.Return(gameObject); else - Debug.LogWarning($"GameObject {gameObject.name} is not registered in the pool or was already returned."); + Debug.LogWarning( + $"GameObject {gameObject.name} is not registered in the pool or was already returned."); } - public void Return(GameObjectPrefab gameObjectReference, UnityEngine.GameObject gameObject) + public void Return(GameObjectPrefab gameObjectReference, GameObject gameObject) { if (_pools.TryGetValue(gameObjectReference.Source.GetInstanceID(), out var pool)) pool.Return(gameObject); } - public void ReleaseInstances(int keep, Action onReleased = null) + public void ReleaseInstances(int keep, Action onReleased = null) { foreach (var pool in _pools.Values) pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(UnityEngine.GameObject gameObject) => _prefabToAssetReference.Remove(gameObject.GetInstanceID()); + private void OnPoolEmpty(GameObjectItemPool pool) + { + pool.Dispose(); + this._pools.Remove(pool.ID); + RemoveReference(pool.ID); + RemoveCacheKey(pool.ID); + } + private void RemoveReference(int poolID) + { + foreach (var keyPair in this._dicTrackingInstancePools) + { + if (keyPair.Value.ID != poolID) + continue; + this._dicTrackingInstancePools.Remove(keyPair.Key); + Debug.LogWarning($"Pool {poolID} is empty and removed from tracking"); + break; + } + } + + private void RemoveCacheKey(int poolID) + { + foreach (var keyPair in _poolKeyCache) + { + if (keyPair.Value.Source.GetInstanceID() != poolID) + continue; + this._poolKeyCache.Remove(keyPair.Key); + break; + } + } + + private void OnReturnToPool(GameObject gameObject) => + this._dicTrackingInstancePools.Remove(gameObject.GetInstanceID()); + public void Dispose() { foreach (var pool in _pools.Values) pool.Dispose(); _pools.Clear(); - _prefabToAssetReference.Clear(); + _dicTrackingInstancePools.Clear(); _poolKeyCache.Clear(); } } diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs index cf6e700..0fd9318 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs @@ -1,6 +1,6 @@ using ZBase.Foundation.Pooling.AddressableAssets; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public class AssetRefGameObjectPoolItem : PoolItem { diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs index 84d5a4c..a393ae1 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs @@ -1,7 +1,16 @@ -using ZBase.Foundation.Pooling.UnityPools; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +using System; +using UnityEngine; +using ZBase.Foundation.Pooling.UnityPools; +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { - public class GameObjectPoolItem : PoolItem + public class GameObjectPoolItem : PoolItem { + public event Action OnItemDestroy; + + protected override void OnDestroy() + { + base.OnDestroy(); + this.OnItemDestroy?.Invoke(this.gameObject); + } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs index e4ee43a..0c0e992 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs @@ -4,7 +4,7 @@ using ZBase.Foundation.Pooling.UnityPools; using Object = UnityEngine.Object; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public class PoolItem : MonoBehaviour where T : Object where TPrefab : IPrefab { @@ -42,7 +42,7 @@ public void SetUp(UnityPool pool, T instance, TPrefab prefab) _prefab = prefab; } - private void OnDestroy() + protected virtual void OnDestroy() { _pool?.RemoveItem(_instance); _prefab?.Release(_instance); diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs index af4bdc5..bb5d4cd 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItemAutoDeSpawnSetUp.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace ZBase.Foundation.Pooling.GameObject.LazyPool +namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public class PoolItemAutoDeSpawnSetUp : MonoBehaviour { diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index 04beb3e..030fe42 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,7 +1,7 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.5", + "version": "2.3.6", "unity": "2021.3", "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", "dependencies": { From c7490bd0e81df4f6419be0ff9e1a19fa1626090b Mon Sep 17 00:00:00 2001 From: DuyCa Date: Mon, 5 Feb 2024 10:05:00 +0700 Subject: [PATCH 24/35] asset --- .../AddressableAssetSettings.asset | 10 ++- .../AssetGroups/Default Local Group.asset | 10 ++- .../AssetGroups/G1.asset | 30 +++++++++ .../AssetGroups/G1.asset.meta | 8 +++ .../AssetGroups/G2.asset | 30 +++++++++ .../AssetGroups/G2.asset.meta | 8 +++ .../Schemas/G1_BundledAssetGroupSchema.asset | 45 +++++++++++++ .../G1_BundledAssetGroupSchema.asset.meta | 8 +++ .../Schemas/G1_ContentUpdateGroupSchema.asset | 16 +++++ .../G1_ContentUpdateGroupSchema.asset.meta | 8 +++ .../Schemas/G2_BundledAssetGroupSchema.asset | 45 +++++++++++++ .../G2_BundledAssetGroupSchema.asset.meta | 8 +++ .../Schemas/G2_ContentUpdateGroupSchema.asset | 16 +++++ .../G2_ContentUpdateGroupSchema.asset.meta | 8 +++ .../AddressGameObjectPool_1.unity | 15 +++-- .../AddressableGameObjectPoolSample1.cs | 13 ++-- .../GameObjectPools/GameObjectPool.unity | 66 +------------------ .../Scripts/GameObjectPoolSample.cs | 19 ++++-- 18 files changed, 273 insertions(+), 90 deletions(-) create mode 100644 Assets/AddressableAssetsData/AssetGroups/G1.asset create mode 100644 Assets/AddressableAssetsData/AssetGroups/G1.asset.meta create mode 100644 Assets/AddressableAssetsData/AssetGroups/G2.asset create mode 100644 Assets/AddressableAssetsData/AssetGroups/G2.asset.meta create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset.meta create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset.meta create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset.meta create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset create mode 100644 Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset.meta diff --git a/Assets/AddressableAssetsData/AddressableAssetSettings.asset b/Assets/AddressableAssetsData/AddressableAssetSettings.asset index d05e75a..aa82499 100644 --- a/Assets/AddressableAssetsData/AddressableAssetSettings.asset +++ b/Assets/AddressableAssetsData/AddressableAssetSettings.asset @@ -13,9 +13,9 @@ MonoBehaviour: m_Name: AddressableAssetSettings m_EditorClassIdentifier: m_DefaultGroup: d9910c93167875b4c99382800fc0d05e - m_CachedHash: + m_currentHash: serializedVersion: 2 - Hash: 00000000000000000000000000000000 + Hash: ea828a1e0a97826edfd1bfbc46e81fe7 m_OptimizeCatalogSize: 0 m_BuildRemoteCatalog: 0 m_BundleLocalCatalog: 0 @@ -32,17 +32,22 @@ MonoBehaviour: m_ShaderBundleNaming: 0 m_ShaderBundleCustomNaming: m_MonoScriptBundleNaming: 0 + m_CheckForContentUpdateRestrictionsOption: 0 m_MonoScriptBundleCustomNaming: m_RemoteCatalogBuildPath: m_Id: m_RemoteCatalogLoadPath: m_Id: + m_ContentStateBuildPathProfileVariableName: + m_CustomContentStateBuildPath: m_ContentStateBuildPath: m_BuildAddressablesWithPlayerBuild: 0 m_overridePlayerVersion: m_GroupAssets: - {fileID: 11400000, guid: 85a41e37c6a6c344ba1b70e8e15b138f, type: 2} - {fileID: 11400000, guid: 4fa3a4f3857831f46b32fd15146ddb84, type: 2} + - {fileID: 11400000, guid: c1bd4023bac138c499ab6bc166a011cc, type: 2} + - {fileID: 11400000, guid: cbaf0f25751d5e943910fa9062905860, type: 2} m_BuildSettings: m_CompileScriptsInVirtualMode: 0 m_CleanupStreamingAssetsAfterBuilds: 1 @@ -103,3 +108,4 @@ MonoBehaviour: m_Settings: {fileID: 11400000} m_NextInstanceId: 0 m_RegisteredServiceTypeRefs: [] + m_PingTimeoutInMilliseconds: 5000 diff --git a/Assets/AddressableAssetsData/AssetGroups/Default Local Group.asset b/Assets/AddressableAssetsData/AssetGroups/Default Local Group.asset index 916c008..44ab8dc 100644 --- a/Assets/AddressableAssetsData/AssetGroups/Default Local Group.asset +++ b/Assets/AddressableAssetsData/AssetGroups/Default Local Group.asset @@ -21,14 +21,12 @@ MonoBehaviour: m_Address: Character_P01 m_ReadOnly: 0 m_SerializedLabels: [] - - m_GUID: 1c14710c0d49c480497e5be810eb4fc4 - m_Address: Character_AddressPool_P01 - m_ReadOnly: 0 - m_SerializedLabels: [] - - m_GUID: 5fa68afe6708644fda728daf092224b3 - m_Address: Character_AddressPool_P02 + FlaggedDuringContentUpdateRestriction: 0 + - m_GUID: d0d1d00d6013742259b0519a178bae7e + m_Address: AddressGameObjectPool_2 m_ReadOnly: 0 m_SerializedLabels: [] + FlaggedDuringContentUpdateRestriction: 0 m_ReadOnly: 0 m_Settings: {fileID: 11400000, guid: e0f6fa325fd1a464cbecb4e3b9f30872, type: 2} m_SchemaSet: diff --git a/Assets/AddressableAssetsData/AssetGroups/G1.asset b/Assets/AddressableAssetsData/AssetGroups/G1.asset new file mode 100644 index 0000000..d3cabb4 --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/G1.asset @@ -0,0 +1,30 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bbb281ee3bf0b054c82ac2347e9e782c, type: 3} + m_Name: G1 + m_EditorClassIdentifier: + m_GroupName: G1 + m_Data: + m_SerializedData: [] + m_GUID: 786c82b3da1eddf4e98e44418269eaac + m_SerializeEntries: + - m_GUID: 1c14710c0d49c480497e5be810eb4fc4 + m_Address: Character_AddressPool_P01 + m_ReadOnly: 0 + m_SerializedLabels: [] + FlaggedDuringContentUpdateRestriction: 0 + m_ReadOnly: 0 + m_Settings: {fileID: 11400000, guid: e0f6fa325fd1a464cbecb4e3b9f30872, type: 2} + m_SchemaSet: + m_Schemas: + - {fileID: 11400000, guid: 26f22837dd630d04caec7ddac57d0d95, type: 2} + - {fileID: 11400000, guid: 45d7f078b1b138e4d8b352635c93aec1, type: 2} diff --git a/Assets/AddressableAssetsData/AssetGroups/G1.asset.meta b/Assets/AddressableAssetsData/AssetGroups/G1.asset.meta new file mode 100644 index 0000000..d45539f --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/G1.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c1bd4023bac138c499ab6bc166a011cc +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AddressableAssetsData/AssetGroups/G2.asset b/Assets/AddressableAssetsData/AssetGroups/G2.asset new file mode 100644 index 0000000..c8f2cf6 --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/G2.asset @@ -0,0 +1,30 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bbb281ee3bf0b054c82ac2347e9e782c, type: 3} + m_Name: G2 + m_EditorClassIdentifier: + m_GroupName: G2 + m_Data: + m_SerializedData: [] + m_GUID: 0c843a54c48305444b92c07cee920462 + m_SerializeEntries: + - m_GUID: 5fa68afe6708644fda728daf092224b3 + m_Address: Character_AddressPool_P02 + m_ReadOnly: 0 + m_SerializedLabels: [] + FlaggedDuringContentUpdateRestriction: 0 + m_ReadOnly: 0 + m_Settings: {fileID: 11400000, guid: e0f6fa325fd1a464cbecb4e3b9f30872, type: 2} + m_SchemaSet: + m_Schemas: + - {fileID: 11400000, guid: b6abdbd3cc0a62c4e8bb71d6d16e7306, type: 2} + - {fileID: 11400000, guid: 28bddb69006143b4f8d9adeff7301fa6, type: 2} diff --git a/Assets/AddressableAssetsData/AssetGroups/G2.asset.meta b/Assets/AddressableAssetsData/AssetGroups/G2.asset.meta new file mode 100644 index 0000000..83a8257 --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/G2.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cbaf0f25751d5e943910fa9062905860 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset new file mode 100644 index 0000000..480c6c7 --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset @@ -0,0 +1,45 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e5d17a21594effb4e9591490b009e7aa, type: 3} + m_Name: G1_BundledAssetGroupSchema + m_EditorClassIdentifier: + m_Group: {fileID: 11400000, guid: c1bd4023bac138c499ab6bc166a011cc, type: 2} + m_InternalBundleIdMode: 1 + m_Compression: 1 + m_IncludeAddressInCatalog: 1 + m_IncludeGUIDInCatalog: 1 + m_IncludeLabelsInCatalog: 1 + m_InternalIdNamingMode: 1 + m_CacheClearBehavior: 0 + m_IncludeInBuild: 1 + m_BundledAssetProviderType: + m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider + m_ForceUniqueProvider: 0 + m_UseAssetBundleCache: 1 + m_UseAssetBundleCrc: 1 + m_UseAssetBundleCrcForCachedBundles: 1 + m_UseUWRForLocalBundles: 0 + m_Timeout: 0 + m_ChunkedTransfer: 0 + m_RedirectLimit: -1 + m_RetryCount: 0 + m_BuildPath: + m_Id: 39f5442237a26e346a93004cc38d7bf0 + m_LoadPath: + m_Id: 306e70fc82f4d384eb13742f59b5bf59 + m_BundleMode: 0 + m_AssetBundleProviderType: + m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider + m_BundleNaming: 1 + m_AssetLoadMode: 0 diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset.meta b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset.meta new file mode 100644 index 0000000..f29085e --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_BundledAssetGroupSchema.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 26f22837dd630d04caec7ddac57d0d95 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset new file mode 100644 index 0000000..b7014ff --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5834b5087d578d24c926ce20cd31e6d6, type: 3} + m_Name: G1_ContentUpdateGroupSchema + m_EditorClassIdentifier: + m_Group: {fileID: 11400000, guid: c1bd4023bac138c499ab6bc166a011cc, type: 2} + m_StaticContent: 0 diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset.meta b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset.meta new file mode 100644 index 0000000..ae0cf2f --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G1_ContentUpdateGroupSchema.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 45d7f078b1b138e4d8b352635c93aec1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset new file mode 100644 index 0000000..29b99e5 --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset @@ -0,0 +1,45 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e5d17a21594effb4e9591490b009e7aa, type: 3} + m_Name: G2_BundledAssetGroupSchema + m_EditorClassIdentifier: + m_Group: {fileID: 11400000, guid: cbaf0f25751d5e943910fa9062905860, type: 2} + m_InternalBundleIdMode: 1 + m_Compression: 1 + m_IncludeAddressInCatalog: 1 + m_IncludeGUIDInCatalog: 1 + m_IncludeLabelsInCatalog: 1 + m_InternalIdNamingMode: 1 + m_CacheClearBehavior: 0 + m_IncludeInBuild: 1 + m_BundledAssetProviderType: + m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider + m_ForceUniqueProvider: 0 + m_UseAssetBundleCache: 1 + m_UseAssetBundleCrc: 1 + m_UseAssetBundleCrcForCachedBundles: 1 + m_UseUWRForLocalBundles: 0 + m_Timeout: 0 + m_ChunkedTransfer: 0 + m_RedirectLimit: -1 + m_RetryCount: 0 + m_BuildPath: + m_Id: 39f5442237a26e346a93004cc38d7bf0 + m_LoadPath: + m_Id: 306e70fc82f4d384eb13742f59b5bf59 + m_BundleMode: 0 + m_AssetBundleProviderType: + m_AssemblyName: Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + m_ClassName: UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider + m_BundleNaming: 1 + m_AssetLoadMode: 0 diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset.meta b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset.meta new file mode 100644 index 0000000..7373bbe --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_BundledAssetGroupSchema.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b6abdbd3cc0a62c4e8bb71d6d16e7306 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset new file mode 100644 index 0000000..b917d6c --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5834b5087d578d24c926ce20cd31e6d6, type: 3} + m_Name: G2_ContentUpdateGroupSchema + m_EditorClassIdentifier: + m_Group: {fileID: 11400000, guid: cbaf0f25751d5e943910fa9062905860, type: 2} + m_StaticContent: 0 diff --git a/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset.meta b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset.meta new file mode 100644 index 0000000..3f28c15 --- /dev/null +++ b/Assets/AddressableAssetsData/AssetGroups/Schemas/G2_ContentUpdateGroupSchema.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 28bddb69006143b4f8d9adeff7301fa6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity index ec81581..fab06ee 100644 --- a/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity +++ b/Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity @@ -228,11 +228,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cdb23546d86448568402c2d071ea936d, type: 3} m_Name: m_EditorClassIdentifier: - _sceneRef: - m_AssetGUID: d0d1d00d6013742259b0519a178bae7e - m_SubObjectName: - m_SubObjectType: - m_EditorAssetChanged: 0 _prefab: _source: m_AssetGUID: d313163ceba02498b974cf73b0605e8a @@ -241,6 +236,16 @@ MonoBehaviour: m_EditorAssetChanged: 0 _parent: {fileID: 0} _prePoolAmount: 0 + _assetReferenceGameObject: + m_AssetGUID: d313163ceba02498b974cf73b0605e8a + m_SubObjectName: + m_SubObjectType: + m_EditorAssetChanged: 0 + _sceneRef: + m_AssetGUID: d0d1d00d6013742259b0519a178bae7e + m_SubObjectName: + m_SubObjectType: + m_EditorAssetChanged: 0 _spawnRadius: 20 _spawnCount: 100 --- !u!1660057539 &9223372036854775807 diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs index 01c4991..05dd89c 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressableGameObjectPoolSample1.cs @@ -3,7 +3,7 @@ using UnityEngine.AddressableAssets; using ZBase.Collections.Pooled.Generic; using ZBase.Foundation.Pooling.AddressableAssets; -using ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions; +using ZBase.Foundation.Pooling.GameObjectItem.LazyPool.Extensions; namespace Pooling.Sample { @@ -11,7 +11,7 @@ public class AddressableGameObjectPoolSample1 : MonoBehaviour { [SerializeField] private AssetRefGameObjectPrefab _prefab; [SerializeField] private AssetReferenceGameObject _assetReferenceGameObject; - + private GameObject _item; private async UniTask Spawn() @@ -61,10 +61,11 @@ private void OnGUI() Return(); if (GUI.Button(new Rect(10, 130, 150, 50), "Release All")) ReleaseAll(); - if (!GUI.Button(new Rect(10, 190, 150, 50), "Load By AssetRef")) - return; - for (int i = 0; i < this._spawnCount; i++) - SpawnByRef().Forget(); + if (GUI.Button(new Rect(10, 190, 150, 50), "Load By AssetRef")) + for (int i = 0; i < this._spawnCount; i++) + SpawnByRef().Forget(); + if (GUI.Button(new Rect(10, 250, 150, 50), "Switch Scene")) + Addressables.LoadSceneAsync(_sceneRef); } [SerializeField] private AssetReference _sceneRef; [SerializeField] private float _spawnRadius = 20f; diff --git a/Assets/PoolSample/GameObjectPools/GameObjectPool.unity b/Assets/PoolSample/GameObjectPools/GameObjectPool.unity index 4d45015..5497875 100644 --- a/Assets/PoolSample/GameObjectPools/GameObjectPool.unity +++ b/Assets/PoolSample/GameObjectPools/GameObjectPool.unity @@ -204,7 +204,8 @@ MonoBehaviour: _source: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} _parent: {fileID: 0} _prePoolAmount: 0 - prefab2: {fileID: 2113338613} + prefab2: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} + sceneID: 0 _spawnRadius: 20 _spawnCount: 20 --- !u!1 &1252375770 @@ -367,68 +368,6 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: bc0a642a3d8c4485fa3e2c739a4cf9c8, type: 3} ---- !u!1001 &2113338612 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_Name - value: P01x - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8942734549851988516, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} ---- !u!1 &2113338613 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8597698371886135454, guid: 60ab07b23a75fbf458c80cba08df9edb, type: 3} - m_PrefabInstance: {fileID: 2113338612} - m_PrefabAsset: {fileID: 0} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -436,4 +375,3 @@ SceneRoots: - {fileID: 1076946245} - {fileID: 1252375773} - {fileID: 1838171512} - - {fileID: 2113338612} diff --git a/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs b/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs index a67bb13..eb5e73a 100644 --- a/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs +++ b/Assets/PoolSample/GameObjectPools/Scripts/GameObjectPoolSample.cs @@ -1,7 +1,7 @@ using Cysharp.Threading.Tasks; using UnityEngine; using ZBase.Collections.Pooled.Generic; -using ZBase.Foundation.Pooling.GameObject.LazyPool.Extensions; +using ZBase.Foundation.Pooling.GameObjectItem.LazyPool.Extensions; using ZBase.Foundation.Pooling.UnityPools; namespace Pooling.Sample @@ -10,6 +10,7 @@ public class GameObjectPoolSample : MonoBehaviour { public GameObjectPrefab prefab1; public GameObject prefab2; + public int sceneID; private async UniTask Spawn() { @@ -39,14 +40,18 @@ private void OnGUI() if (GUI.Button(new Rect(0, 60, 150, 50), "Spawn By Prefab")) for (int i = 0; i < this._spawnCount; i++) SpawnByPrefab().Forget(); - if (!GUI.Button(new Rect(0, 120, 150, 50), "DeSpawn All")) - return; - foreach (var go in _spawned) + if (GUI.Button(new Rect(0, 120, 150, 50), "DeSpawn All")) { - go.SetActive(false); - LazyGameObjectPool.Return(go); + foreach (var go in _spawned) + { + go.SetActive(false); + LazyGameObjectPool.Return(go); + } + _spawned.Clear(); } - _spawned.Clear(); + if (!GUI.Button(new Rect(0, 180, 150, 50), "Switch Scene")) + return; + UnityEngine.SceneManagement.SceneManager.LoadScene(sceneID); } [SerializeField] private float _spawnRadius = 20f; From bb3d6577330f7e721005e2a41b948f711f32f34f Mon Sep 17 00:00:00 2001 From: DuyCa Date: Mon, 5 Feb 2024 11:42:12 +0700 Subject: [PATCH 25/35] string Address Support --- .../GlobalPools/GlobalAssetRefGameObjectPool.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index 481434a..1b9a91a 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -15,6 +15,16 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable private readonly Dictionary _dicTrackingInstancePools = new(); private readonly Dictionary _poolKeyCache = new(); + private readonly Dictionary _poolStringKeyCache = new(); + + public async UniTask Rent(string address) + { + if (_poolStringKeyCache.TryGetValue(address, out var key)) + return await Rent(key); + var assetRef = new AssetReferenceGameObject(address); + this._poolStringKeyCache.Add(address, key = new AssetRefGameObjectPrefab { Source = assetRef, }); + return await Rent(key); + } public async UniTask Rent(AssetReferenceGameObject gameObjectReference) { @@ -68,6 +78,7 @@ public void Dispose() _pools.Clear(); _dicTrackingInstancePools.Clear(); _poolKeyCache.Clear(); + _poolStringKeyCache.Clear(); } private class AssetRefGameObjectPrefabEqualityComparer : IEqualityComparer From 1b6b778ad8df633647922ed2bb2f224581703170 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Mon, 5 Feb 2024 11:42:41 +0700 Subject: [PATCH 26/35] Update package.json --- Packages/ZBase.Foundation.Pooling/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index 030fe42..cad8dc5 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,7 +1,7 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.6", + "version": "2.3.7", "unity": "2021.3", "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", "dependencies": { From 6b20e617b3855f51fe0136aadf66c3f5f9b2da52 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Mon, 5 Feb 2024 11:48:04 +0700 Subject: [PATCH 27/35] update Lazy pool --- .../GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs | 3 +++ Packages/ZBase.Foundation.Pooling/package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs index d58a88c..00d28e2 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs @@ -10,6 +10,9 @@ public static class LazyAssetRefGameObjectPool { private static GlobalAssetRefGameObjectPool GlobalGameObjectPool => SharedPool.Of(); + public static async UniTask Rent(string address) + => await GlobalGameObjectPool.Rent(address); + public static async UniTask Rent(AssetReferenceGameObject gameObjectReference) => await GlobalGameObjectPool.Rent(gameObjectReference); diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index cad8dc5..f097423 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,7 +1,7 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.7", + "version": "2.3.9", "unity": "2021.3", "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", "dependencies": { From 4e6d19a4c3c816035a7a0f55bc67b6f975de2674 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 6 Feb 2024 09:39:18 +0700 Subject: [PATCH 28/35] Rename Menthod --- .../GameObjectLazyPool/Items/PoolItem.cs | 2 +- .../UnityPools/Pools/UnityPool{T,TPrefab}.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs index 0c0e992..d91cf99 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs @@ -44,7 +44,7 @@ public void SetUp(UnityPool pool, T instance, TPrefab prefab) protected virtual void OnDestroy() { - _pool?.RemoveItem(_instance); + _pool?.OnPoolItemDestroy(_instance); _prefab?.Release(_instance); } } diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs index 1c7fe4d..5000ac6 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs @@ -90,7 +90,7 @@ public void Return(T instance) _queue.TryEnqueue(instance.GetInstanceID(), instance); } - public void RemoveItem(T instance) + public void OnPoolItemDestroy(T instance) { if (!instance) return; From d1e2c23624611389963f94aca04ce704b2ef75a0 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 6 Feb 2024 09:42:11 +0700 Subject: [PATCH 29/35] Update AssetRefGameObjectPoolItem.cs --- .../GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs index 0fd9318..988c2e5 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs @@ -1,8 +1,9 @@ -using ZBase.Foundation.Pooling.AddressableAssets; +using UnityEngine; +using ZBase.Foundation.Pooling.AddressableAssets; namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { - public class AssetRefGameObjectPoolItem : PoolItem + public class AssetRefGameObjectPoolItem : PoolItem { } } \ No newline at end of file From c6880a9e8aaed553bd969f2e3bb7e45b0b13f3ea Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 6 Feb 2024 09:47:37 +0700 Subject: [PATCH 30/35] Clean --- .../Pools/AssetRefGameObjectItemPool.cs | 2 +- .../Foundation/Pools/GameObjectItemPool.cs | 2 +- .../Items/AssetRefGameObjectPoolItem.cs | 5 ++--- .../Items/GameObjectPoolItem.cs | 2 +- .../GameObjectLazyPool/Items/PoolItem.cs | 21 ++++++++++--------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs index bbf8b4b..f4a0c06 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs @@ -17,7 +17,7 @@ protected override void ProcessNewInstance(GameObject instance) base.ProcessNewInstance(instance); if (!instance.TryGetComponent(out var poolItem)) poolItem = instance.AddComponent(); - poolItem.SetUp(this, instance, Prefab); + poolItem.SetUp(this, Prefab); } protected override void ReturnPreprocess(GameObject instance) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs index 5d6dd00..403fc54 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs @@ -20,7 +20,7 @@ protected override void ProcessNewInstance(GameObject instance) base.ProcessNewInstance(instance); if (!instance.TryGetComponent(out var poolItem)) poolItem = instance.AddComponent(); - poolItem.SetUp(this, instance, Prefab); + poolItem.SetUp(this, Prefab); poolItem.OnItemDestroy += OnItemDestroy; this._poolItems.Add(instance.GetInstanceID()); } diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs index 988c2e5..eb76ae5 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/AssetRefGameObjectPoolItem.cs @@ -1,9 +1,8 @@ -using UnityEngine; -using ZBase.Foundation.Pooling.AddressableAssets; +using ZBase.Foundation.Pooling.AddressableAssets; namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { - public class AssetRefGameObjectPoolItem : PoolItem + public class AssetRefGameObjectPoolItem : PoolItem { } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs index a393ae1..8564c46 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/GameObjectPoolItem.cs @@ -3,7 +3,7 @@ using ZBase.Foundation.Pooling.UnityPools; namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { - public class GameObjectPoolItem : PoolItem + public class GameObjectPoolItem : PoolItem { public event Action OnItemDestroy; diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs index d91cf99..014d38d 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs @@ -6,12 +6,11 @@ namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { - public class PoolItem : MonoBehaviour where T : Object where TPrefab : IPrefab + public class PoolItem : MonoBehaviour where TPrefab : IPrefab { private float _lifeTime; - private T _instance; private TPrefab _prefab; - private UnityPool _pool; + private UnityPool _pool; private void Awake() { @@ -26,26 +25,28 @@ private void OnEnable() return; StartDeSpawn().Forget(); } - + private async UniTask StartDeSpawn() { if (_lifeTime <= 0) return; - await UniTask.Delay(TimeSpan.FromSeconds(_lifeTime), cancellationToken: this.GetCancellationTokenOnDestroy()); - _pool?.Return(_instance); + if (await UniTask + .Delay(TimeSpan.FromSeconds(_lifeTime), cancellationToken: this.GetCancellationTokenOnDestroy()) + .SuppressCancellationThrow()) + return; + _pool?.Return(gameObject); } - public void SetUp(UnityPool pool, T instance, TPrefab prefab) + public void SetUp(UnityPool pool, TPrefab prefab) { - _instance = instance; _pool = pool; _prefab = prefab; } protected virtual void OnDestroy() { - _pool?.OnPoolItemDestroy(_instance); - _prefab?.Release(_instance); + _pool?.OnPoolItemDestroy(gameObject); + _prefab?.Release(gameObject); } } } \ No newline at end of file From 06d7884526f216584eb66baf2f3184355e78d877 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 6 Feb 2024 10:06:36 +0700 Subject: [PATCH 31/35] Update --- .../AddressablePoolBehaviourSample1.cs | 2 +- ...ersal Render Pipeline Asset_Renderer.asset | 8 ++--- Assets/Render/Universal Renderer Data.asset | 2 +- ...niversalRenderPipelineGlobalSettings.asset | 14 --------- .../Pools/AssetRefGameObjectItemPool.cs | 2 +- .../Foundation/Pools/GameObjectItemPool.cs | 2 +- .../GameObjectLazyPool/Items/PoolItem.cs | 13 ++------ .../UnityPools/Pools/UnityPool{T,TPrefab}.cs | 1 + Packages/manifest.json | 2 +- Packages/packages-lock.json | 30 ++++++++++++------- ProjectSettings/EditorBuildSettings.asset | 8 ++++- 11 files changed, 38 insertions(+), 46 deletions(-) diff --git a/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs b/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs index e61b89d..95d264b 100644 --- a/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs +++ b/Assets/PoolSample/AddressablePools/Scripts/AddressablePoolBehaviourSample1.cs @@ -25,7 +25,7 @@ public class AddressablePoolBehaviourSample1 : MonoBehaviour private readonly List _units = new(); - private async void Start() => await this.pool.Prepool(destroyCancellationToken); + private async void Start() => await this.pool.Prepool(this.GetCancellationTokenOnDestroy()).SuppressCancellationThrow(); // ReSharper disable Unity.PerformanceAnalysis private async UniTask Rent(CancellationToken cancelToken = default) diff --git a/Assets/Render/Universal Render Pipeline Asset_Renderer.asset b/Assets/Render/Universal Render Pipeline Asset_Renderer.asset index 791a29e..171745c 100644 --- a/Assets/Render/Universal Render Pipeline Asset_Renderer.asset +++ b/Assets/Render/Universal Render Pipeline Asset_Renderer.asset @@ -14,11 +14,10 @@ MonoBehaviour: m_EditorClassIdentifier: debugShaders: debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7, type: 3} - hdrDebugViewPS: {fileID: 4800000, guid: 573620ae32aec764abd4d728906d2587, type: 3} m_RendererFeatures: [] m_RendererFeatureMap: m_UseNativeRenderPass: 0 - postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} + postProcessData: {fileID: 0} xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2} shaders: blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3} @@ -27,14 +26,11 @@ MonoBehaviour: samplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3} stencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3} fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3} - fallbackLoadingPS: {fileID: 4800000, guid: 7f888aff2ac86494babad1c2c5daeee2, type: 3} materialErrorPS: {fileID: 4800000, guid: 5fd9a8feb75a4b5894c241777f519d4e, type: 3} coreBlitPS: {fileID: 4800000, guid: 93446b5c5339d4f00b85c159e1159b7c, type: 3} coreBlitColorAndDepthPS: {fileID: 4800000, guid: d104b2fc1ca6445babb8e90b0758136b, type: 3} - blitHDROverlay: {fileID: 4800000, guid: a89bee29cffa951418fc1e2da94d1959, type: 3} cameraMotionVector: {fileID: 4800000, guid: c56b7e0d4c7cb484e959caeeedae9bbf, type: 3} objectMotionVector: {fileID: 4800000, guid: 7b3ede40266cd49a395def176e1bc486, type: 3} - dataDrivenLensFlare: {fileID: 4800000, guid: 6cda457ac28612740adb23da5d39ea92, type: 3} m_AssetVersion: 2 m_OpaqueLayerMask: serializedVersion: 2 @@ -54,4 +50,6 @@ MonoBehaviour: m_DepthPrimingMode: 0 m_CopyDepthMode: 0 m_AccurateGbufferNormals: 0 + m_ClusteredRendering: 0 + m_TileSize: 32 m_IntermediateTextureMode: 1 diff --git a/Assets/Render/Universal Renderer Data.asset b/Assets/Render/Universal Renderer Data.asset index f9cd158..cc34004 100644 --- a/Assets/Render/Universal Renderer Data.asset +++ b/Assets/Render/Universal Renderer Data.asset @@ -17,7 +17,7 @@ MonoBehaviour: m_RendererFeatures: [] m_RendererFeatureMap: m_UseNativeRenderPass: 0 - postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} + postProcessData: {fileID: 0} xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2} shaders: blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3} diff --git a/Assets/Render/UniversalRenderPipelineGlobalSettings.asset b/Assets/Render/UniversalRenderPipelineGlobalSettings.asset index 98f0dfd..35619de 100644 --- a/Assets/Render/UniversalRenderPipelineGlobalSettings.asset +++ b/Assets/Render/UniversalRenderPipelineGlobalSettings.asset @@ -13,16 +13,6 @@ MonoBehaviour: m_Name: UniversalRenderPipelineGlobalSettings m_EditorClassIdentifier: k_AssetVersion: 3 - m_RenderingLayerNames: - - Light Layer default - - Light Layer 1 - - Light Layer 2 - - Light Layer 3 - - Light Layer 4 - - Light Layer 5 - - Light Layer 6 - - Light Layer 7 - m_ValidRenderingLayers: 255 lightLayerName0: Light Layer default lightLayerName1: Light Layer 1 lightLayerName2: Light Layer 2 @@ -34,8 +24,4 @@ MonoBehaviour: m_StripDebugVariants: 1 m_StripUnusedPostProcessingVariants: 0 m_StripUnusedVariants: 1 - m_StripUnusedLODCrossFadeVariants: 1 - m_StripScreenCoordOverrideVariants: 1 supportRuntimeDebugDisplay: 0 - m_ShaderVariantLogLevel: 0 - m_ExportShaderVariants: 1 diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs index f4a0c06..d8f15eb 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs @@ -17,7 +17,7 @@ protected override void ProcessNewInstance(GameObject instance) base.ProcessNewInstance(instance); if (!instance.TryGetComponent(out var poolItem)) poolItem = instance.AddComponent(); - poolItem.SetUp(this, Prefab); + poolItem.SetUp(this); } protected override void ReturnPreprocess(GameObject instance) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs index 403fc54..9c09e34 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs @@ -20,7 +20,7 @@ protected override void ProcessNewInstance(GameObject instance) base.ProcessNewInstance(instance); if (!instance.TryGetComponent(out var poolItem)) poolItem = instance.AddComponent(); - poolItem.SetUp(this, Prefab); + poolItem.SetUp(this); poolItem.OnItemDestroy += OnItemDestroy; this._poolItems.Add(instance.GetInstanceID()); } diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs index 014d38d..a0515c2 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs @@ -9,7 +9,6 @@ namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool public class PoolItem : MonoBehaviour where TPrefab : IPrefab { private float _lifeTime; - private TPrefab _prefab; private UnityPool _pool; private void Awake() @@ -37,16 +36,8 @@ private async UniTask StartDeSpawn() _pool?.Return(gameObject); } - public void SetUp(UnityPool pool, TPrefab prefab) - { - _pool = pool; - _prefab = prefab; - } + public void SetUp(UnityPool pool) => _pool = pool; - protected virtual void OnDestroy() - { - _pool?.OnPoolItemDestroy(gameObject); - _prefab?.Release(gameObject); - } + protected virtual void OnDestroy() => _pool?.OnPoolItemDestroy(gameObject); } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs index 5000ac6..9b68b15 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs @@ -96,6 +96,7 @@ public void OnPoolItemDestroy(T instance) return; ReturnPreprocess(instance); _queue.Remove(instance.GetInstanceID()); + _prefab.Release(instance); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Packages/manifest.json b/Packages/manifest.json index 43534fc..d95f48f 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -6,7 +6,7 @@ "com.unity.ide.rider": "3.0.24", "com.unity.ide.visualstudio": "2.0.18", "com.unity.ide.vscode": "1.2.5", - "com.unity.render-pipelines.universal": "14.0.8", + "com.unity.render-pipelines.universal": "12.1.12", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", "com.unity.timeline": "1.7.5", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 5d4d5f6..fde5219 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -31,7 +31,7 @@ "url": "https://packages.unity.com" }, "com.unity.burst": { - "version": "1.8.7", + "version": "1.8.4", "depth": 1, "source": "registry", "dependencies": { @@ -79,25 +79,24 @@ "url": "https://packages.unity.com" }, "com.unity.render-pipelines.core": { - "version": "14.0.8", + "version": "12.1.12", "depth": 1, "source": "builtin", "dependencies": { "com.unity.ugui": "1.0.0", "com.unity.modules.physics": "1.0.0", - "com.unity.modules.terrain": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0" } }, "com.unity.render-pipelines.universal": { - "version": "14.0.8", + "version": "12.1.12", "depth": 0, "source": "builtin", "dependencies": { "com.unity.mathematics": "1.2.1", "com.unity.burst": "1.8.4", - "com.unity.render-pipelines.core": "14.0.8", - "com.unity.shadergraph": "14.0.8" + "com.unity.render-pipelines.core": "12.1.12", + "com.unity.shadergraph": "12.1.12" } }, "com.unity.scriptablebuildpipeline": { @@ -108,19 +107,19 @@ "url": "https://packages.unity.com" }, "com.unity.searcher": { - "version": "4.9.2", + "version": "4.9.1", "depth": 2, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.shadergraph": { - "version": "14.0.8", + "version": "12.1.12", "depth": 1, "source": "builtin", "dependencies": { - "com.unity.render-pipelines.core": "14.0.8", - "com.unity.searcher": "4.9.2" + "com.unity.render-pipelines.core": "12.1.12", + "com.unity.searcher": "4.9.1" } }, "com.unity.sysroot": { @@ -347,6 +346,17 @@ "version": "1.0.0", "depth": 0, "source": "builtin", + "dependencies": { + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.uielementsnative": "1.0.0" + } + }, + "com.unity.modules.uielementsnative": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", "dependencies": { "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0", diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index ad76be6..c3cc114 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -5,8 +5,14 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 m_Scenes: - - enabled: 1 + - enabled: 0 path: Assets/Scenes/SampleScene.unity guid: 2cda990e2423bbf4892e6590ba056729 + - enabled: 1 + path: Assets/PoolSample/AddressablePools/AddressGameObjectPool_1.unity + guid: f304d0ee1f4f44064b073bf0d64062fb + - enabled: 1 + path: Assets/PoolSample/GameObjectPools/GameObjectPool.unity + guid: 022376461a79a4b7e8bbb68b56ba2d96 m_configObjects: com.unity.addressableassets: {fileID: 11400000, guid: a4ed3d350d7e25f4ea915e3071c5af7b, type: 2} From 054a48962ec22e0876859f5a72829fae25d197b3 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 6 Feb 2024 10:08:19 +0700 Subject: [PATCH 32/35] Update PoolItem.cs --- .../GameObjectLazyPool/Items/PoolItem.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs index a0515c2..b7776e0 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Items/PoolItem.cs @@ -2,7 +2,6 @@ using Cysharp.Threading.Tasks; using UnityEngine; using ZBase.Foundation.Pooling.UnityPools; -using Object = UnityEngine.Object; namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { From 7ede4aba98c55c5d80aea3b00184f27c2db08ee7 Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 6 Feb 2024 10:15:06 +0700 Subject: [PATCH 33/35] Update UniqueQueue{TKey,TValue}.cs --- .../Foundation/Common/UniqueQueue{TKey,TValue}.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs index 32a4b4e..8812242 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/Foundation/Common/UniqueQueue{TKey,TValue}.cs @@ -53,7 +53,7 @@ public bool TryDequeue(out TValue value) return false; } - public void Remove(TKey key) => this._unique.Remove(key, out _); + internal void Remove(TKey key) => this._unique.Remove(key, out _); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TKey key) From ef5aa100ef710d24f2077579f3e4b6f4f2f20a2f Mon Sep 17 00:00:00 2001 From: DuyCa Date: Tue, 6 Feb 2024 10:36:17 +0700 Subject: [PATCH 34/35] Clean --- .../Foundation/Pools/AssetRefGameObjectItemPool.cs | 11 +---------- .../Foundation/Pools/GameObjectItemPool.cs | 7 ------- .../GlobalPools/GlobalAssetRefGameObjectPool.cs | 5 +++-- .../GlobalPools/GlobalGameObjectPool.cs | 5 +++-- .../UnityPools/Pools/GameObjectPool{TPrefab}.cs | 2 ++ .../UnityPools/Pools/UnityPool{T,TPrefab}.cs | 6 ++++-- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs index d8f15eb..19b9e51 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/AssetRefGameObjectItemPool.cs @@ -1,13 +1,10 @@ -using System; -using UnityEngine; +using UnityEngine; using ZBase.Foundation.Pooling.AddressableAssets; namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public class AssetRefGameObjectItemPool : AssetRefGameObjectPool { - internal event Action OnReturn; - public AssetRefGameObjectItemPool(AssetRefGameObjectPrefab prefab) : base(prefab) { } @@ -19,11 +16,5 @@ protected override void ProcessNewInstance(GameObject instance) poolItem = instance.AddComponent(); poolItem.SetUp(this); } - - protected override void ReturnPreprocess(GameObject instance) - { - base.ReturnPreprocess(instance); - OnReturn?.Invoke(instance); - } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs index 9c09e34..f3be035 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs @@ -7,7 +7,6 @@ namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool { public sealed class GameObjectItemPool : GameObjectPool { - internal event Action OnReturn; internal event Action OnPoolEmpty; private readonly List _poolItems = new(); @@ -31,11 +30,5 @@ private void OnItemDestroy(GameObject instance) if(this._poolItems.Count == 0) OnPoolEmpty?.Invoke(this); } - - protected override void ReturnPreprocess(GameObject instance) - { - base.ReturnPreprocess(instance); - OnReturn?.Invoke(instance); - } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs index 1b9a91a..85551bb 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs @@ -39,7 +39,8 @@ public async UniTask Rent(AssetRefGameObjectPrefab gameObjectReferen if (!_pools.TryGetValue(gameObjectReference, out var pool)) { pool = new AssetRefGameObjectItemPool(gameObjectReference); - pool.OnReturn += OnReturnToPool; + pool.OnItemDestroyAction += RemoveTrackingItem; + pool.OnReturnAction += RemoveTrackingItem; this._pools.Add(gameObjectReference, pool); } GameObject item = await pool.Rent(); @@ -69,7 +70,7 @@ public void ReleaseInstances(int keep, System.Action onReleased = nu pool.ReleaseInstances(keep, onReleased); } - private void OnReturnToPool(GameObject gameObject) => _dicTrackingInstancePools.Remove(gameObject.GetInstanceID()); + private void RemoveTrackingItem(GameObject gameObject) => _dicTrackingInstancePools.Remove(gameObject.GetInstanceID()); public void Dispose() { diff --git a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs index 4128777..d910533 100644 --- a/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs +++ b/Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs @@ -28,7 +28,8 @@ public async UniTask Rent(GameObjectPrefab gameObjectReference) if (gameObjectReference.Source.scene.IsValid()) throw new Exception($"Non Prefab not supported {gameObjectReference.Source.name}"); pool = new GameObjectItemPool(gameObjectReference); - pool.OnReturn += OnReturnToPool; + pool.OnReturnAction += RemoveTrackingItem; + pool.OnItemDestroyAction += RemoveTrackingItem; pool.OnPoolEmpty += OnPoolEmpty; this._pools.Add(instanceID, pool); } @@ -92,7 +93,7 @@ private void RemoveCacheKey(int poolID) } } - private void OnReturnToPool(GameObject gameObject) => + private void RemoveTrackingItem(GameObject gameObject) => this._dicTrackingInstancePools.Remove(gameObject.GetInstanceID()); public void Dispose() diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs index 2dc2744..ee95fe4 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs @@ -8,6 +8,7 @@ namespace ZBase.Foundation.Pooling.UnityPools public class GameObjectPool : UnityPool where TPrefab : IPrefab { [SerializeField] private bool _dontApplyPrefabParentOnReturn; + public event Action OnReturnAction; public GameObjectPool() { @@ -34,6 +35,7 @@ protected override void ReturnPreprocess(GameObject instance) instance.SetActive(false); if (_dontApplyPrefabParentOnReturn == false && Prefab != null) instance.transform.SetParent(Prefab.Parent); + OnReturnAction?.Invoke(instance); } } } \ No newline at end of file diff --git a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs index 9b68b15..9e801ce 100644 --- a/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs +++ b/Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs @@ -10,6 +10,8 @@ namespace ZBase.Foundation.Pooling.UnityPools public class UnityPool : IUnityPool, IShareable, IDisposable where T : UnityEngine.Object where TPrefab : IPrefab { + public event Action OnItemDestroyAction; + private readonly UniqueQueue _queue; [SerializeField] private TPrefab _prefab; @@ -90,13 +92,13 @@ public void Return(T instance) _queue.TryEnqueue(instance.GetInstanceID(), instance); } - public void OnPoolItemDestroy(T instance) + public virtual void OnPoolItemDestroy(T instance) { if (!instance) return; - ReturnPreprocess(instance); _queue.Remove(instance.GetInstanceID()); _prefab.Release(instance); + OnItemDestroyAction?.Invoke(instance); } [MethodImpl(MethodImplOptions.AggressiveInlining)] From ed466272bec3d1c4d1ca3decfa53f402a2586e8f Mon Sep 17 00:00:00 2001 From: DuyCa Date: Wed, 7 Feb 2024 09:29:06 +0700 Subject: [PATCH 35/35] Update package.json --- Packages/ZBase.Foundation.Pooling/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/ZBase.Foundation.Pooling/package.json b/Packages/ZBase.Foundation.Pooling/package.json index f097423..a33521a 100644 --- a/Packages/ZBase.Foundation.Pooling/package.json +++ b/Packages/ZBase.Foundation.Pooling/package.json @@ -1,9 +1,9 @@ { "name": "com.zbase.foundation.pooling", "displayName": "ZBase.Foundation.Pooling", - "version": "2.3.9", + "version": "2.3.10", "unity": "2021.3", - "documentationUrl": "https://github.com/Zitga-Tech/ZBase.Foundation.Pooling/blob/main/README.md", + "documentationUrl": "https://github.com/WolffunGame/Unity.Pooling/blob/main/README.md", "dependencies": { "com.cysharp.unitask": "2.3.3", "com.zbase.collections.pooled": "2.8.1"