1
This commit is contained in:
74
Src/Unity/Scripts/Entity/Editor/UnityEntitiesBinaryEditor.cs
Normal file
74
Src/Unity/Scripts/Entity/Editor/UnityEntitiesBinaryEditor.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.Entities.GameEditor
|
||||
{
|
||||
public class UnityEntitiesBinaryEditor : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/Entities/EntitiesBinaryEditor")]
|
||||
public static void Open()
|
||||
{
|
||||
var window = GetWindow<UnityEntitiesBinaryEditor>();
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private Label _base64Label;
|
||||
private void OnEnable()
|
||||
{
|
||||
rootVisualElement.Clear();
|
||||
|
||||
var button = rootVisualElement.Create<Button>();
|
||||
button.clicked += PrintBytes;
|
||||
|
||||
button.text = "获取二进制数据";
|
||||
|
||||
_base64Label = rootVisualElement.Create<Label>();
|
||||
|
||||
var copyButton = rootVisualElement.Create<Button>();
|
||||
copyButton.text = "复制到剪切板";
|
||||
copyButton.clicked += () =>
|
||||
{
|
||||
EditorGUIUtility.systemCopyBuffer = _base64Label.text;
|
||||
};
|
||||
|
||||
var inputField = rootVisualElement.Create<TextField>();
|
||||
inputField.multiline = true;
|
||||
inputField.label = "输入二进制数据";
|
||||
var applyButton = rootVisualElement.Create<Button>();
|
||||
applyButton.text = "应用数据";
|
||||
applyButton.clicked += () =>
|
||||
{
|
||||
|
||||
var bytes = JsonHelper.Get<byte[]>(inputField.value);
|
||||
|
||||
using var ms = new System.IO.MemoryStream(bytes);
|
||||
using var reader = new System.IO.BinaryReader(ms);
|
||||
Debug.Log($"应用数据中,长度为:{ms.Length}");
|
||||
foreach (var header in UnityEntitiesService.QueryComponents<IEntityBinaryHeader>())
|
||||
{
|
||||
header.Deserialize(reader);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void PrintBytes()
|
||||
{
|
||||
using var ms = new System.IO.MemoryStream();
|
||||
using var writer = new System.IO.BinaryWriter(ms);
|
||||
foreach (var header in UnityEntitiesService.QueryComponents<IEntityBinaryHeader>())
|
||||
{
|
||||
header.Serialize(writer);
|
||||
}
|
||||
var bytes = ms.ToArray();
|
||||
writer.Dispose();
|
||||
ms.Dispose();
|
||||
|
||||
_base64Label.text = JsonHelper.Get(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ace44c921aa7cae419c70332a5c75122
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -6,11 +6,11 @@ using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.Entities.Editor
|
||||
namespace BITKit.Entities.GameEditor
|
||||
{
|
||||
public class UnityEntitiesServiceEditor : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/Entities/UnityEntitiesService")]
|
||||
[MenuItem("Tools/Entities/EntitiesService")]
|
||||
public static void Open()
|
||||
{
|
||||
var window = GetWindow<UnityEntitiesServiceEditor>();
|
||||
|
Reference in New Issue
Block a user