using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using DG.Tweening; using DG.Tweening.Core; public class ClockScrolling : MonoBehaviour { public List text_mesh_pros = new List(); int Current = 0; int Last => Current == 0 ? text_mesh_pros.Count - 1 : Current - 1; int Next => Current == text_mesh_pros.Count - 1 ? 0 : Current + 1; float timer; bool hide_scrolling; void Update() { #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.LeftArrow)) { ScrollingUp(); } if (Input.GetKeyDown(KeyCode.RightArrow)) { ScrollingDown(); } #endif timer += Time.deltaTime; if (timer >= 3) { if (!hide_scrolling) { hide_scrolling = true; next_color_tween = text_mesh_pros[Next].DOColor(new Color(1, 1, 1, 0f), 1f); last_color_tween = text_mesh_pros[Last].DOColor(new Color(1, 1, 1, 0f), 1f); } } } TweenerCore next_color_tween; TweenerCore last_color_tween; public void ScrollingUp() { //终止 if (hide_scrolling) { if (next_color_tween.IsPlaying()) { next_color_tween.Kill(); } if (last_color_tween.IsPlaying()) { last_color_tween.Kill(); } } Current = Next; text_mesh_pros[Current].rectTransform.DOAnchorPos(Vector2.zero, 0.25f); DOTween.To(() => text_mesh_pros[Current].fontSize, (_v) => text_mesh_pros[Current].fontSize = _v, 26, 0.25f); text_mesh_pros[Current].DOColor(Color.white, 0.25f); text_mesh_pros[Next].rectTransform.DOAnchorPos(new Vector2(0, -25), 0.25f); DOTween.To(() => text_mesh_pros[Next].fontSize, (_v) => text_mesh_pros[Next].fontSize = _v, 21, 0.25f); text_mesh_pros[Next].DOColor(new Color(1, 1, 1, 0.5f), 0.25f); text_mesh_pros[Last].rectTransform.DOAnchorPos(new Vector2(0, 25), 0.25f); DOTween.To(() => text_mesh_pros[Last].fontSize, (_v) => text_mesh_pros[Last].fontSize = _v, 21, 0.25f); text_mesh_pros[Last].DOColor(new Color(1, 1, 1, 0.5f), 0.25f); timer = 0; hide_scrolling = false; } public void ScrollingDown() { //终止 if (hide_scrolling) { if (next_color_tween.IsPlaying()) { next_color_tween.Kill(); } if (last_color_tween.IsPlaying()) { last_color_tween.Kill(); } } Current = Last; text_mesh_pros[Current].rectTransform.DOAnchorPos(Vector2.zero, 0.25f); DOTween.To(() => text_mesh_pros[Current].fontSize, (_v) => text_mesh_pros[Current].fontSize = _v, 26, 0.25f); text_mesh_pros[Current].DOColor(Color.white, 0.25f); text_mesh_pros[Next].rectTransform.DOAnchorPos(new Vector2(0, -25), 0.25f); DOTween.To(() => text_mesh_pros[Next].fontSize, (_v) => text_mesh_pros[Next].fontSize = _v, 21, 0.25f); text_mesh_pros[Next].DOColor(new Color(1, 1, 1, 0.5f), 0.25f); text_mesh_pros[Last].rectTransform.DOAnchorPos(new Vector2(0, 25), 0.25f); DOTween.To(() => text_mesh_pros[Last].fontSize, (_v) => text_mesh_pros[Last].fontSize = _v, 21, 0.25f); text_mesh_pros[Last].DOColor(new Color(1, 1, 1, 0.5f), 0.25f); timer = 0; hide_scrolling = false; } public void SetNextText(string _text) { //if (_text == "深圳市民中心") //{ // text_mesh_pros[Next].text = "广场1"; //} //else if (_text == "西丽湖校区") //{ // text_mesh_pros[Next].text = "广场2"; //} //else { text_mesh_pros[Next].text = _text; } } public string SetCurrentText(string _text) { //if (_text == "深圳市民中心") //{ // text_mesh_pros[Current].text = "广场1"; //} //else if (_text == "西丽湖校区") //{ // text_mesh_pros[Current].text = "广场2"; //} //else { text_mesh_pros[Current].text = _text; } return _text; } public void SetLastText(string _text) { //if (_text == "深圳市民中心") //{ // text_mesh_pros[Last].text = "广场1"; //} //else if (_text == "西丽湖校区") //{ // text_mesh_pros[Last].text = "广场2"; //} //else { text_mesh_pros[Last].text = _text; } } }