feat: 场景快照支持打印组件值

This commit is contained in:
m0_75251201
2025-11-03 18:56:20 +08:00
parent 2b7943339c
commit 0206a83f56
31 changed files with 455 additions and 61 deletions

View File

@@ -49,4 +49,8 @@
<PackageReference Include="Lib.Harmony" Version="2.4.1"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>
<ItemGroup>
<Folder Include="Api\" />
</ItemGroup>
</Project>

View File

@@ -12,7 +12,7 @@ namespace HideCharacter
public class HideCharacterComponent : MonoBehaviour
{
public HideList? hideList = new HideList();
public bool hide { get; private set; } = false;
private List<Renderer> rendererList = new List<Renderer>();
private GameObject?
@@ -39,45 +39,6 @@ namespace HideCharacter
LevelManager.OnLevelInitialized+=OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
var dllDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var configFilePath = Path.Combine(dllDirectory, "config.json");
if (File.Exists(configFilePath))
{
try
{
var jsonString = File.ReadAllText(configFilePath);
hideList = JsonConvert.DeserializeObject<HideList>(jsonString);
}
catch (JsonSerializationException ex) // 捕获 Newtonsoft.Json 特有的异常
{
Debug.LogError($"JSON 反序列化错误 (Newtonsoft.Json): {ex.Message}");
}
catch (IOException ex)
{
Debug.LogError($"文件读取错误: {ex.Message}");
}
catch (Exception ex)
{
Debug.LogError($"加载配置文件时发生未知错误: {ex.Message}");
}
}
else
{
Debug.LogWarning($"配置文件 '{configFilePath}' 不存在。将使用默认设置。");
try
{
var jsonString = JsonConvert.SerializeObject(hideList, Formatting.Indented);
File.WriteAllText(configFilePath, jsonString);
}
catch (IOException ex)
{
Debug.LogError($"创建配置文件时发生错误: {ex.Message}");
}
catch (Exception ex)
{
Debug.LogError($"创建配置文件时发生未知错误: {ex.Message}");
}
}
}
private void OnDisable()
@@ -205,7 +166,7 @@ namespace HideCharacter
private void Update()
{
if (Input.GetKeyDown(hideList?.hotkey ?? KeyCode.F5))
if (Input.GetKeyDown(ModBehaviour.hideList?.hotkey ?? KeyCode.F5))
{
hide = !hide;
SetCharacterHide(hide);
@@ -214,6 +175,7 @@ namespace HideCharacter
public void SetCharacterHide(bool hide)
{
var hideList = ModBehaviour.hideList;
if (hideList != null)
{
tail?.SetActive(!(hide && hideList.hideTail));

View File

@@ -1,5 +1,9 @@

using System;
using System.IO;
using System.Reflection;
using HarmonyLib;
using Newtonsoft.Json;
using UnityEngine;
using Object = UnityEngine.Object; // 确保引入 UnityEngine 命名空间
@@ -10,9 +14,18 @@ namespace HideCharacter
public static HideCharacterComponent? hideHideCharacterManager=null;
private const string CHILD_GAMEOBJECT_NAME = "HideCharacterManager";
public string MOD_ID = "HideCharacter";
public const string MOD_ID = "HideCharacter";
public const string MOD_NAME = "隐藏角色设置";
private Harmony _harmony;
public bool loadedConfigApi = false;
public static HideList? hideList = new HideList();
private void Awake()
{
loadedConfigApi = Api.ModConfigAPI.Initialize();
}
protected override void OnAfterSetup()
{
AddHideComponent();
@@ -21,6 +34,47 @@ namespace HideCharacter
_harmony=new Harmony(MOD_ID);
_harmony.PatchAll();
}
var dllDirectory = info.path;
var configFilePath = Path.Combine(dllDirectory, "config.json");
if (File.Exists(configFilePath))
{
try
{
var jsonString = File.ReadAllText(configFilePath);
hideList = JsonConvert.DeserializeObject<HideList>(jsonString);
}
catch (JsonSerializationException ex) // 捕获 Newtonsoft.Json 特有的异常
{
Debug.LogError($"JSON 反序列化错误 (Newtonsoft.Json): {ex.Message}");
}
catch (IOException ex)
{
Debug.LogError($"文件读取错误: {ex.Message}");
}
catch (Exception ex)
{
Debug.LogError($"加载配置文件时发生未知错误: {ex.Message}");
}
}
else
{
Debug.LogWarning($"配置文件 '{configFilePath}' 不存在。将使用默认设置。");
try
{
var jsonString = JsonConvert.SerializeObject(hideList, Formatting.Indented);
File.WriteAllText(configFilePath, jsonString);
}
catch (IOException ex)
{
Debug.LogError($"创建配置文件时发生错误: {ex.Message}");
}
catch (Exception ex)
{
Debug.LogError($"创建配置文件时发生未知错误: {ex.Message}");
}
}
if(Api.ModConfigAPI.IsAvailable())
AddConfigSetting();
}
protected override void OnBeforeDeactivate()
@@ -48,6 +102,18 @@ namespace HideCharacter
if (hideHideCharacterManager)
Destroy(hideHideCharacterManager?.gameObject);
}
private void AddConfigSetting()
{
Api.ModConfigAPI.SafeAddBoolDropdownList(MOD_NAME,"hideArmor","隐藏装备",hideList.hideArmor);
}
private void OnConfigChange()
{
}
}
}

View File

@@ -1,6 +1,6 @@
is_global = true
build_property.RootNamespace = HideCharacter
build_property.ProjectDir = D:\vs_project\DuckovMods\HideCharacter\
build_property.ProjectDir = d:\vs_project\DuckovMods\HideCharacter\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.CsWinRTUseWindowsUIXamlProjections = false

View File

@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("折纸的小箱子")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.1")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.1+2af09007f967b42ac04776167f814297d14582e3")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.1+2b7943339c8fff4147e07028e81b3fff19ff0d80")]
[assembly: System.Reflection.AssemblyProductAttribute("HideCharacter")]
[assembly: System.Reflection.AssemblyTitleAttribute("HideCharacter")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.1")]

View File

@@ -1 +1 @@
a90e2d9f75649545c1c6af7e34c572d4df6020158a0438630a9add7fb701918c
881e0b84476729ea6e67f155d7d840fd64b730af85f17eb2df102486efe4db4b

View File

@@ -1 +1 @@
e42d4e2d526b5e9021369ff53676b171dbb78a79de1d260ce81d1d37d0e46cf2
cd9d2ad4bfd553f20993642bd029f6938ef1781f8d488fae23bb311c819125fb