日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UGUI图集管理

發布時間:2025/7/14 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UGUI图集管理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 using UnityEngine; 2 using System.Collections; 3 using System.Collections.Generic; 4 //紋理圖集加載管理 5 public class PPTextureManage : MonoBehaviour { 6 private static GameObject m_pMainObject; 7 private static PPTextureManage m_pContainer = null; 8 public static PPTextureManage getInstance(){ 9 if(m_pContainer == null){ 10 m_pContainer = m_pMainObject.GetComponent<PPTextureManage> (); 11 } 12 return m_pContainer; 13 } 14 private Dictionary<string, Object[]> m_pAtlasDic;//圖集的集合 15 void Awake(){ 16 initData (); 17 } 18 private void initData(){ 19 PPTextureManage.m_pMainObject = gameObject; 20 m_pAtlasDic = new Dictionary<string, Object[]> (); 21 } 22 // Use this for initialization 23 void Start () { 24 } 25 //加載圖集上的一個精靈 26 public Sprite LoadAtlasSprite(string _spriteAtlasPath,string _spriteName){ 27 Sprite _sprite = FindSpriteFormBuffer (_spriteAtlasPath,_spriteName); 28 if (_sprite == null) { 29 Object[] _atlas = Resources.LoadAll (_spriteAtlasPath); 30 m_pAtlasDic.Add (_spriteAtlasPath,_atlas); 31 _sprite = SpriteFormAtlas (_atlas,_spriteName); 32 } 33 return _sprite; 34 } 35 //刪除圖集緩存 36 public void DeleteAtlas(string _spriteAtlasPath){ 37 if (m_pAtlasDic.ContainsKey (_spriteAtlasPath)) { 38 m_pAtlasDic.Remove (_spriteAtlasPath); 39 } 40 } 41 //從緩存中查找圖集,并找出sprite 42 private Sprite FindSpriteFormBuffer(string _spriteAtlasPath,string _spriteName){ 43 if (m_pAtlasDic.ContainsKey (_spriteAtlasPath)) { 44 Object[] _atlas = m_pAtlasDic[_spriteAtlasPath]; 45 Sprite _sprite = SpriteFormAtlas(_atlas,_spriteName); 46 return _sprite; 47 } 48 return null; 49 } 50 //從圖集中,并找出sprite 51 private Sprite SpriteFormAtlas(Object[] _atlas,string _spriteName){ 52 for (int i = 0; i < _atlas.Length; i++) { 53 if (_atlas [i].GetType () == typeof(UnityEngine.Sprite)) { 54 if(_atlas [i].name == _spriteName){ 55 return (Sprite)_atlas [i]; 56 } 57 } 58 } 59 Debug.LogWarning ("圖片名:"+_spriteName+";在圖集中找不到"); 60 return null; 61 } 62 }

?

轉載于:https://www.cnblogs.com/LLWH134/p/8176369.html

總結

以上是生活随笔為你收集整理的UGUI图集管理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。