using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; [UnitCategory("Custom")] public class FadeUIImageNode : Unit { [DoNotSerialize] public ControlInput enter { get; private set; } [DoNotSerialize] public ControlOutput exit { get; private set; } [DoNotSerialize] public ControlOutput state2 { get; private set; } [DoNotSerialize] public ValueInput uiInput { get; private set; } [DoNotSerialize] public ValueInput imageInput { get; private set; } [DoNotSerialize] public ValueInput textInput { get; private set; } [DoNotSerialize] public ValueInput durationInput { get; private set; } [DoNotSerialize] public ValueInput resetInput { get; private set; } private Image image; private TextMeshProUGUI textMeshProUGUI; private float duration; private Canvas canvas; private int childIndex; private float childtimer; private float timer; private float timer2; private bool fadingIn; private bool textIn; private bool init = true; private bool reset; private bool loadOver; private RectTransform rectTransform; private Vector2 initialPosition; private Vector2 targetPosition = Vector2.zero; protected override void Definition() { enter = ControlInput("enter", (flow) => { reset = flow.GetValue(resetInput); if (reset) { Reset(flow); return exit; } else if(!loadOver) { //Moving(flow); //Fading(flow); LoadUiFaded(flow); } else { Fading(flow); } return state2; }); imageInput = ValueInput("image"); durationInput = ValueInput("duration",2.0f); textInput = ValueInput("text"); resetInput = ValueInput("reset", false); uiInput = ValueInput("canvas"); exit = ControlOutput("exit"); state2 = ControlOutput("state"); Succession(enter, exit); } private void Reset(Flow flow) { if(init) { init = false; image = flow.GetValue(imageInput); duration = flow.GetValue(durationInput); textMeshProUGUI = flow.GetValue(textInput); rectTransform = textMeshProUGUI.GetComponent(); canvas = flow.GetValue(uiInput); targetPosition = rectTransform.anchoredPosition; } for (int i = 0; i < canvas.transform.childCount;i++ ) { var child = canvas.transform.GetChild(i); var graphic = child.GetComponent(); graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, 0); } loadOver = false; childIndex = 0; childtimer = 0; timer = 0f; timer2 = 0f; childtimer = 0f; fadingIn = true; textIn = true; initialPosition = Vector2.zero; Debug.Log("s"); } private void Moving(Flow flow) { if(textMeshProUGUI != null) { if(textIn) { timer2 += Time.deltaTime; float t = Mathf.Clamp01(timer2 / duration); Vector2 newPosition = Vector2.Lerp(initialPosition, targetPosition, t); rectTransform.anchoredPosition = newPosition; if (timer2 >= duration) { textIn = false; } } } } private void Fading(Flow flow) { var child = canvas.transform.GetChild(childIndex); Graphic graphic = child.GetComponent(); if (fadingIn) { childtimer += Time.deltaTime; if (childtimer >= duration) { fadingIn = false; } } else { childtimer -= Time.deltaTime; if (childtimer <= 0) { fadingIn = true; } } float alpha = Mathf.Clamp01(childtimer / duration); graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, alpha); } private void LoadUiFaded(Flow flow) { if (childIndex >= canvas.transform.childCount - 1) { loadOver = true; return; } var child = canvas.transform.GetChild(childIndex); Graphic graphic = child.GetComponent(); childtimer += Time.deltaTime; float alpha = Mathf.Clamp01(childtimer / duration); graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, alpha); if (childtimer >= duration) { childIndex++; childtimer = 0; } } }