using System; using UnityEngine; using UnityGameFramework.Runtime; namespace SepCore.InputModule.Runtime { public static class BindingOverridePersistence { public const int CurrentVersion = 2; [Serializable] private class Container { public int version; public string payload; } public static string Serialize(string overridesJson) { Container container = new Container { version = CurrentVersion, payload = overridesJson }; return JsonUtility.ToJson(container); } public static bool TryDeserialize(string storedData, out string overridesJson) { overridesJson = null; if (string.IsNullOrWhiteSpace(storedData)) { return false; } string trimmed = storedData.TrimStart(); if (trimmed.StartsWith("[")) { overridesJson = storedData; return true; } if (trimmed.StartsWith("{")) { Container container; try { container = JsonUtility.FromJson(storedData); } catch (ArgumentException) { Log.Warning("[InputModule] Binding overrides data is corrupted. Skipping load."); return false; } if (container == null) { Log.Warning("[InputModule] Binding overrides data is corrupted. Skipping load."); return false; } if (container.version > CurrentVersion) { Log.Warning("[InputModule] Binding overrides data version {0} is newer than supported version {1}. Skipping load.", container.version, CurrentVersion); return false; } overridesJson = container.payload; return true; } Log.Warning("[InputModule] Unrecognized binding overrides data format. Skipping load."); return false; } } }