合并Switch版本修改

This commit is contained in:
sin365 2025-08-21 10:34:57 +08:00
parent ccf2279947
commit a1aa816426
70 changed files with 7723 additions and 7600 deletions

View File

@ -90,9 +90,14 @@ namespace AxibugEmuOnline.Client.ClientCore
public static void Init(bool isTest = false, bool isUseGUIButton = false, string testSrvIP = "", bool bUseLocalWebApi = false, string mLocalWebApi = "") public static void Init(bool isTest = false, bool isUseGUIButton = false, string testSrvIP = "", bool bUseLocalWebApi = false, string mLocalWebApi = "")
{ {
log = new LogManager(OnLogOut); log = new LogManager(OnLogOut);
//其他平台必要的初始化 //其他平台必要的初始化
if (UnityEngine.Application.platform == RuntimePlatform.PSP2) PSP2Init(); #if UNITY_PSP2
PSP2Init();
#endif
#if UNITY_SWITCH
SwitchInit();
#endif
input = new InputDevicesManager(); input = new InputDevicesManager();
FileDownloader = new FileDownloader(); FileDownloader = new FileDownloader();
@ -153,11 +158,18 @@ namespace AxibugEmuOnline.Client.ClientCore
sonyVitaCommonDialog = new GameObject().AddComponent<SonyVitaCommonDialog>(); sonyVitaCommonDialog = new GameObject().AddComponent<SonyVitaCommonDialog>();
#endif #endif
#if UNITY_SWITCH
//创建创建Switch
switchCommon = new GameObject().AddComponent<SwitchCommon>();
#endif
}
private static void SwitchInit()
{
#if UNITY_SWITCH
AxiNS.instance.Init();
if (!AxiIO.Directory.Exists(App.PersistentDataRootPath()))
AxiIO.Directory.CreateDirectory(App.PersistentDataRootPath());
switchCommon = new GameObject().AddComponent<SwitchCommon>();
switchCommon.gameObject.name = "[SwitchCommon]";
GameObject.DontDestroyOnLoad(switchCommon);
#endif
} }

View File

@ -24,7 +24,7 @@ public class DebuggerByGUI : MonoBehaviour
private Vector2 _scrollLogView = Vector2.zero; private Vector2 _scrollLogView = Vector2.zero;
private Vector2 _scrollCurrentLogView = Vector2.zero; private Vector2 _scrollCurrentLogView = Vector2.zero;
private Vector2 _scrollSystemView = Vector2.zero; private Vector2 _scrollSystemView = Vector2.zero;
private bool _expansion = false; private bool _expansion = false;
private Rect _windowRect = new Rect(0, 0, 100, 60); private Rect _windowRect = new Rect(0, 0, 100, 60);
private int _fps = 0; private int _fps = 0;
@ -32,9 +32,26 @@ public class DebuggerByGUI : MonoBehaviour
private int _frameNumber = 0; private int _frameNumber = 0;
private float _lastShowFPSTime = 0f; private float _lastShowFPSTime = 0f;
private void Start() public bool OpenHubOnStart = false;
public bool AutoShowLastLogLine = false;
public bool OnlyShowErrOnStart = false;
private void Start()
{ {
DontDestroyOnLoad(this.gameObject); if (OpenHubOnStart)
{
_expansion = true;
_windowRect.width = 1000;
_windowRect.height = 600;
}
if (OnlyShowErrOnStart)
{
_showInfoLog = false;
_showWarningLog = false;
}
DontDestroyOnLoad(this.gameObject);
if (AllowDebugging) if (AllowDebugging)
{ {
Application.logMessageReceived += LogHandler; Application.logMessageReceived += LogHandler;
@ -237,16 +254,22 @@ public class DebuggerByGUI : MonoBehaviour
GUILayout.Label(_logInformations[i].message); GUILayout.Label(_logInformations[i].message);
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUI.contentColor = Color.white; GUI.contentColor = Color.white;
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
} }
GUILayout.EndScrollView(); GUILayout.EndScrollView();
_scrollCurrentLogView = GUILayout.BeginScrollView(_scrollCurrentLogView, "Box", GUILayout.Height(100)); _scrollCurrentLogView = GUILayout.BeginScrollView(_scrollCurrentLogView, "Box", GUILayout.Height(100));
if (_currentLogIndex != -1)
if (AutoShowLastLogLine)
{
_scrollLogView.y = Mathf.Lerp(_scrollLogView.y, float.MaxValue, 0.1f);
}
if (_currentLogIndex != -1)
{ {
GUILayout.Label(_logInformations[_currentLogIndex].message + "\r\n\r\n" + _logInformations[_currentLogIndex].stackTrace); GUILayout.Label(_logInformations[_currentLogIndex].message + "\r\n\r\n" + _logInformations[_currentLogIndex].stackTrace);
} }
GUILayout.EndScrollView(); GUILayout.EndScrollView();
} }
#endregion #endregion

View File

@ -147,6 +147,25 @@ namespace AxibugEmuOnline.Client.Settings
controller.SetBinding(EssgeeSingleKey.LEFT, device.JOYSTICK.Left, 1); controller.SetBinding(EssgeeSingleKey.LEFT, device.JOYSTICK.Left, 1);
controller.SetBinding(EssgeeSingleKey.RIGHT, device.JOYSTICK.Right, 1); controller.SetBinding(EssgeeSingleKey.RIGHT, device.JOYSTICK.Right, 1);
} }
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{
controller.SetBinding(EssgeeSingleKey.OPTION_1, device.Plus, 0);
controller.SetBinding(EssgeeSingleKey.OPTION_2, device.Minus, 0);
controller.SetBinding(EssgeeSingleKey.UP, device.Up, 0);
controller.SetBinding(EssgeeSingleKey.DOWN, device.Down, 0);
controller.SetBinding(EssgeeSingleKey.LEFT, device.Left, 0);
controller.SetBinding(EssgeeSingleKey.RIGHT, device.Right, 0);
controller.SetBinding(EssgeeSingleKey.BTN_1, device.A, 0);
controller.SetBinding(EssgeeSingleKey.BTN_2, device.B, 0);
controller.SetBinding(EssgeeSingleKey.BTN_3, device.X, 0);
controller.SetBinding(EssgeeSingleKey.BTN_4, device.Y, 0);
controller.SetBinding(EssgeeSingleKey.UP, device.LeftStick.Up, 1);
controller.SetBinding(EssgeeSingleKey.DOWN, device.LeftStick.Down, 1);
controller.SetBinding(EssgeeSingleKey.LEFT, device.LeftStick.Left, 1);
controller.SetBinding(EssgeeSingleKey.RIGHT, device.LeftStick.Right, 1);
}
} }
public class MasterSystemKeyBinding : EssgeeKeyBinding public class MasterSystemKeyBinding : EssgeeKeyBinding

View File

@ -158,6 +158,27 @@ namespace AxibugEmuOnline.Client.Settings
controller.SetBinding(UMAMEKSingleKey.LEFT, device.JOYSTICK.Left, 1); controller.SetBinding(UMAMEKSingleKey.LEFT, device.JOYSTICK.Left, 1);
controller.SetBinding(UMAMEKSingleKey.RIGHT, device.JOYSTICK.Right, 1); controller.SetBinding(UMAMEKSingleKey.RIGHT, device.JOYSTICK.Right, 1);
} }
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{
controller.SetBinding(UMAMEKSingleKey.INSERT_COIN, device.Minus, 0);
controller.SetBinding(UMAMEKSingleKey.GAMESTART, device.Plus, 0);
controller.SetBinding(UMAMEKSingleKey.UP, device.Up, 0);
controller.SetBinding(UMAMEKSingleKey.DOWN, device.Down, 0);
controller.SetBinding(UMAMEKSingleKey.LEFT, device.Left, 0);
controller.SetBinding(UMAMEKSingleKey.RIGHT, device.Right, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_A, device.A, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_B, device.B, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_C, device.X, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_D, device.Y, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_E, device.LeftSL, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_F, device.RightSL, 0);
controller.SetBinding(UMAMEKSingleKey.UP, device.LeftStick.Up, 1);
controller.SetBinding(UMAMEKSingleKey.DOWN, device.LeftStick.Down, 1);
controller.SetBinding(UMAMEKSingleKey.LEFT, device.LeftStick.Left, 1);
controller.SetBinding(UMAMEKSingleKey.RIGHT, device.LeftStick.Right, 1);
}
} }
public class NEOGEOKeyBinding : MAMEKeyBinding public class NEOGEOKeyBinding : MAMEKeyBinding

View File

@ -16,7 +16,8 @@ public abstract class EmuCoreBinder<T> : InternalEmuCoreBinder,
IDeviceBinder<T, DualShockController_D>, IDeviceBinder<T, DualShockController_D>,
IDeviceBinder<T, XboxController_D>, IDeviceBinder<T, XboxController_D>,
IDeviceBinder<T, PSVController_D>, IDeviceBinder<T, PSVController_D>,
IDeviceBinder<T, ScreenGamepad_D> IDeviceBinder<T, ScreenGamepad_D>,
IDeviceBinder<T, SwitchJoyCon_D>
where T : Enum where T : Enum
{ {
//每一个实例代表一个对应模拟器平台的控制器索引 //每一个实例代表一个对应模拟器平台的控制器索引
@ -83,6 +84,7 @@ public abstract class EmuCoreBinder<T> : InternalEmuCoreBinder,
else if (device is XboxController_D xbC) Bind(xbC, binding); else if (device is XboxController_D xbC) Bind(xbC, binding);
else if (device is PSVController_D psvC) Bind(psvC, binding); else if (device is PSVController_D psvC) Bind(psvC, binding);
else if (device is ScreenGamepad_D screenGamepad) Bind(screenGamepad, binding); else if (device is ScreenGamepad_D screenGamepad) Bind(screenGamepad, binding);
else if (device is SwitchJoyCon_D nsJoyCon) Bind(nsJoyCon, binding);
else throw new NotImplementedException($"{device.GetType()}"); else throw new NotImplementedException($"{device.GetType()}");
} }
@ -305,4 +307,5 @@ public abstract class EmuCoreBinder<T> : InternalEmuCoreBinder,
public abstract void Bind(XboxController_D device, ControllerBinder controller); public abstract void Bind(XboxController_D device, ControllerBinder controller);
public abstract void Bind(PSVController_D device, ControllerBinder controller); public abstract void Bind(PSVController_D device, ControllerBinder controller);
public abstract void Bind(ScreenGamepad_D device, ControllerBinder controller); public abstract void Bind(ScreenGamepad_D device, ControllerBinder controller);
public abstract void Bind(SwitchJoyCon_D device, ControllerBinder controller);
} }

View File

@ -121,5 +121,22 @@ namespace AxibugEmuOnline.Client.Settings
controller.SetBinding(EnumButtonType.UP, device.JOYSTICK.Up, 1); controller.SetBinding(EnumButtonType.UP, device.JOYSTICK.Up, 1);
controller.SetBinding(EnumButtonType.DOWN, device.JOYSTICK.Down, 1); controller.SetBinding(EnumButtonType.DOWN, device.JOYSTICK.Down, 1);
} }
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{
controller.SetBinding(EnumButtonType.LEFT, device.Left, 0);
controller.SetBinding(EnumButtonType.RIGHT, device.Right, 0);
controller.SetBinding(EnumButtonType.UP, device.Up, 0);
controller.SetBinding(EnumButtonType.DOWN, device.Down, 0);
controller.SetBinding(EnumButtonType.A, device.A, 0);
controller.SetBinding(EnumButtonType.B, device.B, 0);
controller.SetBinding(EnumButtonType.SELECT, device.Minus, 0);
controller.SetBinding(EnumButtonType.START, device.Plus, 0);
controller.SetBinding(EnumButtonType.MIC, device.RightSL, 0);
controller.SetBinding(EnumButtonType.LEFT, device.LeftStick.Left, 1);
controller.SetBinding(EnumButtonType.RIGHT, device.LeftStick.Right, 1);
controller.SetBinding(EnumButtonType.UP, device.LeftStick.Up, 1);
controller.SetBinding(EnumButtonType.DOWN, device.LeftStick.Down, 1);
}
} }
} }

View File

@ -112,5 +112,20 @@ namespace AxibugEmuOnline.Client
controller.SetBinding(EnumCommand.SelectItemRight, device.JOYSTICK.Right, 1); controller.SetBinding(EnumCommand.SelectItemRight, device.JOYSTICK.Right, 1);
controller.SetBinding(EnumCommand.SelectItemUp, device.JOYSTICK.Up, 1); controller.SetBinding(EnumCommand.SelectItemUp, device.JOYSTICK.Up, 1);
} }
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{
controller.SetBinding(EnumCommand.Back, device.A, 0);
controller.SetBinding(EnumCommand.Enter, device.B, 0);
controller.SetBinding(EnumCommand.OptionMenu, device.Plus, 0);
controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0);
controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0);
controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0);
controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0);
controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1);
controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1);
controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1);
controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1);
}
} }
} }

View File

@ -73,32 +73,48 @@ namespace AxibugEmuOnline.Client.InputDevices
{ {
return m_devices.Values; return m_devices.Values;
} }
List<string> templog = new List<string>();
/// <summary> 由外部驱动的逻辑更新入口 </summary> /// <summary> 由外部驱动的逻辑更新入口 </summary>
public void Update() public void Update()
{ {
foreach (var device in m_devices.Values) device.Update(); foreach (var device in m_devices.Values) device.Update();
DebugInputSystem(); //string HadDrive = "";
} //foreach (var device in InputSystem.devices)
//{
// if (device is Mouse)
// continue;
// bool bhadflag = false;
// templog.Clear();
// for (int i = 0; i < device.allControls.Count; i++)
// {
// if (device.allControls[i].IsPressed(0))
// {
// if (device.allControls[i].name.ToLower() == "anykey")
// continue;
// bhadflag = true;
// string keyname = $"{device.allControls[i].GetType().FullName}|{device.allControls[i].name},";
// templog.Add(keyname);
// }
// }
// if (bhadflag)
// {
// HadDrive += $" D:{device.GetType().FullName}|{device.GetType().BaseType.FullName}|{device.name}, K:";
// foreach (var s in templog)
// {
// HadDrive += s;
// }
// }
//}
//if (!string.IsNullOrEmpty(HadDrive))
//{
// Debug.Log($"Had Drive: {HadDrive}");
//}
private static void DebugInputSystem()
{
return;
#if ENABLE_INPUT_SYSTEM
foreach (var device in InputSystem.devices)
{
if (device is Mouse)
continue;
for (int i = 0; i < device.allControls.Count; i++)
{
if (device.allControls[i].IsPressed(0))
{
Debug.Log($"{device.displayName}| {device.allControls[i].displayName}|{device.allControls[i].name}");
}
}
}
#endif
} }
} }
} }

View File

@ -172,6 +172,8 @@ namespace AxibugEmuOnline.Client
public unsafe void Save(uint sequence, byte[] savData, byte[] screenShotData) public unsafe void Save(uint sequence, byte[] savData, byte[] screenShotData)
{ {
if (IsBusy) return;
var filePath = FilePath; var filePath = FilePath;
var header = new Header var header = new Header

View File

@ -26,8 +26,8 @@ namespace AxibugEmuOnline.Client
} }
m_sequece = (uint)netData.Sequence; m_sequece = (uint)netData.Sequence;
m_downloadTask = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{netData.SavUrl}?v={m_sequece}"); m_downloadTask = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{netData.SavUrl}");
m_downloadTaskImg = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{netData.SavImgUrl}?v={m_sequece}"); m_downloadTaskImg = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{netData.SavImgUrl}");
Host.SetSavingFlag(); Host.SetSavingFlag();
} }
@ -52,25 +52,14 @@ namespace AxibugEmuOnline.Client
if (m_downloadTaskImg.downloadHandler.bHadErr) //下载失败 if (m_downloadTaskImg.downloadHandler.bHadErr) //下载失败
{ {
FSM.GetState<SyncFailedState>().Error = m_downloadTaskImg.downloadHandler.ErrInfo; FSM.ChangeState<IdleState>();
FSM.ChangeState<SyncFailedState>();
return; return;
} }
try var savData = Host.CloudAPI.UnGzipData(m_downloadTask.downloadHandler.data);
{ var imgData = Host.CloudAPI.UnGzipData(m_downloadTaskImg.downloadHandler.data);
var savData = Host.CloudAPI.UnGzipData(m_downloadTask.downloadHandler.data); Host.Save(m_sequece, savData, imgData);
var imgData = m_downloadTaskImg.downloadHandler.data; //图片数据已被服务器解压 FSM.ChangeState<SyncedState>();
Host.Save(m_sequece, savData, imgData);
FSM.ChangeState<SyncedState>();
}
catch
{
FSM.GetState<SyncFailedState>().Error = "云存档解压失败";
FSM.ChangeState<SyncFailedState>();
return;
}
} }
} }

View File

@ -1,9 +1,11 @@
using AxibugEmuOnline.Client; using AxibugEmuOnline.Client;
using AxibugEmuOnline.Client.ClientCore;
using UnityEngine; using UnityEngine;
public class SwitchCommon : MonoBehaviour public class SwitchCommon : MonoBehaviour
{ {
void Start() void Start()
{ {
Debug.Log("SwitchCommon Start");
TickLoop.LoopAction_15s += ApplyCommit; TickLoop.LoopAction_15s += ApplyCommit;
} }

View File

@ -92,16 +92,18 @@ namespace AxibugEmuOnline.Client
public override void OnExcute(OptionUI optionUI, ref bool cancelHide) public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{ {
if (m_savFile.IsBusy) //取消同步进程 if (m_savFile.IsBusy)
{ {
m_savFile.FSM.ChangeState<SaveFile.IdleState>(); OverlayManager.PopTip("存档正在同步中");
cancelHide = true;
return;
} }
var stateData = m_ingameUI.Core.GetStateBytes(); var stateData = m_ingameUI.Core.GetStateBytes();
var tex = m_ingameUI.Core.OutputPixel; var tex = m_ingameUI.Core.OutputPixel;
var screenData = tex.ToJPG(m_ingameUI.Core.DrawCanvas.transform.localScale); var screenData = tex.ToJPG(m_ingameUI.Core.DrawCanvas.transform.localScale);
m_savFile.Save(m_savFile.Sequecen + 1, stateData, screenData); m_savFile.Save(m_savFile.Sequecen, stateData, screenData);
} }
} }
@ -165,6 +167,7 @@ namespace AxibugEmuOnline.Client
public override void OnExcute(OptionUI optionUI, ref bool cancelHide) public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{ {
if (m_savFile.GetCurrentState() is not SaveFile.ConflictState) return; if (m_savFile.GetCurrentState() is not SaveFile.ConflictState) return;
cancelHide = true;
m_savFile.FSM.ChangeState<SaveFile.DownloadingState>(); m_savFile.FSM.ChangeState<SaveFile.DownloadingState>();
} }
} }
@ -184,6 +187,7 @@ namespace AxibugEmuOnline.Client
public override void OnExcute(OptionUI optionUI, ref bool cancelHide) public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{ {
if (m_savFile.GetCurrentState() is not SaveFile.ConflictState) return; if (m_savFile.GetCurrentState() is not SaveFile.ConflictState) return;
cancelHide = true;
m_savFile.FSM.ChangeState<SaveFile.UploadingState>(); m_savFile.FSM.ChangeState<SaveFile.UploadingState>();
} }
} }

View File

@ -92,18 +92,27 @@ namespace AxibugEmuOnline.Client
{ {
Canvas.ForceUpdateCanvases(); Canvas.ForceUpdateCanvases();
var topParent = FindTopOptionUI();
var totalWidth = GetTotalWidth(topParent);
Vector2 end = new Vector2(-totalWidth, MenuRoot.anchoredPosition.y);
if (m_popTween != null) if (m_popTween != null)
{ {
Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y);
m_popTween.ChangeEndValue(end, false); m_popTween.ChangeEndValue(end, false);
} }
else else
{ {
topParent.MenuRoot.anchoredPosition = end; Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y);
var topParent = m_parent;
while (topParent != null && topParent.m_parent != null)
{
topParent = topParent.m_parent;
}
if (topParent != null)
{
topParent.MenuRoot.anchoredPosition = end;
}
else
{
MenuRoot.anchoredPosition = end;
}
} }
RebuildSelectIndex(); RebuildSelectIndex();
} }
@ -214,6 +223,7 @@ namespace AxibugEmuOnline.Client
if (!m_bPoped) if (!m_bPoped)
{ {
m_bPoped = true; m_bPoped = true;
Vector2 start = new Vector2(0, MenuRoot.anchoredPosition.y); Vector2 start = new Vector2(0, MenuRoot.anchoredPosition.y);
Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y); Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y);
@ -224,8 +234,19 @@ namespace AxibugEmuOnline.Client
var moveDelta = value - start; var moveDelta = value - start;
start = value; start = value;
var topParent = FindTopOptionUI(); var topParent = m_parent;
topParent.MenuRoot.anchoredPosition += moveDelta; while (topParent != null && topParent.m_parent != null)
{
topParent = topParent.m_parent;
}
if (topParent != null)
{
topParent.MenuRoot.anchoredPosition += moveDelta;
}
else
{
MenuRoot.anchoredPosition += moveDelta;
}
}, },
end, end,
0.3f 0.3f
@ -235,30 +256,7 @@ namespace AxibugEmuOnline.Client
m_lastCS = CommandDispatcher.Instance.Mode; m_lastCS = CommandDispatcher.Instance.Mode;
CommandDispatcher.Instance.Mode = CommandListener.ScheduleType.Normal; CommandDispatcher.Instance.Mode = CommandListener.ScheduleType.Normal;
} }
}
OptionUI FindTopOptionUI()
{
if (m_parent == null) return this;
var topParent = m_parent;
while (topParent != null && topParent.m_parent != null)
{
topParent = topParent.m_parent;
}
return topParent;
}
static float GetTotalWidth(OptionUI root)
{
float totalWidth = root.MenuRoot.rect.width;
if (root.m_child != null)
{
totalWidth += GetTotalWidth(root.m_child);
}
return totalWidth;
} }
/// <summary> /// <summary>

View File

@ -21,6 +21,8 @@ namespace AxibugEmuOnline.Client
get => m_target; get => m_target;
set set
{ {
if (m_target == value) return;
m_target = value; m_target = value;
if (m_target == null) if (m_target == null)
{ {