1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using UnityEngine;
- namespace ET.Client
- {
- public class GameObjectPool : Singleton<GameObjectPool>
- {
- private readonly Dictionary<string, AudioClip> audioPool = new();
- private readonly Dictionary<string, Sprite> cardSpritePool = new();
-
- public List<GameObject> fightCardItemPools = new List<GameObject>();
- public List<GameObject> disCardItemPools = new List<GameObject>();
- public List<GameObject> chatFastItemPools = new List<GameObject>();
- public List<GameObject> chatFaceItemPools = new List<GameObject>();
- public void ClearCache()
- {
- foreach(var ac in audioPool.Values)
- {
- ac.UnloadAudioData();
- }
- audioPool.Clear();
- cardSpritePool.Clear();
- disCardItemPools.Clear();
- fightCardItemPools.Clear();
- chatFastItemPools.Clear();
- }
- public async ETTask<AudioClip> AcquireSound(string abName)
- {
- if(audioPool.TryGetValue(abName, out var ac))
- {
- return ac;
- }
-
- await ResourcesComponentHelper.Instance.LoadAssetAsync(GameUtil.Instance.GetSceneComponent(), "fightsound");
- UnityEngine.Object soundObj = ResourcesComponentHelper.Instance.GetAssetAsync("fightsound", abName);
- var aac = soundObj as AudioClip ;
- aac.LoadAudioData();
- audioPool.Add(abName, aac);
- return aac;
- }
- public async ETTask<Sprite> AcquireSprite(string abName)
- {
- if (cardSpritePool.TryGetValue(abName, out var sp))
- {
- return sp;
- }
- await ResourcesComponentHelper.Instance.LoadAssetAsync(GameUtil.Instance.GetSceneComponent(), "majiangatlas");
- UnityEngine.Object spriteObj = ResourcesComponentHelper.Instance.GetAssetAsync("majiangatlas", abName);
- Texture2D texture = spriteObj as Texture2D;
- var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);
- cardSpritePool.Add(abName, sprite);
- return sprite;
- }
- }
- }
|