using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; using UnityEngine.UI; using Assets.Scripts; //using ZenFulcrum.EmbeddedBrowser; public class RowerTraceAnimated : MonoBehaviour { // Start is called before the first frame update Vector3? v1, v2, v3; void Start() { //print(v1.Value.ToString() + v2.Value.ToString() + v3.Value.ToString()); } private void Awake() { if (!v1.HasValue) v1 = transform.localPosition; if (!v2.HasValue) v2 = transform.Find("p1").localPosition; if (!v3.HasValue) v3 = transform.Find("p2").localPosition; } /// /// /// /// /// /// /// public Sequence startAnimation(float time, TweenCallback callback, int type = 0) { //if (sq != null && sq.IsPlaying()) //{ // return null; //} Transform c = transform, c1 = c.Find("p1"), c2 = c.Find("p2"); var rect = c.GetComponent(); var dirOffset = 0f; if (type == 1) dirOffset = -1f * rect.sizeDelta.y; var offset = rect.sizeDelta.y / 2; var sq = DOTween.Sequence(); sq.AppendCallback(() => { c2.localPosition = v3.Value + new Vector3(0, dirOffset, 0); c2.localRotation = Quaternion.Euler(new Vector3(type == 1 ? 270 : 90, 0, 0)); c2.GetComponent().color = Utils.HexToColorHtml("#353543FF"); callback(); //print(c.localPosition.ToString() + c.Find("p1").localPosition.ToString() + c.Find("p2").localPosition.ToString()); }); var sq1 = DOTween.Sequence(); sq1.Join(c2.GetComponent().DOFade(0, time)); sq1.Join(c.DORotate(new Vector3(type == 1 ? 90 : -90, 0, 0), time)); sq1.Join(c.DOLocalMoveY(v1.Value.y + (type == 0 ? -offset : offset), time)); sq1.Join(c.DOLocalMoveZ(v1.Value.z + offset, time)); //var sq2 = DOTween.Sequence(); //sq2.Append(c.DOLocalMoveZ(v1.Value.z + offset*0.14f, time * 0.5f)); //sq2.Append(c.DOLocalMoveZ(v1.Value.z + offset, time * 0.5f)); //sq1.Join(sq2); sq.Append(sq1); sq.AppendCallback(() => { var tmp = c1; c1 = c2; c2 = tmp; c1.name = "p1"; c2.name = "p2"; c.localPosition = v1.Value; c1.localPosition = v2.Value; c2.localPosition = v3.Value + new Vector3(0, dirOffset, 0); c.localRotation = Quaternion.Euler(Vector3.zero); c1.localRotation = Quaternion.Euler(Vector3.zero); c2.localRotation = Quaternion.Euler(new Vector3(type == 1 ? 270 : 90, 0, 0)); }); sq.Play(); return sq; } // Update is called once per frame void Update() { } } //var c = transform.Find("Container"); //int i = 1; //UIManager.AddEvent(transform.Find("Button").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => // { // var sq = DOTween.Sequence(); // i++; // sq.AppendCallback(() => // { // c.Find("p1").SetAsLastSibling(); // c.Find(i % 2 == 0 ? "p2" : "p3").SetAsLastSibling(); // }); // sq.Join(c.DORotate(new Vector3(90 * (i % 2 == 0 ? -1 : 1), 0, 0), 1)); // sq.Join(c.DOLocalMoveY(50 * (i % 2 == 0 ? -1 : 1), 1f)); // sq.Append(c.DOLocalMoveZ(0, 0.5f)); // sq.Append(c.DOLocalMoveZ(50, 0.5f)); // sq.Play(); // }); //int i = 1; //UIManager.AddEvent(transform.Find("Button").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => //{ //});