fix: 重建 OpeningFlowController.cs,修复字段声明丢失导致的编译错误

之前 structured edit 替换方法时丢失了所有 [SerializeField] 字段声明
现在删掉重建完整文件,字段全部在类开头正确声明
This commit is contained in:
yangbear
2026-06-29 20:43:11 +08:00
parent 4147d6e800
commit 34c57b51fe
@@ -4,21 +4,34 @@ using System.Collections;
/// <summary> /// <summary>
/// 片头动画流程控制器:控制 man 的 Idle → Shoot → Fall 流程, /// 片头动画流程控制器:控制 man 的 Idle → Shoot → Fall 流程,
/// 摔倒后黑幕转场,显示 woman 和 maninjury。 /// 摔倒后黑幕转场,显示 woman 和 maninjury,切换到 camera2
/// 挂在一个独立的空 GameObject 上(如 SceneRoot /// 挂载在 [Managers] 上,由 PageController 在用户选定固定方式后调用
/// </summary> /// </summary>
public class OpeningFlowController : MonoBehaviour public class OpeningFlowController : MonoBehaviour
{ {
[Header("=== 角色引用 ===")]
[SerializeField] private Animator _manAnimator;
[SerializeField] private Animator _man2Animator;
[SerializeField] private GameObject _man2Object;
[SerializeField] private GameObject _womanObject;
[SerializeField] private GameObject _manInjuryObject;
[Header("=== 黑幕 UI ===")]
[SerializeField] private GameObject _blackScreenPanel;
[SerializeField] private Image _blackScreenImage;
[Header("=== 时间配置 ===")]
[SerializeField] private float _idleDuration = 2f;
[SerializeField] private float _fadeDuration = 1f;
[SerializeField] private float _fallHoldDuration = 1.5f;
private void Start() private void Start()
{ {
// 自动查找引用
AutoAssignReferences(); AutoAssignReferences();
// 初始状态确认:woman 和 maninjury 应该隐藏
if (_womanObject != null) _womanObject.SetActive(false); if (_womanObject != null) _womanObject.SetActive(false);
if (_manInjuryObject != null) _manInjuryObject.SetActive(false); if (_manInjuryObject != null) _manInjuryObject.SetActive(false);
// BlackScreenPanel:保持 active,但确保 alpha=0(透明不可见)
if (_blackScreenPanel != null) if (_blackScreenPanel != null)
{ {
_blackScreenPanel.SetActive(true); _blackScreenPanel.SetActive(true);
@@ -27,7 +40,6 @@ public class OpeningFlowController : MonoBehaviour
Debug.Log("[OpeningFlow] BlackScreenPanel 已就绪,初始透明"); Debug.Log("[OpeningFlow] BlackScreenPanel 已就绪,初始透明");
} }
// 不自动启动动画流程 —— 等待用户选择模式和固定方式后由 PageController 触发
Debug.Log("[OpeningFlow] 就绪,等待用户选择模式和固定方式。"); Debug.Log("[OpeningFlow] 就绪,等待用户选择模式和固定方式。");
} }
@@ -47,12 +59,10 @@ public class OpeningFlowController : MonoBehaviour
if (_womanObject == null) _womanObject = GameObject.Find("woman"); if (_womanObject == null) _womanObject = GameObject.Find("woman");
if (_manInjuryObject == null) _manInjuryObject = GameObject.Find("maninjury"); if (_manInjuryObject == null) _manInjuryObject = GameObject.Find("maninjury");
// BlackScreenPanel:先用常规 Find,找不到再用 includeInactive 兜底
if (_blackScreenPanel == null) if (_blackScreenPanel == null)
_blackScreenPanel = GameObject.Find("BlackScreenPanel"); _blackScreenPanel = GameObject.Find("BlackScreenPanel");
if (_blackScreenPanel == null) if (_blackScreenPanel == null)
{ {
// 兜底:搜索非活跃对象
var allImages = FindObjectsOfType<Image>(true); var allImages = FindObjectsOfType<Image>(true);
foreach (var img in allImages) foreach (var img in allImages)
{ {
@@ -74,14 +84,9 @@ public class OpeningFlowController : MonoBehaviour
Debug.Log($"[OpeningFlow] BlackScreenPanel 已找到: activeInHierarchy={_blackScreenPanel.activeInHierarchy}, Image={_blackScreenImage != null}"); Debug.Log($"[OpeningFlow] BlackScreenPanel 已找到: activeInHierarchy={_blackScreenPanel.activeInHierarchy}, Image={_blackScreenImage != null}");
} }
/// <summary>
/// 公开方法:由 PageController 在用户选定固定方式后调用。
/// 播放片头动画(man Idle→Shoot→Fall→黑幕转场→显示woman+maninjury),
/// 完成后回调 onComplete。
/// </summary>
public void PlayOpeningFlow(System.Action onComplete) public void PlayOpeningFlow(System.Action onComplete)
{ {
Debug.Log("[OpeningFlow] PlayOpeningFlow() 被调用,开始播放片头动画。"); Debug.Log("[OpeningFlow] PlayOpeningFlow() 被调用");
StartCoroutine(RunOpeningFlow(onComplete)); StartCoroutine(RunOpeningFlow(onComplete));
} }
@@ -89,7 +94,6 @@ public class OpeningFlowController : MonoBehaviour
{ {
Debug.Log("=== [OpeningFlow] 片头动画流程开始 ==="); Debug.Log("=== [OpeningFlow] 片头动画流程开始 ===");
// 强制重置 man 所有动画参数,确保从 Idle 状态开始
if (_manAnimator != null) if (_manAnimator != null)
{ {
_manAnimator.SetBool("IsStart", false); _manAnimator.SetBool("IsStart", false);
@@ -97,16 +101,10 @@ public class OpeningFlowController : MonoBehaviour
_manAnimator.Play("manIdle", 0, 0f); _manAnimator.Play("manIdle", 0, 0f);
Debug.Log("[OpeningFlow] man Animator 已重置: IsStart=false, IsFull=false, 强制播放 manIdle"); Debug.Log("[OpeningFlow] man Animator 已重置: IsStart=false, IsFull=false, 强制播放 manIdle");
} }
else
{
Debug.LogWarning("[OpeningFlow] _manAnimator 为空!");
}
// Step 1: man 和 man2 同时 Idle,持续 _idleDuration 秒
Debug.Log($"[OpeningFlow] Step1: man + man2 Idle ({_idleDuration}s)"); Debug.Log($"[OpeningFlow] Step1: man + man2 Idle ({_idleDuration}s)");
yield return new WaitForSeconds(_idleDuration); yield return new WaitForSeconds(_idleDuration);
// Step 2: man 投篮动画 Shoot (3.15s)
Debug.Log("[OpeningFlow] Step2: man Shoot 动画开始"); Debug.Log("[OpeningFlow] Step2: man Shoot 动画开始");
if (_manAnimator != null) if (_manAnimator != null)
{ {
@@ -117,41 +115,25 @@ public class OpeningFlowController : MonoBehaviour
_manAnimator.SetBool("IsStart", false); _manAnimator.SetBool("IsStart", false);
Debug.Log("[OpeningFlow] Step2: man Shoot 动画结束"); Debug.Log("[OpeningFlow] Step2: man Shoot 动画结束");
} }
else
{
Debug.LogWarning("[OpeningFlow] _manAnimator 为空,跳过 Step2");
}
// Step 3: man 摔倒动画 manfull,等待动画播完 + 停留缓冲
Debug.Log("[OpeningFlow] Step3: man Fall 动画开始"); Debug.Log("[OpeningFlow] Step3: man Fall 动画开始");
if (_manAnimator != null) if (_manAnimator != null)
{ {
_manAnimator.SetBool("IsFull", true); _manAnimator.SetBool("IsFull", true);
Debug.Log("[OpeningFlow] man IsFull=true, 触发 manfull"); Debug.Log("[OpeningFlow] man IsFull=true, 触发 manfull");
// 等待 manfull 动画播放完成(2.1s
yield return new WaitForSeconds(2.1f); yield return new WaitForSeconds(2.1f);
Debug.Log("[OpeningFlow] Step3: man Fall 动画结束"); Debug.Log("[OpeningFlow] Step3: man Fall 动画结束");
// 摔倒后停留缓冲,让玩家看清摔倒结果
Debug.Log($"[OpeningFlow] Step3: 摔倒后停留缓冲 {_fallHoldDuration}s");
yield return new WaitForSeconds(_fallHoldDuration); yield return new WaitForSeconds(_fallHoldDuration);
} Debug.Log($"[OpeningFlow] Step3: 摔倒后停留缓冲 {_fallHoldDuration}s 结束");
else
{
Debug.LogWarning("[OpeningFlow] _manAnimator 为空,跳过 Step3");
} }
// Step 4: 黑幕转场 —— 渐入 -> 切换角色+摄像机 -> 渐出
Debug.Log("[OpeningFlow] Step4: 黑幕转场开始"); Debug.Log("[OpeningFlow] Step4: 黑幕转场开始");
yield return StartCoroutine(FadeBlackScreen(0f, 1f)); yield return StartCoroutine(FadeBlackScreen(0f, 1f));
// 切换角色
if (_man2Object != null) { _man2Object.SetActive(false); Debug.Log("[OpeningFlow] man2 已隐藏"); } if (_man2Object != null) { _man2Object.SetActive(false); Debug.Log("[OpeningFlow] man2 已隐藏"); }
if (_womanObject != null) { _womanObject.SetActive(true); Debug.Log("[OpeningFlow] woman 已显示"); } if (_womanObject != null) { _womanObject.SetActive(true); Debug.Log("[OpeningFlow] woman 已显示"); }
if (_manInjuryObject != null) { _manInjuryObject.SetActive(true); Debug.Log("[OpeningFlow] maninjury 已显示"); } if (_manInjuryObject != null) { _manInjuryObject.SetActive(true); Debug.Log("[OpeningFlow] maninjury 已显示"); }
// 切换摄像机到 camera2
SwitchToCamera2(); SwitchToCamera2();
yield return new WaitForSeconds(0.3f); yield return new WaitForSeconds(0.3f);
@@ -161,9 +143,6 @@ public class OpeningFlowController : MonoBehaviour
onComplete?.Invoke(); onComplete?.Invoke();
} }
/// <summary>
/// 切换到 camera2,禁用主摄像机
/// </summary>
private void SwitchToCamera2() private void SwitchToCamera2()
{ {
var camera2Go = GameObject.Find("camera2"); var camera2Go = GameObject.Find("camera2");
@@ -175,30 +154,19 @@ public class OpeningFlowController : MonoBehaviour
cam2.enabled = true; cam2.enabled = true;
Debug.Log("[OpeningFlow] camera2 已启用"); Debug.Log("[OpeningFlow] camera2 已启用");
} }
else else Debug.LogWarning("[OpeningFlow] camera2 上没有 Camera 组件");
{
Debug.LogWarning("[OpeningFlow] camera2 上没有 Camera 组件!");
}
// 禁用主摄像机(MainCamera 或标签为 MainCamera 的)
var mainCam = Camera.main; var mainCam = Camera.main;
if (mainCam != null) if (mainCam != null) { mainCam.enabled = false; Debug.Log("[OpeningFlow] 主摄像机已禁用"); }
{
mainCam.enabled = false;
Debug.Log("[OpeningFlow] 主摄像机已禁用");
}
}
else
{
Debug.LogWarning("[OpeningFlow] 未找到 camera2,摄像机未切换");
} }
else Debug.LogWarning("[OpeningFlow] 未找到 camera2");
} }
private IEnumerator FadeBlackScreen(float fromAlpha, float toAlpha) private IEnumerator FadeBlackScreen(float fromAlpha, float toAlpha)
{ {
if (_blackScreenPanel == null || _blackScreenImage == null) if (_blackScreenPanel == null || _blackScreenImage == null)
{ {
Debug.LogWarning("[OpeningFlow] BlackScreenPanelImage 为空,跳过转场"); Debug.LogWarning("[OpeningFlow] BlackScreenPanel/Image 为空,跳过转场");
yield break; yield break;
} }
@@ -217,7 +185,4 @@ public class OpeningFlowController : MonoBehaviour
if (toAlpha <= 0.01f) if (toAlpha <= 0.01f)
_blackScreenPanel.SetActive(false); _blackScreenPanel.SetActive(false);
} }
[SerializeField] private float _fallHoldDuration = 1.5f;
} }