fix: 修复黑幕不显示的根因 — BlackScreenPanel active=false 导致 GameObject.Find 找不到
根因: BlackScreenPanel 初始 active=false,GameObject.Find() 只能找活跃对象 → _blackScreenPanel 一直为 null → FadeBlackScreen() 直接 yield break 跳过 修复: 1. 场景中激活 BlackScreenPanel(alpha=0 所以视觉不可见) 2. AutoAssignReferences() 增加 FindObjectsOfType<Image>(true) 兜底 3. Start() 改为保持 BlackScreenPanel active + alpha=0,而非 SetActive(false) 4. 增加 Debug.Log 确认 BlackScreenPanel 找到状态
This commit is contained in:
@@ -9,21 +9,6 @@ using System.Collections;
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 自动查找引用
|
||||
@@ -32,7 +17,15 @@ public class OpeningFlowController : MonoBehaviour
|
||||
// 初始状态确认:woman 和 maninjury 应该隐藏
|
||||
if (_womanObject != null) _womanObject.SetActive(false);
|
||||
if (_manInjuryObject != null) _manInjuryObject.SetActive(false);
|
||||
if (_blackScreenPanel != null) _blackScreenPanel.SetActive(false);
|
||||
|
||||
// BlackScreenPanel:保持 active,但确保 alpha=0(透明不可见)
|
||||
if (_blackScreenPanel != null)
|
||||
{
|
||||
_blackScreenPanel.SetActive(true);
|
||||
if (_blackScreenImage != null)
|
||||
_blackScreenImage.color = new Color(0, 0, 0, 0);
|
||||
Debug.Log("[OpeningFlow] BlackScreenPanel 已就绪,初始透明");
|
||||
}
|
||||
|
||||
// 不自动启动动画流程 —— 等待用户选择模式和固定方式后由 PageController 触发
|
||||
Debug.Log("[OpeningFlow] 就绪,等待用户选择模式和固定方式。");
|
||||
@@ -53,9 +46,32 @@ public class OpeningFlowController : MonoBehaviour
|
||||
|
||||
if (_womanObject == null) _womanObject = GameObject.Find("woman");
|
||||
if (_manInjuryObject == null) _manInjuryObject = GameObject.Find("maninjury");
|
||||
if (_blackScreenPanel == null) _blackScreenPanel = GameObject.Find("BlackScreenPanel");
|
||||
if (_blackScreenImage == null && _blackScreenPanel != null)
|
||||
|
||||
// BlackScreenPanel:先用常规 Find,找不到再用 includeInactive 兜底
|
||||
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)
|
||||
_blackScreenImage = _blackScreenPanel.GetComponent<Image>();
|
||||
|
||||
if (_blackScreenPanel == null)
|
||||
Debug.LogWarning("[OpeningFlow] BlackScreenPanel 未找到!黑幕转场将不会显示");
|
||||
else
|
||||
Debug.Log($"[OpeningFlow] BlackScreenPanel 已找到: activeInHierarchy={_blackScreenPanel.activeInHierarchy}, Image={_blackScreenImage != null}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user