using Unity.VisualScripting; using UnityEngine; using Cinemachine; [UnitCategory("Custom")] public class RotateVirtualCameraNode : Unit { [DoNotSerialize] public ControlInput enter { get; private set; } [DoNotSerialize] public ControlOutput exit { get; private set; } [DoNotSerialize] public ValueInput sensitivityInput { get; private set; } [DoNotSerialize] public ValueInput minRotationInput { get; private set; } // Minimum rotation limit [DoNotSerialize] public ValueInput maxRotationInput { get; private set; } // Maximum rotation limit private float rotationX = 0f; // Track the rotation around the X axis protected override void Definition() { enter = ControlInput("enter", (flow) => { // Get the current game object (target object) var targetObject = flow.stack.gameObject; // Get the Virtual Camera from the child object var vcam = targetObject.transform.GetChild(0).GetComponent(); // Get sensitivity float sensitivity = flow.GetValue(sensitivityInput); // Get rotation limits float minRotation = flow.GetValue(minRotationInput); float maxRotation = flow.GetValue(maxRotationInput); // Get input (mouse or touch) float inputX, inputY; if (Input.touchSupported && Input.touchCount > 0) { Touch touch = Input.GetTouch(0); inputX = touch.deltaPosition.x; inputY = touch.deltaPosition.y; } else { inputX = Input.GetAxis("Mouse X"); inputY = Input.GetAxis("Mouse Y"); } // Rotate around the Y axis vcam.transform.RotateAround(targetObject.transform.position, Vector3.up, inputX * sensitivity); // Calculate the desired rotation around the X axis float desiredRotationX = rotationX - inputY * sensitivity; desiredRotationX = Mathf.Clamp(desiredRotationX, minRotation, maxRotation); // Limit the rotation to the specified range // Calculate the actual rotation difference float rotationDifferenceX = desiredRotationX - rotationX; // Apply the rotation around the X axis vcam.transform.RotateAround(targetObject.transform.position, vcam.transform.right, rotationDifferenceX); // Update the tracked rotation rotationX = desiredRotationX; return exit; // Continue execution }); exit = ControlOutput("exit"); sensitivityInput = ValueInput("sensitivity", 2f); // Default sensitivity minRotationInput = ValueInput("minRotation", -45f); // Default minimum rotation maxRotationInput = ValueInput("maxRotation", 45f); // Default maximum rotation } }