备份CatanBuilding瘦身独立工程
This commit is contained in:
98
Assets/Scripts/UI/UIButtonScale.cs
Normal file
98
Assets/Scripts/UI/UIButtonScale.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
[AddComponentMenu("UGUI/UI/UIButtonScale")]
|
||||
public class UIButtonScale : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
|
||||
{
|
||||
public float Speed = 0.02f;
|
||||
public Vector3 To = new Vector3 (0.8f, 0.8f, 0.8f);
|
||||
|
||||
Vector3 _from = Vector3.one;
|
||||
bool _bScale = false; // scale down, false; scale up, ture
|
||||
bool _bRunning = false;
|
||||
Button _Button;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_Button = gameObject.GetComponent<Button>();
|
||||
_from = transform.localScale;
|
||||
}
|
||||
|
||||
/*void Start()
|
||||
{
|
||||
//_from = transform.localScale;
|
||||
}*/
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
SetNormal();
|
||||
}
|
||||
|
||||
void OnApplicationFocus(bool focus)
|
||||
{
|
||||
if(!focus)
|
||||
{
|
||||
SetNormal();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown (PointerEventData event_data)
|
||||
{
|
||||
if (null != _Button && !_Button.interactable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_bScale = false;
|
||||
_bRunning = true;
|
||||
}
|
||||
|
||||
public void OnPointerUp (PointerEventData event_data)
|
||||
{
|
||||
/*if(!_Button.interactable && !_bRunning)
|
||||
{
|
||||
return;
|
||||
}*/
|
||||
|
||||
_bScale = true;
|
||||
_bRunning = true;
|
||||
}
|
||||
|
||||
public void SetNormal()
|
||||
{
|
||||
_bScale = true;
|
||||
_bRunning = false;
|
||||
transform.localScale = _from;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(!_bRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_bScale)
|
||||
{
|
||||
transform.localScale -= _from * Speed;
|
||||
|
||||
if (transform.localScale.x <= To.x)
|
||||
{
|
||||
transform.localScale = To;
|
||||
_bRunning = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localScale += _from * Speed;
|
||||
|
||||
if (transform.localScale.x >= _from.x)
|
||||
{
|
||||
transform.localScale = _from;
|
||||
_bRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user