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(mainSceneInput); radius = flow.GetValue(radiusInput); var renderer = mainScene.GetComponent(); var material = renderer.material; material.SetFloat("_radius",radius); rotation = mainScene.transform.rotation; return exit; }); show = ControlInput("show", (flow) => { switchspeed = flow.GetValue(switchspeedInput); mainScene = flow.GetValue(mainSceneInput); target = flow.GetValue(targetInput); frequency = flow.GetValue(frequencyInput); var renderer = mainScene.GetComponent(); 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(switchspeedInput); mainScene = flow.GetValue(mainSceneInput); frequency = flow.GetValue(frequencyInput); var renderer = mainScene.GetComponent(); 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("mainSceneInput"); targetInput = ValueInput("target"); radiusInput = ValueInput("radius", -3f); switchspeedInput = ValueInput("switchspeed", 1f); frequencyInput = ValueInput("frequency", 1f); exit = ControlOutput("exit"); Succession(enter, exit); } }