45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace AlicizaX.UI
|
|
{
|
|
/// <summary>
|
|
/// Transform 旋转状态控制
|
|
/// 控制对象的本地欧拉角旋转
|
|
/// </summary>
|
|
[Serializable]
|
|
[ControlerStateName("Transform/Rotation")]
|
|
[ControlerStateAttachType(true)]
|
|
public class TransformRotationState : ControllerStateBase
|
|
{
|
|
[SerializeField] private Vector3 _rotation;
|
|
[HideInInspector] [SerializeField] private Vector3 _defaultRotation;
|
|
|
|
public override void Init(UXControllerStateRecorder recorder)
|
|
{
|
|
if (recorder != null && recorder.transform != null)
|
|
{
|
|
_defaultRotation = recorder.transform.localEulerAngles;
|
|
}
|
|
}
|
|
|
|
public override void Execute(UXControllerStateRecorder recorder, int entryIndex, int selectionIndex)
|
|
{
|
|
if (recorder != null && recorder.transform != null)
|
|
{
|
|
recorder.transform.localEulerAngles = (entryIndex == selectionIndex) ? _rotation : _defaultRotation;
|
|
}
|
|
}
|
|
|
|
public override bool Valid(UXControllerStateRecorder recorder)
|
|
{
|
|
return recorder != null && recorder.transform != null;
|
|
}
|
|
|
|
public override string GetDescription()
|
|
{
|
|
return $"匹配时: 旋转={_rotation}, 默认={_defaultRotation}";
|
|
}
|
|
}
|
|
}
|