using System; using UnityEngine; using System.IO; namespace CharacterPreview { [Serializable] public class ConfigData { public Vector3 modelPosition; public Vector3 modelRotation; public float modelScale; public bool use = false; public bool tip = true; public bool hideCamera = true; public bool showSetEditButton = true; public bool canEdit = true; public float editSpeed = 1; public bool showEquipment = true; } [Serializable] public class Config { private string configSavePath; public ConfigData data = new ConfigData(); public Config(string savePath) { configSavePath = savePath; } public void Save() { data.use = true; var json = JsonUtility.ToJson(data, true); File.WriteAllText(configSavePath, json); } public static Config Load(string savePath) { if (!File.Exists(savePath)) { try { File.Create(savePath).Dispose(); } catch (IOException ex) { Debug.LogError($"Failed to create empty config file at {savePath}: {ex.Message}"); return new Config(savePath) { data = new ConfigData() }; } } var json = File.ReadAllText(savePath); var loadedData = JsonUtility.FromJson(json); var config = new Config(savePath); config.data = loadedData ?? new ConfigData(); return config; } } }