Files
JJBB/Assets/Project/Script/GUI/Mission/MissionitemEffectTween.cs
2024-08-23 15:49:34 +08:00

61 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MissionitemEffectTween : MonoBehaviour {
public Image _parentBG;
private RectTransform _bgRect;
private void OnEnable()
{
this.gameObject.transform.localPosition = Vector3.zero;
if (_parentBG == null)
_parentBG = GetComponentInParent<Image>();
if (_bgRect == null)
_bgRect = _parentBG.GetComponent<RectTransform>();
_pathCountIndex = 0;
StartMove();
}
private List<Vector3> pathList = new List<Vector3>();
private int _pathCountIndex = 0; //判断当前要取哪个点
public void StartMove()
{
Hashtable args = new Hashtable();
args.Add("looptype", "none");
args.Add("easeType", iTween.EaseType.easeOutQuad);
pathList.Clear();
var pos1 = Vector3.zero;
pathList.Add(pos1);
var pos2 = new Vector3(_bgRect.sizeDelta.x, 0, 0);
pathList.Add(pos2);
var pos3 = new Vector3(_bgRect.sizeDelta.x, -_bgRect.sizeDelta.y, 0);
pathList.Add(pos3);
var pos4 = new Vector3(0, -_bgRect.sizeDelta.y, 0);
pathList.Add(pos4);
args.Add("islocal", true);
args.Add("position", pathList[_pathCountIndex % 4]);
_pathCountIndex %= 4;
_pathCountIndex += 1; //自加一次
args.Add("speed", 100.0f);
args.Add("oncomplete", "OnPathEnd"); //递归?
iTween.MoveTo(gameObject, args);
}
//每个点结束的时候取下个点
public void OnPathEnd()
{
iTween.Stop(this.gameObject);
StartMove();
}
}