186 lines
5.9 KiB
C#
186 lines
5.9 KiB
C#
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
using Games.Mission;
|
|
using Games.Events;
|
|
using GCGame;
|
|
using Module.Log;
|
|
|
|
public class CommonItemContainerItem : UIItemBase
|
|
{
|
|
#region
|
|
|
|
public class ItemInfo
|
|
{
|
|
public int itemID;
|
|
public int itemNum;
|
|
public string itemSprite;
|
|
public string itemQuality;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
public Text m_ItemNum;
|
|
public Text m_ItemName;
|
|
public Image m_ItemImg;
|
|
public Image m_ItemQuality;
|
|
public RectTransform _ItemSlot;
|
|
|
|
protected ItemInfo _ItemParam;
|
|
|
|
public override void Show(Hashtable hash)
|
|
{
|
|
base.Show();
|
|
|
|
_ItemParam = (ItemInfo)hash["InitObj"];
|
|
InitItem(_ItemParam);
|
|
|
|
|
|
}
|
|
|
|
public void InitItem(ItemInfo itemParam)
|
|
{
|
|
_ItemParam = itemParam;
|
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(itemParam.itemID, 0);
|
|
if (commonItem != null && itemParam.itemNum > 0)
|
|
{
|
|
m_ItemImg.gameObject.SetActive(true);
|
|
if(m_ItemNum != null)
|
|
m_ItemNum.text = Utils.ConvertLargeNumToString(itemParam.itemNum);
|
|
if(m_ItemName != null)
|
|
m_ItemName.text = Utils.GetItemNameColor(itemParam.itemID);
|
|
LoadAssetBundle.Instance.SetImageSprite(m_ItemImg, commonItem.Icon);
|
|
LoadAssetBundle.Instance.SetImageSprite(m_ItemQuality, GCGame.Utils.GetItemQualityFrame(commonItem));
|
|
if (commonItem.QualityEffect > 0)
|
|
{
|
|
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, m_ItemImg.transform);
|
|
}
|
|
else
|
|
{
|
|
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, m_ItemImg.transform);
|
|
}
|
|
|
|
}
|
|
else if (!string.IsNullOrEmpty(itemParam.itemSprite))
|
|
{
|
|
m_ItemImg.gameObject.SetActive(true);
|
|
if (m_ItemNum != null)
|
|
m_ItemNum.text = Utils.ConvertLargeNumToString(itemParam.itemNum);
|
|
LoadAssetBundle.Instance.SetImageSprite(m_ItemImg, itemParam.itemSprite);
|
|
LoadAssetBundle.Instance.SetImageSprite(m_ItemQuality, GCGame.Utils.GetItemQualityFrame(0));
|
|
}
|
|
else
|
|
{
|
|
m_ItemImg.gameObject.SetActive(false);
|
|
if (m_ItemNum != null)
|
|
m_ItemNum.text = "";
|
|
}
|
|
}
|
|
|
|
public override void OnItemClick()
|
|
{
|
|
if (_ClickEvent == null)
|
|
{
|
|
if (_ItemParam == null)
|
|
return;
|
|
ItemTooltipsLogic.ShowItemTooltip(_ItemParam.itemID, ItemTooltipsLogic.ShowType.Info, transform.position);
|
|
}
|
|
else
|
|
{
|
|
base.OnItemClick();
|
|
}
|
|
}
|
|
|
|
#region quality effect
|
|
|
|
private static List<Transform> _WaittingBinds = new List<Transform>();
|
|
public static string _BindEffecName = "QualityEffect";
|
|
private const string _effectParentHash = "EffectParent";
|
|
|
|
// 注意: 临时修改需求,狂化目前不会控制显示。
|
|
// 但是现在仍然用 isFrenzy == true 控制特效。量大待改
|
|
public static void ShowQualityEffect(bool isFrenzy, int effectID, Transform effectParent)
|
|
{
|
|
if (effectParent == null)
|
|
return;
|
|
|
|
if (isFrenzy)
|
|
{
|
|
Tab_Effect tab = TableManager.GetEffectByID(effectID, 0);
|
|
if (tab == null)
|
|
{
|
|
LogModule.ErrorLog("No effect by id : {0} in CommonItemTipsSlot", 7405);
|
|
return;
|
|
}
|
|
var bindTran = effectParent.Find(_BindEffecName);
|
|
if (bindTran != null)
|
|
{
|
|
|
|
bindTran.gameObject.SetActive(true);
|
|
bindTran.gameObject.transform.localPosition = Vector3.zero;
|
|
float scale = (effectParent as RectTransform).rect.width / 72 * 1.0f;
|
|
bindTran.transform.localScale = new Vector3(scale, scale, scale);
|
|
}
|
|
else
|
|
{
|
|
if (!_WaittingBinds.Contains(effectParent))
|
|
{
|
|
LoadAssetBundle.Instance.LoadGameObject(LoadAssetBundle.BUNDLE_PATH_EFFECT, tab.Path,
|
|
(string assetName, GameObject assetItem, Hashtable hashTable) =>
|
|
{
|
|
if (assetItem != null)
|
|
{
|
|
GameManager.gameManager.StartCoroutine(SetEffect(assetItem, effectParent));
|
|
}
|
|
}, null);
|
|
_WaittingBinds.Add(effectParent);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var bindTran = effectParent.Find(_BindEffecName);
|
|
if (bindTran != null)
|
|
{
|
|
Destroy(bindTran.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static IEnumerator SetEffect(GameObject assetItem, Transform effectParent)
|
|
{
|
|
var newEffect = Instantiate(assetItem);
|
|
newEffect.transform.SetParent(effectParent, false);
|
|
newEffect.transform.localPosition = Vector3.zero;
|
|
newEffect.name = _BindEffecName;
|
|
//UIParticleSystem script = newEffect.EnsureComponent<UIParticleSystem>();
|
|
//if (script != null)
|
|
//{
|
|
// script.Init();
|
|
//}
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
//var bindTran = effectParent.GetComponent<RectTransform>();
|
|
//var selfTran = newEffect.GetComponent<RectTransform>();
|
|
//if (bindTran != null && selfTran != null)
|
|
//{
|
|
// selfTran.sizeDelta = new Vector2(bindTran.rect.width + 55, bindTran.rect.height + 55);
|
|
//}
|
|
if (assetItem != null && effectParent != null && newEffect != null)
|
|
{
|
|
float scale = (effectParent as RectTransform).rect.width / 72 * 1.0f;
|
|
|
|
newEffect.transform.localScale = new Vector3(scale, scale, scale);
|
|
}
|
|
|
|
_WaittingBinds.Remove(effectParent);
|
|
}
|
|
|
|
#endregion
|
|
}
|