using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; using System; using UnityEngine.UIElements; [UnitCategory("Custom")] public class CubeRotateNode : Unit { [SerializeField] public ControlInput enter { get; private set; } [SerializeField] public ControlInput show { get; private set; } [SerializeField] public ControlInput rotate { get; private set; } [DoNotSerialize] public ControlOutput exit { get; private set; } [DoNotSerialize] public ControlOutput showed { get; private set; } [DoNotSerialize] public ControlOutput rotated { get; private set; } [DoNotSerialize] public ValueInput CubeframeInput { get; private set; } [DoNotSerialize] public ValueInput SwitchSpeedInput { get; private set; } [DoNotSerialize] public ValueInput lengthInput { get; private set; } [DoNotSerialize] public ValueInput EulersInput { get; private set; } [DoNotSerialize] public ValueInput targetInput { get; private set; } [DoNotSerialize] public ValueInput scaleInput { get; private set; } [DoNotSerialize] public ValueInput otherInput { get; private set; } [DoNotSerialize] public ValueInput stateInput { get; private set; } [DoNotSerialize] public ValueInput setEulerInput { get; private set; } [DoNotSerialize] public ValueOutput stateOutput { get; private set; } [DoNotSerialize] public ValueOutput otherOutput { get; private set; } private GameObject Cubeframe; private float state; private float SwitchSpeed; private float length; private bool setEuler; private float SitaY; private Vector3 local ; private Vector3 Eulers; private Quaternion rotation; private Quaternion localrotate; private Collider target; private GameObject other; protected override void Definition() { enter = ControlInput("enter", (flow) => { Cubeframe = flow.GetValue(CubeframeInput); length = flow.GetValue(lengthInput); other = new GameObject(); other.transform.rotation = Cubeframe.transform.rotation; other.transform.position = Cubeframe.transform.position; flow.SetValue(otherOutput, other); return exit; }); rotate = ControlInput("rotate", (flow) => { Cubeframe = flow.GetValue(CubeframeInput); SwitchSpeed = flow.GetValue(SwitchSpeedInput); target = flow.GetValue(targetInput); Eulers = flow.GetValue(EulersInput); local = flow.GetValue(scaleInput); state = flow.GetValue(stateInput); setEuler = flow.GetValue(setEulerInput); /*if (!setEuler) { setEuler = true; //flow.SetValue(setEulerOutput, setEuler); }*/ if (state >= 0) { state -= Time.deltaTime * SwitchSpeed; var z = Mathf.Clamp(1 - state, 0.01f, 1); var x = 1+ (1.01f - z) * (length - 1); Vector3 Scale = new Vector3 (x * local.x, local.y, z * local.z); Cubeframe.transform.localScale = Scale; } Quaternion localrotation = Quaternion.Euler(Eulers * Time.deltaTime); Cubeframe.transform.localRotation *= localrotation; //flow.SetValue(otherOutput, other); flow.SetValue(stateOutput, state); return rotated; }); show = ControlInput("show", (flow) => { Cubeframe = flow.GetValue(CubeframeInput); SwitchSpeed = flow.GetValue(SwitchSpeedInput); target = flow.GetValue(targetInput); Eulers = flow.GetValue(EulersInput); other = flow.GetValue(otherInput); state = flow.GetValue(stateInput); local = flow.GetValue(scaleInput); rotation = other.transform.localRotation; setEuler = flow.GetValue(setEulerInput); if (setEuler) { //setEuler = false; localrotate = Cubeframe.transform.rotation; } setFace(target.transform.position); if (state <= 1) { state += Time.deltaTime * SwitchSpeed; var z = Mathf.Clamp(1 - state, 0.01f, 1); var x = 1 + (1 - z) * (length - 1); Vector3 Scale = new Vector3(x * local.x, local.y, z * local.z); Cubeframe.transform.localScale = Scale; Cubeframe.transform.rotation = Quaternion.Lerp(localrotate, rotation, state); } else { Cubeframe.transform.rotation = rotation; } flow.SetValue(otherOutput, other); flow.SetValue(stateOutput, state); return showed; }); CubeframeInput = ValueInput("CubeframeInput"); SwitchSpeedInput = ValueInput("SwitchSpeedInput",1f); lengthInput = ValueInput("lengthInput", 1.5f); EulersInput = ValueInput("EulersInput"); targetInput = ValueInput("targetInput"); otherInput = ValueInput("otherInput"); scaleInput = ValueInput("scaleInput"); stateInput = ValueInput("stateInput"); setEulerInput = ValueInput("setEulerInput"); stateOutput = ValueOutput("stateOutput"); otherOutput = ValueOutput("otherOutput"); exit = ControlOutput("exit"); showed = ControlOutput("showed"); rotated = ControlOutput("rotated"); Succession(enter, exit); Succession(show, showed); Succession(rotate, rotated); } private void setFace(Vector3 pos) { var forward = -other.transform.forward; pos -= other.transform.position; pos.y = 0; pos = pos.normalized; var dot = Vector3.Dot(forward, pos); var cross = Vector3.Cross(forward, pos); var sita = Mathf.Acos(dot) * Mathf.Rad2Deg; if (cross.y > 0) { sita *= -1; } if (Mathf.Abs(sita) > 0.02f) { rotation = rotation * Quaternion.Euler(0f, -sita, 0f); other.transform.rotation = rotation; } } }