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

@@ -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()
{
}
}
}