using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XGUI
{
public class XScaleTween : MonoBehaviour
{
public Ease m_ease = Ease.InOutBack;
public Vector3 startValue = new Vector3(0.8f, 0.8f, 0.8f);
public Vector3 endValue = new Vector3(1f, 1f, 1f);
public float duration = 1.0f;
public float delay = 0.0f;
public int loops = 0;
public LoopType loopType;
private RectTransform rm_transform;
public bool playAutomatically = false;
private void Awake()
{
rm_transform = gameObject.GetComponent<RectTransform>();
}
public void SetPivot(float fx, float fy)
{
Vector2 sizeD = rm_transform.sizeDelta;
rm_transform.pivot = new Vector2(sizeD.x / fx, sizeD.y / fy);
}
private void OnEnable()
{
if (playAutomatically) Play();
}
private void OnDisable()
{
Stop();
}
public void Play()
{
if (rm_transform == null) return;
ResetEx();
if (delay > 0)
Invoke("DoPlay", this.delay);
else
DoPlay();
}
private void DoPlay()
{
rm_transform.localScale = startValue;
rm_transform.DOScale(endValue, duration).SetLoops(loops, loopType);
}
public void ResetEx()
{
CancelInvoke();
rm_transform.localScale = startValue;
rm_transform.DOKill();
}
public void Stop()
{
rm_transform.localScale = endValue;
rm_transform.DOKill();
}
private void OnDestroy()
{
rm_transform.DOKill();
}
}
}
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace XGUI
{
public class XSimpleMove : MonoBehaviour
{
public enum EaseType
{
dotweenEase = 1,
animCurve = 2,
}
[SerializeField]
private AnimationCurve animCurve = new AnimationCurve(new Keyframe[] { new Keyframe(0f, 0f), new Keyframe(3f, 40f) });
public EaseType m_easeType = EaseType.dotweenEase;
public Ease m_ease = Ease.InOutBack;
public RectTransform startPos;
public RectTransform endPos;
public float duration = 1.0f;
public float delay = 0.0f;
private RectTransform m_transform;
public bool playAutomatically = false;
void Awake()
{
m_transform = gameObject.GetComponent<RectTransform>();
}
private void OnEnable()
{
if (playAutomatically) Play(null);
}
private void OnDisable()
{
Stop();
}
public void Play(TweenCallback onCompleFun)
{
if (m_transform == null || startPos == null) return;
ResetEx();
m_transform.anchoredPosition = startPos.anchoredPosition;
if (delay > 0)
StartCoroutine(DoWait(onCompleFun));
else
DoPlay(onCompleFun);
}
private IEnumerator DoWait(TweenCallback onCompleFun)
{
yield return new WaitForSeconds(delay);
DoPlay(onCompleFun);
}
private void DoPlay(TweenCallback onCompleFun)
{
Tweener tweener = m_transform.DOAnchorPos(endPos.anchoredPosition, duration);
if (m_easeType == EaseType.animCurve)
tweener.SetEase(animCurve);
else
tweener.SetEase(m_ease);
if (onCompleFun != null)
{
tweener.OnComplete(delegate () {
onCompleFun();
});
}
}
public void ResetEx()
{
if (startPos == null) return;
m_transform.anchoredPosition = startPos.anchoredPosition;
m_transform.DOKill();
}
public void Stop()
{
if(m_transform != null && endPos != null)
{
m_transform.anchoredPosition = endPos.anchoredPosition;
m_transform.DOKill();
}
}
private void OnDestroy()
{
m_transform.DOKill();
}
}
}