feat(ui): 为旋钮交互添加旋转光标状态
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3063,6 +3063,7 @@ MonoBehaviour:
|
||||
option: {fileID: 21300000, guid: 36cede42403990247aced1b45d623dd5, type: 3}
|
||||
interactive: {fileID: 21300000, guid: 66a05b2333c3fa644a843877ae9da3bd, type: 3}
|
||||
holding: {fileID: 21300000, guid: acc8d5eb5db1c184ba494e0142fa4d85, type: 3}
|
||||
rotating: {fileID: 21300000, guid: a4813d9b6f041d04680fe4a365bc3e1a, type: 3}
|
||||
disable: {fileID: 21300000, guid: c79f612e713a64245b3c78d6ac145b52, type: 3}
|
||||
--- !u!114 &947129554
|
||||
MonoBehaviour:
|
||||
|
||||
@@ -155,6 +155,7 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
|
||||
private EventTriggerEx _eventTrigger;
|
||||
private bool _useEventTrigger;
|
||||
private bool _isPointerOver;
|
||||
|
||||
private Material _ringProgressMaterial;
|
||||
|
||||
@@ -206,6 +207,8 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
_eventTrigger.Register(EventTriggerType.PointerDown, OnEventPointerDown);
|
||||
_eventTrigger.Register(EventTriggerType.PointerUp, OnEventPointerUp);
|
||||
_eventTrigger.Register(EventTriggerType.Drag, OnEventDrag);
|
||||
_eventTrigger.Register(EventTriggerType.PointerEnter, OnEventPointerEnter);
|
||||
_eventTrigger.Register(EventTriggerType.PointerExit, OnEventPointerExit);
|
||||
}
|
||||
|
||||
EnsureKnobLid();
|
||||
@@ -327,7 +330,14 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
{
|
||||
if (_eventTrigger == null) return;
|
||||
var triggers = _eventTrigger.triggers;
|
||||
var needed = new[] { EventTriggerType.PointerDown, EventTriggerType.PointerUp, EventTriggerType.Drag };
|
||||
var needed = new[]
|
||||
{
|
||||
EventTriggerType.PointerDown,
|
||||
EventTriggerType.PointerUp,
|
||||
EventTriggerType.Drag,
|
||||
EventTriggerType.PointerEnter,
|
||||
EventTriggerType.PointerExit
|
||||
};
|
||||
foreach (var t in needed)
|
||||
{
|
||||
if (triggers.Any(e => e.eventID == t)) continue;
|
||||
@@ -376,6 +386,34 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
ContinueDrag(pointerData.position);
|
||||
}
|
||||
|
||||
private void OnEventPointerEnter(BaseEventData eventData)
|
||||
{
|
||||
_isPointerOver = true;
|
||||
UpdateRotationCursor();
|
||||
}
|
||||
|
||||
private void OnEventPointerExit(BaseEventData eventData)
|
||||
{
|
||||
_isPointerOver = false;
|
||||
UpdateRotationCursor();
|
||||
}
|
||||
|
||||
private void UpdateRotationCursor()
|
||||
{
|
||||
if ((!_isPointerOver && !_isDragging) || !IsAvailable)
|
||||
{
|
||||
ClearRotationCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
CursorManager.Instance?.SetInteractionCursor(this, CursorStateEnum.Rotating);
|
||||
}
|
||||
|
||||
private void ClearRotationCursor()
|
||||
{
|
||||
CursorManager.Instance?.ClearInteractionCursor(this);
|
||||
}
|
||||
|
||||
private void HandleMouseInputFallback()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
@@ -444,6 +482,7 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
SetInteractionHighlightVisible(false);
|
||||
|
||||
_isDragging = true;
|
||||
UpdateRotationCursor();
|
||||
_prevMouseAngle = GetMouseAngleDeg(Input.mousePosition);
|
||||
ClearIdleState();
|
||||
onPowerAdjustmentStart?.Invoke();
|
||||
@@ -473,6 +512,7 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
{
|
||||
if (!_isDragging) return;
|
||||
_isDragging = false;
|
||||
UpdateRotationCursor();
|
||||
|
||||
if (_knobAngle > 10f)
|
||||
StartIdleCountdown();
|
||||
@@ -709,6 +749,7 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
_failCount++;
|
||||
YarnVariableStorage.Instance?.SetValue("$knobFailCount", (float)_failCount);
|
||||
_hasFailed = true;
|
||||
ClearRotationCursor();
|
||||
Debug.Log($"[KnobController] Failure #{_failCount} at {_currentPower:F1}%, waiting for snapback...");
|
||||
|
||||
// 不立即触发 UI/事件,等旋钮回弹完成后再触发
|
||||
@@ -854,6 +895,7 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
|
||||
if (knobPlate != null) knobPlate.color = _plateOriginalColor;
|
||||
HideInfoPanel();
|
||||
UpdateRotationCursor();
|
||||
|
||||
Debug.Log("[KnobController] Reset");
|
||||
}
|
||||
@@ -864,6 +906,7 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
public void Lock()
|
||||
{
|
||||
_isLocked = true;
|
||||
ClearRotationCursor();
|
||||
Debug.Log("[KnobController] Locked");
|
||||
}
|
||||
|
||||
@@ -873,6 +916,7 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
public void Unlock()
|
||||
{
|
||||
_isLocked = false;
|
||||
UpdateRotationCursor();
|
||||
}
|
||||
|
||||
public void SetMinAcceptablePower(float minPower)
|
||||
@@ -883,11 +927,19 @@ namespace AibisDream.MiniGame.HuoShan
|
||||
public void ForceSuccess()
|
||||
{
|
||||
_hasSucceeded = true;
|
||||
ClearRotationCursor();
|
||||
onPowerAdjustmentSuccess?.Invoke(_currentPower);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_isPointerOver = false;
|
||||
ClearRotationCursor();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearRotationCursor();
|
||||
if (_ringProgressMaterial == null) return;
|
||||
|
||||
if (Application.isPlaying)
|
||||
|
||||
@@ -10,9 +10,11 @@ namespace AibisDream
|
||||
[SerializeField] private GameObject border;
|
||||
|
||||
[Header("指针图片")] public Sprite defaultCursor;
|
||||
public Sprite nextTalk, talking, option, interactive, holding, disable;
|
||||
public Sprite nextTalk, talking, option, interactive, holding, rotating, disable;
|
||||
|
||||
private Image _cursor;
|
||||
private Object _interactionCursorOwner;
|
||||
private CursorStateEnum _interactionCursorState;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -97,6 +99,11 @@ namespace AibisDream
|
||||
else
|
||||
{
|
||||
// 非对话处理指针交互
|
||||
if (_interactionCursorOwner != null)
|
||||
{
|
||||
return _interactionCursorState;
|
||||
}
|
||||
|
||||
var triggerEnum = EventSystemEx.Instance.GetPointerState();
|
||||
return HandleDraggingState(triggerEnum);
|
||||
}
|
||||
@@ -137,9 +144,24 @@ namespace AibisDream
|
||||
CursorStateEnum.InOption => option,
|
||||
CursorStateEnum.Dragging => holding,
|
||||
CursorStateEnum.PointerOver => interactive,
|
||||
CursorStateEnum.Rotating => rotating != null ? rotating : interactive,
|
||||
_ => defaultCursor,
|
||||
};
|
||||
}
|
||||
|
||||
public void SetInteractionCursor(Object owner, CursorStateEnum state)
|
||||
{
|
||||
if (owner == null) return;
|
||||
_interactionCursorOwner = owner;
|
||||
_interactionCursorState = state;
|
||||
}
|
||||
|
||||
public void ClearInteractionCursor(Object owner)
|
||||
{
|
||||
if (owner != null && _interactionCursorOwner != owner) return;
|
||||
_interactionCursorOwner = null;
|
||||
_interactionCursorState = CursorStateEnum.Default;
|
||||
}
|
||||
}
|
||||
|
||||
public enum CursorStateEnum
|
||||
@@ -149,6 +171,7 @@ namespace AibisDream
|
||||
WaitForAdvance,
|
||||
InOption,
|
||||
Dragging,
|
||||
PointerOver
|
||||
PointerOver,
|
||||
Rotating
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user