43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using UnityEngine;
|
|
using Framework;
|
|
using System;
|
|
using Gameplay;
|
|
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<GameObject>(prefabPath,OnPrefabLoaded);
|
|
|
|
}
|
|
|
|
private void OnPrefabLoaded(GameObject @object)
|
|
{
|
|
if (@object != null)
|
|
{
|
|
_itemGo = UnityEngine.Object.Instantiate(@object);
|
|
_itemGo.transform.SetParent( _parentGo.transform);
|
|
_itemGo.transform.localPosition = Vector3.zero;
|
|
_itemGo.transform.localScale= Vector3.one;
|
|
AssetManager.Instance.LoadAssetOnCallBack<Sprite>(TableManager.Instance.Tables.Item.Get(_Id).IconPath, OnIconLoaded);
|
|
}
|
|
}
|
|
|
|
private void OnIconLoaded(Sprite sprite)
|
|
{
|
|
CommonUtils.GetComponent<Image>(_itemGo, "icon").sprite= sprite;
|
|
}
|
|
|
|
|
|
}
|