RunNode 接入游戏主流程
- NodeMapForm:节点地图
- NodeItem:节点入口
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using GeometryTD.CustomEvent;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class MenuForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
[SerializeField] private TMP_Text _startButtonText;
|
||||
[SerializeField] private TMP_Text _settingsButtonText;
|
||||
[SerializeField] private TMP_Text _exitButtonText;
|
||||
|
||||
private MenuFormContext _context;
|
||||
|
||||
public void RefreshUI(MenuFormContext context)
|
||||
{
|
||||
_context = context;
|
||||
if (_context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetText(_titleText, _context.TitleText);
|
||||
SetText(_startButtonText, _context.StartButtonText);
|
||||
SetText(_settingsButtonText, _context.SettingsButtonText);
|
||||
SetText(_exitButtonText, _context.ExitButtonText);
|
||||
}
|
||||
|
||||
public void OnStartButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuStartRequestedEventArgs.Create());
|
||||
}
|
||||
|
||||
public void OnSettingsButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuSettingsRequestedEventArgs.Create());
|
||||
}
|
||||
|
||||
public void OnExitButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuExitRequestedEventArgs.Create());
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is MenuFormContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("MenuForm requires MenuFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_context = null;
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
private static void SetText(TMP_Text textComponent, string value)
|
||||
{
|
||||
if (textComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
textComponent.text = value ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdf317aa70fe94f44a332b6ee6ef5bbc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,10 +1,16 @@
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Procedure;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TestMenuForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private GameObject combatButtonObject;
|
||||
[SerializeField] private GameObject eventButtonObject;
|
||||
[SerializeField] private GameObject shopButtonObject;
|
||||
|
||||
private TestMenuFormContext _context;
|
||||
|
||||
public void RefreshUI(TestMenuFormContext context)
|
||||
@@ -12,8 +18,17 @@ namespace GeometryTD.UI
|
||||
_context = context;
|
||||
if (_context == null)
|
||||
{
|
||||
SetButtonVisible(combatButtonObject, false);
|
||||
SetButtonVisible(eventButtonObject, false);
|
||||
SetButtonVisible(shopButtonObject, false);
|
||||
return;
|
||||
}
|
||||
|
||||
SetButtonVisible(
|
||||
combatButtonObject,
|
||||
_context.CurrentNodeType == RunNodeType.Combat || _context.CurrentNodeType == RunNodeType.BossCombat);
|
||||
SetButtonVisible(eventButtonObject, _context.CurrentNodeType == RunNodeType.Event);
|
||||
SetButtonVisible(shopButtonObject, _context.CurrentNodeType == RunNodeType.Shop);
|
||||
}
|
||||
|
||||
public void OnCombatButtonClick()
|
||||
@@ -47,8 +62,19 @@ namespace GeometryTD.UI
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_context = null;
|
||||
SetButtonVisible(combatButtonObject, false);
|
||||
SetButtonVisible(eventButtonObject, false);
|
||||
SetButtonVisible(shopButtonObject, false);
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
private static void SetButtonVisible(GameObject buttonObject, bool visible)
|
||||
{
|
||||
if (buttonObject != null)
|
||||
{
|
||||
buttonObject.SetActive(visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user