fixed issues with triggers at witch house
This commit is contained in:
@@ -37,27 +37,35 @@ namespace Beyond
|
||||
{
|
||||
MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty);
|
||||
m_menuScroll = FindObjectOfType<MenuScroll>();
|
||||
m_menuScroll.OnOpened += DisableButtonImage;
|
||||
m_menuScroll.OnClosed += EnableButtonImage;
|
||||
if (m_menuScroll != null)
|
||||
{
|
||||
m_menuScroll.OnOpened += DisableButtonImage;
|
||||
m_menuScroll.OnClosed += EnableButtonImage;
|
||||
}
|
||||
|
||||
m_UIPanel.onOpen.AddListener(OnOpen);
|
||||
m_UIPanel.onClose.AddListener(OnClose);
|
||||
if (m_UIPanel != null)
|
||||
{
|
||||
m_UIPanel.onOpen.AddListener(OnOpen);
|
||||
m_UIPanel.onClose.AddListener(OnClose);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
TryToStartAutohideCoroutine();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Clean up listeners if needed
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
MessageSystem.RemoveListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty);
|
||||
if (m_UIPanel.gameObject != null)
|
||||
|
||||
if (m_menuScroll != null)
|
||||
{
|
||||
m_menuScroll.OnOpened -= DisableButtonImage;
|
||||
m_menuScroll.OnClosed -= EnableButtonImage;
|
||||
}
|
||||
|
||||
if (m_UIPanel != null && m_UIPanel.gameObject != null)
|
||||
{
|
||||
m_UIPanel.onOpen.RemoveListener(OnOpen);
|
||||
m_UIPanel.onClose.RemoveListener(OnClose);
|
||||
@@ -66,14 +74,20 @@ namespace Beyond
|
||||
|
||||
public void OnMessage(MessageArgs messageArgs)
|
||||
{
|
||||
// Optional but recommended: check if active before processing message
|
||||
if (!gameObject.activeInHierarchy) return;
|
||||
|
||||
switch (messageArgs.message)
|
||||
{
|
||||
case QuestMachineMessages.QuestStateChangedMessage:
|
||||
if ((QuestState)messageArgs.values[1] == QuestState.Active)
|
||||
{
|
||||
m_UIPanel.Close();
|
||||
m_UIPanel.Open();
|
||||
TryToStartAutohideCoroutine();
|
||||
if (m_UIPanel != null)
|
||||
{
|
||||
m_UIPanel.Close();
|
||||
m_UIPanel.Open();
|
||||
}
|
||||
// The OnOpen listener will call TryToStartAutohideCoroutine
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -99,50 +113,65 @@ namespace Beyond
|
||||
|
||||
private void DisableButtonImage()
|
||||
{
|
||||
if (m_buttonImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (m_buttonImage == null) return;
|
||||
m_buttonImage.enabled = false;
|
||||
}
|
||||
|
||||
private void EnableButtonImage()
|
||||
{
|
||||
if (m_buttonImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (m_buttonImage == null) return;
|
||||
m_buttonImage.enabled = true;
|
||||
}
|
||||
|
||||
private IEnumerator COR_AutoHide()
|
||||
{
|
||||
yield return new WaitForSeconds(m_autoHideTime);
|
||||
m_UIPanel.Close();
|
||||
if (m_UIPanel != null)
|
||||
{
|
||||
m_UIPanel.Close();
|
||||
}
|
||||
m_hiddingCoroutine = null;
|
||||
}
|
||||
|
||||
|
||||
private void OnClose()
|
||||
{
|
||||
m_hiddingCoroutine = null;
|
||||
SetImageToClosed();
|
||||
}
|
||||
|
||||
private void TryToStartAutohideCoroutine()
|
||||
{
|
||||
if (!m_autoHide)
|
||||
return;
|
||||
if (m_hiddingCoroutine != null )
|
||||
// Stop the coroutine if the panel is closed manually
|
||||
if (m_hiddingCoroutine != null)
|
||||
{
|
||||
StopCoroutine(m_hiddingCoroutine);
|
||||
m_hiddingCoroutine = null;
|
||||
}
|
||||
m_hiddingCoroutine = StartCoroutine(COR_AutoHide());
|
||||
SetImageToClosed();
|
||||
}
|
||||
|
||||
|
||||
private void OnOpen()
|
||||
{
|
||||
SetImageToOpen();
|
||||
TryToStartAutohideCoroutine();
|
||||
}
|
||||
|
||||
private void TryToStartAutohideCoroutine()
|
||||
{
|
||||
// FIX: Check if the GameObject is active before starting a coroutine.
|
||||
// This prevents the "Coroutine couldn't be started" error.
|
||||
if (!gameObject.activeInHierarchy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_autoHide)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop any previously running hide coroutine to reset the timer
|
||||
if (m_hiddingCoroutine != null)
|
||||
{
|
||||
StopCoroutine(m_hiddingCoroutine);
|
||||
}
|
||||
|
||||
// This is line 139 from your original script
|
||||
m_hiddingCoroutine = StartCoroutine(COR_AutoHide());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user