test portal, test hub, animation improvements

This commit is contained in:
2025-09-19 14:49:14 +02:00
parent 9653e67a99
commit 6feee0019a
14 changed files with 51109 additions and 416 deletions

View File

@@ -80,12 +80,12 @@ namespace Beyond
Debug.LogError("Probably there is no data for scene : " + LevelToLoadName + " in levelLoaderData");
return;
}
/*
if (!_levelToLoadData.IsUnlocked)
{
return;
}
*/
_trigger.enabled = false;
FadeCanvasGroup.Instance.BeforeLoadingFade();
}

View File

@@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
@@ -11,10 +10,17 @@ namespace Beyond
{
[SerializeField] private List<LevelData> _levelData = new List<LevelData>();
public List<LevelData> LevelDataList => _levelData;
public LevelData GetData(string levelName)
{
return _levelData.FirstOrDefault(x => x.LevelName == levelName);
}
public List<string> GetAllLevelNames()
{
return _levelData.Select(x => x.LevelName).ToList();
}
}
[System.Serializable]
@@ -22,8 +28,8 @@ namespace Beyond
{
public string LevelName;
public string LevelNameToDisplay;
public string DialogueVariableName; // This is used to check if the level is unlocked
public LoadSceneMode LoadSceneMode;
public bool IsUnlocked;
// The "public bool IsUnlocked;" field has been removed.
}
}

View File

@@ -1,77 +1,98 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Invector;
using PixelCrushers.DialogueSystem;
using Sirenix.OdinInspector;
using UnityEngine;
using System.Collections;
namespace Beyond
{
[RequireComponent(typeof(DialogueSystemTrigger))]
[RequireComponent(typeof(bTriggerGenericAction))]
//[vClassHeader("PortalTrigger", false, iconName = "triggerIcon")]
public class PortalTrigger : MonoBehaviour
{
private static bool s_luaMethodRegistered = false;
private static bool s_luaMethodRegistered = false;
private DialogueSystemTrigger m_dialogueTrigger;
private bTriggerGenericAction m_genericTrigger;
private string m_levelToLoad;
private string[] m_levelVariableName =
{
"", "WastelandTravelUnlocked", "GardenTravelUnlocked","TempleTravelUnlocked",
"ValleyTravelUnlocked", "ChamberTravelUnlocked", "CourtTravelUnlocked"
};
public enum Levels
{
NONE,
WASTELAND,
GARDEN,
TEMPLE,
RIVER_VALLEY,
SCROLL_CHAMBER,
COURT,
};
public Levels m_exludeLevel;
private bool m_wasExluded;
void SetDialogueVariable(Levels level, bool unlocked)
{
DialogueLua.SetVariable(m_levelVariableName[(int)level], unlocked);
}
[Title("Level Configuration")]
[Tooltip("Assign your LevelLoaderData ScriptableObject here. This is the source for all level information.")]
[Required]
public LevelLoaderData levelLoaderData;
bool GetDialogueVariable(Levels level)
[Title("Direct Loading")]
[Tooltip("If true, the trigger will load the specified level directly without showing a dialogue.")]
public bool useDirectLoad = false;
[Tooltip("The name of the level to load directly.")]
[ShowIf("useDirectLoad")]
[ValueDropdown("GetLevelNamesForDropdown")]
public string directLoadLevelName;
[Title("Dialogue Configuration")]
[Tooltip("A list of levels to temporarily hide from the dialogue-based level selection.")]
[HideIf("useDirectLoad")]
[ValueDropdown("GetLevelNamesForDropdown")]
public List<string> excludedLevels = new List<string>();
private Dictionary<string, bool> m_originalDialogueStates = new Dictionary<string, bool>();
#region Lua & Dialogue Variable Management
void SetDialogueVariable(string levelName, bool unlocked)
{
return DialogueLua.GetVariable(m_levelVariableName[(int)level]).asBool;
if (levelLoaderData == null) return;
LevelData data = levelLoaderData.GetData(levelName);
if (data != null && !string.IsNullOrEmpty(data.DialogueVariableName))
{
DialogueLua.SetVariable(data.DialogueVariableName, unlocked);
}
}
public void ExcludeLevel(Levels level, bool exclude)
bool GetDialogueVariable(string levelName)
{
if (level == Levels.NONE)
return;
if (exclude)
if (levelLoaderData == null) return false;
LevelData data = levelLoaderData.GetData(levelName);
if (data != null && !string.IsNullOrEmpty(data.DialogueVariableName))
{
if (!m_wasExluded && GetDialogueVariable(level))
return DialogueLua.GetVariable(data.DialogueVariableName).asBool;
}
return false;
}
private void ExcludeSelectedLevels()
{
m_originalDialogueStates.Clear();
foreach (string levelName in excludedLevels)
{
bool originalState = GetDialogueVariable(levelName);
m_originalDialogueStates[levelName] = originalState;
if (originalState)
{
SetDialogueVariable(level, false);
m_wasExluded = true;
}
}
else if (m_wasExluded)
{
SetDialogueVariable(level, true);
m_wasExluded = false;
SetDialogueVariable(levelName, false);
}
}
}
private void RestoreExcludedLevels()
{
if (m_originalDialogueStates.Count == 0) return;
foreach (var entry in m_originalDialogueStates)
{
SetDialogueVariable(entry.Key, entry.Value);
}
m_originalDialogueStates.Clear();
}
private void RegisterLuaFunctions()
{
if (!s_luaMethodRegistered)
{
Lua.RegisterFunction("LoadLevel", this, SymbolExtensions.GetMethodInfo(() => LoadLevel((string) null)));
// Note: The Lua function is still named "LoadLevel" for consistency with your Dialogue entries.
// It correctly calls our C# method StartLevelLoad.
Lua.RegisterFunction("LoadLevel", this, SymbolExtensions.GetMethodInfo(() => StartLevelLoad((string)null)));
s_luaMethodRegistered = true;
}
}
@@ -84,54 +105,117 @@ namespace Beyond
s_luaMethodRegistered = false;
}
}
// Start is called before the first frame update
#endregion
#region Unity Lifecycle & Triggers
protected void Start()
{
//base.Start();
m_dialogueTrigger = GetComponent<DialogueSystemTrigger>();
m_genericTrigger = GetComponent<bTriggerGenericAction>();
FadeCanvasGroup.Instance.OnLoadingFadeOutEnd.AddListener(LoadLevel);
// ### FIX HERE ###
// Changed "LoadLevel" to "LoadLevelScene" to match the renamed method.
FadeCanvasGroup.Instance.OnLoadingFadeOutEnd.AddListener(LoadLevelScene);
m_genericTrigger.OnPressActionInput.AddListener(OnPressAction);
m_genericTrigger.OnPlayerExit.AddListener((arg0 => { UnregisterLuaFunctions();}));
m_genericTrigger.OnPlayerExit.AddListener((go) =>
{
RestoreExcludedLevels();
UnregisterLuaFunctions();
});
}
private void OnDestroy()
{
if (FadeCanvasGroup.Instance != null)
{
// ### FIX HERE ###
// Changed "LoadLevel" to "LoadLevelScene" to match the renamed method.
FadeCanvasGroup.Instance.OnLoadingFadeOutEnd.RemoveListener(LoadLevelScene);
}
if (m_genericTrigger != null)
{
m_genericTrigger.OnPressActionInput.RemoveListener(OnPressAction);
}
RestoreExcludedLevels();
UnregisterLuaFunctions();
}
private void OnPressAction()
{
RegisterLuaFunctions();
ExcludeLevel(m_exludeLevel, true);
if (m_exludeLevel != Levels.NONE)
if (useDirectLoad)
{
StartLevelLoad(directLoadLevelName);
}
else
{
RegisterLuaFunctions();
ExcludeSelectedLevels();
m_dialogueTrigger.OnUse();
}
m_dialogueTrigger.OnUse();
}
private void OnDestroy()
{
FadeCanvasGroup.Instance.OnLoadingFadeOutEnd.RemoveListener(LoadLevel);
ExcludeLevel(m_exludeLevel, false);
m_genericTrigger.OnPressActionInput.RemoveListener(m_dialogueTrigger.OnUse);
UnregisterLuaFunctions();
}
[Button]
public void UnloackLevel(Levels level)
{
SetDialogueVariable(level, true);
}
#endregion
private void LoadLevel()
{
ProxySceneLoader.LoadScene(m_levelToLoad);
#region Level Loading
}
private void LoadLevel(string name)
/// <summary>
/// This is called by Lua from dialogue or directly by OnPressAction. It begins the fade out.
/// </summary>
private void StartLevelLoad(string name)
{
if (string.IsNullOrEmpty(name) || levelLoaderData.GetData(name) == null)
{
Debug.LogError($"Level '{name}' not found in LevelLoaderData or name is invalid.");
return;
}
m_levelToLoad = name;
FadeCanvasGroup.Instance.BeforeLoadingFade();
}
/// <summary>
/// This is called after the fade-out animation has finished. It loads the scene.
/// </summary>
private void LoadLevelScene()
{
if (string.IsNullOrEmpty(m_levelToLoad)) return;
LevelData levelData = levelLoaderData.GetData(m_levelToLoad);
if (levelData != null)
{
ProxySceneLoader.LoadScene(levelData.LevelName);
}
else
{
Debug.LogError($"Failed to find level data for '{m_levelToLoad}' during scene loading.");
}
}
#endregion
#region Editor & Debugging
private IEnumerable GetLevelNamesForDropdown()
{
if (levelLoaderData != null)
{
return levelLoaderData.GetAllLevelNames();
}
return new List<string>();
}
[Button("Unlock Level (For Debugging)")]
public void UnlockLevel([ValueDropdown("GetLevelNamesForDropdown")] string levelName)
{
if(!string.IsNullOrEmpty(levelName))
{
SetDialogueVariable(levelName, true);
Debug.Log($"Set {levelName} to unlocked.");
}
}
#endregion
}
}