Thomas ICHÉ
5 年前
当前提交
901eaac8
共有 3 个文件被更改,包括 126 次插入 和 128 次删除
-
14Runtime/GameLevel.cs
-
94Runtime/LevelScripting/Actions/GameLevelLoadAction.cs
-
146Runtime/Managers/Implementations/GameManager.cs
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using GameplayIngredients.LevelStreaming; |
|||
using GameplayIngredients; |
|||
public class GameLevel : ScriptableObject |
|||
namespace GameplayIngredients |
|||
[ReorderableList, Scene] |
|||
public string[] StartupScenes; |
|||
public class GameLevel : ScriptableObject |
|||
{ |
|||
[ReorderableList, Scene] |
|||
public string[] StartupScenes; |
|||
} |
|||
|
|
|||
using System.Linq; |
|||
using System.Collections.Generic; |
|||
using GameplayIngredients; |
|||
using GameplayIngredients.Actions; |
|||
public class GameLevelLoadAction : ActionBase |
|||
namespace GameplayIngredients.Actions |
|||
public enum Target |
|||
public class GameLevelLoadAction : ActionBase |
|||
MainMenu, |
|||
First, |
|||
Previous, |
|||
Current, |
|||
Next, |
|||
Last, |
|||
SpecifiedLevel, |
|||
FromGameSave, |
|||
} |
|||
public bool ShowUI = true; |
|||
public Target level = Target.First; |
|||
[NonNullCheck, ShowIf("isSpecified"), Tooltip("Which Level to Load/Unload, when selected 'Specified' level")] |
|||
public GameLevel specifiedLevel; |
|||
public enum Target |
|||
{ |
|||
MainMenu, |
|||
First, |
|||
Previous, |
|||
Current, |
|||
Next, |
|||
Last, |
|||
SpecifiedLevel, |
|||
FromGameSave, |
|||
} |
|||
public bool ShowUI = true; |
|||
public Target level = Target.First; |
|||
[NonNullCheck, ShowIf("isSpecified"), Tooltip("Which Level to Load/Unload, when selected 'Specified' level")] |
|||
public GameLevel specifiedLevel; |
|||
[ShowIf("isGameSave")] |
|||
public int UserSaveIndex = 0; |
|||
[ShowIf("isGameSave")] |
|||
public string UserSaveName = "Progress"; |
|||
[ShowIf("isGameSave")] |
|||
public int UserSaveIndex = 0; |
|||
[ShowIf("isGameSave")] |
|||
public string UserSaveName = "Progress"; |
|||
[ReorderableList] |
|||
public Callable[] OnComplete; |
|||
|
|||
private bool isSpecified() { return level == Target.SpecifiedLevel; } |
|||
private bool isGameSave() { return level == Target.FromGameSave; } |
|||
[ReorderableList] |
|||
public Callable[] OnComplete; |
|||
public override void Execute(GameObject instigator = null) |
|||
{ |
|||
int index = -2; |
|||
var manager = Manager.Get<GameManager>(); |
|||
private bool isSpecified() { return level == Target.SpecifiedLevel; } |
|||
private bool isGameSave() { return level == Target.FromGameSave; } |
|||
switch (level) |
|||
public override void Execute(GameObject instigator = null) |
|||
case Target.MainMenu: index = -1; break; |
|||
case Target.First: index = 0; break; |
|||
case Target.Last: index = manager.MainGameLevels.Length - 1; break; |
|||
case Target.Current: index = manager.currentLevel; break; |
|||
case Target.Previous: index = Mathf.Max(0, manager.currentLevel-1); break; |
|||
case Target.Next: index = Mathf.Min(manager.MainGameLevels.Length - 1, manager.currentLevel + 1); break; |
|||
case Target.SpecifiedLevel: |
|||
if(specifiedLevel != null && manager.MainGameLevels.Contains(specifiedLevel)) |
|||
{ |
|||
index = manager.MainGameLevels.ToList().IndexOf(specifiedLevel); |
|||
} |
|||
break; |
|||
case Target.FromGameSave: index = manager.currentSaveProgress; break; |
|||
int index = -2; |
|||
var manager = Manager.Get<GameManager>(); |
|||
|
|||
switch (level) |
|||
{ |
|||
case Target.MainMenu: index = -1; break; |
|||
case Target.First: index = 0; break; |
|||
case Target.Last: index = manager.MainGameLevels.Length - 1; break; |
|||
case Target.Current: index = manager.currentLevel; break; |
|||
case Target.Previous: index = Mathf.Max(0, manager.currentLevel - 1); break; |
|||
case Target.Next: index = Mathf.Min(manager.MainGameLevels.Length - 1, manager.currentLevel + 1); break; |
|||
case Target.SpecifiedLevel: |
|||
if (specifiedLevel != null && manager.MainGameLevels.Contains(specifiedLevel)) |
|||
{ |
|||
index = manager.MainGameLevels.ToList().IndexOf(specifiedLevel); |
|||
} |
|||
break; |
|||
case Target.FromGameSave: index = manager.currentSaveProgress; break; |
|||
} |
|||
manager.SwitchLevel(index, ShowUI, OnComplete); |
|||
|
|||
manager.SwitchLevel(index, ShowUI, OnComplete); |
|||
|
|||
} |
|||
} |
|
|||
using GameplayIngredients; |
|||
using System.Collections.Generic; |
|||
using GameplayIngredients.Logic; |
|||
[ManagerDefaultPrefab("GameManager")] |
|||
public class GameManager : Manager |
|||
namespace GameplayIngredients |
|||
[Header("Events")] |
|||
[ReorderableList] |
|||
public Callable[] OnGameStart; |
|||
[ReorderableList] |
|||
public Callable[] OnLevelLoaded; |
|||
[ReorderableList] |
|||
public Callable[] OnMainMenuLoaded; |
|||
[ManagerDefaultPrefab("GameManager")] |
|||
public class GameManager : Manager |
|||
{ |
|||
[Header("Events")] |
|||
[ReorderableList] |
|||
public Callable[] OnGameStart; |
|||
[ReorderableList] |
|||
public Callable[] OnLevelLoaded; |
|||
[ReorderableList] |
|||
public Callable[] OnMainMenuLoaded; |
|||
[Header("Levels"),NonNullCheck] |
|||
public GameLevel MainMenuGameLevel; |
|||
[ReorderableList,NonNullCheck] |
|||
public GameLevel[] MainGameLevels; |
|||
[Header("Levels"), NonNullCheck] |
|||
public GameLevel MainMenuGameLevel; |
|||
[ReorderableList, NonNullCheck] |
|||
public GameLevel[] MainGameLevels; |
|||
[Header("Save")] |
|||
public string ProgressSaveName = "Progress"; |
|||
[Header("Save")] |
|||
public string ProgressSaveName = "Progress"; |
|||
[Header("Messages")] |
|||
public string MainMenuStartMessage = "MAINMENU_START"; |
|||
public string GameLevelStartMessage = "GAME_START"; |
|||
[Header("Messages")] |
|||
public string MainMenuStartMessage = "MAINMENU_START"; |
|||
public string GameLevelStartMessage = "GAME_START"; |
|||
public int currentLevel { get; private set; } = -2; |
|||
public int currentLevel { get; private set; } = -2; |
|||
public int currentSaveProgress { |
|||
get { Manager.Get<GameSaveManager>().LoadUserSave(0); return Manager.Get<GameSaveManager>().GetInt(ProgressSaveName, GameSaveManager.Location.User); } |
|||
set { Manager.Get<GameSaveManager>().SetInt(ProgressSaveName, GameSaveManager.Location.User, value); Manager.Get<GameSaveManager>().SaveUserSave(0); } |
|||
} |
|||
public int currentSaveProgress |
|||
{ |
|||
get { Manager.Get<GameSaveManager>().LoadUserSave(0); return Manager.Get<GameSaveManager>().GetInt(ProgressSaveName, GameSaveManager.Location.User); } |
|||
set { Manager.Get<GameSaveManager>().SetInt(ProgressSaveName, GameSaveManager.Location.User, value); Manager.Get<GameSaveManager>().SaveUserSave(0); } |
|||
} |
|||
GameObject m_CurrentLevelSwitch; |
|||
GameObject m_CurrentLevelSwitch; |
|||
public void Start() |
|||
{ |
|||
currentLevel = int.MinValue; |
|||
Callable.Call(OnGameStart); |
|||
Manager.Get<GameSaveManager>().LoadUserSave(0); |
|||
} |
|||
public void Start() |
|||
{ |
|||
currentLevel = int.MinValue; |
|||
Callable.Call(OnGameStart); |
|||
Manager.Get<GameSaveManager>().LoadUserSave(0); |
|||
} |
|||
Callable GetCurrentLevelSwitch(int targetLevel, bool showUI = false, Callable[] onComplete = null) |
|||
{ |
|||
GameObject go = new GameObject(); |
|||
go.name = $"LevelSwtich {currentLevel} -> {targetLevel}"; |
|||
go.transform.parent = this.transform; |
|||
m_CurrentLevelSwitch = go; |
|||
Callable GetCurrentLevelSwitch(int targetLevel, bool showUI = false, Callable[] onComplete = null) |
|||
{ |
|||
GameObject go = new GameObject(); |
|||
go.name = $"LevelSwtich {currentLevel} -> {targetLevel}"; |
|||
go.transform.parent = this.transform; |
|||
m_CurrentLevelSwitch = go; |
|||
var cameraFade = go.AddComponent<FullScreenFadeAction>(); |
|||
var loadLevel = go.AddComponent<StreamingLevelAction>(); |
|||
var sendMessage = go.AddComponent<SendMessageAction>(); |
|||
var destroy = go.AddComponent<DestroyObjectAction>(); |
|||
var next = go.AddComponent<Logic>(); |
|||
var cameraFade = go.AddComponent<FullScreenFadeAction>(); |
|||
var loadLevel = go.AddComponent<StreamingLevelAction>(); |
|||
var sendMessage = go.AddComponent<SendMessageAction>(); |
|||
var destroy = go.AddComponent<DestroyObjectAction>(); |
|||
var next = go.AddComponent<Logic.Logic>(); |
|||
cameraFade.Fading = FullScreenFadeManager.FadeMode.ToBlack; |
|||
cameraFade.Name = "Fade to Black"; |
|||
cameraFade.Duration = 1.0f; |
|||
cameraFade.OnComplete = new Callable[]{ loadLevel }; |
|||
cameraFade.Fading = FullScreenFadeManager.FadeMode.ToBlack; |
|||
cameraFade.Name = "Fade to Black"; |
|||
cameraFade.Duration = 1.0f; |
|||
cameraFade.OnComplete = new Callable[] { loadLevel }; |
|||
loadLevel.Name = $"Load {(targetLevel < 0? "Main menu" : MainGameLevels[targetLevel].name)}"; |
|||
loadLevel.ShowUI = showUI; |
|||
loadLevel.Action = LevelStreamingManager.StreamingAction.Replace; |
|||
var level = targetLevel < 0 ? MainMenuGameLevel : MainGameLevels[targetLevel]; |
|||
loadLevel.SceneToActivate = level.StartupScenes[0]; |
|||
loadLevel.Scenes = level.StartupScenes; |
|||
loadLevel.OnLoadComplete = new Callable[] { sendMessage, destroy, next }; |
|||
loadLevel.Name = $"Load {(targetLevel < 0 ? "Main menu" : MainGameLevels[targetLevel].name)}"; |
|||
loadLevel.ShowUI = showUI; |
|||
loadLevel.Action = LevelStreamingManager.StreamingAction.Replace; |
|||
var level = targetLevel < 0 ? MainMenuGameLevel : MainGameLevels[targetLevel]; |
|||
loadLevel.SceneToActivate = level.StartupScenes[0]; |
|||
loadLevel.Scenes = level.StartupScenes; |
|||
loadLevel.OnLoadComplete = new Callable[] { sendMessage, destroy, next }; |
|||
string message = targetLevel == -1 ? MainMenuStartMessage : GameLevelStartMessage; |
|||
sendMessage.Name = $"Send {message}"; |
|||
sendMessage.MessageToSend = message; |
|||
string message = targetLevel == -1 ? MainMenuStartMessage : GameLevelStartMessage; |
|||
sendMessage.Name = $"Send {message}"; |
|||
sendMessage.MessageToSend = message; |
|||
destroy.ObjectsToDestroy = new GameObject[] { go }; |
|||
destroy.ObjectsToDestroy = new GameObject[] { go }; |
|||
var nextActions = targetLevel < 0 ? OnMainMenuLoaded : OnLevelLoaded; |
|||
next.Calls = nextActions.Concat(onComplete).ToArray(); |
|||
var nextActions = targetLevel < 0 ? OnMainMenuLoaded : OnLevelLoaded; |
|||
next.Calls = nextActions.Concat(onComplete).ToArray(); |
|||
// Return first callable
|
|||
return cameraFade; |
|||
} |
|||
// Return first callable
|
|||
return cameraFade; |
|||
} |
|||
public void SwitchLevel(int nextLevel, bool showUI = false, Callable[] onComplete = null) |
|||
{ |
|||
if (m_CurrentLevelSwitch == null) |
|||
public void SwitchLevel(int nextLevel, bool showUI = false, Callable[] onComplete = null) |
|||
var call = GetCurrentLevelSwitch(nextLevel, showUI, onComplete); |
|||
call.Execute(); |
|||
currentLevel = nextLevel; |
|||
if (m_CurrentLevelSwitch == null) |
|||
{ |
|||
var call = GetCurrentLevelSwitch(nextLevel, showUI, onComplete); |
|||
call.Execute(); |
|||
currentLevel = nextLevel; |
|||
} |
|||
else |
|||
Debug.LogWarning("SwitchLevel : an Operation was still in progress and switching level could not be done. "); |
|||
else |
|||
Debug.LogWarning("SwitchLevel : an Operation was still in progress and switching level could not be done. "); |
|||
|
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue