using UnityEngine; using Framework; using System; using PhxhSDK; using UnityEngine.UI; public class ItemObj { GameObject _parentGo; Action _acion;//用来做点击事件 int _Id; GameObject _itemGo; public ItemObj(int itemId,GameObject parentObject,Action click=null) { string prefabPath = "Assets/Art/UI/Prefab/MainScene/ShowCharacter/Item.prefab"; _parentGo = parentObject; _acion = click; _Id = itemId; AssetManager.GetSingleton().LoadAssetOnCallBack(prefabPath,OnPrefabLoaded); } private void OnPrefabLoaded(GameObject @object) { if (@object != null) { _itemGo = UnityEngine.Object.Instantiate(@object); _itemGo.transform.parent = _parentGo.transform; _itemGo.transform.localPosition = Vector3.zero; _itemGo.transform.localScale= Vector3.one; AssetManager.Instance.LoadAssetOnCallBack(TableManager.Instance.Tables.Item.Get(_Id).IconPath, OnIconLoaded); } } private void OnIconLoaded(Sprite sprite) { Utils.CommonUtils.GetComponent(_itemGo, "icon").sprite= sprite; } }