201 lines
5.5 KiB
C#
201 lines
5.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using System.Collections;
|
|
using System;
|
|
using GCGame.Table;
|
|
using Module.Log;
|
|
|
|
public class SkillBarItem : UIItemSelect, IDropHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
|
|
{
|
|
public Image _SkillIcon;
|
|
|
|
private int _SkillItemIdx;
|
|
public int SkillItemIdx
|
|
{
|
|
get
|
|
{
|
|
return _SkillItemIdx;
|
|
}
|
|
}
|
|
|
|
private int _OwnSkillIdx;
|
|
public int OwnSkillIdx
|
|
{
|
|
get
|
|
{
|
|
return _OwnSkillIdx;
|
|
}
|
|
set
|
|
{
|
|
_OwnSkillIdx = value;
|
|
}
|
|
}
|
|
|
|
public override void Show(Hashtable hash)
|
|
{
|
|
base.Show();
|
|
|
|
var _Page = (int)hash["InitObj"];
|
|
}
|
|
|
|
public void InitSkillBar(int skillIdx, int skillItemIdx)
|
|
{
|
|
_SkillItemIdx = skillItemIdx;
|
|
_OwnSkillIdx = skillIdx;
|
|
|
|
_SkillIcon.gameObject.SetActive(false);
|
|
if (Singleton<ObjManager>.GetInstance().MainPlayer.OwnSkillInfo.Length <= skillIdx || skillIdx < 0)
|
|
return;
|
|
|
|
Tab_SkillEx skillEx = Singleton<ObjManager>.GetInstance().MainPlayer.OwnSkillInfo[skillIdx].SkillExTable;
|
|
if (skillEx == null)
|
|
return;
|
|
|
|
Tab_SkillBase skillBase = Singleton<ObjManager>.GetInstance().MainPlayer.OwnSkillInfo[skillIdx].SkillBaseTable;
|
|
if (skillEx == null)
|
|
return;
|
|
|
|
_SkillIcon.gameObject.SetActive(true);
|
|
LoadAssetBundle.Instance.SetImageSprite(_SkillIcon, skillBase.Icon);
|
|
}
|
|
|
|
#region event
|
|
|
|
private static bool _HasDropSucess = false;
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
int state = GameManager.gameManager.PlayerDataPool.GetPropInt(PropID.PropertyID.STATE);
|
|
if ((state & 2) > 0)
|
|
{
|
|
SkillRootLogic.canDrag = false;
|
|
GUIData.AddNotifyData("#{4748}");
|
|
}
|
|
else
|
|
{
|
|
SkillRootLogic.canDrag = true;
|
|
}
|
|
|
|
if(SkillRootLogic.canDrag == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!SkillRootLogic.Instance().CanDragSkillItem())
|
|
return;
|
|
if (_OwnSkillIdx == -1) //当前拖拽的目标为空
|
|
return;
|
|
|
|
_HasDropSucess = false;
|
|
SkillRootLogic.Instance()._DragSkillOwnIdx = _OwnSkillIdx;
|
|
SkillRootLogic.Instance()._DragSkillBar = this;
|
|
SkillRootLogic.Instance()._DragIcon.sprite = _SkillIcon.sprite;
|
|
SkillRootLogic.Instance()._DragIcon.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
if (SkillRootLogic.canDrag == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (SkillRootLogic.Instance()._DragIcon.isActiveAndEnabled)
|
|
SetDraggedPosition(eventData);
|
|
}
|
|
|
|
private void SetDraggedPosition(PointerEventData eventData)
|
|
{
|
|
|
|
var rt = SkillRootLogic.Instance()._DragIcon.rectTransform;
|
|
Vector3 globalMousePos;
|
|
if (RectTransformUtility.ScreenPointToWorldPointInRectangle(SkillRootLogic.Instance().GetComponent<RectTransform>(), eventData.position, eventData.pressEventCamera, out globalMousePos))
|
|
{
|
|
rt.position = globalMousePos;
|
|
}
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
if (SkillRootLogic.canDrag == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
LogModule.DebugLog("OnEndDrag");
|
|
|
|
SkillRootLogic.Instance()._DragSkillOwnIdx = -1;
|
|
SkillRootLogic.Instance()._DragIcon.sprite = null;
|
|
SkillRootLogic.Instance()._DragIcon.gameObject.SetActive(false);
|
|
SkillRootLogic.Instance()._DragSkillBar = null;
|
|
|
|
if (!_HasDropSucess)
|
|
{
|
|
_SkillIcon.gameObject.SetActive(false);
|
|
_OwnSkillIdx = -1;
|
|
|
|
SkillRootLogic.Instance().ClearSkillBar(_SkillItemIdx);
|
|
}
|
|
}
|
|
|
|
public void OnDrop(PointerEventData data)
|
|
{
|
|
if (SkillRootLogic.canDrag == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (SkillRootLogic.Instance()._DragSkillBar == null)
|
|
{ //set new
|
|
if (SkillRootLogic.Instance()._DragSkillOwnIdx < 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_SkillIcon.gameObject.SetActive(true);
|
|
_SkillIcon.sprite = SkillRootLogic.Instance()._DragIcon.sprite;
|
|
|
|
_OwnSkillIdx = SkillRootLogic.Instance()._DragSkillOwnIdx;
|
|
SkillRootLogic.Instance().ChangeSkillBar(_SkillItemIdx);
|
|
}
|
|
else
|
|
{
|
|
|
|
var tempSprite = _SkillIcon.sprite;
|
|
_SkillIcon.sprite = SkillRootLogic.Instance()._DragSkillBar._SkillIcon.sprite;
|
|
SkillRootLogic.Instance()._DragSkillBar._SkillIcon.sprite = tempSprite;
|
|
SkillRootLogic.Instance().ExChangeSkillBar(_SkillItemIdx);
|
|
|
|
var tempSkillIdx = _OwnSkillIdx;
|
|
_OwnSkillIdx = SkillRootLogic.Instance()._DragSkillBar.OwnSkillIdx;
|
|
SkillRootLogic.Instance()._DragSkillBar.OwnSkillIdx = tempSkillIdx;
|
|
|
|
if (SkillRootLogic.Instance()._DragSkillBar.OwnSkillIdx < 0)
|
|
{
|
|
SkillRootLogic.Instance()._DragSkillBar._SkillIcon.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
SkillRootLogic.Instance()._DragSkillBar._SkillIcon.gameObject.SetActive(true);
|
|
}
|
|
|
|
if (OwnSkillIdx < 0)
|
|
{
|
|
_SkillIcon.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_SkillIcon.gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
_HasDropSucess = true;
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|