307 lines
9.9 KiB
C#
307 lines
9.9 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
using UnityEngine.UI;
|
|||
|
using Games.Item;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using GCGame.Table;
|
|||
|
using System.Linq;
|
|||
|
using Games.AnimationModule;
|
|||
|
|
|||
|
public class ShortCutItemControl : MonoBehaviour {
|
|||
|
|
|||
|
// 由于抽奖特殊情形,需要等动画播放完毕后才提示获得物品
|
|||
|
public static bool CanShow = true; // 控制能否显示
|
|||
|
|
|||
|
public static ShortCutItemControl Instance;
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
Instance = null;
|
|||
|
}
|
|||
|
|
|||
|
private List<int> itemGuidList = new List<int>();
|
|||
|
public ulong GetFirstItemID()
|
|||
|
{
|
|||
|
if (GlobalData.MyShortCutItemGuidList!= null
|
|||
|
&& GlobalData.MyShortCutItemGuidList.Count > 0)
|
|||
|
{
|
|||
|
return GlobalData.MyShortCutItemGuidList[0];
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public Image _ItemQuality;
|
|||
|
public Image itemIcon;
|
|||
|
public Button useButton;
|
|||
|
public Button closeButton;
|
|||
|
public Text descText;
|
|||
|
public Text btnDesc;
|
|||
|
|
|||
|
public GameItem m_Item = null;
|
|||
|
public int m_useItemCount = 0;
|
|||
|
public bool isVirtualItem = false;
|
|||
|
|
|||
|
public int m_AnimationId = -1;
|
|||
|
public int m_VirualItemId = -1;
|
|||
|
public Text _Num;
|
|||
|
|
|||
|
public bool InitMyitem()
|
|||
|
{
|
|||
|
ulong itemGuid = GetFirstItemID(); //获取第一个的ID
|
|||
|
if (GlobeVar.IsGUIDValid(itemGuid))
|
|||
|
{
|
|||
|
InitTrueItem(itemGuid); //创建实例化道具
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
GlobalData.MyShortCutItemGuidList.Remove(itemGuid);
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public void InitTrueItem(ulong itemGuid)
|
|||
|
{
|
|||
|
Debug.Log("ShortCutItem.InitTrueItem itemGuid:" + itemGuid);
|
|||
|
if (_Num.gameObject.activeInHierarchy)
|
|||
|
_Num.gameObject.SetActive(false);
|
|||
|
GameItemContainer backPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|||
|
if (backPack == null)
|
|||
|
{
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
int itemId = -1;
|
|||
|
if(backPack.GetItemByGuid(itemGuid) != null)
|
|||
|
{
|
|||
|
itemId = backPack.GetItemByGuid(itemGuid).DataID;
|
|||
|
}else
|
|||
|
{
|
|||
|
if(GlobalData.MyShortCutItemGuidList.Contains(itemGuid))
|
|||
|
GlobalData.MyShortCutItemGuidList.Remove(itemGuid);
|
|||
|
if (!InitMyitem())
|
|||
|
{
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
}
|
|||
|
Debug.Log("ShortCutItem.InitTrueItem itemId:" + itemId);
|
|||
|
|
|||
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(itemId, 0);
|
|||
|
if(commonItem != null)
|
|||
|
{
|
|||
|
//帮会物品处理一下
|
|||
|
if (commonItem.ClassID == 4
|
|||
|
&& (commonItem.SubClassID == 20 || commonItem.SubClassID == 13)
|
|||
|
&& GameManager.gameManager.PlayerDataPool.IsHaveGuild() == false)
|
|||
|
{
|
|||
|
if (GlobalData.MyShortCutItemGuidList.Contains(itemGuid))
|
|||
|
GlobalData.MyShortCutItemGuidList.Remove(itemGuid);
|
|||
|
if (!InitMyitem())
|
|||
|
{
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
return;
|
|||
|
}
|
|||
|
#region 时装图标分男女
|
|||
|
int _PlayerProfession = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession; //获取玩家职业
|
|||
|
if (_PlayerProfession == 0 || _PlayerProfession == 2)
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(itemIcon, commonItem.Icon);//男
|
|||
|
}
|
|||
|
else if (_PlayerProfession == 1 || _PlayerProfession == 3)
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(itemIcon, commonItem.Iconnv); //女
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
//LoadAssetBundle.Instance.SetImageSprite(itemIcon, commonItem.Icon);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ItemQuality, GCGame.Utils.GetItemQualityFrame(commonItem.Quality));
|
|||
|
if (commonItem.QualityEffect > 0)
|
|||
|
{
|
|||
|
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, itemIcon.transform);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, itemIcon.transform);
|
|||
|
}
|
|||
|
|
|||
|
descText.text = commonItem.Name;
|
|||
|
isVirtualItem = false;
|
|||
|
m_Item = GameManager.gameManager.PlayerDataPool.BackPack.GetItemByGuid(itemGuid);
|
|||
|
if (m_Item == null)
|
|||
|
{
|
|||
|
if(GlobalData.MyShortCutItemGuidList.Contains(itemGuid))
|
|||
|
GlobalData.MyShortCutItemGuidList.Remove(itemGuid);
|
|||
|
|
|||
|
if (!InitMyitem())
|
|||
|
{
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
}else
|
|||
|
{
|
|||
|
if(m_Item.StackCount > 1)
|
|||
|
{
|
|||
|
_Num.gameObject.SetActive(true);
|
|||
|
_Num.text = m_Item.StackCount.ToString();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_Num.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (!InitMyitem())
|
|||
|
{
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//虚拟物品非道具 只是显示给客户端看一下就行 具体是功能
|
|||
|
public void initMyVirtualItem(string pathName, string desc, int itemQuality, int animationId, int virualItemId)
|
|||
|
{
|
|||
|
m_VirualItemId = virualItemId;
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(itemIcon, pathName);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ItemQuality, GCGame.Utils.GetItemQualityFrame(itemQuality));
|
|||
|
descText.text = desc; //设置道具的描述
|
|||
|
m_AnimationId = animationId;
|
|||
|
isVirtualItem = true;
|
|||
|
|
|||
|
StartCoroutine(AutoUseItem());
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public int L_VirualItemId = -1;
|
|||
|
bool L_isUsingA = false;
|
|||
|
//经验加成丹
|
|||
|
public void L_initMyeLixirItem(string pathName, string desc,int virualItemId, int itemQuality)
|
|||
|
{
|
|||
|
L_VirualItemId = virualItemId;
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(itemIcon, pathName);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ItemQuality, GCGame.Utils.GetItemQualityFrame(itemQuality));
|
|||
|
descText.text = desc;
|
|||
|
isVirtualItem = false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private int _countTime = 0;
|
|||
|
IEnumerator AutoUseItem()
|
|||
|
{
|
|||
|
while (gameObject.activeInHierarchy)
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(1.0f);
|
|||
|
_countTime++;
|
|||
|
if (_countTime >= 5)
|
|||
|
{
|
|||
|
itemUse();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void itemUse()
|
|||
|
{
|
|||
|
StopAllCoroutines();
|
|||
|
if (isVirtualItem)//非快捷使用道具 执行特殊动作或者计时
|
|||
|
{
|
|||
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(m_VirualItemId, 0);
|
|||
|
if (commonItem == null)
|
|||
|
return;
|
|||
|
|
|||
|
int m_CurMissionId = GameManager.gameManager.MissionManager.m_CurActionMissionId;
|
|||
|
Tab_MissionBase missionBase = TableManager.GetMissionBaseByID(m_CurMissionId, 0);
|
|||
|
if (missionBase == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Tab_MissionLogic missionLogic = TableManager.GetMissionLogicByID(missionBase.LogicID, 0);
|
|||
|
if (missionLogic == null)
|
|||
|
return;
|
|||
|
|
|||
|
int index = GameManager.gameManager.MissionManager.getCurMissionIndex(m_CurMissionId);
|
|||
|
Tab_MissionEnterArea enterArea = TableManager.GetMissionEnterAreaByID(missionLogic.GetLogicIDbyIndex(index), 0);
|
|||
|
if (enterArea == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
btnDesc.text = enterArea.BtnDesc;
|
|||
|
int animationId = enterArea.AnimationId;
|
|||
|
|
|||
|
//播放动作 放在前,用于判断是否打断采集的状态
|
|||
|
if (Singleton<ObjManager>.GetInstance().MainPlayer)
|
|||
|
{
|
|||
|
//切换到动作合集状态(各种动作)
|
|||
|
Singleton<ObjManager>.GetInstance().MainPlayer.OnSwithObjAnimState(GameDefine_Globe.OBJ_ANIMSTATE.STATE_FINSH);
|
|||
|
Singleton<ObjManager>.GetInstance().MainPlayer.AnimLogic.Play(enterArea.AnimationId);
|
|||
|
}
|
|||
|
|
|||
|
UIManager.ShowUI(UIInfo.CollectItemSlider, delegate (bool bSuccess, object param)
|
|||
|
{
|
|||
|
if (bSuccess)
|
|||
|
{
|
|||
|
CollectItemSliderLogic.Instance().setTime(enterArea.AnimationTime, m_CurMissionId, m_VirualItemId, enterArea.MissionDesc);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
isVirtualItem = false;
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// 使用经验加成丹
|
|||
|
if (L_VirualItemId == 919)
|
|||
|
{
|
|||
|
//Debug.LogError("经验加成丹ID === " + m_VirualItemId);
|
|||
|
Games.Item.GameItem gameItem = GameManager.gameManager.PlayerDataPool.BackPack.GetItemByDataID(L_VirualItemId);
|
|||
|
//ItemTooltipsLogic.ItemUse(gameItem);
|
|||
|
ItemTooltipsLogic.UseGameProp(gameItem);
|
|||
|
|
|||
|
CloseWindow();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{2840}");
|
|||
|
if (m_Item == null || m_Item.StackCount < 0)
|
|||
|
{
|
|||
|
if (!InitMyitem())
|
|||
|
{
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//全部使用
|
|||
|
if (Singleton<ObjManager>.Instance.MainPlayer != null)
|
|||
|
{
|
|||
|
Singleton<ObjManager>.Instance.MainPlayer.BulkUseItem(m_Item, m_Item.StackCount);
|
|||
|
GlobalData.MyShortCutItemGuidList.Remove(m_Item.Guid);
|
|||
|
m_Item = null;
|
|||
|
if (!InitMyitem())
|
|||
|
{
|
|||
|
CloseWindow();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//关闭弹窗
|
|||
|
public void CloseWindow()
|
|||
|
{
|
|||
|
GlobalData.MyShortCutItemGuidList.Clear();
|
|||
|
UIManager.CloseUI(UIInfo.ShortCutItem);
|
|||
|
}
|
|||
|
}
|
|||
|
|