清warning,整理载具升级相关代码,升级材料图标显示
parent
342f515170
commit
344590f7d9
|
|
@ -65,8 +65,8 @@ public class UIGiftCodeAwardsController: UIWindow
|
|||
{
|
||||
itemParent.SetActive(true);
|
||||
|
||||
ItemObj itemObj = new ItemObj((int)mItems.Ids[i], CommonUtils.GetGameObject(itemParent, "item"));
|
||||
await itemObj.Init();
|
||||
ItemObj itemObj = await ItemObj.InitItemObjFromPrefab((int)mItems.Ids[i], CommonUtils.GetGameObject(itemParent, "item"));
|
||||
//await itemObj.Init();
|
||||
//CommonUtils.GetComponent<TMP_Text>(itemParent, "value").text = mItems.Counts[i].ToString();
|
||||
allName += TableManager.Instance.Tables.Item.Get((int)mItems.Ids[i]).ID+"X"+ mItems.Counts[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using TMPro;
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ItemObj
|
||||
public class ItemObj : UIGameObjectWrapper
|
||||
{
|
||||
GameObject _parentGo;
|
||||
Action _action;//用来做点击事件
|
||||
|
|
@ -18,7 +18,7 @@ public class ItemObj
|
|||
DataItem Cfg;
|
||||
Button clickBtn;
|
||||
UIType _type;
|
||||
int count=0;
|
||||
int count = 0;
|
||||
|
||||
public enum interactiveType
|
||||
{
|
||||
|
|
@ -36,99 +36,50 @@ public class ItemObj
|
|||
|
||||
|
||||
//美术没出图前都用这
|
||||
public ItemObj(int itemId, GameObject parentObject, UIType uIType, int itemCount = 0)
|
||||
public ItemObj(int itemId, GameObject parentObject, UIType uIType, GameObject go, int itemCount = 0, bool isScale = false) : base(go, isScale)
|
||||
{
|
||||
InitData(itemId, parentObject, itemCount );
|
||||
InitData(itemId, parentObject, itemCount);
|
||||
_type = uIType;
|
||||
}
|
||||
|
||||
|
||||
//现在仅giftcode使用,后面改
|
||||
public ItemObj(int itemId, GameObject parentObject)
|
||||
{
|
||||
InitData(itemId, parentObject);
|
||||
}
|
||||
|
||||
|
||||
public async UniTask Init()
|
||||
{
|
||||
await LoadPrefabTest();
|
||||
RefreshDetail();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private async UniTask LoadPrefabTest()
|
||||
{
|
||||
string prefabPath = "Assets/Art/UI/Prefab/MainScene/ShowCharacter/ItemObj.prefab";
|
||||
GameObject go= await AssetManager.GetSingleton().LoadAssetAsync<GameObject>(prefabPath);
|
||||
if (go == null)
|
||||
{
|
||||
DebugUtil.LogError("");
|
||||
}
|
||||
_itemGo = UnityEngine.Object.Instantiate(go);
|
||||
_itemGo = go;
|
||||
_itemGo.transform.SetParent(_parentGo.transform);
|
||||
_itemGo.transform.localPosition = Vector3.zero;
|
||||
_itemGo.transform.localScale = Vector3.one;
|
||||
RefreshDetail();
|
||||
|
||||
BindButton(FindObj("click"), OnClickBtnClick);
|
||||
}
|
||||
|
||||
|
||||
private void RefreshDetail()
|
||||
public static async UniTask<ItemObj> InitItemObjFromPrefab(int itemId, GameObject parentObject, UIType uIType, int itemCount = 0)
|
||||
{
|
||||
CommonUtils.GetGameObject(_itemGo, "test2").SetActive(_type == UIType.mail);
|
||||
CommonUtils.GetGameObject(_itemGo, "test1").SetActive(_type == UIType.cultivate);
|
||||
CommonUtils.GetGameObject(_itemGo, "test3").SetActive(_type == UIType.shop);
|
||||
|
||||
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test2/icon/Text_StuffNum").text = count.ToString(); ;
|
||||
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test2/icon/Text_StuffNum").text = count.ToString(); ;
|
||||
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test3/Image_Bar/Text_ItemNum").text = count.ToString(); ;
|
||||
|
||||
CommonUtils.GetGameObject(_itemGo, "DebugID").SetActive(DisplayIDForCeHua.IsDisplayID);
|
||||
CommonUtils.GetComponent<TMP_Text>(_itemGo, "DebugID").text = _Id.ToString();
|
||||
GameObject newGo = await LoadPrefabTest();
|
||||
ItemObj itemObj = new ItemObj(itemId, parentObject, uIType, newGo, itemCount);
|
||||
itemObj.IsScaleShow = true;
|
||||
return itemObj;
|
||||
}
|
||||
private void InitData(int itemId,GameObject paObj,int itemCount=0)
|
||||
|
||||
//现在仅giftcode使用,后面改
|
||||
public ItemObj(int itemId, GameObject parentObject, GameObject go, bool isScale = false) : base(go, isScale)
|
||||
{
|
||||
_parentGo = paObj;
|
||||
_Id = itemId;
|
||||
count= itemCount;
|
||||
Cfg = TableManager.GetSingleton().Tables.Item.GetOrDefault(itemId);
|
||||
if(Cfg==null)
|
||||
{
|
||||
DebugUtil.LogError("物品表没有配置id为{0}的物品,请检查配置", itemId);
|
||||
}
|
||||
}
|
||||
|
||||
InitData(itemId, parentObject);
|
||||
_itemGo = go;
|
||||
_itemGo.transform.SetParent(_parentGo.transform);
|
||||
_itemGo.transform.localPosition = Vector3.zero;
|
||||
RefreshDetail();
|
||||
|
||||
private void OnClickBtnClick()
|
||||
BindButton(FindObj("click"), OnClickBtnClick);
|
||||
}
|
||||
public static async UniTask<ItemObj> InitItemObjFromPrefab(int itemId, GameObject parentObject)
|
||||
{
|
||||
if(_action != null)
|
||||
{
|
||||
_action.Invoke();
|
||||
return;
|
||||
}
|
||||
//下面写物品默认点击事件
|
||||
|
||||
GameObject newGo = await LoadPrefabTest();
|
||||
ItemObj itemObj = new ItemObj(itemId, parentObject, newGo);
|
||||
itemObj.IsScaleShow = true;
|
||||
return itemObj;
|
||||
}
|
||||
|
||||
public void RefreshGoods(GameObject itemGo,int itemId)
|
||||
public void AddButtonListener(Action callback)
|
||||
{
|
||||
switch (Cfg.Type)
|
||||
{
|
||||
case ItemType.Normal:
|
||||
break;
|
||||
case ItemType.Character:
|
||||
break;
|
||||
case ItemType.Useable:
|
||||
break;
|
||||
case ItemType.Vehicle:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
_action = callback;
|
||||
}
|
||||
|
||||
//相关设置
|
||||
public void SetScale(float scale)
|
||||
{
|
||||
|
|
@ -157,10 +108,85 @@ public class ItemObj
|
|||
}
|
||||
|
||||
}
|
||||
private void OnIconLoaded(Sprite sprite)
|
||||
|
||||
public void RefreshGoods(GameObject itemGo, int itemId)
|
||||
{
|
||||
CommonUtils.GetComponent<Image>(_itemGo, "test1/icon").sprite= sprite;
|
||||
switch (Cfg.Type)
|
||||
{
|
||||
case ItemType.Normal:
|
||||
break;
|
||||
case ItemType.Character:
|
||||
break;
|
||||
case ItemType.Useable:
|
||||
break;
|
||||
case ItemType.Vehicle:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region 私有方法
|
||||
private static async UniTask<GameObject> LoadPrefabTest()
|
||||
{
|
||||
string prefabPath = "Assets/Art/UI/Prefab/MainScene/ShowCharacter/ItemObj.prefab";
|
||||
GameObject go = await AssetManager.GetSingleton().LoadAssetAsync<GameObject>(prefabPath);
|
||||
if (go == null)
|
||||
{
|
||||
DebugUtil.LogError("");
|
||||
}
|
||||
GameObject ret = UnityEngine.Object.Instantiate(go);
|
||||
|
||||
//_itemGo.transform.SetParent(_parentGo.transform);
|
||||
//ret.transform.localPosition = Vector3.zero;
|
||||
ret.transform.localScale = Vector3.one;
|
||||
//RefreshDetail();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private void RefreshDetail()
|
||||
{
|
||||
CommonUtils.GetGameObject(_itemGo, "test2").SetActive(_type == UIType.mail);
|
||||
CommonUtils.GetGameObject(_itemGo, "test1").SetActive(_type == UIType.cultivate);
|
||||
CommonUtils.GetGameObject(_itemGo, "test3").SetActive(_type == UIType.shop);
|
||||
|
||||
//CommonUtils.GetComponent<TMP_Text>(_itemGo, "test2/icon/Text_StuffNum").text = count.ToString();
|
||||
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test2/icon/Text_StuffNum").text = count.ToString();
|
||||
CommonUtils.GetComponent<TMP_Text>(_itemGo, "test3/Image_Bar/Text_ItemNum").text = count.ToString();
|
||||
|
||||
CommonUtils.GetGameObject(_itemGo, "DebugID").SetActive(DisplayIDForCeHua.IsDisplayID);
|
||||
CommonUtils.GetComponent<TMP_Text>(_itemGo, "DebugID").text = _Id.ToString();
|
||||
|
||||
OnIconLoaded();
|
||||
}
|
||||
private void InitData(int itemId, GameObject paObj, int itemCount = 0)
|
||||
{
|
||||
_parentGo = paObj;
|
||||
_Id = itemId;
|
||||
count = itemCount;
|
||||
Cfg = CategoryManager.Instance.GetItemData(itemId);
|
||||
if (Cfg == null)
|
||||
{
|
||||
DebugUtil.LogError("物品表没有配置id为{0}的物品,请检查配置", itemId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnClickBtnClick()
|
||||
{
|
||||
if (_action != null)
|
||||
{
|
||||
_action.Invoke();
|
||||
return;
|
||||
}
|
||||
//下面写物品默认点击事件
|
||||
|
||||
}
|
||||
private async void OnIconLoaded()
|
||||
{
|
||||
var spritePath = CommonUtils.GetItemPath(_Id);
|
||||
CommonUtils.GetComponent<Image>(_itemGo, string.Format("test{0}/icon", (int)_type + 1)).sprite = await LoadAssetAsync<Sprite>(spritePath);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,17 +27,6 @@ using ScrollView = PhxhSDK.PhxhScrollView;
|
|||
|
||||
public class UI_BuyEnergyController : UIWindow
|
||||
{
|
||||
#region enum
|
||||
/// <summary>
|
||||
/// 补充体力方式 ( 与窗口内顺序对应 )
|
||||
/// </summary>
|
||||
//public enum RechargeMethod
|
||||
//{
|
||||
// Recharge_byItem,
|
||||
// Recharge_byCurrency
|
||||
//}//TODO 考虑后续以json方式存储补充体力方式信息
|
||||
#endregion
|
||||
|
||||
#region Temporary_Constant
|
||||
private const int DEFAULT_USAGE_AMOUNT = 1;//默认使用数目,使用时的最小量
|
||||
#endregion
|
||||
|
|
@ -250,6 +239,7 @@ public class UI_BuyEnergyController : UIWindow
|
|||
//invoke when open window
|
||||
protected override void OnShowWindow(object data = null)
|
||||
{
|
||||
base.OnShowWindow(data);
|
||||
bool chooseMethod = false;
|
||||
for (int i = 0; i < EnergyManager.Instance.ItemIDBuyEnergyCount() - 1; i++)
|
||||
{
|
||||
|
|
@ -283,13 +273,13 @@ public class UI_BuyEnergyController : UIWindow
|
|||
//invoke when reload window
|
||||
protected override void OnReloadWindow(object data = null)
|
||||
{
|
||||
|
||||
}
|
||||
base.OnReloadWindow(data);
|
||||
}
|
||||
|
||||
//invoke when close window
|
||||
protected override void OnHideWindow()
|
||||
{
|
||||
|
||||
base.OnHideWindow();
|
||||
}
|
||||
|
||||
//invoke when destroy
|
||||
|
|
|
|||
|
|
@ -770,14 +770,18 @@ public class UI_CategoryController : UIWindow
|
|||
}
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 道具来源数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
int AcquisitionAmount()
|
||||
{
|
||||
if (dataItem != null && dataItem.Acquisition!=null)
|
||||
if (dataItem != null && dataItem.Acquisition != null)
|
||||
{
|
||||
return dataItem.Acquisition.Length;
|
||||
}
|
||||
|
||||
DebugUtil.LogWarning("no aqusition!id: " + ID);
|
||||
DebugUtil.LogError("无道具信息或未配置道具来源! 道具id: " + ID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -425,9 +425,17 @@ public class UI_VehicleLevelUpController : UIWindow
|
|||
|
||||
if (hpLvUpTime + attackLvUpTime + defenseLvUpTime != 0 && _upGradeDic.Count > 0)
|
||||
{
|
||||
var typeArray = _upGradeDic.Keys.ToArray();
|
||||
var countArray = _upGradeDic.Values.ToArray();
|
||||
NetHelper.VehicleUpgrade((uint)mVehicleData.Cfg.ID, typeArray, countArray);
|
||||
if (CheckMaterialEnough())
|
||||
{
|
||||
var typeArray = _upGradeDic.Keys.ToArray();
|
||||
var countArray = _upGradeDic.Values.ToArray();
|
||||
NetHelper.VehicleUpgrade((uint)mVehicleData.Cfg.ID, typeArray, countArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("BuyEnergy_failed"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -548,16 +556,22 @@ public class UI_VehicleLevelUpController : UIWindow
|
|||
GetSumCostItem(ref costItems);
|
||||
for (int i = 0; i < Material_count; i++)
|
||||
{
|
||||
//TODO 这里可以做成复用不用销毁原来obj
|
||||
GameObject itemParent = FindObj(string.Format("Image_BG/UI_Materals/{0}", (i + 1).ToString()));
|
||||
CommonUtils.DestoryAllChildGameObject(CommonUtils.GetGameObject(itemParent, "item"));
|
||||
|
||||
if ((i + 1) <= costItems.Count)
|
||||
{
|
||||
itemParent.SetActive(true);
|
||||
|
||||
ItemObj itemObj = new ItemObj(costItems[i].Id, CommonUtils.GetGameObject(itemParent, "item"),
|
||||
int itemID = (int)costItems[i].Id;
|
||||
ItemObj itemObj = await ItemObj.InitItemObjFromPrefab(itemID, CommonUtils.GetGameObject(itemParent, "item"),
|
||||
ItemObj.UIType.cultivate);
|
||||
await itemObj.Init();
|
||||
//await itemObj.Init();
|
||||
itemObj.AddButtonListener(() =>
|
||||
{
|
||||
DebugUtil.Log("点击物品ID: " + itemID);
|
||||
});
|
||||
//TODO 数字显示是不是反了
|
||||
CommonUtils.GetComponent<TMP_Text>(itemParent, "value").text =
|
||||
Actor.Instance.Item.GetItemCount(costItems[i].Id) + "/" + costItems[i].Count;
|
||||
bool isFUll = Actor.Instance.Item.GetItemCount(costItems[i].Id) >= costItems[i].Count;
|
||||
|
|
@ -593,10 +607,10 @@ public class UI_VehicleLevelUpController : UIWindow
|
|||
if ((i + 1) <= costItems.Count)
|
||||
{
|
||||
itemParent.SetActive(true);
|
||||
|
||||
int itemCount = (int)CategoryManager.Instance.GetItemCount(costItems[i].Id);
|
||||
CommonUtils.GetComponent<TMP_Text>(itemParent, "value").text =
|
||||
Actor.Instance.Item.GetItemCount(costItems[i].Id) + "/" + costItems[i].Count;
|
||||
bool isFUll = Actor.Instance.Item.GetItemCount(costItems[i].Id) >= costItems[i].Count;
|
||||
itemCount + "/" + costItems[i].Count;
|
||||
bool isFUll = itemCount >= costItems[i].Count;
|
||||
CommonUtils.GetGameObject(itemParent, "Image_Red").SetActive(!isFUll);
|
||||
CommonUtils.GetGameObject(itemParent, "Image_Green02").SetActive(isFUll);
|
||||
}
|
||||
|
|
@ -641,6 +655,19 @@ public class UI_VehicleLevelUpController : UIWindow
|
|||
CommonUtils.ItemXNumber(dataVehicleUpgradeDefense.CostItems[i], defenseLvUpTime));
|
||||
}
|
||||
}
|
||||
private bool CheckMaterialEnough()
|
||||
{
|
||||
List<cfg.item.ItemCounts> costItems = new List<cfg.item.ItemCounts>();
|
||||
GetSumCostItem(ref costItems);
|
||||
for (int i = 0; i < costItems.Count; i++)
|
||||
{
|
||||
if (CategoryManager.Instance.GetItemCount(costItems[i].Id) < costItems[i].Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsMaxLevel()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue