You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.EventSystems; |
|
using UnityEngine.UI; |
|
|
|
public class ItemButton : MonoBehaviour,IPointerDownHandler,IPointerUpHandler { |
|
//商城道具按钮 |
|
public Button self_; |
|
//位置 |
|
public Transform outside_; |
|
public Transform target_; |
|
//原来的列表位置 |
|
public Transform initial_; |
|
//public Transform selfTransform_; |
|
//用来获取光标位置 |
|
public GameObject iconObj; |
|
private bool ischosed = false; |
|
private bool isOwn = false; |
|
//横向范围界定 |
|
public float LimitLine; |
|
|
|
//按下按钮 |
|
public void OnPointerDown(PointerEventData eventData) |
|
{ |
|
self_.transform.SetParent(outside_); |
|
ischosed = true; |
|
} |
|
|
|
//抬起按钮 |
|
public void OnPointerUp(PointerEventData eventData) |
|
{ |
|
print(self_.transform.localPosition.x); |
|
if (self_.transform.localPosition.x < -LimitLine) |
|
{ |
|
self_.transform.SetParent(target_); |
|
self_.transform.localPosition = new Vector3(0f, 0f, 0f); |
|
ischosed = false; |
|
} |
|
else { |
|
self_.transform.SetParent(initial_); |
|
self_.transform.localPosition = new Vector3(0f, 0f, 0f); |
|
ischosed = false; |
|
} |
|
|
|
} |
|
|
|
private void Update() |
|
{ |
|
if (ischosed) { |
|
self_.transform.position = iconObj.transform.position; |
|
} |
|
} |
|
}
|
|
|