123 lines
3.5 KiB
C#
123 lines
3.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using GCGame.Table;
|
|
using UnityEngine.EventSystems;
|
|
using System;
|
|
|
|
public class ChildSkillCommonItem :MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler{
|
|
public Image _ItemQuality;
|
|
public Image _ItemIcon;
|
|
public Text _ItemName;
|
|
public Text _ItemDesc;
|
|
public Text _ItemCount;
|
|
|
|
public GameObject _ItemGetBtn;
|
|
public GameObject _Mark;
|
|
|
|
private int _ItemId = -1;
|
|
private int _CurTotalCount = 0; //客户端自检使用
|
|
public void InitItemInfo(int itemId)
|
|
{
|
|
_ItemId = itemId;
|
|
var commonItem = TableManager.GetCommonItemByID(_ItemId, 0);
|
|
if(commonItem == null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
Debug.LogError("CommonItem is null : " + _ItemId);
|
|
return;
|
|
}
|
|
|
|
this.gameObject.SetActive(true);
|
|
LoadAssetBundle.Instance.SetImageSprite(_ItemQuality, GCGame.Utils.GetItemQualityFrame(commonItem));
|
|
LoadAssetBundle.Instance.SetImageSprite(_ItemIcon, commonItem.Icon);
|
|
_ItemName.text = commonItem.Name;
|
|
_ItemDesc.text = commonItem.Tips;
|
|
_CurTotalCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_ItemId);
|
|
_ItemGetBtn.SetActive(_CurTotalCount <= 0);
|
|
|
|
_ItemCount.text = _CurTotalCount + "";
|
|
}
|
|
|
|
public void OnItemGetBtn()
|
|
{
|
|
ItemTooltipsLogic.ShowItemTooltip(_ItemId, ItemTooltipsLogic.ShowType.Info, _ItemIcon.transform.position);
|
|
}
|
|
|
|
public void OnItemClick()
|
|
{
|
|
ReqUseItem();
|
|
}
|
|
|
|
public void ReqUseItem()
|
|
{
|
|
var backPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|
|
|
if(backPack == null)
|
|
{
|
|
Debug.LogError("backPack is null");
|
|
return;
|
|
}
|
|
|
|
ReqChildrenUseItem req = new ReqChildrenUseItem();
|
|
req.itemGuid = (long)backPack.GetItemGuidByDataID(_ItemId);
|
|
req.useCount = 1;
|
|
req.SendMsg();
|
|
}
|
|
|
|
public void ShowMask(bool isShow)
|
|
{
|
|
_Mark.SetActive(isShow);
|
|
}
|
|
|
|
private bool _HasRefreshItemCount = true;
|
|
public void RefreshItemCount()
|
|
{
|
|
_CurTotalCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_ItemId);
|
|
_ItemCount.EnsureVal(_CurTotalCount + "");
|
|
_ItemGetBtn.SetActive(_CurTotalCount <= 0);
|
|
_HasRefreshItemCount = true;
|
|
}
|
|
|
|
#region 快速连续使用物品
|
|
private float _ClickCountTime = 0.0f;
|
|
private float _ClickContinuteTime = 1.0f; //点击超过时间,则连续使用
|
|
//private float _AutoUseCountTime = 0.0f;
|
|
//private float _AutoUseContinuteTime = 0.1f; //0.1s使用一次物品
|
|
private bool _IsContinutesUse = false;
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
_IsContinutesUse = true;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(_IsContinutesUse)
|
|
{
|
|
_ClickCountTime += Time.deltaTime;
|
|
if (_ClickCountTime >= _ClickContinuteTime)
|
|
{
|
|
if (_HasRefreshItemCount)
|
|
{
|
|
_HasRefreshItemCount = false;
|
|
ReqUseItem();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
_ClickCountTime = 0.0f;
|
|
//_AutoUseCountTime = 0.0f;
|
|
_IsContinutesUse = false;
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
OnItemClick();
|
|
}
|
|
#endregion
|
|
}
|