UI调整,事件派发机制抽象结构调整

This commit is contained in:
ALIENJACK\alien 2024-09-12 16:20:11 +08:00
parent f8fc518a44
commit 040c23e001
12 changed files with 283 additions and 39 deletions

View File

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

View File

@ -0,0 +1,18 @@
{
"name": "AxibugEmuOnline.Editor",
"rootNamespace": "AxibugEmuOnline.Editors",
"references": [
"GUID:3fe77f1eed9fc0847a86648f644fe815"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a37804d4d608e1e4bb8204f442ab0e60
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,45 @@
using AxibugEmuOnline.Client;
using System;
using UnityEditor;
using UnityEngine;
namespace AxibugEmuOnline.Editors
{
[CustomEditor(typeof(CommandDispatcher))]
public class CommandDispatcherEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
var dispacather = target as CommandDispatcher;
dispacather.GetRegisters(out var normal, out var solo);
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.LabelField("NORMAL");
foreach (var item in normal)
{
Draw(item);
}
EditorGUILayout.EndVertical();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.LabelField("SOLO");
foreach (var item in solo)
{
Draw(item);
}
EditorGUILayout.EndVertical();
Repaint();
}
private void Draw(CommandExecuter item)
{
EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
using (new EditorGUI.DisabledGroupScope(!item.Enable))
EditorGUILayout.ObjectField(item.gameObject, typeof(GameObject), false);
EditorGUILayout.EndHorizontal();
}
}
}

View File

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

View File

@ -182,12 +182,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 74796456}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
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: 0}
m_RootOrder: 2
m_Father: {fileID: 1335662459}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!224 &246947326 stripped
RectTransform:
@ -1107,6 +1107,40 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3}
--- !u!1 &1335662458
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1335662459}
m_Layer: 0
m_Name: IMPORTENT
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1335662459
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1335662458}
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:
- {fileID: 1639312037}
- {fileID: 74796459}
- {fileID: 1427887270}
- {fileID: 1599240741}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1427887268
GameObject:
m_ObjectHideFlags: 0
@ -1136,25 +1170,20 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4471d8231d16ba3469228e09d4cb3a81, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!224 &1427887270
RectTransform:
--- !u!4 &1427887270
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1427887268}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
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: 0}
m_RootOrder: 3
m_Father: {fileID: 1335662459}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 960, y: 540}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1498586261
GameObject:
m_ObjectHideFlags: 3
@ -1196,7 +1225,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1599240737
GameObject:
@ -1291,8 +1320,8 @@ RectTransform:
m_Children:
- {fileID: 1983793178}
- {fileID: 246947326}
m_Father: {fileID: 0}
m_RootOrder: 4
m_Father: {fileID: 1335662459}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
@ -1375,11 +1404,11 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1639312034}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
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: 0}
m_Father: {fileID: 1335662459}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!224 &1983793178 stripped
@ -1394,6 +1423,54 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 1599240741}
m_Modifications:
- target: {fileID: 1714682891259844147, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1714682891259844147, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1714682891259844147, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1714682891259844147, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1714682891259844147, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1714682891259844147, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2780569438310375802, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2780569438310375802, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2780569438310375802, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2780569438310375802, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2780569438310375802, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2780569438310375802, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4478785627166277609, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_Name
value: OptionUI
@ -1486,5 +1563,29 @@ PrefabInstance:
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6503369113137645357, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6503369113137645357, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6503369113137645357, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6503369113137645357, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6503369113137645357, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6503369113137645357, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}

View File

@ -49,6 +49,9 @@ namespace AxibugEmuOnline.Client.ClientCore
GameObject.DontDestroyOnLoad(go);
coRunner = go.AddComponent<CoroutineRunner>();
var importNode = GameObject.Find("IMPORTENT");
GameObject.DontDestroyOnLoad(importNode);
StartCoroutine(AppTickFlow());
}

View File

@ -1,5 +1,3 @@
using AxibugEmuOnline.Client.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
@ -9,7 +7,11 @@ namespace AxibugEmuOnline.Client
{
public static CommandDispatcher Instance { get; private set; }
/// <summary> 平级注册对象,都会响应指令 </summary>
List<CommandExecuter> m_register = new List<CommandExecuter>();
/// <summary> 独占注册对象,指令会被列表中最后一个对象独占 </summary>
List<CommandExecuter> m_registerHigh = new List<CommandExecuter>();
Dictionary<KeyCode, EnumCommand> m_keyMapper = new Dictionary<KeyCode, EnumCommand>();
private void Awake()
@ -41,14 +43,26 @@ namespace AxibugEmuOnline.Client
public void RegistController(CommandExecuter controller)
{
if (m_register.Contains(controller)) { return; }
if (!controller.AloneMode)
{
if (m_register.Contains(controller)) { return; }
m_register.Add(controller);
m_register.Add(controller);
}
else
{
if (m_registerHigh.Contains(controller)) { return; }
m_registerHigh.Add(controller);
}
}
public void UnRegistController(CommandExecuter menuItemController)
{
m_register.Remove(menuItemController);
if (!menuItemController.AloneMode)
m_register.Remove(menuItemController);
else
m_registerHigh.Remove(menuItemController);
}
readonly List<CommandExecuter> oneFrameRegister = new List<CommandExecuter>();
@ -56,31 +70,60 @@ namespace AxibugEmuOnline.Client
{
foreach (var item in m_keyMapper)
{
peekRegister(oneFrameRegister);
if (Input.GetKeyDown(item.Key))
{
oneFrameRegister.Clear();
oneFrameRegister.AddRange(m_register);
for (int i = 0; i < oneFrameRegister.Count; i++)
foreach (var controller in oneFrameRegister)
{
var controller = oneFrameRegister[i];
if (!controller.Enable) continue;
controller.ExecuteCommand(item.Value, false);
}
}
if (Input.GetKeyUp(item.Key))
{
oneFrameRegister.Clear();
oneFrameRegister.AddRange(m_register);
for (int i = 0; i < oneFrameRegister.Count; i++)
foreach (var controller in oneFrameRegister)
{
var controller = oneFrameRegister[i];
if (!controller.Enable) continue;
controller.ExecuteCommand(item.Value, true);
}
}
}
}
private List<CommandExecuter> peekRegister(List<CommandExecuter> results)
{
results.Clear();
if (m_registerHigh.Count > 0)
{
for (int i = m_registerHigh.Count - 1; i >= 0; i--)
{
var controller = m_registerHigh[i];
if (controller.Enable)
{
results.Add(controller);
return results;
}
}
}
foreach (var controller in m_register)
{
if (!controller.Enable) continue;
results.Add(controller);
}
return results;
}
#if UNITY_EDITOR
public void GetRegisters(out IReadOnlyList<CommandExecuter> normal, out IReadOnlyList<CommandExecuter> alone)
{
normal = m_register;
alone = m_registerHigh;
}
#endif
}
}

View File

@ -18,6 +18,7 @@ namespace AxibugEmuOnline.Client
float PulseInvoke_Interval = 0.05f;
public abstract bool Enable { get; }
public virtual bool AloneMode { get; }
protected virtual void Awake()
{

View File

@ -11,7 +11,7 @@ namespace AxibugEmuOnline.Client
protected List<MenuItem> m_runtimeMenuUI = new List<MenuItem>();
public override bool Enable => enabled;
private MenuItem m_enteredItem = null;
protected MenuItem m_enteredItem = null;
protected int m_selectIndex = -1;

View File

@ -17,6 +17,8 @@ namespace AxibugEmuOnline.Client
[Header("Ä£°å")]
[SerializeField] OptionUI_ExecuteItem TEMPLATE_EXECUTEITEM;
public override bool AloneMode => true;
private bool m_bPoped = false;
private List<MonoBehaviour> m_runtimeMenuItems = new List<MonoBehaviour>();
@ -77,6 +79,7 @@ namespace AxibugEmuOnline.Client
{
if (m_bPoped)
{
CommandDispatcher.Instance.UnRegistController(this);
m_bPoped = false;
Canvas.ForceUpdateCanvases();
var width = MenuRoot.rect.width;
@ -118,7 +121,7 @@ namespace AxibugEmuOnline.Client
protected override void OnSelectMenuChanged()
{
}
}

View File

@ -66,8 +66,9 @@ namespace AxibugEmuOnline.Client
protected override bool OnCmdEnter()
{
LaunchUI.Instance.ToDetailMenuLayout();
base.OnCmdEnter();
LaunchUI.Instance.ToDetailMenuLayout();
var item = GetItemUIByIndex(SelectIndex);
item.SetSelectState(false);
@ -77,6 +78,7 @@ namespace AxibugEmuOnline.Client
protected override void OnCmdBack()
{
base.OnCmdBack();
LaunchUI.Instance.ToMainMenuLayout();
var item = GetItemUIByIndex(SelectIndex);
item.SetSelectState(true);
@ -84,12 +86,14 @@ namespace AxibugEmuOnline.Client
protected override void OnCmdSelectItemUp()
{
SelectIndex--;
if (m_enteredItem == null)
SelectIndex--;
}
protected override void OnCmdSelectItemDown()
{
SelectIndex++;
if (m_enteredItem == null)
SelectIndex++;
}
public virtual void SetSelect(bool select)