浏览代码

Implicit Game Events for Game Manager

/main
Thomas ICHÉ 5 年前
当前提交
645f9ec8
共有 3 个文件被更改,包括 88 次插入3 次删除
  1. 16
      Runtime/Managers/Implementations/GameManager.cs
  2. 64
      Runtime/LevelScripting/Events/OnGameManagerLevelStart.cs
  3. 11
      Runtime/LevelScripting/Events/OnGameManagerLevelStart.cs.meta

16
Runtime/Managers/Implementations/GameManager.cs


[Header("Save")]
public string ProgressSaveName = "Progress";
[Header("Messages")]
public string MainMenuStartMessage = "MAINMENU_START";
public string GameLevelStartMessage = "GAME_START";
public static string MainMenuStartMessage = "GAME_MANAGER_MAINMENU_START";
public static string GameLevelStartMessage = "GAME_MANAGER_GAME_START";
public int currentLevel { get; private set; } = -2;

Callable GetCurrentLevelSwitch(int targetLevel, bool showUI = false, Callable[] onComplete = null)
{
if(targetLevel < 0 && MainMenuGameLevel == null)
{
Debug.LogError("GameManager : Could not load Main Menu.");
return null;
}
else if (targetLevel >= 0 && (MainGameLevels == null || MainGameLevels.Length < targetLevel + 1 || MainGameLevels[targetLevel] == null))
{
Debug.LogError($"GameManager : Could not load Level #{targetLevel}");
return null;
}
GameObject go = new GameObject();
go.name = $"LevelSwtich {currentLevel} -> {targetLevel}";
go.transform.parent = this.transform;

64
Runtime/LevelScripting/Events/OnGameManagerLevelStart.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Events
{
public class OnGameManagerLevelStart : EventBase
{
public enum GameManagerLevelType
{
MainMenu,
GameLevel
}
public GameManagerLevelType levelType { get { return m_LevelType; } }
[SerializeField]
protected GameManagerLevelType m_LevelType = GameManagerLevelType.GameLevel;
string m_Message;
[ReorderableList]
public Callable[] OnMessageRecieved;
void OnEnable()
{
m_Message = GetMessage(m_LevelType);
Messager.RegisterMessage(m_Message, Execute);
}
void OnDisable()
{
Messager.RemoveMessage(m_Message, Execute);
}
static string GetMessage(GameManagerLevelType type)
{
switch(type)
{
case GameManagerLevelType.MainMenu: return GameManager.MainMenuStartMessage;
default:
case GameManagerLevelType.GameLevel: return GameManager.GameLevelStartMessage;
}
}
void Execute()
{
try
{
Callable.Call(OnMessageRecieved, gameObject);
}
catch (System.Exception e)
{
UnityEngine.Debug.LogError(string.Format("OnMessageEvent : Exception Caught while catching message '{0}' on Object '{1}'", m_Message, gameObject.name));
UnityEngine.Debug.LogException(e);
}
}
}
}

11
Runtime/LevelScripting/Events/OnGameManagerLevelStart.cs.meta


fileFormatVersion: 2
guid: 2089a4bf3f6e46d40be6510a3989744d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存