fixed issues with triggers at witch house
This commit is contained in:
@@ -29,88 +29,16 @@ namespace Beyond
|
||||
|
||||
public static Action<TriggerDescriptor> ActionTriggerEnter;
|
||||
public static Action<TriggerDescriptor> ActionTriggerExit;
|
||||
/*
|
||||
public static Action<GameObject> LadderTriggerEnter;
|
||||
public static Action<GameObject> LadderTriggerExit;
|
||||
|
||||
public static Action<GameObject> FootbridgeTriggerEnter;
|
||||
public static Action<GameObject> FootbridgeTriggerExit;
|
||||
|
||||
public static Action<GameObject> EnterFootbridge;
|
||||
public static Action<GameObject> ExitFootbridge;
|
||||
public UnityEvent OnHideOnTriggerEnter;
|
||||
public UnityEvent OnHideOnTriggerExit;
|
||||
|
||||
public UnityEvent OnActionTriggerEnter;
|
||||
public UnityEvent OnActionTriggerExit;
|
||||
|
||||
public UnityEvent OnLadderTriggerEnter;
|
||||
public UnityEvent OnLadderTriggerExit;
|
||||
|
||||
public UnityEvent OnFootbridgeTriggerEnter;
|
||||
public UnityEvent OnFootbridgeTriggerExit;
|
||||
|
||||
public UnityEvent OnEnterFootbridge;
|
||||
public UnityEvent OnExitFootbridge;
|
||||
*/
|
||||
|
||||
private bool usingFootbridge;
|
||||
|
||||
private TriggerDescriptor m_currentDesc;
|
||||
|
||||
private List<TriggerDescriptor> m_Triggers = new List<TriggerDescriptor>();
|
||||
|
||||
// NEW: Dictionary for reference counting to handle multiple colliders
|
||||
private Dictionary<TriggerDescriptor, int> m_TriggerCounts = new Dictionary<TriggerDescriptor, int>();
|
||||
|
||||
private GameStateManager.State m_prevGameState = GameStateManager.State.NORMAL;
|
||||
|
||||
/*
|
||||
private List<TriggerObject> m_triggers = new List<TriggerObject>();
|
||||
public enum TriggerType
|
||||
{
|
||||
Dialogue,
|
||||
Ladder,
|
||||
Generic,
|
||||
Collectable,
|
||||
COUNT
|
||||
};
|
||||
|
||||
public struct TriggerObject : IComparable<TriggerObject>, IComparable
|
||||
{
|
||||
public GameObject obj;
|
||||
public TriggerType type;
|
||||
|
||||
public int CompareTo(TriggerObject other)
|
||||
{
|
||||
return type.CompareTo(other.type);
|
||||
}
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return 1;
|
||||
return obj is TriggerObject other ? CompareTo(other) : throw new ArgumentException($"Object must be of type {nameof(TriggerObject)}");
|
||||
}
|
||||
|
||||
public static bool operator <(TriggerObject left, TriggerObject right)
|
||||
{
|
||||
return left.CompareTo(right) < 0;
|
||||
}
|
||||
|
||||
public static bool operator >(TriggerObject left, TriggerObject right)
|
||||
{
|
||||
return left.CompareTo(right) > 0;
|
||||
}
|
||||
|
||||
public static bool operator <=(TriggerObject left, TriggerObject right)
|
||||
{
|
||||
return left.CompareTo(right) <= 0;
|
||||
}
|
||||
|
||||
public static bool operator >=(TriggerObject left, TriggerObject right)
|
||||
{
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (LadderButton)
|
||||
@@ -133,11 +61,6 @@ return left.CompareTo(right) >= 0;
|
||||
}
|
||||
if (RunButton)
|
||||
RunButton.gameObject.SetActive(!disableRun);
|
||||
|
||||
//if (TargetButton)
|
||||
// TargetButton.gameObject.SetActive(true);
|
||||
//if (JumpButton)
|
||||
// JumpButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void OnActionTrigger(bool activate, TriggerDescriptor.TriggerType type)
|
||||
@@ -162,37 +85,21 @@ return left.CompareTo(right) >= 0;
|
||||
AttackButton.gameObject.SetActive(!activate);
|
||||
if (SpellButton)
|
||||
SpellButton.gameObject.SetActive(!activate);
|
||||
//if (ComsumableButton)
|
||||
// ComsumableButton.gameObject.SetActive(!activate);
|
||||
//if (ComsumableFaithButton)
|
||||
// ComsumableFaithButton.gameObject.SetActive(!activate);
|
||||
if (powerButtonsParent)
|
||||
{
|
||||
powerButtonsParent.SetActive(!activate);
|
||||
}
|
||||
if (RunButton && !disableRun)
|
||||
RunButton.interactable = !activate;
|
||||
//if (TargetButton)
|
||||
// TargetButton.interactable = !activate;
|
||||
//if (JumpButton)
|
||||
// JumpButton.interactable = !activate;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ActionTriggerEnter += OnInvokeActionTriggerEnter;
|
||||
ActionTriggerExit += OnInvokeActionTriggerExit;
|
||||
GameStateManager.Instance.m_OnStateChanged.AddListener(OnGameStateChanged);
|
||||
if (GameStateManager.Instance)
|
||||
GameStateManager.Instance.m_OnStateChanged.AddListener(OnGameStateChanged);
|
||||
|
||||
/*
|
||||
LadderTriggerEnter += OnInvokeLadderTriggerEnter;
|
||||
LadderTriggerExit += OnInvokeLadderTriggerExit;
|
||||
FootbridgeTriggerEnter += OnInvokeFootbridgeTriggerEnter;
|
||||
FootbridgeTriggerExit += OnInvokeFootbridgeTriggerExit;
|
||||
EnterFootbridge += OnInvokeEnterFootbridge;
|
||||
ExitFootbridge += OnInvokeExitFootbridge;
|
||||
*/
|
||||
//OnInvokeActionTriggerExit(gameObject);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
@@ -202,14 +109,6 @@ return left.CompareTo(right) >= 0;
|
||||
ActionTriggerExit -= OnInvokeActionTriggerExit;
|
||||
if (GameStateManager.Instance)
|
||||
GameStateManager.Instance.m_OnStateChanged.RemoveListener(OnGameStateChanged);
|
||||
/*
|
||||
LadderTriggerEnter -= OnInvokeLadderTriggerEnter;
|
||||
LadderTriggerExit -= OnInvokeLadderTriggerExit;
|
||||
FootbridgeTriggerEnter -= OnInvokeFootbridgeTriggerEnter;
|
||||
FootbridgeTriggerExit -= OnInvokeFootbridgeTriggerExit;
|
||||
EnterFootbridge -= OnInvokeEnterFootbridge;
|
||||
ExitFootbridge -= OnInvokeExitFootbridge;
|
||||
*/
|
||||
}
|
||||
|
||||
void OnGameStateChanged(GameStateManager.State state)
|
||||
@@ -234,99 +133,48 @@ return left.CompareTo(right) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private void OnInvokeHideOnTriggerEnter()
|
||||
{
|
||||
DebugLog("OnInvokeHideOnTriggerEnter");
|
||||
OnHideOnTriggerEnter?.Invoke();
|
||||
}
|
||||
|
||||
private void OnInvokeHideOnTriggerExit()
|
||||
{
|
||||
DebugLog("OnInvokeHideOnTriggerExit");
|
||||
OnHideOnTriggerExit?.Invoke();
|
||||
}
|
||||
|
||||
private void OnInvokeEnterFootbridge(GameObject gameObject)
|
||||
{
|
||||
DebugLog("OnInvokeEnterFootbridge");
|
||||
usingFootbridge = true;
|
||||
OnInvokeHideOnTriggerEnter();
|
||||
OnEnterFootbridge?.Invoke();
|
||||
}
|
||||
|
||||
private void OnInvokeExitFootbridge(GameObject gameObject)
|
||||
{
|
||||
DebugLog("OnInvokeExitFootbridge");
|
||||
usingFootbridge = false;
|
||||
OnInvokeHideOnTriggerExit();
|
||||
OnExitFootbridge?.Invoke();
|
||||
}
|
||||
|
||||
private void OnInvokeFootbridgeTriggerEnter(GameObject gameObject)
|
||||
{
|
||||
if (usingFootbridge) return;
|
||||
DebugLog("OnInvokeFootbridgeTriggerEnter");
|
||||
OnFootbridgeTriggerEnter?.Invoke();
|
||||
OnInvokeHideOnTriggerEnter();
|
||||
}
|
||||
|
||||
private void OnInvokeFootbridgeTriggerExit(GameObject gameObject)
|
||||
{
|
||||
if (usingFootbridge) return;
|
||||
DebugLog("OnInvokeFootbridgeTriggerExit");
|
||||
OnFootbridgeTriggerExit?.Invoke();
|
||||
OnInvokeHideOnTriggerExit();
|
||||
}
|
||||
*/
|
||||
|
||||
// CORRECTED: Handles multiple colliders entering the same trigger.
|
||||
private void OnInvokeActionTriggerEnter(TriggerDescriptor to)
|
||||
{
|
||||
DebugLog("OnInvokeActionTriggerEnter");
|
||||
//OnActionTrigger(true, to.type);
|
||||
//OnActionTriggerEnter?.Invoke();
|
||||
//OnInvokeHideOnTriggerEnter();
|
||||
if (!m_Triggers.Contains(to))
|
||||
DebugLog("OnInvokeActionTriggerEnter for: " + to.obj.name);
|
||||
if (!m_TriggerCounts.ContainsKey(to))
|
||||
{
|
||||
m_Triggers.Add(to);
|
||||
m_TriggerCounts.Add(to, 1); // Add to dictionary with a count of 1.
|
||||
}
|
||||
else
|
||||
{
|
||||
m_TriggerCounts[to]++; // If already present, just increment the count.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CORRECTED: Handles multiple colliders exiting the same trigger.
|
||||
private void OnInvokeActionTriggerExit(TriggerDescriptor to)
|
||||
{
|
||||
//OnActionTrigger(false, to.type);
|
||||
DebugLog("OnInvokeActionTriggerExit");
|
||||
//OnActionTriggerExit?.Invoke();
|
||||
//OnInvokeHideOnTriggerExit();
|
||||
if (m_Triggers.Contains(to))
|
||||
DebugLog("OnInvokeActionTriggerExit for: " + to.obj.name);
|
||||
if (m_TriggerCounts.ContainsKey(to))
|
||||
{
|
||||
m_Triggers.Remove(to);
|
||||
if (to == m_currentDesc)
|
||||
m_TriggerCounts[to]--; // Decrement the reference count.
|
||||
|
||||
// Only remove the trigger completely if this was the last collider to exit.
|
||||
if (m_TriggerCounts[to] <= 0)
|
||||
{
|
||||
OnActionTrigger(false, to.type);
|
||||
m_currentDesc = null;
|
||||
m_TriggerCounts.Remove(to); // Clean up the dictionary.
|
||||
m_Triggers.Remove(to);
|
||||
if (to == m_currentDesc)
|
||||
{
|
||||
OnActionTrigger(false, to.type);
|
||||
m_currentDesc = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This error should no longer occur with the new logic.
|
||||
Debug.LogError("Exitting trigger that is not on the list! " + to.obj.name, this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private void OnInvokeLadderTriggerEnter(GameObject gameObject)
|
||||
{
|
||||
DebugLog("OnInvokeLadderTriggerEnter");
|
||||
OnLadderTriggerEnter?.Invoke();
|
||||
OnInvokeHideOnTriggerEnter();
|
||||
}
|
||||
|
||||
private void OnInvokeLadderTriggerExit(GameObject gameObject)
|
||||
{
|
||||
DebugLog("OnInvokeLadderTriggerExit");
|
||||
OnLadderTriggerExit?.Invoke();
|
||||
OnInvokeHideOnTriggerExit();
|
||||
}
|
||||
*/
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var gameState = GameStateManager.Instance.CurrentState;
|
||||
@@ -371,6 +219,12 @@ return left.CompareTo(right) >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// This handles the case where the last trigger was removed from the list
|
||||
else if (m_currentDesc != null)
|
||||
{
|
||||
OnActionTrigger(false, m_currentDesc.type);
|
||||
m_currentDesc = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,6 @@ namespace Beyond
|
||||
public bool disableHUD = true;
|
||||
|
||||
[vHelpBox("Changes interaction image")]
|
||||
//public bool isDialogueTrigger = false;
|
||||
|
||||
public TriggerDescriptor.TriggerType triggerType = TriggerDescriptor.TriggerType.Generic;
|
||||
|
||||
public UnityEvent OnPlayerMatchTargetPosition;
|
||||
@@ -130,6 +128,11 @@ namespace Beyond
|
||||
|
||||
private void OnActionEndAnimation(GameObject gameObject)
|
||||
{
|
||||
// THIS SECTION WAS THE PRIMARY CAUSE OF THE DOUBLE-EXIT CALL.
|
||||
// The logic below was removed because the trigger exit should only happen
|
||||
// when the player physically leaves the collider, which is already
|
||||
// handled by the OnInvalidate event that calls OnActionTriggerExit.
|
||||
/*
|
||||
if (disableHUD)
|
||||
{
|
||||
ActionTriggerEvent.ActionTriggerExit?.Invoke(m_triggerDescriptor);
|
||||
@@ -139,6 +142,7 @@ namespace Beyond
|
||||
{
|
||||
Player.Instance.ResetIntaractableButtonImage();
|
||||
}
|
||||
*/
|
||||
|
||||
if (!m_enableInteractionLegality)
|
||||
{
|
||||
@@ -165,12 +169,10 @@ namespace Beyond
|
||||
{
|
||||
m_faded = true;
|
||||
FadeCanvasGroup.Instance.FadeOut(1f / m_fadeSpeed);
|
||||
//.InvokeFade(m_fadeInCurve, m_fadeSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
FadeCanvasGroup.Instance.FadeIn(1f / m_fadeSpeed);
|
||||
//FadeCanvasGroup.InvokeFade(m_fadeOutCurve, m_fadeSpeed);
|
||||
}
|
||||
|
||||
private void OnFadeInEnd()
|
||||
|
||||
Reference in New Issue
Block a user