using System.Collections.Generic; using BehaviorDesigner.Runtime; using Cysharp.Threading.Tasks; using Framework; namespace Gameplay.BT { public partial class BTImplement { private Dictionary> _behaviorPoolDic = new (); private Dictionary _loadedRecord = new (); public async UniTask PreLoadAI(HashSet aiNames, int initCount) { foreach (var behaviorName in aiNames) { if (_behaviorPoolDic.ContainsKey(behaviorName)) { continue; } var entry = await LoadBehaviorAsset(behaviorName); var behaviorPool = new ObjectPool( entry.InstanceExternalBehavior, null, null, initCount); _behaviorPoolDic.Add(behaviorName, behaviorPool); } } private void ClearPool() { foreach (var behaviorPool in _behaviorPoolDic.Values) { behaviorPool.Destroy(); } _behaviorPoolDic.Clear(); UnloadAllRes(); } private async UniTask GetBehavior(string behaviorName) { ObjectPool behaviorPool; if (!_behaviorPoolDic.ContainsKey(behaviorName)) { var entry = await LoadBehaviorAsset(behaviorName); if (!_behaviorPoolDic.ContainsKey(behaviorName)) { behaviorPool = new ObjectPool( entry.InstanceExternalBehavior); _behaviorPoolDic.Add(behaviorName, behaviorPool); } } behaviorPool = _behaviorPoolDic[behaviorName]; var behavior = behaviorPool.Get(); return behavior; } private void ReleaseBehavior(string behaviorName, ExternalBehavior behavior) { if (!_behaviorPoolDic.TryGetValue(behaviorName, out var behaviorPool)) return; behaviorPool.Release(behavior); } } }