diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab b/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab similarity index 98% rename from AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab rename to AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab index 4bef424..6d24d5d 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab +++ b/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab @@ -441,10 +441,10 @@ RectTransform: m_Father: {fileID: 4232056520494431727} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 180, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 272, y: 240} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &4232056521759880273 CanvasRenderer: @@ -466,7 +466,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3} m_Name: m_EditorClassIdentifier: - m_Material: {fileID: 0} + m_Material: {fileID: 2100000, guid: 07e28fcb992bc124e986f9d8ff3beb97, type: 2} m_Color: {r: 1, g: 1, b: 1, a: 1} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} @@ -474,7 +474,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 8400000, guid: ffe34aaf87e4b9942b4c2ac05943d444, type: 2} + m_Texture: {fileID: 0} m_UVRect: serializedVersion: 2 x: 0 diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab.meta b/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab.meta similarity index 100% rename from AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab.meta rename to AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab.meta diff --git a/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/OptionUI.prefab b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/OptionUI.prefab index 2cdea5c..8cef0dd 100644 --- a/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/OptionUI.prefab +++ b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/OptionUI.prefab @@ -229,7 +229,7 @@ RectTransform: 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: 0, y: 0} + m_AnchoredPosition: {x: 204, y: 488} m_SizeDelta: {x: 100, y: 100} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &2800056879890978085 diff --git a/AxibugEmuOnline.Client/Assets/Scene/Emu_NES.unity b/AxibugEmuOnline.Client/Assets/Scene/Emu_NES.unity index f8d05ee..0c2051e 100644 --- a/AxibugEmuOnline.Client/Assets/Scene/Emu_NES.unity +++ b/AxibugEmuOnline.Client/Assets/Scene/Emu_NES.unity @@ -174,53 +174,9 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 4232056521131536012, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: RomName - value: mario.nes - objectReference: {fileID: 0} - target: {fileID: 4232056521131536013, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} propertyPath: m_Name value: NesEmulator objectReference: {fileID: 0} - - target: {fileID: 4232056521759880274, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_Enabled - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880274, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_Texture - value: - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880274, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_Material - value: - objectReference: {fileID: 2100000, guid: 07e28fcb992bc124e986f9d8ff3beb97, type: 2} - - target: {fileID: 4232056521759880275, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_AnchorMax.x - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880275, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_AnchorMax.y - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880275, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_AnchorMin.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880275, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_AnchorMin.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880275, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_SizeDelta.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880275, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_SizeDelta.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4232056521759880276, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3} diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs index c07def7..6517770 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs @@ -5,34 +5,33 @@ namespace AxibugEmuOnline.Client.Manager { public class AppEmu { + private GameObject m_emuInstance; + public void BeginGame(RomFile romFile) { - if (InGameUI.Instance.Enable) return; + if (m_emuInstance != null) return; switch (romFile.Platform) { case EnumPlatform.NES: - App.SceneLoader.BeginLoad("Scene/Emu_NES", () => - { - var nesEmu = GameObject.FindObjectOfType(); - nesEmu.StartGame(romFile); + var nesEmu = GameObject.Instantiate(Resources.Load("NES/NesEmulator")).GetComponent(); + m_emuInstance = nesEmu.gameObject; - LaunchUI.Instance.HideMainMenu(); - InGameUI.Instance.Show(romFile, nesEmu); - }); + nesEmu.StartGame(romFile); + LaunchUI.Instance.HideMainMenu(); + InGameUI.Instance.Show(romFile, nesEmu); break; } } public void StopGame() { - if (!InGameUI.Instance.enabled) return; + if (m_emuInstance == null) return; + GameObject.Destroy(m_emuInstance); + m_emuInstance = null; - App.SceneLoader.BeginLoad("Scene/AxibugEmuOnline.Client", () => - { - InGameUI.Instance.Hide(); - LaunchUI.Instance.ShowMainMenu(); - }); + InGameUI.Instance.Hide(); + LaunchUI.Instance.ShowMainMenu(); } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs index f99d8e8..fa811a5 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs @@ -1,3 +1,5 @@ +using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.Manager; using System; using System.Collections.Generic; @@ -9,17 +11,24 @@ namespace AxibugEmuOnline.Client public RomFile RomFile => m_rom; public override bool Enable => gameObject.activeInHierarchy; + + /// 指示该游戏实例是否处于联网模式 + public bool IsOnline { get; private set; } + private RomFile m_rom; private object m_core; private object m_state; - private InGameUI_SaveState m_saveStateMenu; - private InGameUI_LoadState m_loadStateMenu; + private List menus = new List(); + protected override void Awake() { Instance = this; gameObject.SetActiveEx(false); + menus.Add(new InGameUI_SaveState(this)); + menus.Add(new InGameUI_LoadState(this)); + menus.Add(new InGameUI_QuitGame(this)); base.Awake(); } @@ -56,16 +65,12 @@ namespace AxibugEmuOnline.Client { return false; } - } public void Show(RomFile currentRom, object core) { CommandDispatcher.Instance.RegistController(this); - m_saveStateMenu = new InGameUI_SaveState(this); - m_loadStateMenu = new InGameUI_LoadState(this); - m_rom = currentRom; m_core = core; @@ -81,7 +86,12 @@ namespace AxibugEmuOnline.Client protected override void OnCmdOptionMenu() { - OptionUI.Instance.Pop(new List { m_saveStateMenu, m_loadStateMenu }); + OptionUI.Instance.Pop(menus); + } + + public void QuitGame() + { + App.emu.StopGame(); } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_LoadState.cs b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_LoadState.cs index 8a4863d..e36a63b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_LoadState.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_LoadState.cs @@ -7,6 +7,7 @@ namespace AxibugEmuOnline.Client public class InGameUI_LoadState : ExecuteMenu { private InGameUI m_gameUI; + public override bool Visible => !m_gameUI.IsOnline; public InGameUI_LoadState(InGameUI gameUI) : base("读取快照", null) { diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_QuitGame.cs b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_QuitGame.cs new file mode 100644 index 0000000..f16faca --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_QuitGame.cs @@ -0,0 +1,18 @@ +namespace AxibugEmuOnline.Client +{ + public class InGameUI_QuitGame : ExecuteMenu + { + private InGameUI m_gameUI; + + + public InGameUI_QuitGame(InGameUI gameUI) : base("退出", null) + { + m_gameUI = gameUI; + } + + public override void OnExcute() + { + m_gameUI.QuitGame(); + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_QuitGame.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_QuitGame.cs.meta new file mode 100644 index 0000000..9cc1510 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_QuitGame.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7689fa8f7ddd5654f914b93a4f0efada +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs index 94516fc..871873c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs @@ -9,6 +9,8 @@ namespace AxibugEmuOnline.Client { private InGameUI m_gameUI; + public override bool Visible => !m_gameUI.IsOnline; + public InGameUI_SaveState(InGameUI gameUI) : base("保存快照", null) { m_gameUI = gameUI; diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs index 46fe147..edb254f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs @@ -62,6 +62,54 @@ namespace AxibugEmuOnline.Client MenuRoot.anchoredPosition = temp; } + protected override void Update() + { + UpdateMenuState(); + } + + private void UpdateMenuState() + { + bool dirty = false; + foreach (var menuItem in m_runtimeMenuItems) + { + if (menuItem.gameObject.activeSelf != menuItem.Visible) + { + dirty = true; + menuItem.gameObject.SetActive(menuItem.Visible); + } + } + if (dirty) + { + if (m_runtimeMenuItems[SelectIndex].Visible == false) + { + bool find = false; + int currentSelect = SelectIndex; + while (currentSelect >= 0) + { + currentSelect--; + if (m_runtimeMenuItems[currentSelect].Visible) + { + find = true; + } + } + if (!find) + { + currentSelect = SelectIndex; + while (currentSelect < m_runtimeMenuItems.Count) + { + if (m_runtimeMenuItems[currentSelect].Visible) + { + find = true; + } + } + } + + if (find) + SelectIndex = currentSelect; + } + } + } + public void Pop(List menus, int defaultIndex = 0) { ReleaseRuntimeMenus(); diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI_MenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI_MenuItem.cs index c9e82b0..7115085 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI_MenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI_MenuItem.cs @@ -12,6 +12,8 @@ namespace AxibugEmuOnline.Client [SerializeField] Text m_MenuNameTxt; [SerializeField] Image m_Icon; + public bool Visible => m_Menu.Visible; + protected OptionMenu m_Menu; public void SetData(OptionMenu menuData)