我在c#中创建了一个状态机来改变视图。
当我将屏幕划分为多个画布时,问题就开始了。
例如,我有外部菜单,内部屏幕,hud。
不是每个州都希望看到所有这些。
例如: 登录屏幕仅显示登录菜单。
市场只显示市场菜单和外部菜单(外部菜单是注销按钮,用户详细信息按钮)。
世界地图显示世界地图屏幕,外部菜单和hud。
我做了什么:
当改变状态时,我只是隐藏所有内容并只显示正确的内容,但效率不高。
我认为我应该做什么:
我想到的另一种方法是每个州,每个行动只显示和隐藏相关画布以进行特定更改,但是,它是过度的,需要大量的工作,但有点高效。
我的问题是:
是否有任何有效但又易于管理的中间方法?
这里的记录是我正在使用的代码:
public class GameManager : MonoBehaviour {
public LoginController loginController;
public HudController hudController;
public WorldMapController worldMapController;
public MarketMenuController marketMenuController;
public GameState currentState;
public enum GameState
{
EntryMenu,
WorldMap,
MarketMenu,
}
protected Infrastructure.Base.Application.Application application;
protected EventManager eventManager;
void Start ()
{
ChangeState(GameState.EntryMenu);
application = Infrastructure.Base.Application.Application.getInstance();
eventManager = application.eventManager;
application.eventManager.AddListener<LoginSuccessfulEvent>(this.OnLoginSuccessful);
application.eventManager.AddListener<LogoutSuccessfulEvent>(this.OnLogoutSuccessful);
application.eventManager.AddListener<PlayerOpenedMarketEvent>(this.OnPlayerOpenMarket);
application.eventManager.AddListener<PlayerExitMarketEvent>(this.OnPlayerExitMarket);
}
void EntryMenuState()
{
loginController.Show();
}
void WorldMapState()
{
hudController.Show();
worldMapController.Show();
}
void StarOrbitState()
{
hudController.Show();
starScreenController.Show();
}
void StarMenuState()
{
hudController.Show();
starMenuController.Show();
}
void MarketMenuState()
{
hudController.Show();
marketMenuController.Show();
}
public void ChangeState(GameState newState)
{
HideAll();
currentState = newState;
StartCoroutine(newState.ToString() + "State", currentState);
}
void OnLoginSuccessful(LoginSuccessfulEvent e)
{
ChangeState(GameState.MarketMenu);
}
void OnLogoutSuccessful(LogoutSuccessfulEvent e)
{
ChangeState(GameState.EntryMenu);
}
void OnPlayerExitStarMenu(PlayerDepartFromStarEvent e)
{
ChangeState(GameState.StarOrbit);
}
void OnPlayerOpenMarket(PlayerOpenedMarketEvent e)
{
ChangeState(GameState.MarketMenu);
}
void OnPlayerExitMarket(PlayerExitMarketEvent e)
{
ChangeState(GameState.StarMenu);
}
void HideAll()
{
loginController.Hide();
worldMapController.Hide();
hudController.Hide();
marketMenuController.Hide();
}
}