重构UI菜单继承结构

This commit is contained in:
ALIENJACK\alien 2024-09-12 15:08:48 +08:00
parent d2f48a56e7
commit 7d7b864c1b
12 changed files with 518 additions and 251 deletions

View File

@ -1,5 +1,101 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &782102846085628909
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6503369113137645357}
- component: {fileID: 6442047476311195174}
- component: {fileID: 394891843266770919}
- component: {fileID: 5658511545186035791}
m_Layer: 5
m_Name: Icon
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6503369113137645357
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 782102846085628909}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2780569438310375802}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 25, y: -25}
m_SizeDelta: {x: 40, y: 40}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6442047476311195174
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 782102846085628909}
m_CullTransparentMesh: 1
--- !u!114 &394891843266770919
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 782102846085628909}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &5658511545186035791
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 782102846085628909}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: -1
m_PreferredWidth: 40
m_PreferredHeight: 40
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!1 &793983410033291345
GameObject:
m_ObjectHideFlags: 0
@ -106,13 +202,14 @@ GameObject:
m_Component:
- component: {fileID: 2780569438310375802}
- component: {fileID: 9142037267599823005}
- component: {fileID: 3721725547312714320}
m_Layer: 5
m_Name: ExecuteItem_Template
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &2780569438310375802
RectTransform:
m_ObjectHideFlags: 0
@ -124,14 +221,15 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 6503369113137645357}
- {fileID: 1714682891259844147}
m_Father: {fileID: 5397686940312333149}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 124.5, y: -540}
m_SizeDelta: {x: 209, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &9142037267599823005
MonoBehaviour:
@ -146,12 +244,12 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_Left: 5
m_Right: 5
m_Top: 5
m_Bottom: 5
m_ChildAlignment: 4
m_Spacing: 0
m_Spacing: 12
m_ChildForceExpandWidth: 0
m_ChildForceExpandHeight: 0
m_ChildControlWidth: 1
@ -159,6 +257,20 @@ MonoBehaviour:
m_ChildScaleWidth: 0
m_ChildScaleHeight: 0
m_ReverseArrangement: 0
--- !u!114 &3721725547312714320
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2500436782395572584}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eb6aef4a36f116c42a45843286be880c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MenuNameTxt: {fileID: 1824253632728291860}
m_Icon: {fileID: 394891843266770919}
--- !u!1 &3968697266383191021
GameObject:
m_ObjectHideFlags: 0
@ -211,12 +323,12 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 10
m_Right: 10
m_Top: 10
m_Bottom: 10
m_Left: 20
m_Right: 20
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 4
m_Spacing: 0
m_Spacing: 12
m_ChildForceExpandWidth: 0
m_ChildForceExpandHeight: 0
m_ChildControlWidth: 1
@ -288,6 +400,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
MenuRoot: {fileID: 5397686940312333149}
TEMPLATE_EXECUTEITEM: {fileID: 3721725547312714320}
--- !u!1 &6998597834321643812
GameObject:
m_ObjectHideFlags: 0
@ -318,12 +431,12 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2780569438310375802}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 130.5, y: -25}
m_SizeDelta: {x: 147, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6532365540230118336
CanvasRenderer:
@ -355,7 +468,7 @@ MonoBehaviour:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 18
m_FontSize: 26
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1

View File

@ -1482,5 +1482,9 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5397686940312333149, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}

View File

@ -1,3 +1,5 @@
using AxibugEmuOnline.Client.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
@ -7,29 +9,29 @@ namespace AxibugEmuOnline.Client
{
public static CommandDispatcher Instance { get; private set; }
List<MenuItemController> m_register = new List<MenuItemController>();
Dictionary<KeyCode, MenuItemController.EnumCommand> m_keyMapper = new Dictionary<KeyCode, MenuItemController.EnumCommand>();
List<CommandExecuter> m_register = new List<CommandExecuter>();
Dictionary<KeyCode, EnumCommand> m_keyMapper = new Dictionary<KeyCode, EnumCommand>();
private void Awake()
{
Instance = this;
m_keyMapper.Add(KeyCode.A, MenuItemController.EnumCommand.SelectItemLeft);
m_keyMapper.Add(KeyCode.D, MenuItemController.EnumCommand.SelectItemRight);
m_keyMapper.Add(KeyCode.W, MenuItemController.EnumCommand.SelectItemUp);
m_keyMapper.Add(KeyCode.S, MenuItemController.EnumCommand.SelectItemDown);
m_keyMapper.Add(KeyCode.K, MenuItemController.EnumCommand.Enter);
m_keyMapper.Add(KeyCode.L, MenuItemController.EnumCommand.Back);
m_keyMapper.Add(KeyCode.I, MenuItemController.EnumCommand.OptionMenu);
m_keyMapper.Add(KeyCode.A, EnumCommand.SelectItemLeft);
m_keyMapper.Add(KeyCode.D, EnumCommand.SelectItemRight);
m_keyMapper.Add(KeyCode.W, EnumCommand.SelectItemUp);
m_keyMapper.Add(KeyCode.S, EnumCommand.SelectItemDown);
m_keyMapper.Add(KeyCode.K, EnumCommand.Enter);
m_keyMapper.Add(KeyCode.L, EnumCommand.Back);
m_keyMapper.Add(KeyCode.I, EnumCommand.OptionMenu);
m_keyMapper.Add(KeyCode.LeftArrow, MenuItemController.EnumCommand.SelectItemLeft);
m_keyMapper.Add(KeyCode.RightArrow, MenuItemController.EnumCommand.SelectItemRight);
m_keyMapper.Add(KeyCode.UpArrow, MenuItemController.EnumCommand.SelectItemUp);
m_keyMapper.Add(KeyCode.DownArrow, MenuItemController.EnumCommand.SelectItemDown);
m_keyMapper.Add(KeyCode.Return, MenuItemController.EnumCommand.Enter);
m_keyMapper.Add(KeyCode.Escape, MenuItemController.EnumCommand.Back);
m_keyMapper.Add(KeyCode.RightShift, MenuItemController.EnumCommand.OptionMenu);
m_keyMapper.Add(KeyCode.LeftShift, MenuItemController.EnumCommand.OptionMenu);
m_keyMapper.Add(KeyCode.LeftArrow, EnumCommand.SelectItemLeft);
m_keyMapper.Add(KeyCode.RightArrow, EnumCommand.SelectItemRight);
m_keyMapper.Add(KeyCode.UpArrow, EnumCommand.SelectItemUp);
m_keyMapper.Add(KeyCode.DownArrow, EnumCommand.SelectItemDown);
m_keyMapper.Add(KeyCode.Return, EnumCommand.Enter);
m_keyMapper.Add(KeyCode.Escape, EnumCommand.Back);
m_keyMapper.Add(KeyCode.RightShift, EnumCommand.OptionMenu);
m_keyMapper.Add(KeyCode.LeftShift, EnumCommand.OptionMenu);
}
private void OnDestroy()
@ -37,19 +39,19 @@ namespace AxibugEmuOnline.Client
Instance = null;
}
public void RegistController(MenuItemController controller)
public void RegistController(CommandExecuter controller)
{
if (m_register.Contains(controller)) { return; }
m_register.Add(controller);
}
public void UnRegistController(MenuItemController menuItemController)
public void UnRegistController(CommandExecuter menuItemController)
{
m_register.Remove(menuItemController);
}
readonly List<MenuItemController> oneFrameRegister = new List<MenuItemController>();
readonly List<CommandExecuter> oneFrameRegister = new List<CommandExecuter>();
private void Update()
{
foreach (var item in m_keyMapper)
@ -62,7 +64,7 @@ namespace AxibugEmuOnline.Client
for (int i = 0; i < oneFrameRegister.Count; i++)
{
var controller = oneFrameRegister[i];
if (!controller.enabled) continue;
if (!controller.Enable) continue;
controller.ExecuteCommand(item.Value, false);
}
}
@ -74,11 +76,122 @@ namespace AxibugEmuOnline.Client
for (int i = 0; i < oneFrameRegister.Count; i++)
{
var controller = oneFrameRegister[i];
if (!controller.enabled) continue;
if (!controller.Enable) continue;
controller.ExecuteCommand(item.Value, true);
}
}
}
}
}
public abstract class CommandExecuter : MonoBehaviour
{
private PulseInvoker m_pulsInvoker_Left;
private PulseInvoker m_pulsInvoker_Right;
private PulseInvoker m_pulsInvoker_Up;
private PulseInvoker m_pulsInvoker_Down;
[SerializeField]
float PulseInvoke_Delay = 0.4f;
[SerializeField]
float PulseInvoke_Interval = 0.05f;
public abstract bool Enable { get; }
protected virtual void Awake()
{
m_pulsInvoker_Left = new PulseInvoker(OnCmdSelectItemLeft, PulseInvoke_Delay, PulseInvoke_Interval);
m_pulsInvoker_Right = new PulseInvoker(OnCmdSelectItemRight, PulseInvoke_Delay, PulseInvoke_Interval);
m_pulsInvoker_Up = new PulseInvoker(OnCmdSelectItemUp, PulseInvoke_Delay, PulseInvoke_Interval);
m_pulsInvoker_Down = new PulseInvoker(OnCmdSelectItemDown, PulseInvoke_Delay, PulseInvoke_Interval);
}
protected virtual void Update()
{
m_pulsInvoker_Left.Update(Time.deltaTime);
m_pulsInvoker_Right.Update(Time.deltaTime);
m_pulsInvoker_Up.Update(Time.deltaTime);
m_pulsInvoker_Down.Update(Time.deltaTime);
}
public void ExecuteCommand(EnumCommand cmd, bool cancel)
{
if (!cancel)
{
switch (cmd)
{
case EnumCommand.SelectItemLeft:
m_pulsInvoker_Left.SetActive();
OnCmdSelectItemLeft();
break;
case EnumCommand.SelectItemRight:
m_pulsInvoker_Right.SetActive();
OnCmdSelectItemRight();
break;
case EnumCommand.SelectItemUp:
m_pulsInvoker_Up.SetActive();
OnCmdSelectItemUp();
break;
case EnumCommand.SelectItemDown:
m_pulsInvoker_Down.SetActive();
OnCmdSelectItemDown();
break;
case EnumCommand.Enter:
if (OnCmdEnter())
{
m_pulsInvoker_Left.DisActive();
m_pulsInvoker_Right.DisActive();
m_pulsInvoker_Up.DisActive();
m_pulsInvoker_Down.DisActive();
}
break;
case EnumCommand.Back:
OnCmdBack();
break;
case EnumCommand.OptionMenu:
OnCmdOptionMenu();
break;
}
}
else
{
switch (cmd)
{
case EnumCommand.SelectItemLeft:
m_pulsInvoker_Left.DisActive(); break;
case EnumCommand.SelectItemRight:
m_pulsInvoker_Right.DisActive(); break;
case EnumCommand.SelectItemUp:
m_pulsInvoker_Up.DisActive(); break;
case EnumCommand.SelectItemDown:
m_pulsInvoker_Down.DisActive(); break;
}
}
}
protected virtual void OnCmdSelectItemLeft() { }
protected virtual void OnCmdSelectItemRight() { }
protected virtual void OnCmdSelectItemUp() { }
protected virtual void OnCmdSelectItemDown() { }
protected virtual void OnCmdOptionMenu() { }
protected virtual bool OnCmdEnter() => false;
protected virtual void OnCmdBack() { }
protected abstract void OnSelectMenuChanged();
}
public enum EnumCommand
{
SelectItemLeft,
SelectItemRight,
SelectItemUp,
SelectItemDown,
Enter,
Back,
OptionMenu
}
}

View File

@ -4,35 +4,15 @@ using UnityEngine;
namespace AxibugEmuOnline.Client
{
public abstract class MenuItemController : MonoBehaviour
public abstract class MenuItemController : CommandExecuter
{
public enum EnumCommand
{
SelectItemLeft,
SelectItemRight,
SelectItemUp,
SelectItemDown,
Enter,
Back,
OptionMenu
}
[SerializeField]
protected Transform m_menuItemRoot;
protected List<MenuItem> m_runtimeMenuUI = new List<MenuItem>();
public override bool Enable => enabled;
private PulseInvoker m_pulsInvoker_Left;
private PulseInvoker m_pulsInvoker_Right;
private PulseInvoker m_pulsInvoker_Up;
private PulseInvoker m_pulsInvoker_Down;
private MenuItem m_enteredItem = null;
[SerializeField]
float PulseInvoke_Delay = 0.4f;
[SerializeField]
float PulseInvoke_Interval = 0.05f;
protected int m_selectIndex = -1;
public virtual int SelectIndex
@ -61,87 +41,6 @@ namespace AxibugEmuOnline.Client
Canvas.ForceUpdateCanvases();
SelectIndex = 0;
m_pulsInvoker_Left = new PulseInvoker(OnCmdSelectItemLeft, PulseInvoke_Delay, PulseInvoke_Interval);
m_pulsInvoker_Right = new PulseInvoker(OnCmdSelectItemRight, PulseInvoke_Delay, PulseInvoke_Interval);
m_pulsInvoker_Up = new PulseInvoker(OnCmdSelectItemUp, PulseInvoke_Delay, PulseInvoke_Interval);
m_pulsInvoker_Down = new PulseInvoker(OnCmdSelectItemDown, PulseInvoke_Delay, PulseInvoke_Interval);
}
protected virtual void Update()
{
m_pulsInvoker_Left.Update(Time.deltaTime);
m_pulsInvoker_Right.Update(Time.deltaTime);
m_pulsInvoker_Up.Update(Time.deltaTime);
m_pulsInvoker_Down.Update(Time.deltaTime);
}
public void ExecuteCommand(EnumCommand cmd, bool cancel)
{
if (!cancel)
{
switch (cmd)
{
case EnumCommand.SelectItemLeft:
m_pulsInvoker_Left.SetActive();
OnCmdSelectItemLeft();
break;
case EnumCommand.SelectItemRight:
m_pulsInvoker_Right.SetActive();
OnCmdSelectItemRight();
break;
case EnumCommand.SelectItemUp:
m_pulsInvoker_Up.SetActive();
OnCmdSelectItemUp();
break;
case EnumCommand.SelectItemDown:
m_pulsInvoker_Down.SetActive();
OnCmdSelectItemDown();
break;
case EnumCommand.Enter:
if (m_enteredItem == null)
{
var willEnterItem = GetItemUIByIndex(SelectIndex);
bool res = OnCmdEnter(willEnterItem);
if (res)
{
m_enteredItem = willEnterItem;
m_pulsInvoker_Left.DisActive();
m_pulsInvoker_Right.DisActive();
m_pulsInvoker_Up.DisActive();
m_pulsInvoker_Down.DisActive();
}
}
break;
case EnumCommand.Back:
if (m_enteredItem != null)
{
OnCmdBack(m_enteredItem);
m_enteredItem = null;
}
break;
case EnumCommand.OptionMenu:
OnCmdOptionMenu();
break;
}
}
else
{
switch (cmd)
{
case EnumCommand.SelectItemLeft:
m_pulsInvoker_Left.DisActive(); break;
case EnumCommand.SelectItemRight:
m_pulsInvoker_Right.DisActive(); break;
case EnumCommand.SelectItemUp:
m_pulsInvoker_Up.DisActive(); break;
case EnumCommand.SelectItemDown:
m_pulsInvoker_Down.DisActive(); break;
}
}
}
protected virtual MenuItem GetItemUIByIndex(int index)
@ -149,19 +48,30 @@ namespace AxibugEmuOnline.Client
return m_runtimeMenuUI[SelectIndex];
}
protected virtual void OnCmdSelectItemLeft() { }
protected override bool OnCmdEnter()
{
if (m_enteredItem == null)
{
var willEnterItem = GetItemUIByIndex(SelectIndex);
bool res = willEnterItem.OnEnterItem();
if (res)
{
m_enteredItem = willEnterItem;
}
return res;
}
protected virtual void OnCmdSelectItemRight() { }
protected virtual void OnCmdSelectItemUp() { }
protected virtual void OnCmdSelectItemDown() { }
protected virtual void OnCmdOptionMenu() { }
protected virtual bool OnCmdEnter(MenuItem item) => item.OnEnterItem();
protected virtual bool OnCmdBack(MenuItem item) => item.OnExitItem();
protected abstract void OnSelectMenuChanged();
return false;
}
protected override void OnCmdBack()
{
if (m_enteredItem != null)
{
m_enteredItem.OnExitItem();
m_enteredItem = null;
}
}
}
public abstract class MenuItemController<T> : MenuItemController
@ -189,10 +99,5 @@ namespace AxibugEmuOnline.Client
if (CommandDispatcher.Instance != null)
CommandDispatcher.Instance.UnRegistController(this);
}
}
}

View File

@ -1,79 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace AxibugEmuOnline.Client
{
public class OptionUI : MonoBehaviour
{
public static OptionUI Instance { get; private set; }
[SerializeField]
RectTransform MenuRoot;
private bool m_bPoped = false;
private void Awake()
{
Instance = this;
}
private void Start()
{
Canvas.ForceUpdateCanvases();
var width = MenuRoot.rect.size.x;
var temp = MenuRoot.anchoredPosition;
temp.x = -width;
}
public void Pop(IEnumerable<OptionMenu> menus)
{
}
public void Hide()
{
}
}
public abstract class OptionMenu
{
public string Name { get; protected set; }
public OptionMenu(string name)
{
Name = name;
}
}
public abstract class ExecuteMenu : OptionMenu
{
protected ExecuteMenu(string name) : base(name) { }
public abstract void OnExcute();
}
public abstract class ValueSetMenu : OptionMenu
{
protected ValueSetMenu(string name) : base(name) { }
public abstract Type ValueType { get; }
public abstract object ValueRaw { get; }
public abstract void OnValueChanged(object newValue);
}
public abstract class ValueSetMenu<T> : ValueSetMenu
{
public sealed override Type ValueType => typeof(T);
public T Value { get; private set; }
public sealed override object ValueRaw => Value;
public sealed override void OnValueChanged(object newValue)
{
Value = (T)newValue;
}
protected ValueSetMenu(string name) : base(name) { }
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 65c17e13e38c7dd459e5c74ff9b37e87
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,166 @@
using DG.Tweening;
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace AxibugEmuOnline.Client
{
public class OptionUI : CommandExecuter
{
public static OptionUI Instance { get; private set; }
[SerializeField]
RectTransform MenuRoot;
[Space]
[Header("Ä£°å")]
[SerializeField] OptionUI_ExecuteItem TEMPLATE_EXECUTEITEM;
private bool m_bPoped = false;
private List<MonoBehaviour> m_runtimeMenuItems = new List<MonoBehaviour>();
protected override void Awake()
{
Instance = this;
TEMPLATE_EXECUTEITEM.gameObject.SetActiveEx(false);
base.Awake();
}
private void Start()
{
Canvas.ForceUpdateCanvases();
var width = MenuRoot.rect.size.x;
var temp = MenuRoot.anchoredPosition;
temp.x = width;
MenuRoot.anchoredPosition = temp;
}
protected override void Update()
{
if (Input.GetKeyDown(KeyCode.T))
{
if (m_bPoped) Hide();
else Pop(new List<OptionMenu>
{
new ExecuteMenu("²âÊԲ˵¥1"),
new ExecuteMenu("Copilot"),
new ExecuteMenu("ChatGPT 4o"),
});
}
}
public void Pop(IEnumerable<OptionMenu> menus)
{
ReleaseRuntimeMenus();
foreach (var menu in menus) CreateRuntimeMenuItem(menu);
CommandDispatcher.Instance.RegistController(this);
if (!m_bPoped)
{
m_bPoped = true;
DOTween.To(
() => MenuRoot.anchoredPosition.x,
(value) =>
{
var temp = MenuRoot.anchoredPosition;
temp.x = value;
MenuRoot.anchoredPosition = temp;
},
0,
0.3f
).SetEase(Ease.OutCubic);
}
}
public void Hide()
{
if (m_bPoped)
{
m_bPoped = false;
Canvas.ForceUpdateCanvases();
var width = MenuRoot.rect.width;
DOTween.To(
() => MenuRoot.anchoredPosition.x,
(value) =>
{
var temp = MenuRoot.anchoredPosition;
temp.x = value;
MenuRoot.anchoredPosition = temp;
},
width,
0.3f
).SetEase(Ease.OutCubic);
}
}
private void CreateRuntimeMenuItem(OptionMenu menuData)
{
if (menuData is ExecuteMenu executeMenu)
{
var menuUI = GameObject.Instantiate(TEMPLATE_EXECUTEITEM.gameObject, TEMPLATE_EXECUTEITEM.transform.parent).GetComponent<OptionUI_ExecuteItem>();
menuUI.gameObject.SetActive(true);
menuUI.SetData(executeMenu);
m_runtimeMenuItems.Add(menuUI);
}
}
private void ReleaseRuntimeMenus()
{
foreach (var item in m_runtimeMenuItems)
{
Destroy(item.gameObject);
}
m_runtimeMenuItems.Clear();
}
public override bool Enable => m_bPoped;
protected override void OnSelectMenuChanged()
{
}
}
public abstract class OptionMenu
{
public string Name { get; protected set; }
public Sprite Icon { get; protected set; }
public OptionMenu(string name, Sprite icon = null)
{
Name = name;
Icon = icon;
}
}
public class ExecuteMenu : OptionMenu
{
public ExecuteMenu(string name, Sprite icon = null) : base(name, icon) { }
public virtual void OnExcute() { }
}
public abstract class ValueSetMenu : OptionMenu
{
public ValueSetMenu(string name) : base(name) { }
public abstract Type ValueType { get; }
public abstract object ValueRaw { get; }
public abstract void OnValueChanged(object newValue);
}
public class ValueSetMenu<T> : ValueSetMenu
{
public sealed override Type ValueType => typeof(T);
public T Value { get; private set; }
public sealed override object ValueRaw => Value;
public sealed override void OnValueChanged(object newValue)
{
Value = (T)newValue;
}
protected ValueSetMenu(string name) : base(name) { }
}
}

View File

@ -0,0 +1,22 @@
using UnityEngine;
using UnityEngine.UI;
namespace AxibugEmuOnline.Client
{
public class OptionUI_ExecuteItem : MonoBehaviour
{
[SerializeField] Text m_MenuNameTxt;
[SerializeField] Image m_Icon;
public void SetData(ExecuteMenu executeMenu)
{
m_MenuNameTxt.text = executeMenu.Name;
if (executeMenu.Icon == null) m_Icon.gameObject.SetActiveEx(false);
else
{
m_Icon.gameObject.SetActiveEx(true);
m_Icon.sprite = executeMenu.Icon;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb6aef4a36f116c42a45843286be880c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -22,10 +22,12 @@ namespace AxibugEmuOnline.Client
private TweenerCore<int, int, NoOptions> rollTween;
protected virtual void Awake()
protected override void Awake()
{
m_selected = false;
if (alphaGroup != null) alphaGroup.alpha = 0;
base.Awake();
}
public override void Init(List<MenuData> menuDataList)
@ -62,22 +64,22 @@ namespace AxibugEmuOnline.Client
}
}
protected override bool OnCmdEnter(MenuItem item)
protected override bool OnCmdEnter()
{
LaunchUI.Instance.ToDetailMenuLayout();
base.OnCmdEnter();
var item = GetItemUIByIndex(SelectIndex);
item.SetSelectState(false);
base.OnCmdEnter(item);
return true;
}
protected override bool OnCmdBack(MenuItem item)
protected override void OnCmdBack()
{
base.OnCmdBack();
LaunchUI.Instance.ToMainMenuLayout();
var item = GetItemUIByIndex(SelectIndex);
item.SetSelectState(true);
base.OnCmdBack(item);
return true;
}
protected override void OnCmdSelectItemUp()

View File

@ -60,14 +60,16 @@ namespace AxibugEmuOnline.Client
public override void Init(List<MenuData> menuDataList) { }
protected override bool OnCmdEnter(MenuItem item)
protected override bool OnCmdEnter()
{
var item = GetItemUIByIndex(SelectIndex);
return item.OnEnterItem();
}
protected override bool OnCmdBack(MenuItem item)
protected override void OnCmdBack()
{
return item.OnExitItem();
var item = GetItemUIByIndex(SelectIndex);
item.OnExitItem();
}
private void LateUpdate()