您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
183 行
5.1 KiB
183 行
5.1 KiB
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<bool>(resetInput);
|
|
if (reset)
|
|
{
|
|
Reset(flow);
|
|
return exit;
|
|
}
|
|
else if(!loadOver)
|
|
{
|
|
//Moving(flow);
|
|
//Fading(flow);
|
|
LoadUiFaded(flow);
|
|
|
|
}
|
|
else
|
|
{
|
|
Fading(flow);
|
|
}
|
|
return state2;
|
|
});
|
|
|
|
|
|
imageInput = ValueInput<Image>("image");
|
|
durationInput = ValueInput<float>("duration",2.0f);
|
|
textInput = ValueInput<TextMeshProUGUI>("text");
|
|
resetInput = ValueInput<bool>("reset", false);
|
|
uiInput = ValueInput<Canvas>("canvas");
|
|
|
|
exit = ControlOutput("exit");
|
|
state2 = ControlOutput("state");
|
|
Succession(enter, exit);
|
|
}
|
|
|
|
private void Reset(Flow flow)
|
|
{
|
|
if(init)
|
|
{
|
|
init = false;
|
|
image = flow.GetValue<Image>(imageInput);
|
|
duration = flow.GetValue<float>(durationInput);
|
|
textMeshProUGUI = flow.GetValue<TextMeshProUGUI>(textInput);
|
|
rectTransform = textMeshProUGUI.GetComponent<RectTransform>();
|
|
canvas = flow.GetValue<Canvas>(uiInput);
|
|
targetPosition = rectTransform.anchoredPosition;
|
|
}
|
|
|
|
for (int i = 0; i < canvas.transform.childCount;i++ )
|
|
{
|
|
var child = canvas.transform.GetChild(i);
|
|
var graphic = child.GetComponent<Graphic>();
|
|
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<Graphic>();
|
|
|
|
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<Graphic>();
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|