2026-06-29 20:25:57 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 片头动画流程控制器:控制 man 的 Idle → Shoot → Fall 流程,
|
2026-06-29 20:43:11 +08:00
|
|
|
/// 摔倒后黑幕转场,显示 woman 和 maninjury,切换到 camera2。
|
|
|
|
|
/// 挂载在 [Managers] 上,由 PageController 在用户选定固定方式后调用。
|
2026-06-29 20:25:57 +08:00
|
|
|
/// </summary>
|
|
|
|
|
public class OpeningFlowController : MonoBehaviour
|
|
|
|
|
{
|
2026-06-29 20:43:11 +08:00
|
|
|
[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;
|
|
|
|
|
|
2026-06-29 20:25:57 +08:00
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
AutoAssignReferences();
|
|
|
|
|
|
|
|
|
|
if (_womanObject != null) _womanObject.SetActive(false);
|
|
|
|
|
if (_manInjuryObject != null) _manInjuryObject.SetActive(false);
|
2026-06-29 20:41:12 +08:00
|
|
|
|
|
|
|
|
if (_blackScreenPanel != null)
|
|
|
|
|
{
|
|
|
|
|
_blackScreenPanel.SetActive(true);
|
|
|
|
|
if (_blackScreenImage != null)
|
|
|
|
|
_blackScreenImage.color = new Color(0, 0, 0, 0);
|
|
|
|
|
Debug.Log("[OpeningFlow] BlackScreenPanel 已就绪,初始透明");
|
|
|
|
|
}
|
2026-06-29 20:25:57 +08:00
|
|
|
|
|
|
|
|
Debug.Log("[OpeningFlow] 就绪,等待用户选择模式和固定方式。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AutoAssignReferences()
|
|
|
|
|
{
|
|
|
|
|
var manGo = GameObject.Find("man");
|
|
|
|
|
if (manGo != null && _manAnimator == null)
|
|
|
|
|
_manAnimator = manGo.GetComponent<Animator>();
|
|
|
|
|
|
|
|
|
|
var man2Go = GameObject.Find("man2");
|
|
|
|
|
if (man2Go != null)
|
|
|
|
|
{
|
|
|
|
|
if (_man2Animator == null) _man2Animator = man2Go.GetComponent<Animator>();
|
|
|
|
|
if (_man2Object == null) _man2Object = man2Go;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_womanObject == null) _womanObject = GameObject.Find("woman");
|
|
|
|
|
if (_manInjuryObject == null) _manInjuryObject = GameObject.Find("maninjury");
|
2026-06-29 20:41:12 +08:00
|
|
|
|
|
|
|
|
if (_blackScreenPanel == null)
|
|
|
|
|
_blackScreenPanel = GameObject.Find("BlackScreenPanel");
|
|
|
|
|
if (_blackScreenPanel == null)
|
|
|
|
|
{
|
|
|
|
|
var allImages = FindObjectsOfType<Image>(true);
|
|
|
|
|
foreach (var img in allImages)
|
|
|
|
|
{
|
|
|
|
|
if (img.name == "BlackScreenPanel")
|
|
|
|
|
{
|
|
|
|
|
_blackScreenPanel = img.gameObject;
|
|
|
|
|
_blackScreenImage = img;
|
|
|
|
|
Debug.Log("[OpeningFlow] BlackScreenPanel 通过 includeInactive 兜底找到");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (_blackScreenPanel != null && _blackScreenImage == null)
|
2026-06-29 20:25:57 +08:00
|
|
|
_blackScreenImage = _blackScreenPanel.GetComponent<Image>();
|
2026-06-29 20:41:12 +08:00
|
|
|
|
|
|
|
|
if (_blackScreenPanel == null)
|
|
|
|
|
Debug.LogWarning("[OpeningFlow] BlackScreenPanel 未找到!黑幕转场将不会显示");
|
|
|
|
|
else
|
|
|
|
|
Debug.Log($"[OpeningFlow] BlackScreenPanel 已找到: activeInHierarchy={_blackScreenPanel.activeInHierarchy}, Image={_blackScreenImage != null}");
|
2026-06-29 20:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayOpeningFlow(System.Action onComplete)
|
|
|
|
|
{
|
2026-06-29 20:43:11 +08:00
|
|
|
Debug.Log("[OpeningFlow] PlayOpeningFlow() 被调用");
|
2026-06-29 20:25:57 +08:00
|
|
|
StartCoroutine(RunOpeningFlow(onComplete));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerator RunOpeningFlow(System.Action onComplete)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("=== [OpeningFlow] 片头动画流程开始 ===");
|
|
|
|
|
|
2026-06-29 20:35:12 +08:00
|
|
|
if (_manAnimator != null)
|
|
|
|
|
{
|
|
|
|
|
_manAnimator.SetBool("IsStart", false);
|
|
|
|
|
_manAnimator.SetBool("IsFull", false);
|
|
|
|
|
_manAnimator.Play("manIdle", 0, 0f);
|
|
|
|
|
Debug.Log("[OpeningFlow] man Animator 已重置: IsStart=false, IsFull=false, 强制播放 manIdle");
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-29 20:25:57 +08:00
|
|
|
Debug.Log($"[OpeningFlow] Step1: man + man2 Idle ({_idleDuration}s)");
|
|
|
|
|
yield return new WaitForSeconds(_idleDuration);
|
|
|
|
|
|
2026-06-29 20:54:39 +08:00
|
|
|
// Step 2: Shoot —— 每帧强制 IsFull=false 防止 Animator 中途切走
|
2026-06-29 20:25:57 +08:00
|
|
|
Debug.Log("[OpeningFlow] Step2: man Shoot 动画开始");
|
|
|
|
|
if (_manAnimator != null)
|
|
|
|
|
{
|
2026-06-29 20:35:12 +08:00
|
|
|
_manAnimator.SetBool("IsFull", false);
|
2026-06-29 20:25:57 +08:00
|
|
|
_manAnimator.SetBool("IsStart", true);
|
2026-06-29 20:54:39 +08:00
|
|
|
Debug.Log("[OpeningFlow] man IsStart=true, IsFull=false, 触发 Shoot,每帧锁定 IsFull=false");
|
|
|
|
|
|
|
|
|
|
float shootElapsed = 0f;
|
|
|
|
|
while (shootElapsed < 3.15f)
|
|
|
|
|
{
|
|
|
|
|
shootElapsed += Time.deltaTime;
|
|
|
|
|
_manAnimator.SetBool("IsFull", false);
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
2026-06-29 20:25:57 +08:00
|
|
|
_manAnimator.SetBool("IsStart", false);
|
|
|
|
|
Debug.Log("[OpeningFlow] Step2: man Shoot 动画结束");
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-29 20:54:39 +08:00
|
|
|
// Step 3: 摔倒 —— manfull 2.1s + 停留1s
|
2026-06-29 20:25:57 +08:00
|
|
|
Debug.Log("[OpeningFlow] Step3: man Fall 动画开始");
|
|
|
|
|
if (_manAnimator != null)
|
|
|
|
|
{
|
|
|
|
|
_manAnimator.SetBool("IsFull", true);
|
2026-06-29 20:54:39 +08:00
|
|
|
Debug.Log("[OpeningFlow] man IsFull=true, 触发 manfull (2.1s)");
|
2026-06-29 20:25:57 +08:00
|
|
|
yield return new WaitForSeconds(2.1f);
|
2026-06-29 20:54:39 +08:00
|
|
|
Debug.Log("[OpeningFlow] Step3: man Fall 动画结束, 停留1s");
|
|
|
|
|
yield return new WaitForSeconds(1f);
|
2026-06-29 20:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-29 20:54:39 +08:00
|
|
|
// Step 4: 黑幕转场 —— 渐入 -> 切换角色+摄像机 -> 渐出
|
2026-06-29 20:25:57 +08:00
|
|
|
Debug.Log("[OpeningFlow] Step4: 黑幕转场开始");
|
|
|
|
|
yield return StartCoroutine(FadeBlackScreen(0f, 1f));
|
|
|
|
|
|
2026-06-29 20:54:39 +08:00
|
|
|
// 隐藏 man 和 man2,显示 woman 和 maninjury
|
|
|
|
|
if (_manAnimator != null) { _manAnimator.gameObject.SetActive(false); Debug.Log("[OpeningFlow] man 已隐藏"); }
|
2026-06-29 20:25:57 +08:00
|
|
|
if (_man2Object != null) { _man2Object.SetActive(false); Debug.Log("[OpeningFlow] man2 已隐藏"); }
|
|
|
|
|
if (_womanObject != null) { _womanObject.SetActive(true); Debug.Log("[OpeningFlow] woman 已显示"); }
|
|
|
|
|
if (_manInjuryObject != null) { _manInjuryObject.SetActive(true); Debug.Log("[OpeningFlow] maninjury 已显示"); }
|
|
|
|
|
|
2026-06-29 20:35:12 +08:00
|
|
|
SwitchToCamera2();
|
|
|
|
|
|
2026-06-29 20:25:57 +08:00
|
|
|
yield return new WaitForSeconds(0.3f);
|
|
|
|
|
yield return StartCoroutine(FadeBlackScreen(1f, 0f));
|
|
|
|
|
|
|
|
|
|
Debug.Log("=== [OpeningFlow] 片头动画流程完成 ===");
|
|
|
|
|
onComplete?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-29 20:35:12 +08:00
|
|
|
private void SwitchToCamera2()
|
|
|
|
|
{
|
|
|
|
|
var camera2Go = GameObject.Find("camera2");
|
|
|
|
|
if (camera2Go != null)
|
|
|
|
|
{
|
|
|
|
|
var cam2 = camera2Go.GetComponent<Camera>();
|
|
|
|
|
if (cam2 != null)
|
|
|
|
|
{
|
|
|
|
|
cam2.enabled = true;
|
|
|
|
|
Debug.Log("[OpeningFlow] camera2 已启用");
|
|
|
|
|
}
|
2026-06-29 20:43:11 +08:00
|
|
|
else Debug.LogWarning("[OpeningFlow] camera2 上没有 Camera 组件");
|
2026-06-29 20:35:12 +08:00
|
|
|
|
|
|
|
|
var mainCam = Camera.main;
|
2026-06-29 20:43:11 +08:00
|
|
|
if (mainCam != null) { mainCam.enabled = false; Debug.Log("[OpeningFlow] 主摄像机已禁用"); }
|
2026-06-29 20:35:12 +08:00
|
|
|
}
|
2026-06-29 20:43:11 +08:00
|
|
|
else Debug.LogWarning("[OpeningFlow] 未找到 camera2");
|
2026-06-29 20:35:12 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-29 20:25:57 +08:00
|
|
|
private IEnumerator FadeBlackScreen(float fromAlpha, float toAlpha)
|
|
|
|
|
{
|
|
|
|
|
if (_blackScreenPanel == null || _blackScreenImage == null)
|
|
|
|
|
{
|
2026-06-29 20:43:11 +08:00
|
|
|
Debug.LogWarning("[OpeningFlow] BlackScreenPanel/Image 为空,跳过转场");
|
2026-06-29 20:25:57 +08:00
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_blackScreenPanel.SetActive(true);
|
|
|
|
|
|
|
|
|
|
float elapsed = 0f;
|
|
|
|
|
while (elapsed < _fadeDuration)
|
|
|
|
|
{
|
|
|
|
|
elapsed += Time.deltaTime;
|
|
|
|
|
float t = Mathf.Clamp01(elapsed / _fadeDuration);
|
|
|
|
|
_blackScreenImage.color = new Color(0, 0, 0, Mathf.Lerp(fromAlpha, toAlpha, t));
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_blackScreenImage.color = new Color(0, 0, 0, toAlpha);
|
|
|
|
|
if (toAlpha <= 0.01f)
|
|
|
|
|
_blackScreenPanel.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|