diff --git a/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/InGameUI.prefab b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/InGameUI.prefab new file mode 100644 index 0000000..895b9a6 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/InGameUI.prefab @@ -0,0 +1,50 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1963501579241001457 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1963501579241001456} + - component: {fileID: 6933127467485204299} + m_Layer: 5 + m_Name: InGameUI + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1963501579241001456 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1963501579241001457} + 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: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &6933127467485204299 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1963501579241001457} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6c4cbb81b8f22ed499382b6eb9e6299e, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/InGameUI.prefab.meta b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/InGameUI.prefab.meta new file mode 100644 index 0000000..9d7aab1 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/InGameUI.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 334eee9f85f308347844f8f5e99167c3 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/LaunchUI.prefab b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/LaunchUI.prefab index d058f0d..4a7d26f 100644 --- a/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/LaunchUI.prefab +++ b/AxibugEmuOnline.Client/Assets/Resources/UIPrefabs/LaunchUI.prefab @@ -85,9 +85,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fb4f275956ba18440b061e92278f13cd, type: 3} m_Name: m_EditorClassIdentifier: - m_menuItemRoot: {fileID: 7102897325704768026} PulseInvoke_Delay: 0.4 PulseInvoke_Interval: 0.05 + m_menuItemRoot: {fileID: 7102897325704768026} GroupRoot: {fileID: 5247317738185020566} Template: {fileID: 2502609279043838113, guid: ece591129eb9bcc48bd83ec153c98018, type: 3} MenuSetting: @@ -227,7 +227,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_SizeDelta: {x: 0.00012207031, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &1639091783724093861 CanvasRenderer: @@ -319,6 +319,7 @@ MonoBehaviour: m_EditorClassIdentifier: MainMenuRoot: {fileID: 1924338507} MainMenu: {fileID: 4533431376032812611} + BG: {fileID: 1639091783724093860} m_detailLayoutPosition: {x: 55, y: -140} m_LayoutChangeSpeed: 1000 --- !u!1 &3732356966700017678 diff --git a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity index 68a56ea..8caaa7b 100644 --- a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity +++ b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity @@ -1107,6 +1107,11 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3} +--- !u!224 &1318590597 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + m_PrefabInstance: {fileID: 1963501580473600373} + m_PrefabAsset: {fileID: 0} --- !u!1 &1335662458 GameObject: m_ObjectHideFlags: 0 @@ -1305,7 +1310,7 @@ Canvas: m_SortingBucketNormalizedSize: 0 m_AdditionalShaderChannelsFlag: 1 m_SortingLayerID: 0 - m_SortingOrder: 0 + m_SortingOrder: 1 m_TargetDisplay: 0 --- !u!224 &1599240741 RectTransform: @@ -1320,6 +1325,7 @@ RectTransform: m_Children: - {fileID: 1983793178} - {fileID: 246947326} + - {fileID: 1318590597} m_Father: {fileID: 1335662459} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1416,6 +1422,103 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 1639091784002085428, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3} m_PrefabInstance: {fileID: 730698711} m_PrefabAsset: {fileID: 0} +--- !u!1001 &1963501580473600373 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 1599240741} + m_Modifications: + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_Pivot.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_Pivot.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_AnchorMax.x + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_AnchorMax.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_AnchorMin.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_AnchorMin.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_SizeDelta.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_SizeDelta.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_AnchoredPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_AnchoredPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1963501579241001457, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} + propertyPath: m_Name + value: InGameUI + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 334eee9f85f308347844f8f5e99167c3, type: 3} --- !u!1001 &4478785627007410708 PrefabInstance: m_ObjectHideFlags: 0 @@ -1587,5 +1690,17 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 7896211045508186424, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} + propertyPath: m_Color.b + value: 0.3773585 + objectReference: {fileID: 0} + - target: {fileID: 7896211045508186424, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} + propertyPath: m_Color.g + value: 0.16444026 + objectReference: {fileID: 0} + - target: {fileID: 7896211045508186424, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} + propertyPath: m_Color.r + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3} diff --git a/AxibugEmuOnline.Client/Assets/Script/App.cs b/AxibugEmuOnline.Client/Assets/Script/App.cs index ce20111..75e5377 100644 --- a/AxibugEmuOnline.Client/Assets/Script/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/App.cs @@ -136,34 +136,5 @@ namespace AxibugEmuOnline.Client.ClientCore Debug.Log("[AxibugEmuOnline]:" + msg); } - private static RomFile m_currentGame; - public static void BeginGame(RomFile romFile) - { - if (m_currentGame != null) return; - - m_currentGame = romFile; - - switch (romFile.Platform) - { - case EnumPlatform.NES: - SceneLoader.BeginLoad("Scene/Emu_NES", () => - { - LaunchUI.Instance.HideMainMenu(); - var nesEmu = GameObject.FindObjectOfType(); - nesEmu.StartGame(romFile); - }); - break; - } - } - - public static void StopGame() - { - if (m_currentGame == null) return; - - SceneLoader.BeginLoad("Scene/AxibugEmuOnline.Client", () => - { - LaunchUI.Instance.ShowMainMenu(); - }); - } } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs index a9a2640..c07def7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs @@ -1,7 +1,38 @@ -namespace AxibugEmuOnline.Client.Manager +using AxibugEmuOnline.Client.ClientCore; +using UnityEngine; + +namespace AxibugEmuOnline.Client.Manager { public class AppEmu { + public void BeginGame(RomFile romFile) + { + if (InGameUI.Instance.Enable) return; + switch (romFile.Platform) + { + case EnumPlatform.NES: + App.SceneLoader.BeginLoad("Scene/Emu_NES", () => + { + var nesEmu = GameObject.FindObjectOfType(); + nesEmu.StartGame(romFile); + + LaunchUI.Instance.HideMainMenu(); + InGameUI.Instance.Show(romFile, nesEmu); + }); + break; + } + } + + public void StopGame() + { + if (!InGameUI.Instance.enabled) return; + + App.SceneLoader.BeginLoad("Scene/AxibugEmuOnline.Client", () => + { + InGameUI.Instance.Hide(); + LaunchUI.Instance.ShowMainMenu(); + }); + } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs b/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs index 3a3ebe1..dfda12a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs +++ b/AxibugEmuOnline.Client/Assets/Script/MonoCom/TickLoop.cs @@ -27,7 +27,15 @@ namespace AxibugEmuOnline.Client Application.targetFrameRate = 60; NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdPing, OnCmdPing); - NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdPong, OnCmdPong); + NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdPong, OnCmdPong); + +#if UNITY_EDITOR + UnityEditor.EditorApplication.playModeStateChanged += (state) => + { + if (state == UnityEditor.PlayModeStateChange.ExitingPlayMode) + OnApplicationQuit(); + }; +#endif } float LastPingTime; private void Update() @@ -44,13 +52,13 @@ namespace AxibugEmuOnline.Client void OnApplicationQuit() { - App.log.Debug("OnApplicationQuit"); + App.log.Debug("OnApplicationQuit"); App.network.bAutoReConnect = false; + if (App.network.isConnected) { App.network.CloseConntect(); } - App.network.CancelReConnect(); } diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreDebuger.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreDebuger.cs index 86d827a..1195191 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreDebuger.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreDebuger.cs @@ -1,19 +1,18 @@ -using UnityEngine; +using AxibugEmuOnline.Client.ClientCore; using VirtualNes.Core.Debug; namespace AxibugEmuOnline.Client { public class CoreDebuger : IDebugerImpl { - public void Log(string message) { - Debug.Log(message); + App.log.Info(message); } public void LogError(string message) { - Debug.LogError(message); + App.log.Error(message); } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs index f3f8857..67371d2 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs @@ -15,6 +15,7 @@ namespace AxibugEmuOnline.Client public VideoProvider VideoProvider; public AudioProvider AudioProvider; + private void Start() { @@ -85,13 +86,6 @@ namespace AxibugEmuOnline.Client UnityEditor.EditorUtility.SetDirty(db); UnityEditor.AssetDatabase.SaveAssets(); } - - [ContextMenu("GetState")] - public void GetState() - { - var state = NesCore.GetState(); - var bytes = state.ToBytes(); - } #endif } } diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab index de3b472..4bef424 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.prefab @@ -44,7 +44,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a6a09b6a4cf4c2d4f994a13fd7e89d6f, type: 3} m_Name: m_EditorClassIdentifier: - NesEmu: {fileID: 4232056521131536012} m_as: {fileID: 8726979175317618791} --- !u!82 &8726979175317618791 AudioSource: @@ -258,6 +257,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: NesEmu: {fileID: 4232056521131536012} + DrawCanvas: {fileID: 4232056520494431724} Image: {fileID: 4232056521759880274} --- !u!1 &4232056520494431712 GameObject: @@ -308,7 +308,7 @@ Canvas: m_GameObject: {fileID: 4232056520494431712} m_Enabled: 1 serializedVersion: 3 - m_RenderMode: 0 + m_RenderMode: 1 m_Camera: {fileID: 0} m_PlaneDistance: 100 m_PixelPerfect: 0 @@ -409,7 +409,6 @@ MonoBehaviour: m_EditorClassIdentifier: VideoProvider: {fileID: 4232056520112715744} AudioProvider: {fileID: 9003897287163669553} - RomName: --- !u!1 &4232056521759880276 GameObject: m_ObjectHideFlags: 0 diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/VideoProvider.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/VideoProvider.cs index ea8c838..1a92750 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/VideoProvider.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/VideoProvider.cs @@ -8,6 +8,7 @@ namespace AxibugEmuOnline.Client public class VideoProvider : MonoBehaviour { public NesEmulator NesEmu; + public Canvas DrawCanvas; public RawImage Image; @@ -18,6 +19,11 @@ namespace AxibugEmuOnline.Client private Texture2D pPal; + private void Awake() + { + DrawCanvas.worldCamera = Camera.main; + } + public void SetDrawData(uint[] screenData, byte[] lineColorMode, int screenWidth, int screenHeight) { if (wrapTex == null) diff --git a/AxibugEmuOnline.Client/Assets/Script/Network/NetworkHelper.cs b/AxibugEmuOnline.Client/Assets/Script/Network/NetworkHelper.cs index 56c7ac7..13363bc 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Network/NetworkHelper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Network/NetworkHelper.cs @@ -84,8 +84,8 @@ namespace AxibugEmuOnline.Client.Network //抛出网络数据 //网络线程直接抛 - if(CMDID == (int)CommandID.CmdPing || CMDID == (int)CommandID.CmdPong) - NetMsg.Instance.PostNetMsgEvent(CMDID,ERRCODE, data); + if (CMDID == (int)CommandID.CmdPing || CMDID == (int)CommandID.CmdPong) + NetMsg.Instance.PostNetMsgEvent(CMDID, ERRCODE, data); else//加入队列,主线程来取 NetMsg.Instance.EnqueueNesMsg(CMDID, ERRCODE, data); } @@ -109,15 +109,7 @@ namespace AxibugEmuOnline.Client.Network ReConnect(); } - CancellationTokenSource cts; - Task ReConnectTask; - public void CancelReConnect() - { - App.log.Debug("CancelReConnect"); - cts?.Cancel(); - cts = null; - ReConnectTask = null; - } + Thread ReConnectTask = null; /// /// 自动重连 /// @@ -125,8 +117,7 @@ namespace AxibugEmuOnline.Client.Network { if (ReConnectTask != null) return; - cts = new CancellationTokenSource(); - ReConnectTask = new Task(() => + ReConnectTask = new Thread(() => { bool bflagDone = false; do @@ -142,17 +133,24 @@ namespace AxibugEmuOnline.Client.Network App.log.Info($"触发重连后的自动逻辑!"); OnReConnected?.Invoke(); } - } while (!bflagDone); + } while (!bflagDone && App.network.bAutoReConnect); + + if (!App.network.bAutoReConnect) + { + if (App.network.isConnected) + { + App.network.CloseConntect(); + } + } ReConnectTask = null; - cts = null; - }, cts.Token); + }); ReConnectTask.Start(); } bool CheckIsConnectd() { Socket socket = GetClientSocket(); - if(socket == null) + if (socket == null) return false; return socket.Connected; } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs.meta index 3367dd6..19a70a8 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs.meta +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: -50 icon: {instanceID: 0} userData: assetBundleName: diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI.meta b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI.meta new file mode 100644 index 0000000..63fc870 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6f12f7770db8ede41906b080df9cbec0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs new file mode 100644 index 0000000..6f5810e --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; + +namespace AxibugEmuOnline.Client +{ + public class InGameUI : CommandExecuter + { + + public static InGameUI Instance { get; private set; } + + public RomFile RomFile => m_rom; + public override bool Enable => gameObject.activeInHierarchy; + private RomFile m_rom; + private object m_core; + + private InGameUI_SaveState m_saveMenu; + + protected override void Awake() + { + Instance = this; + gameObject.SetActiveEx(false); + base.Awake(); + } + + private void OnDestroy() + { + Instance = null; + } + + public T GetCore() => (T)m_core; + + public void Show(RomFile currentRom, object core) + { + m_saveMenu = new InGameUI_SaveState(this); + CommandDispatcher.Instance.RegistController(this); + + m_rom = currentRom; + m_core = core; + gameObject.SetActiveEx(true); + } + + public void Hide() + { + CommandDispatcher.Instance.UnRegistController(this); + + m_rom = null; + m_core = null; + gameObject.SetActiveEx(false); + } + + protected override void OnCmdOptionMenu() + { + OptionUI.Instance.Pop(new List { m_saveMenu }); + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs.meta new file mode 100644 index 0000000..b83e7fd --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c4cbb81b8f22ed499382b6eb9e6299e +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 new file mode 100644 index 0000000..3791d53 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs @@ -0,0 +1,29 @@ +using AxibugEmuOnline.Client.ClientCore; +using System.Diagnostics; + +namespace AxibugEmuOnline.Client +{ + public class InGameUI_SaveState : ExecuteMenu + { + private InGameUI m_gameUI; + + public InGameUI_SaveState(InGameUI gameUI) : base("", null) + { + m_gameUI = gameUI; + } + + public override void OnExcute() + { + Stopwatch sw = Stopwatch.StartNew(); + switch (m_gameUI.RomFile.Platform) + { + case EnumPlatform.NES: + var state = m_gameUI.GetCore().NesCore.GetState(); + App.log.Info($"{m_gameUI.RomFile.Platform}===>մС{state.ToBytes().Length}"); + break; + } + sw.Stop(); + App.log.Info($"{m_gameUI.RomFile.Platform}====>ȡպʱ:{sw.Elapsed.TotalMilliseconds}ms"); + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs.meta new file mode 100644 index 0000000..a321a31 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI_SaveState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a9b3cce3fed9054d9bcf411a142f9d7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/LaunchUI.cs b/AxibugEmuOnline.Client/Assets/Script/UI/LaunchUI.cs index 051c015..2e49518 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/LaunchUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/LaunchUI.cs @@ -3,6 +3,7 @@ using DG.Tweening; using DG.Tweening.Core; using DG.Tweening.Plugins.Options; using UnityEngine; +using UnityEngine.UI; namespace AxibugEmuOnline.Client { @@ -12,6 +13,8 @@ namespace AxibugEmuOnline.Client RectTransform MainMenuRoot; [SerializeField] MainMenuController MainMenu; + [SerializeField] + Image BG; Vector2 m_mainLayoutPosition; [SerializeField] @@ -26,19 +29,19 @@ namespace AxibugEmuOnline.Client private void Awake() { Instance = this; - DontDestroyOnLoad(this); - DontDestroyOnLoad(Camera.main.gameObject); m_mainLayoutPosition = MainMenuRoot.anchoredPosition; MainMenu.ListenControlAction = true; } public void HideMainMenu() { + BG.gameObject.SetActiveEx(false); MainMenuRoot.gameObject.SetActiveEx(false); } public void ShowMainMenu() { + BG.gameObject.SetActiveEx(true); MainMenuRoot.gameObject.SetActiveEx(true); } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs index 03e043d..72135e7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs @@ -1,7 +1,6 @@ using DG.Tweening; using System; using System.Collections.Generic; -using UnityEditor; using UnityEngine; namespace AxibugEmuOnline.Client @@ -160,6 +159,7 @@ namespace AxibugEmuOnline.Client protected override bool OnCmdEnter() { m_runtimeMenuItems[SelectIndex].OnExecute(); + Hide(); return true; } } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs index b477703..9892b9b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/RomItem.cs @@ -82,7 +82,7 @@ namespace AxibugEmuOnline.Client } else { - App.BeginGame(m_romfile); + App.emu.BeginGame(m_romfile); return false; } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs index f9a6a03..71ba330 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs @@ -2,6 +2,7 @@ { public struct BLOCKHDR : IStateBufferObject { + public readonly bool Valid => !string.IsNullOrEmpty(ID); public string ID; public ushort Reserved; public ushort BlockVersion; @@ -9,10 +10,13 @@ public readonly void SaveState(StateBuffer buffer) { - buffer.Write(ID); - buffer.Write(Reserved); - buffer.Write(BlockVersion); - buffer.Write(BlockSize); + if (Valid) + { + buffer.Write(ID); + buffer.Write(Reserved); + buffer.Write(BlockVersion); + buffer.Write(BlockSize); + } } public readonly uint GetSize() diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs index d1f5ddb..d5d4609 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs @@ -42,35 +42,59 @@ namespace VirtualNes.Core HEADER.SaveState(buffer); - regBLOCK.SaveState(buffer); - reg.SaveState(buffer); + if (regBLOCK.Valid) + { + regBLOCK.SaveState(buffer); + reg.SaveState(buffer); + } - ramBLOCK.SaveState(buffer); - ram.SaveState(buffer); + if (regBLOCK.Valid) + { + ramBLOCK.SaveState(buffer); + ram.SaveState(buffer); + } - if(WRAM!=null) buffer.Write(WRAM); + if (WRAM != null) buffer.Write(WRAM); - mmuBLOCK.SaveState(buffer); - mmu.SaveState(buffer); - buffer.Write(CPU_MEM_BANK.ToArray()); - buffer.Write(VRAM); - buffer.Write(CRAM.ToArray()); + if (mmuBLOCK.Valid) + { + mmuBLOCK.SaveState(buffer); + mmu.SaveState(buffer); + buffer.Write(CPU_MEM_BANK.ToArray()); + buffer.Write(VRAM); + buffer.Write(CRAM.ToArray()); + } - mmcBLOCK.SaveState(buffer); - mmc.SaveState(buffer); + if (mmcBLOCK.Valid) + { + mmcBLOCK.SaveState(buffer); + mmc.SaveState(buffer); + } - ctrBLOCK.SaveState(buffer); - ctr.SaveState(buffer); + if (ctrBLOCK.Valid) + { + ctrBLOCK.SaveState(buffer); + ctr.SaveState(buffer); + } - sndBLOCK.SaveState(buffer); - snd.SaveState(buffer); + if (sndBLOCK.Valid) + { + sndBLOCK.SaveState(buffer); + snd.SaveState(buffer); + } - dskBLOCK.SaveState(buffer); - dsk.SaveState(buffer); - buffer.Write(dskdata); + if (dskBLOCK.Valid) + { + dskBLOCK.SaveState(buffer); + dsk.SaveState(buffer); + buffer.Write(dskdata); + } - exctrBLOCK.SaveState(buffer); - exctr.SaveState(buffer); + if (exctrBLOCK.Valid) + { + exctrBLOCK.SaveState(buffer); + exctr.SaveState(buffer); + } return buffer.Data.ToArray(); } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs index b5c86f2..d46ed31 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs @@ -56,6 +56,8 @@ namespace VirtualNes.Core } public void Write(string value) { + if (value == null) return; + Write(Encoding.ASCII.GetBytes(value)); } public void Write(double value)