using UnityEngine; namespace InfinityCode.uPano.Actions { /// /// Sets a new position for the Transform /// [AddComponentMenu("uPano/Actions/For Everything/Set Transform Rotation")] public class SetTransformRotation : AnimatedAction { /// /// Transform for which you want to set the rotation /// public Transform target; /// /// From rotation is the current rotation /// public bool fromIsOriginal = true; /// /// From rotation /// public Vector3 fromRotation; /// /// To rotation is the delta to the original rotation /// public bool toIsDelta = false; /// /// To rotation /// public Vector3 toRotation; /// /// Rotation in local space? /// public bool useLocalSpace = true; protected override void SetAnimatedValue(float f) { if (target == null) return; Vector3 t = toRotation; if (toIsDelta) t += initialValue; Quaternion r = Quaternion.Lerp(Quaternion.Euler(initialValue), Quaternion.Euler(t), f); if (useLocalSpace) target.localRotation = r; else target.rotation = r; } protected override void SetFixedValue() { Vector3 t = toRotation; if (toIsDelta) t += initialValue; Quaternion r = Quaternion.Euler(t); if (useLocalSpace) target.localRotation = r; else target.rotation = r; } protected override void StoreInitialValue() { if (fromIsOriginal) { if (useLocalSpace) initialValue = target.localRotation.eulerAngles; else initialValue = target.rotation.eulerAngles; } else initialValue = fromRotation; } } }