2023-12-13 16:51:07 +08:00
|
|
|
|
using cfg.ActorCfg;
|
2023-12-22 14:12:25 +08:00
|
|
|
|
using cfg.item;
|
2023-12-13 16:51:07 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Framework;
|
2023-12-05 12:49:29 +08:00
|
|
|
|
using Gameplay;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using PhxhSDK;
|
2023-12-13 16:51:07 +08:00
|
|
|
|
using System;
|
2023-12-22 14:12:25 +08:00
|
|
|
|
using TMPro;
|
2023-12-13 16:51:07 +08:00
|
|
|
|
using UnityEngine;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
public class ItemObj
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject _parentGo;
|
2023-12-13 16:51:07 +08:00
|
|
|
|
Action _action;//用来做点击事件
|
2023-10-19 15:00:19 +08:00
|
|
|
|
int _Id;
|
|
|
|
|
|
GameObject _itemGo;
|
2023-12-13 16:51:07 +08:00
|
|
|
|
DataItem Cfg;
|
|
|
|
|
|
Button clickBtn;
|
|
|
|
|
|
UIType _type;
|
2023-12-22 14:12:25 +08:00
|
|
|
|
int count=0;
|
2023-12-13 16:51:07 +08:00
|
|
|
|
|
|
|
|
|
|
public enum interactiveType
|
|
|
|
|
|
{
|
|
|
|
|
|
normail,
|
|
|
|
|
|
selected,
|
|
|
|
|
|
gray,
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-18 19:02:27 +08:00
|
|
|
|
public enum UIType//测试,正式美术图出来后弃用
|
2023-12-13 16:51:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
cultivate,
|
|
|
|
|
|
mail,
|
2024-01-08 13:13:35 +08:00
|
|
|
|
shop,
|
2023-12-13 16:51:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-23 15:07:04 +08:00
|
|
|
|
|
|
|
|
|
|
//美术没出图前都用这
|
|
|
|
|
|
public ItemObj(int itemId, GameObject parentObject, UIType uIType, int itemCount = 0)
|
2023-12-13 16:51:07 +08:00
|
|
|
|
{
|
2024-01-23 15:07:04 +08:00
|
|
|
|
InitData(itemId, parentObject, itemCount );
|
|
|
|
|
|
_type = uIType;
|
|
|
|
|
|
}
|
2023-12-22 14:12:25 +08:00
|
|
|
|
|
2023-12-13 16:51:07 +08:00
|
|
|
|
|
2024-01-23 15:07:04 +08:00
|
|
|
|
//现在仅giftcode使用,后面改
|
|
|
|
|
|
public ItemObj(int itemId, GameObject parentObject)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitData(itemId, parentObject);
|
2023-12-13 16:51:07 +08:00
|
|
|
|
}
|
2024-01-23 15:07:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-12-13 16:51:07 +08:00
|
|
|
|
public async UniTask Init()
|
|
|
|
|
|
{
|
2024-01-23 15:07:04 +08:00
|
|
|
|
await LoadPrefabTest();
|
2024-01-19 19:13:27 +08:00
|
|
|
|
RefreshDetail();
|
2023-12-13 16:51:07 +08:00
|
|
|
|
}
|
2023-12-22 14:12:25 +08:00
|
|
|
|
|
2024-01-19 19:13:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-01-23 15:07:04 +08:00
|
|
|
|
|
|
|
|
|
|
private async UniTask LoadPrefabTest()
|
2024-01-18 15:45:51 +08:00
|
|
|
|
{
|
2024-01-23 15:07:04 +08:00
|
|
|
|
string prefabPath = "Assets/Art/UI/Prefab/MainScene/ShowCharacter/ItemObj.prefab";
|
|
|
|
|
|
GameObject go= await AssetManager.GetSingleton().LoadAssetAsync<GameObject>(prefabPath);
|
|
|
|
|
|
if (go == null)
|
2024-01-18 15:45:51 +08:00
|
|
|
|
{
|
2024-01-23 15:07:04 +08:00
|
|
|
|
DebugUtil.LogError("");
|
2024-01-18 15:45:51 +08:00
|
|
|
|
}
|
2024-01-23 15:07:04 +08:00
|
|
|
|
_itemGo = UnityEngine.Object.Instantiate(go);
|
2023-12-13 16:51:07 +08:00
|
|
|
|
_itemGo.transform.SetParent(_parentGo.transform);
|
|
|
|
|
|
_itemGo.transform.localPosition = Vector3.zero;
|
|
|
|
|
|
_itemGo.transform.localScale = Vector3.one;
|
2024-01-19 19:13:27 +08:00
|
|
|
|
RefreshDetail();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-23 15:07:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-01-19 19:13:27 +08:00
|
|
|
|
private void RefreshDetail()
|
|
|
|
|
|
{
|
2024-01-18 13:57:01 +08:00
|
|
|
|
CommonUtils.GetGameObject(_itemGo, "test2").SetActive(_type == UIType.mail);
|
|
|
|
|
|
CommonUtils.GetGameObject(_itemGo, "test1").SetActive(_type == UIType.cultivate);
|
|
|
|
|
|
CommonUtils.GetGameObject(_itemGo, "test3").SetActive(_type == UIType.shop);
|
|
|
|
|
|
|
2023-12-22 14:12:25 +08:00
|
|
|
|
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test2/icon/Text_StuffNum").text = count.ToString(); ;
|
2024-01-08 13:13:35 +08:00
|
|
|
|
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test2/icon/Text_StuffNum").text = count.ToString(); ;
|
2024-01-08 20:00:27 +08:00
|
|
|
|
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test3/Image_Bar/Text_ItemNum").text = count.ToString(); ;
|
2024-01-08 13:13:35 +08:00
|
|
|
|
|
2024-01-18 19:02:27 +08:00
|
|
|
|
CommonUtils.GetGameObject(_itemGo, "DebugID").SetActive(DisplayIDForCeHua.IsDisplayID);
|
|
|
|
|
|
CommonUtils.GetComponent<TMP_Text>(_itemGo, "DebugID").text = _Id.ToString();
|
2023-12-13 16:51:07 +08:00
|
|
|
|
}
|
2024-01-23 15:07:04 +08:00
|
|
|
|
private void InitData(int itemId,GameObject paObj,int itemCount=0)
|
2023-12-13 16:51:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
_parentGo = paObj;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
_Id = itemId;
|
2024-01-23 15:07:04 +08:00
|
|
|
|
count= itemCount;
|
2023-12-13 16:51:07 +08:00
|
|
|
|
Cfg = TableManager.GetSingleton().Tables.Item.GetOrDefault(itemId);
|
|
|
|
|
|
if(Cfg==null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("物品表没有配置id为{0}的物品,请检查配置", itemId);
|
2023-12-22 14:12:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-23 15:07:04 +08:00
|
|
|
|
|
2023-12-13 16:51:07 +08:00
|
|
|
|
|
|
|
|
|
|
private void OnClickBtnClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_action != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_action.Invoke();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//下面写物品默认点击事件
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-13 16:51:07 +08:00
|
|
|
|
public void RefreshGoods(GameObject itemGo,int itemId)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2023-12-13 16:51:07 +08:00
|
|
|
|
switch (Cfg.Type)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2023-12-13 16:51:07 +08:00
|
|
|
|
case ItemType.Normal:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ItemType.Character:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ItemType.Useable:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ItemType.Vehicle:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2023-12-13 16:51:07 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2024-01-23 15:07:04 +08:00
|
|
|
|
//相关设置
|
|
|
|
|
|
public void SetScale(float scale)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (_itemGo == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("itemobj害没生成,调整下顺序呢");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
_itemGo.transform.localScale = new Vector3(scale, scale, scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-13 16:51:07 +08:00
|
|
|
|
public void SetState(interactiveType interType)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (interType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case interactiveType.normail:
|
|
|
|
|
|
CommonUtils.GetGameObject(_itemGo, "state/Gray").SetActive(false);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-12-13 16:51:07 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case interactiveType.selected:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case interactiveType.gray:
|
|
|
|
|
|
CommonUtils.GetGameObject(_itemGo, "state/Gray").SetActive(true);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private void OnIconLoaded(Sprite sprite)
|
|
|
|
|
|
{
|
2023-12-13 16:51:07 +08:00
|
|
|
|
CommonUtils.GetComponent<Image>(_itemGo, "test1/icon").sprite= sprite;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|