低版本C#兼容 完善移植工具

This commit is contained in:
sin365 2024-12-25 23:48:55 +08:00
parent dc9d42de5c
commit 64b9c02ef7
7 changed files with 290 additions and 155 deletions

View File

@ -5,6 +5,7 @@ using System.Linq;
using UnityEditor; using UnityEditor;
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement;
public class AxiProjectTools : EditorWindow public class AxiProjectTools : EditorWindow
{ {
@ -95,11 +96,6 @@ public class AxiProjectTools : EditorWindow
if (com == null) if (com == null)
continue; continue;
if (com.name.Contains("VideoPlayer"))
{
}
MonoBehaviour monoCom = com as MonoBehaviour; MonoBehaviour monoCom = com as MonoBehaviour;
if (monoCom == null) if (monoCom == null)
continue; continue;
@ -262,11 +258,13 @@ public class AxiProjectTools : EditorWindow
} }
[MenuItem("Axibug移植工具/[5]UnPack所有预制体")] [MenuItem("Axibug移植工具/[5]UnPack所有嵌套预制体和场景中的预制体")]
public static void UnpackPrefabs() public static void UnpackPrefabs()
{ {
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths(); #if UNITY_2018_4_OR_NEWER
GoTAxiProjectToolsSence();
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
int prefabCount = 0; int prefabCount = 0;
foreach (string path in allAssetPaths) foreach (string path in allAssetPaths)
@ -278,13 +276,41 @@ public class AxiProjectTools : EditorWindow
prefabCount++; prefabCount++;
} }
} }
Debug.Log($"Unpacked {prefabCount} prefabs."); Debug.Log($"{prefabCount}个预制体Unpack");
Debug.Log("<Color=#FFF333>处理完毕 [5]UnPack所有预制体</color>"); string[] sceneGuids = AssetDatabase.FindAssets("t:scene");
} foreach (string guid in sceneGuids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
if (path.Contains(toolSenceName))
continue;
static void UnpackPrefab(string prefabPath) EditorSceneManager.OpenScene(path);
Scene currentScene = SceneManager.GetActiveScene();
GameObject[] rootObjects = currentScene.GetRootGameObjects();
foreach (GameObject rootObj in rootObjects)
{
// 遍历场景中的所有对象
TraverseHierarchy(rootObj);
}
// Save the scene // 获取当前打开的场景
currentScene = EditorSceneManager.GetActiveScene();
// 保存场景到文件(默认路径和名称)
bool success = EditorSceneManager.SaveScene(currentScene, currentScene.path);
Debug.Log($"{currentScene.name}场景中 所有物体Unpack");
}
GoTAxiProjectToolsSence();
Debug.Log("<Color=#FFF333>处理完毕 [5]UnPack所有预制体</color>");
#else
Debug.Log("低版本不要执行本函数");
#endif
}
static void UnpackPrefab(string prefabPath)
{ {
#if UNITY_2018_4_OR_NEWER
GameObject prefabInstance = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath); GameObject prefabInstance = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if (prefabInstance == null) if (prefabInstance == null)
{ {
@ -296,10 +322,14 @@ public class AxiProjectTools : EditorWindow
TraverseHierarchy(obj); TraverseHierarchy(obj);
PrefabUtility.SaveAsPrefabAsset(obj, prefabPath); PrefabUtility.SaveAsPrefabAsset(obj, prefabPath);
GameObject.DestroyImmediate(obj); GameObject.DestroyImmediate(obj);
#else
Debug.Log("低版本不要执行本函数");
#endif
} }
static void TraverseHierarchy(GameObject obj) static void TraverseHierarchy(GameObject obj)
{ {
#if UNITY_2018_4_OR_NEWER
// 检查该对象是否是预制体的实例 // 检查该对象是否是预制体的实例
if (PrefabUtility.IsPartOfPrefabInstance(obj)) if (PrefabUtility.IsPartOfPrefabInstance(obj))
{ {
@ -313,6 +343,9 @@ public class AxiProjectTools : EditorWindow
{ {
TraverseHierarchy(obj.transform.GetChild(i).gameObject); TraverseHierarchy(obj.transform.GetChild(i).gameObject);
} }
#else
Debug.Log("低版本不要执行本函数");
#endif
} }

View File

@ -1,6 +1,8 @@
using AxibugEmuOnline.Client; using AxibugEmuOnline.Client;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using System.Collections.Generic;
namespace AxibugEmuOnline.Editors namespace AxibugEmuOnline.Editors
{ {
[CustomEditor(typeof(CommandDispatcher))] [CustomEditor(typeof(CommandDispatcher))]
@ -13,8 +15,8 @@ namespace AxibugEmuOnline.Editors
if (!Application.isPlaying) return; if (!Application.isPlaying) return;
var dispacather = target as CommandDispatcher; var dispacather = target as CommandDispatcher;
IReadOnlyList<CommandExecuter> normal; IReadOnlyList<CommandExecuter> solo;
dispacather.GetRegisters(out var normal, out var solo); dispacather.GetRegisters(out normal, out solo);
EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.LabelField("NORMAL"); EditorGUILayout.LabelField("NORMAL");

View File

@ -60,7 +60,7 @@ namespace AxiReplay
if (!bNetInit) if (!bNetInit)
{ {
data = default(ReplayStep); data = default(ReplayStep);
frameDiff = default; frameDiff = default(int);
inputDiff = false; inputDiff = false;
return false; return false;
} }
@ -73,7 +73,7 @@ namespace AxiReplay
if (!bNetInit) if (!bNetInit)
{ {
data = default(ReplayStep); data = default(ReplayStep);
frameDiff = default; frameDiff = default(int);
inputDiff = false; inputDiff = false;
return false; return false;
} }

View File

@ -5,152 +5,154 @@ using System.Text;
namespace AxiReplay namespace AxiReplay
{ {
public class ReplayWriter : IReplayWriter public class ReplayWriter : IReplayWriter
{ {
public ReplayData.ReplayFormat mFormat { get; private set; } public ReplayData.ReplayFormat mFormat { get; private set; }
public Encoding TexEncoding { get; private set; } public Encoding TexEncoding { get; private set; }
ReplayHandler handler; ReplayHandler handler;
string mTitle; string mTitle;
string mNote; string mNote;
int mAllFrame; int mAllFrame;
int mAllTime; int mAllTime;
long mData; long mData;
int mSingleInputLenght; int mSingleInputLenght;
int mSingleDataLenght; int mSingleDataLenght;
MemoryStream mStream; MemoryStream mStream;
BinaryWriter mBinaryWriter; BinaryWriter mBinaryWriter;
int mCurrFrame; int mCurrFrame;
UInt64 mCurrInput; UInt64 mCurrInput;
ReplayStep wirteStep; ReplayStep wirteStep;
List<string> dbgList = new List<string>(); List<string> dbgList = new List<string>();
public ReplayWriter(string Title, string Note, ReplayData.ReplayFormat format, Encoding encoding) public ReplayWriter(string Title, string Note, ReplayData.ReplayFormat format, Encoding encoding)
{ {
mTitle = Title; mTitle = Title;
mNote = Note; mNote = Note;
TexEncoding = encoding; TexEncoding = encoding;
mFormat = format; mFormat = format;
switch (mFormat) switch (mFormat)
{ {
case ReplayData.ReplayFormat.FM32IP64: mSingleInputLenght = sizeof(UInt64); break; case ReplayData.ReplayFormat.FM32IP64: mSingleInputLenght = sizeof(UInt64); break;
case ReplayData.ReplayFormat.FM32IP32: mSingleInputLenght = sizeof(UInt32); break; case ReplayData.ReplayFormat.FM32IP32: mSingleInputLenght = sizeof(UInt32); break;
case ReplayData.ReplayFormat.FM32IP16: mSingleInputLenght = sizeof(UInt16); break; case ReplayData.ReplayFormat.FM32IP16: mSingleInputLenght = sizeof(UInt16); break;
case ReplayData.ReplayFormat.FM32IPBYTE: mSingleInputLenght = sizeof(byte); break; case ReplayData.ReplayFormat.FM32IPBYTE: mSingleInputLenght = sizeof(byte); break;
} }
mSingleDataLenght = (sizeof(UInt32)) + mSingleInputLenght; mSingleDataLenght = (sizeof(UInt32)) + mSingleInputLenght;
mStream = new MemoryStream(); mStream = new MemoryStream();
mBinaryWriter = new BinaryWriter(mStream); mBinaryWriter = new BinaryWriter(mStream);
mCurrFrame = -1; mCurrFrame = -1;
mCurrInput = int.MaxValue; mCurrInput = int.MaxValue;
wirteStep = new ReplayStep(); wirteStep = new ReplayStep();
dbgList.Clear(); dbgList.Clear();
} }
int byFrameIdx = 0; int byFrameIdx = 0;
/// <summary> /// <summary>
/// 往前推进帧的,指定帧下标 /// 往前推进帧的,指定帧下标
/// </summary> /// </summary>
/// <param name="frameInput"></param> /// <param name="frameInput"></param>
public void NextFramebyFrameIdx(int FrameID, UInt64 frameInput) public void NextFramebyFrameIdx(int FrameID, UInt64 frameInput)
{ {
TakeFrame(FrameID - byFrameIdx, frameInput); TakeFrame(FrameID - byFrameIdx, frameInput);
byFrameIdx = FrameID; byFrameIdx = FrameID;
} }
/// <summary> /// <summary>
/// 往前推进1帧的Input /// 往前推进1帧的Input
/// </summary> /// </summary>
/// <param name="frameInput"></param> /// <param name="frameInput"></param>
public void NextFrame(UInt64 frameInput) public void NextFrame(UInt64 frameInput)
{ {
TakeFrame(1, frameInput); TakeFrame(1, frameInput);
} }
/// <summary> /// <summary>
/// 往前推进指定帧数量的Input /// 往前推进指定帧数量的Input
/// </summary> /// </summary>
/// <param name="frameInput"></param> /// <param name="frameInput"></param>
public void TakeFrame(int addFrame, UInt64 frameInput) public void TakeFrame(int addFrame, UInt64 frameInput)
{ {
if (addFrame < 0) if (addFrame < 0)
{ {
} }
mCurrFrame += addFrame; mCurrFrame += addFrame;
if (mCurrInput == frameInput) if (mCurrInput == frameInput)
return; return;
mCurrInput = frameInput; mCurrInput = frameInput;
wirteStep.FrameStartID = mCurrFrame; wirteStep.FrameStartID = mCurrFrame;
wirteStep.InPut = mCurrInput; wirteStep.InPut = mCurrInput;
dbgList.Add($"{mCurrFrame} | {mCurrInput}"); dbgList.Add($"{mCurrFrame} | {mCurrInput}");
switch (mFormat) switch (mFormat)
{ {
case ReplayData.ReplayFormat.FM32IP64: case ReplayData.ReplayFormat.FM32IP64:
mBinaryWriter.Write(wirteStep.FrameStartID); mBinaryWriter.Write(wirteStep.FrameStartID);
mBinaryWriter.Write(wirteStep.InPut); mBinaryWriter.Write(wirteStep.InPut);
break; break;
case ReplayData.ReplayFormat.FM32IP32: case ReplayData.ReplayFormat.FM32IP32:
mBinaryWriter.Write(BitConverter.GetBytes(wirteStep.All64Data), 0, 4 + 4); mBinaryWriter.Write(BitConverter.GetBytes(wirteStep.All64Data), 0, 4 + 4);
break; break;
case ReplayData.ReplayFormat.FM32IP16: case ReplayData.ReplayFormat.FM32IP16:
mBinaryWriter.Write(BitConverter.GetBytes(wirteStep.All64Data), 0, 4 + 2); mBinaryWriter.Write(BitConverter.GetBytes(wirteStep.All64Data), 0, 4 + 2);
break; break;
case ReplayData.ReplayFormat.FM32IPBYTE: case ReplayData.ReplayFormat.FM32IPBYTE:
mBinaryWriter.Write(BitConverter.GetBytes(wirteStep.All64Data), 0, 4 + 1); mBinaryWriter.Write(BitConverter.GetBytes(wirteStep.All64Data), 0, 4 + 1);
break; break;
} }
} }
public void SaveData(string path, bool bWithDump = false, string dumppath = null) public void SaveData(string path, bool bWithDump = false, string dumppath = null)
{ {
ReplayData.GetStringByteData(mTitle, out byte[] titleData, out int titleLenghtWithEnd, TexEncoding); byte[] titleData; int titleLenghtWithEnd;
ReplayData.GetStringByteData(mNote, out byte[] noteData, out int noteLenghtWithEnd, TexEncoding); ReplayData.GetStringByteData(mTitle, out titleData, out titleLenghtWithEnd, TexEncoding);
byte[] noteData; int noteLenghtWithEnd;
ReplayData.GetStringByteData(mNote, out noteData, out noteLenghtWithEnd, TexEncoding);
ReplayHandler handler = new ReplayHandler(); ReplayHandler handler = new ReplayHandler();
handler.Format = (int)this.mFormat; handler.Format = (int)this.mFormat;
handler.DataOffset = ReplayData.HandlerLenght; handler.DataOffset = ReplayData.HandlerLenght;
handler.CreateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); handler.CreateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
handler.AllFrame = wirteStep.FrameStartID; handler.AllFrame = wirteStep.FrameStartID;
handler.SingleLenght = mSingleDataLenght; handler.SingleLenght = mSingleDataLenght;
using (FileStream fs = new FileStream(path, FileMode.Create)) using (FileStream fs = new FileStream(path, FileMode.Create))
{ {
using (BinaryWriter bw = new BinaryWriter(fs)) using (BinaryWriter bw = new BinaryWriter(fs))
{ {
//写入Handler //写入Handler
bw.Write(ReplayData.GetHandlerData(handler)); bw.Write(ReplayData.GetHandlerData(handler));
//写入Data //写入Data
bw.Write(mStream.ToArray()); bw.Write(mStream.ToArray());
} }
} }
if (bWithDump) if (bWithDump)
{ {
List<string> temp = new List<string>(); List<string> temp = new List<string>();
temp.Add($"Format => {handler.Format}"); temp.Add($"Format => {handler.Format}");
temp.Add($"DataOffset => {handler.DataOffset}"); temp.Add($"DataOffset => {handler.DataOffset}");
temp.Add($"CreateTime => {handler.CreateTime}"); temp.Add($"CreateTime => {handler.CreateTime}");
temp.Add($"AllFrame => {handler.AllFrame}"); temp.Add($"AllFrame => {handler.AllFrame}");
temp.Add($"SingleLenght => {handler.SingleLenght}"); temp.Add($"SingleLenght => {handler.SingleLenght}");
dbgList.InsertRange(0, temp); dbgList.InsertRange(0, temp);
File.WriteAllLines(dumppath, dbgList); File.WriteAllLines(dumppath, dbgList);
} }
} }
public void Dispose() public void Dispose()
{ {
mStream.Dispose(); mStream.Dispose();
mBinaryWriter.Dispose(); mBinaryWriter.Dispose();
//TODO //TODO
} }
} }
} }

View File

@ -1,7 +1,92 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: eb76ae7b43c117c449fe04e536cf3f34 guid: eb76ae7b43c117c449fe04e536cf3f34
MonoAssemblyImporter: PluginImporter:
serializedVersion: 1 externalObjects: {}
serializedVersion: 2
iconMap: {} iconMap: {}
executionOrder: {} executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
- first:
'': Any
second:
enabled: 0
settings:
Exclude Editor: 0
Exclude Linux: 1
Exclude Linux64: 1
Exclude LinuxUniversal: 1
Exclude OSXUniversal: 1
Exclude PSP2: 0
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
- first:
Facebook: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Facebook: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
PSP2: PSP2
second:
enabled: 1
settings: {}
- first:
Standalone: Linux
second:
enabled: 0
settings:
CPU: x86
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: x86_64
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData: userData:
assetBundleName:
assetBundleVariant:

View File

@ -64,7 +64,9 @@ namespace AxibugEmuOnline.Client
else return null; else return null;
} }
static HashSet<uint> s_temp = new HashSet<uint>(4); //static HashSet<uint> s_temp = new HashSet<uint>(4);
//低版本不能这样初始化
static HashSet<uint> s_temp = new HashSet<uint>();
public uint? GetFreeSlotIndex() public uint? GetFreeSlotIndex()
{ {
s_temp.Clear(); s_temp.Clear();
@ -84,14 +86,25 @@ namespace AxibugEmuOnline.Client
public void LetControllerConnect(int conIndex, uint slotIndex) public void LetControllerConnect(int conIndex, uint slotIndex)
{ {
var targetController = conIndex switch Controller targetController;
switch (conIndex)
{ {
0 => Controller0, case 0: targetController = Controller0;break;
1 => Controller1, case 1: targetController = Controller1; break;
2 => Controller2, case 2: targetController = Controller2; break;
3 => Controller3, case 3: targetController = Controller3; break;
_ => throw new System.Exception($"Not Allowed conIndex Range: {conIndex}") default:
}; throw new System.Exception($"Not Allowed conIndex Range: {conIndex}");
break;
}
//var targetController = conIndex switch
//{
// 0 => Controller0,
// 1 => Controller1,
// 2 => Controller2,
// 3 => Controller3,
// _ => throw new System.Exception($"Not Allowed conIndex Range: {conIndex}")
//};
if (targetController.ConnectSlot.HasValue) return; if (targetController.ConnectSlot.HasValue) return;

View File

@ -44,7 +44,7 @@ public class SonyVitaCommonDialog : MonoBehaviour
Debug.Log("IME text: " + result.text); Debug.Log("IME text: " + result.text);
if (result.result == Sony.Vita.Dialog.Ime.EnumImeDialogResult.RESULT_OK) if (result.result == Sony.Vita.Dialog.Ime.EnumImeDialogResult.RESULT_OK)
{ {
resultAct.Invoke(result); resultAct.Invoke(result.text);
resultAct = null; resultAct = null;
} }
} }