您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
169 行
5.8 KiB
169 行
5.8 KiB
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using static COSXML.Model.Object.SelectObjectResult;
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
[UnitCategory("Custom")]
|
|
public class StateChangeNode : Unit
|
|
{
|
|
[DoNotSerialize]
|
|
public ControlInput enter { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ControlInput show { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ControlInput rotate { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ControlOutput exit { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ValueInput mainSceneInput { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ValueInput targetInput { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ValueInput radiusInput { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ValueInput switchspeedInput { get; private set; }
|
|
|
|
[DoNotSerialize]
|
|
public ValueInput frequencyInput { get; private set; }
|
|
|
|
private GameObject mainScene;
|
|
private GameObject target;
|
|
private float radius;
|
|
private float state = 0;
|
|
private float state2 = 0;
|
|
private float time = 0;
|
|
private float switchspeed;
|
|
private float size = 0.2f;
|
|
private float frequency;
|
|
|
|
private bool setface = true;
|
|
private Quaternion rotation;
|
|
private Quaternion localrotation;
|
|
|
|
|
|
protected override void Definition()
|
|
{
|
|
enter = ControlInput("enter", (flow) =>
|
|
{
|
|
mainScene = flow.GetValue<GameObject>(mainSceneInput);
|
|
radius = flow.GetValue<float>(radiusInput);
|
|
var renderer = mainScene.GetComponent<MeshRenderer>();
|
|
var material = renderer.material;
|
|
material.SetFloat("_radius",radius);
|
|
rotation = mainScene.transform.rotation;
|
|
return exit;
|
|
});
|
|
|
|
show = ControlInput("show", (flow) =>
|
|
{
|
|
switchspeed = flow.GetValue<float>(switchspeedInput);
|
|
mainScene = flow.GetValue<GameObject>(mainSceneInput);
|
|
target = flow.GetValue<GameObject>(targetInput);
|
|
frequency = flow.GetValue<float>(frequencyInput);
|
|
var renderer = mainScene.GetComponent<MeshRenderer>();
|
|
var material = renderer.material;
|
|
|
|
|
|
if (setface && target != null)
|
|
{
|
|
var sita = time * frequency * 0.628f;
|
|
sita = Mathf.Repeat(sita - mainScene.transform.rotation.y + Mathf.PI, Mathf.PI * 2) - Mathf.PI + mainScene.transform.rotation.y;
|
|
time = sita / 0.628f / frequency;
|
|
|
|
setface = false;
|
|
Vector3 pos = target.transform.position - mainScene.transform.position;
|
|
pos.y = 0;
|
|
pos = pos.normalized;
|
|
Vector3 forward = -mainScene.transform.forward;
|
|
var dot = Vector3.Dot(forward, pos);
|
|
var cross = Vector3.Cross(forward, pos);
|
|
sita = Mathf.Acos(dot) * Mathf.Rad2Deg;
|
|
if (cross.y > 0) { sita *= -1; }
|
|
if (Math.Abs(sita) > 0.02)
|
|
{
|
|
//mainScene.transform.Rotate(-Vector3.up, sita);
|
|
rotation = mainScene.transform.rotation * Quaternion.Euler(0f, -sita, 0f);
|
|
}
|
|
localrotation = mainScene.transform.rotation;
|
|
material.SetFloat("_time", time);
|
|
}
|
|
if (state2 <= 1)
|
|
{
|
|
state2 += Time.deltaTime * switchspeed;
|
|
material.SetFloat("_state2", state2);
|
|
mainScene.transform.rotation = Quaternion.Lerp(localrotation, rotation, state2);
|
|
}
|
|
else if (state <= 1)
|
|
{
|
|
state += Time.deltaTime * switchspeed;
|
|
material.SetFloat("_state", state);
|
|
}
|
|
else if (size <= 1)
|
|
{
|
|
size += Time.deltaTime * switchspeed;
|
|
material.SetFloat("_size", size);
|
|
}
|
|
|
|
return exit;
|
|
});
|
|
|
|
rotate = ControlInput("rotate", (flow) =>
|
|
{
|
|
if (!setface)
|
|
{
|
|
time = 0;
|
|
setface = true;
|
|
}
|
|
switchspeed = flow.GetValue<float>(switchspeedInput);
|
|
mainScene = flow.GetValue<GameObject>(mainSceneInput);
|
|
frequency = flow.GetValue<float>(frequencyInput);
|
|
var renderer = mainScene.GetComponent<MeshRenderer>();
|
|
var material = renderer.material;
|
|
if (state <=0) time += Time.deltaTime;
|
|
//if (time > PI2) time -= PI2;
|
|
if (state2 >= 0 )
|
|
{
|
|
if (size >=0.2)
|
|
{
|
|
size -= Time.deltaTime * switchspeed;
|
|
material.SetFloat("_size", size);
|
|
}
|
|
else if (state >= 0)
|
|
{
|
|
state -= Time.deltaTime * switchspeed;
|
|
material.SetFloat("_state", state);
|
|
}
|
|
else
|
|
{
|
|
state2 -= Time.deltaTime * switchspeed;
|
|
material.SetFloat("_state2", state2);
|
|
}
|
|
}
|
|
material.SetFloat("_time", time);
|
|
material.SetFloat("_Frequency", frequency);
|
|
return exit;
|
|
});
|
|
|
|
mainSceneInput = ValueInput<GameObject>("mainSceneInput");
|
|
targetInput = ValueInput<GameObject>("target");
|
|
radiusInput = ValueInput<float>("radius", -3f);
|
|
switchspeedInput = ValueInput<float>("switchspeed", 1f);
|
|
frequencyInput = ValueInput<float>("frequency", 1f);
|
|
exit = ControlOutput("exit");
|
|
Succession(enter, exit);
|
|
}
|
|
|
|
|
|
}
|