76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Steamworks;
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|