fix(tutorial): complete click targets from UI events
Publish UPM package / publish (push) Successful in 2s
Publish UPM package / publish (push) Successful in 2s
This commit is contained in:
@@ -43,6 +43,8 @@ namespace ShrinkTutorial
|
||||
private ShrinkTutorialMaskShape _clickTargetArmedShape;
|
||||
private int _clickTargetArmedFrame;
|
||||
private bool _clickTargetArmedWithTouch;
|
||||
private Button _clickTargetButton;
|
||||
private ShrinkTutorialAnchor _clickTargetAnchor;
|
||||
private float _stepAutoTimer;
|
||||
private string _receivedCustomEvent = string.Empty;
|
||||
|
||||
@@ -214,6 +216,7 @@ namespace ShrinkTutorial
|
||||
_stepCompleted = false;
|
||||
_stepCompletionQueued = false;
|
||||
_clickTargetArmed = false;
|
||||
UnbindClickTargetEvents();
|
||||
_stepAutoTimer = tutorial.steps[stepIndex].autoDelay;
|
||||
_receivedCustomEvent = string.Empty;
|
||||
|
||||
@@ -237,6 +240,8 @@ namespace ShrinkTutorial
|
||||
if (targetTransform)
|
||||
LogDebug($"Resolved target for step {stepIndex}: {GetTransformPath(targetTransform)}");
|
||||
|
||||
BindClickTargetEvents(step, targetTransform);
|
||||
|
||||
EmitSignal(step.enterSignal);
|
||||
_dialog.SetSkipVisible(ResolveSettings().showSkipButton);
|
||||
|
||||
@@ -249,6 +254,7 @@ namespace ShrinkTutorial
|
||||
yield return null;
|
||||
}
|
||||
|
||||
UnbindClickTargetEvents();
|
||||
EmitSignal(step.exitSignal);
|
||||
_dialog.Hide();
|
||||
|
||||
@@ -364,6 +370,9 @@ namespace ShrinkTutorial
|
||||
|
||||
private void TickClickTargetCompletion(ShrinkTutorialStep step, Transform targetTransform)
|
||||
{
|
||||
if (_clickTargetButton || _clickTargetAnchor)
|
||||
return;
|
||||
|
||||
if (!_clickTargetArmed &&
|
||||
targetTransform &&
|
||||
ShrinkTutorialTargetUtility.TryBuildScreenRect(targetTransform, out var targetRect) &&
|
||||
@@ -427,6 +436,58 @@ namespace ShrinkTutorial
|
||||
QueueStepCompletion();
|
||||
}
|
||||
|
||||
private void BindClickTargetEvents(ShrinkTutorialStep step, Transform targetTransform)
|
||||
{
|
||||
if (step.completeCondition != ShrinkTutorialCompleteCondition.ClickTarget || !targetTransform)
|
||||
return;
|
||||
|
||||
_clickTargetButton = targetTransform.GetComponent<Button>() ??
|
||||
targetTransform.GetComponentInParent<Button>() ??
|
||||
targetTransform.GetComponentInChildren<Button>(true);
|
||||
if (_clickTargetButton)
|
||||
{
|
||||
_clickTargetButton.onClick.AddListener(HandleClickTargetEvent);
|
||||
LogDebug($"Bound ClickTarget button event: {GetTransformPath(_clickTargetButton.transform)}");
|
||||
return;
|
||||
}
|
||||
|
||||
_clickTargetAnchor = targetTransform.GetComponent<ShrinkTutorialAnchor>() ??
|
||||
targetTransform.GetComponentInParent<ShrinkTutorialAnchor>() ??
|
||||
targetTransform.GetComponentInChildren<ShrinkTutorialAnchor>(true);
|
||||
if (_clickTargetAnchor)
|
||||
{
|
||||
_clickTargetAnchor.Clicked += HandleClickTargetPointerEvent;
|
||||
LogDebug($"Bound ClickTarget anchor event: {GetTransformPath(_clickTargetAnchor.transform)}");
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleClickTargetEvent()
|
||||
{
|
||||
LogDebug($"ClickTarget button event received, tutorial={_currentTutorial?.tutorialId}, step={_currentStepIndex}");
|
||||
QueueStepCompletion();
|
||||
}
|
||||
|
||||
private void HandleClickTargetPointerEvent(PointerEventData eventData)
|
||||
{
|
||||
if (eventData != null && eventData.button != PointerEventData.InputButton.Left)
|
||||
return;
|
||||
|
||||
LogDebug($"ClickTarget pointer event received, tutorial={_currentTutorial?.tutorialId}, step={_currentStepIndex}");
|
||||
QueueStepCompletion();
|
||||
}
|
||||
|
||||
private void UnbindClickTargetEvents()
|
||||
{
|
||||
if (_clickTargetButton)
|
||||
_clickTargetButton.onClick.RemoveListener(HandleClickTargetEvent);
|
||||
|
||||
if (_clickTargetAnchor)
|
||||
_clickTargetAnchor.Clicked -= HandleClickTargetPointerEvent;
|
||||
|
||||
_clickTargetButton = null;
|
||||
_clickTargetAnchor = null;
|
||||
}
|
||||
|
||||
private static bool IsPointInsideTarget(Rect targetRect, ShrinkTutorialMaskShape maskShape, Vector2 screenPosition)
|
||||
{
|
||||
return maskShape == ShrinkTutorialMaskShape.Circle
|
||||
@@ -577,6 +638,7 @@ namespace ShrinkTutorial
|
||||
_runner = null;
|
||||
_stepCompletionQueued = false;
|
||||
_clickTargetArmed = false;
|
||||
UnbindClickTargetEvents();
|
||||
|
||||
TryStartQueuedTutorial();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace ShrinkTutorial
|
||||
{
|
||||
public class ShrinkTutorialAnchor : MonoBehaviour
|
||||
public class ShrinkTutorialAnchor : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
[SerializeField] private string anchorId = string.Empty;
|
||||
|
||||
public string AnchorId => anchorId;
|
||||
public event Action<PointerEventData> Clicked;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
Clicked?.Invoke(eventData);
|
||||
}
|
||||
|
||||
public void SetAnchorId(string value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user