201 lines
5.4 KiB
C#
201 lines
5.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Games.GlobeDefine;
|
|
using GCGame.Table;
|
|
using Games.Item;
|
|
using System;
|
|
|
|
public class EquipAutoUseLogic : UIControllerBase<EquipAutoUseLogic>
|
|
{
|
|
|
|
public Transform m_Trans;
|
|
public CommonItemPlotBase m_ItemSlot;
|
|
public Text _BtnText;
|
|
|
|
private List<GameItem> _AutoEquips = new List<GameItem>();
|
|
private static Hashtable needShowHash;
|
|
private bool hasInit = false;
|
|
|
|
void OnEnable()
|
|
{
|
|
SetInstance(this);
|
|
hasInit = false;
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
SetInstance(null);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
UpdateAutoUse();
|
|
}
|
|
|
|
public void CloseWindow()
|
|
{
|
|
needShowHash = null;
|
|
hasInit = false;
|
|
_AutoEquips.Clear();
|
|
UIManager.CloseUI(UIInfo.EquipAutoUseRoot);
|
|
}
|
|
|
|
static void ShowUIOver(bool bSuccess, object param)
|
|
{
|
|
if (bSuccess)
|
|
{
|
|
Hashtable hash = param as Hashtable;
|
|
GameItem gameItem = hash["GameItem"] as GameItem;
|
|
if (EquipAutoUseLogic.Instance() != null)
|
|
{
|
|
//if (EquipRemindLogic.Instance() != null)
|
|
//{
|
|
// ItemRemindLogic.Instance().m_Trans.localPosition = new Vector3(210, 400, 0);
|
|
//}
|
|
EquipAutoUseLogic.Instance().PushShowEquip(gameItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PushShowEquip(GameItem gameitem)
|
|
{
|
|
for (int i = 0; i < _AutoEquips.Count; ++i)
|
|
{
|
|
if (_AutoEquips[i].GetEquipSlotIndex() == gameitem.GetEquipSlotIndex())
|
|
{
|
|
if (_AutoEquips[i].BaseCombat < gameitem.BaseCombat)
|
|
{
|
|
if (m_ItemSlot.ShowingItem == _AutoEquips[i])
|
|
{
|
|
m_ItemSlot.ShowItem(gameitem);
|
|
}
|
|
_AutoEquips[i] = gameitem;
|
|
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
hasInit = true;
|
|
//_StartAutoTime = Time.time;
|
|
_AutoEquips.Add(gameitem);
|
|
if (_AutoEquips.Count == 1)
|
|
{
|
|
ShowNext();
|
|
}
|
|
}
|
|
|
|
public void OnBtnUse()
|
|
{
|
|
var gameitem = _AutoEquips[0];
|
|
if (gameitem.CanEquipItem() && IsEquipBetter(gameitem))
|
|
{
|
|
if (Singleton<ObjManager>.Instance.MainPlayer.CheckEquipItem(gameitem))
|
|
{
|
|
GameManager.gameManager.SoundManager.PlaySoundEffect(144);
|
|
Singleton<ObjManager>.Instance.MainPlayer.EquipItem(gameitem);
|
|
|
|
//wearGuid = _AutoEquip.Guid;
|
|
}
|
|
}
|
|
_AutoEquips.RemoveAt(0);
|
|
//UIManager.CloseUI(UIInfo.EquipAutoUseRoot);
|
|
ShowNext();
|
|
}
|
|
|
|
public void ShowNext()
|
|
{
|
|
if (_AutoEquips.Count == 0)
|
|
{
|
|
CloseWindow();
|
|
}
|
|
else
|
|
{
|
|
_StartAutoTime = Time.time;
|
|
m_ItemSlot.ShowItem(_AutoEquips[0]);
|
|
}
|
|
}
|
|
|
|
private float _StartAutoTime = 0;
|
|
public void UpdateAutoUse()
|
|
{
|
|
if(hasInit)
|
|
{
|
|
var time = (int)(_AutoTime - (Time.time - _StartAutoTime));
|
|
if (time <= 0)
|
|
{
|
|
if (Singleton<ObjManager>.Instance.MainPlayer != null)
|
|
{
|
|
OnBtnUse();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_BtnText.text = StrDictionary.GetClientDictionaryString("#{3874}") + string.Format("({0}s)", time);
|
|
}
|
|
}
|
|
}
|
|
|
|
#region
|
|
|
|
private static int _AutoEquipLv = -1;
|
|
private static float _AutoTime = 5.0f;
|
|
|
|
public static void OnGetEquip(GameItem gameItem)
|
|
{
|
|
if (_AutoEquipLv < 0)
|
|
{
|
|
_AutoEquipLv = SystemParam.GetSystemParam_INT(21);
|
|
}
|
|
|
|
if (Singleton<ObjManager>.Instance.MainPlayer.BaseAttr.Level > _AutoEquipLv)
|
|
return;
|
|
|
|
if (!gameItem.CanEquipItem())
|
|
return;
|
|
|
|
GameItemContainer EquipPack = GameManager.gameManager.PlayerDataPool.EquipPack;
|
|
var equipItem = EquipPack.GetItem(gameItem.GetEquipSlotIndex());
|
|
if (equipItem.IsValid() && equipItem.BaseCombat >= gameItem.BaseCombat)
|
|
return;
|
|
|
|
PushEquip(gameItem);
|
|
}
|
|
|
|
public static bool IsEquipBetter(GameItem gameItem)
|
|
{
|
|
GameItemContainer EquipPack = GameManager.gameManager.PlayerDataPool.EquipPack;
|
|
var equipItem = EquipPack.GetItem(gameItem.GetEquipSlotIndex());
|
|
if (equipItem.IsValid() && equipItem.BaseCombat >= gameItem.BaseCombat)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void PushEquip(GameItem gameItem)
|
|
{
|
|
needShowHash = new Hashtable();
|
|
needShowHash.Add("GameItem", gameItem);
|
|
|
|
// 针对强化界面特殊,处理,等待界面关闭后,再显示可自动穿戴
|
|
if(EquipEnhanceRoot.Instance() != null && EquipEnhanceRoot.Instance().gameObject.activeInHierarchy)
|
|
{
|
|
return;
|
|
}
|
|
|
|
UIManager.ShowUI(UIInfo.EquipAutoUseRoot, ShowUIOver, needShowHash);
|
|
}
|
|
|
|
// 当装备强化界面存在时,不能显示自动穿戴,只有在关闭后才可以。
|
|
public static void AutoRelease()
|
|
{
|
|
if(needShowHash != null)
|
|
{
|
|
UIManager.ShowUI(UIInfo.EquipAutoUseRoot, ShowUIOver, needShowHash);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|