存档UI功能完成
This commit is contained in:
parent
209c82da80
commit
4116a05b6c
AxibugEmuOnline.Client/Assets
@ -1688,7 +1688,7 @@ RectTransform:
|
||||
m_GameObject: {fileID: 5162569472849600096}
|
||||
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_LocalScale: {x: 1, y: -1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 5970282275929291192}
|
||||
|
@ -124,16 +124,20 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
|
||||
m_headerCache = new Header();
|
||||
IntPtr ptr = Marshal.AllocHGlobal(headerSize);
|
||||
Marshal.StructureToPtr(m_headerCache, ptr, false);
|
||||
Marshal.Copy(raw, 0, ptr, headerSize);
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
fixed (Header* headPtr = &m_headerCache)
|
||||
{
|
||||
var headP=(byte*)headPtr;
|
||||
Marshal.Copy(raw, 0, (IntPtr)headP, sizeof(Header));
|
||||
}
|
||||
|
||||
savData = new byte[m_headerCache.DataLength];
|
||||
Array.Copy(raw, headerSize, savData, 0, savData.Length);
|
||||
screenShotData = new byte[m_headerCache.ScreenShotLength];
|
||||
Array.Copy(raw, headerSize + savData.Length, screenShotData, 0, screenShotData.Length);
|
||||
|
||||
m_savDataCaches = savData;
|
||||
m_screenShotCaches = screenShotData;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -171,9 +175,10 @@ namespace AxibugEmuOnline.Client
|
||||
Sequecen = sequence;
|
||||
|
||||
m_headerCache = header;
|
||||
IsEmpty = false;
|
||||
m_savDataCaches = savData;
|
||||
m_screenShotCaches = screenShotData;
|
||||
|
||||
m_cacheOutdate = true;
|
||||
IsEmpty = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AxibugEmuOnline.Client.ClientCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AxibugEmuOnline.Client
|
||||
{
|
||||
@ -22,7 +23,7 @@ namespace AxibugEmuOnline.Client
|
||||
foreach (var savFile in saveFiles)
|
||||
{
|
||||
if (savFile.AutoSave) continue;
|
||||
result.Add(new SaveSlotMenu(savFile));
|
||||
result.Add(new SaveSlotMenu(m_gameUI, savFile));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -33,16 +34,24 @@ namespace AxibugEmuOnline.Client
|
||||
public override Type MenuUITemplateType => typeof(OptionUI_SavSlotItem);
|
||||
public SaveFile SavFile { get; private set; }
|
||||
|
||||
private InGameUI m_ingameUI;
|
||||
|
||||
public override bool Visible => !SavFile.AutoSave;
|
||||
|
||||
public SaveSlotMenu(SaveFile savFile)
|
||||
public SaveSlotMenu(InGameUI inGameui, SaveFile savFile)
|
||||
{
|
||||
SavFile = savFile;
|
||||
m_ingameUI = inGameui;
|
||||
}
|
||||
|
||||
public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
|
||||
{
|
||||
cancelHide = true;//保存后不关闭
|
||||
cancelHide = true;
|
||||
var stateData = m_ingameUI.Core.GetStateBytes();
|
||||
var tex = m_ingameUI.Core.OutputPixel;
|
||||
var screenData = tex.ToJPG();
|
||||
|
||||
SavFile.Save(SavFile.Sequecen, stateData, screenData);
|
||||
}
|
||||
|
||||
public override string Name => SavFile.AutoSave ? "自动存档" : $"存档{SavFile.SlotIndex}";
|
||||
|
@ -62,6 +62,7 @@ namespace AxibugEmuOnline.Client
|
||||
public override void OnExecute(OptionUI optionUI, ref bool cancelHide)
|
||||
{
|
||||
MenuData.OnExcute(optionUI, ref cancelHide);
|
||||
RefreshUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,5 +54,38 @@ namespace AxibugEmuOnline.Client
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
public static byte[] ToJPG(this Texture texture)
|
||||
{
|
||||
Texture2D outputTex = null;
|
||||
if (texture is RenderTexture rt)
|
||||
{
|
||||
outputTex = ConvertFromRenderTexture(rt);
|
||||
}
|
||||
else if (texture is Texture2D)
|
||||
{
|
||||
outputTex = texture as Texture2D;
|
||||
}
|
||||
|
||||
return outputTex.EncodeToJPG();
|
||||
}
|
||||
|
||||
private static Texture2D ConvertFromRenderTexture(RenderTexture rt)
|
||||
{
|
||||
// 创建临时RenderTexture并拷贝内容
|
||||
RenderTexture tempRT = RenderTexture.GetTemporary(rt.width, rt.height, 0, RenderTextureFormat.ARGB32);
|
||||
Graphics.Blit(rt, tempRT);
|
||||
|
||||
// 读取到Texture2D
|
||||
Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false);
|
||||
RenderTexture.active = tempRT;
|
||||
tex.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0);
|
||||
tex.Apply();
|
||||
|
||||
// 释放资源
|
||||
RenderTexture.active = null;
|
||||
RenderTexture.ReleaseTemporary(tempRT);
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user