feat: 上一步/下一步支持woman步进撤销重做

- StepManager新增自由步进模式(无Config时):
  InitWomanSteps/RecordWomanStep/WomanStepPrevious/WomanStepNext
- PreviousStep/NextStep在_activeSteps为null时走woman步进
- TouchPositionHandler点击后通知StepManager.RecordWomanStep
- PageController在实验启动时调用InitWomanSteps初始化
- 上一步→woman回到上个位置+显示对应touchPoint
- 下一步→woman移到下个位置+显示对应touchPoint
This commit is contained in:
yangbear
2026-06-30 14:32:30 +08:00
parent 524ad732f9
commit 2df79866d0
4 changed files with 173 additions and 21 deletions
+62 -7
View File
@@ -124,18 +124,15 @@ public class StepManager : MonoBehaviour
public void NextStep()
{
if (_activeSteps == null) return;
if (_currentStepIndex >= _activeSteps.Length - 1)
{
CompleteExperiment();
return;
}
if (_activeSteps == null) { WomanStepNext(); return; }
if (_currentStepIndex >= _activeSteps.Length - 1) { CompleteExperiment(); return; }
GoToStep(_currentStepIndex + 1);
}
public void PreviousStep()
{
if (_activeSteps == null || _currentStepIndex <= 0) return;
if (_activeSteps == null) { WomanStepPrevious(); return; }
if (_currentStepIndex <= 0) return;
GoToStep(_currentStepIndex - 1);
}
@@ -178,4 +175,62 @@ public class StepManager : MonoBehaviour
GameManager.Instance.CurrentFixationMethod = newFixation;
Initialize(GameManager.Instance.CurrentExperimentType, GameManager.Instance.CurrentMode, newFixation);
}
public void InitWomanSteps()
{
_womanObject = GameObject.Find("woman");
_touchArrayObject = GameObject.Find("touchArray");
var pts = GameObject.Find("womanPointArray");
if (pts != null) { _womanMaxStep = pts.transform.childCount; _womanPositions = new Transform[_womanMaxStep]; for (int i = 0; i < _womanMaxStep; i++) _womanPositions[i] = pts.transform.GetChild(i); }
if (_touchArrayObject != null) { _touchPoints = new GameObject[_touchArrayObject.transform.childCount]; for (int i = 0; i < _touchPoints.Length; i++) _touchPoints[i] = _touchArrayObject.transform.GetChild(i).gameObject; }
_womanStepIndex = 0;
Debug.Log($"StepManager: Woman步进已初始化, 共{_womanMaxStep}个位置");
}
public void RecordWomanStep(int newStepIndex) { _womanStepIndex = Mathf.Clamp(newStepIndex, 0, _womanMaxStep); Debug.Log($"StepManager: Woman步进 -> {_womanStepIndex}"); OnStepChanged?.Invoke(_womanStepIndex); }
private void WomanStepPrevious()
{
if (_womanStepIndex <= 0) return;
_womanStepIndex--;
MoveWomanToStep(_womanStepIndex);
UpdateTouchVisibility(_womanStepIndex);
Debug.Log($"StepManager: Woman撤销 -> {_womanStepIndex}");
OnStepChanged?.Invoke(_womanStepIndex);
}
private void WomanStepNext()
{
if (_womanStepIndex >= _womanMaxStep) return;
_womanStepIndex++;
MoveWomanToStep(_womanStepIndex);
UpdateTouchVisibility(_womanStepIndex);
Debug.Log($"StepManager: Woman前进 -> {_womanStepIndex}");
OnStepChanged?.Invoke(_womanStepIndex);
}
private void MoveWomanToStep(int step)
{
if (_womanObject == null || _womanPositions == null || step <= 0 || step > _womanPositions.Length) return;
var t = _womanPositions[step - 1];
_womanObject.transform.position = t.position;
_womanObject.transform.rotation = t.rotation;
}
private void UpdateTouchVisibility(int step)
{
if (_touchPoints == null) return;
for (int i = 0; i < _touchPoints.Length; i++) _touchPoints[i].SetActive(i == step - 1);
}
[Header("=== Woman 步进追踪(不依赖 Config ===")]
[SerializeField] private GameObject _womanObject;
[SerializeField] private GameObject _touchArrayObject;
private int _womanStepIndex = 0;
private int _womanMaxStep = 3;
private Transform[] _womanPositions;
private GameObject[] _touchPoints;
}
@@ -39,6 +39,11 @@ public class TouchPositionHandler : MonoBehaviour
Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name}");
}
// 通知 StepManager 记录步骤
int stepIndex = transform.GetSiblingIndex() + 1;
var sm = FindObjectOfType<StepManager>();
if (sm != null) sm.RecordWomanStep(stepIndex);
StopAllCoroutines();
if (_meshRenderer != null) _meshRenderer.enabled = false;
+1 -1
View File
@@ -304,7 +304,7 @@ public class PageController : MonoBehaviour
{
Debug.Log("PageController: 片头动画完成,显示 ExperimentPanel");
ActivateExperimentObjects();
ShowPage(Page.Experiment);
var smW = FindObjectOfType<StepManager>(); if (smW != null) smW.InitWomanSteps(); ShowPage(Page.Experiment);
var stepManager = FindObjectOfType<StepManager>();
if (stepManager != null)