forked from undreamai/LLMUnity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LLMSerializedSettings.cs
67 lines (57 loc) · 2 KB
/
LLMSerializedSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using UnityEngine;
namespace LLMUnity
{
[Serializable]
public struct LLMSerializedSettings
{
private const string PLAYER_PREFS_KEY = "LLMSettings";
public static string ServerCommand
{
set { SetServerCommand(value); }
get { return Deserialize().serverCommand; }
}
[SerializeField] private string serverCommand;
[SerializeField] private string hardwareHash;
[SerializeField] private string version;
public void Serialize()
{
string json = JsonUtility.ToJson(this);
PlayerPrefs.SetString(PLAYER_PREFS_KEY, json);
}
private static void SetServerCommand(string value)
{
LLMSerializedSettings settings = Deserialize();
settings.serverCommand = value;
settings.hardwareHash = LLMUnitySetup.GetHardwareHash();
settings.version = LLMVersion.VERSION;
settings.Serialize();
}
public static bool HasServerCommand()
{
// Check if the key exists
bool hasKey = PlayerPrefs.HasKey(PLAYER_PREFS_KEY);
if (!hasKey) return false;
LLMSerializedSettings settings = Deserialize();
// Check if the hash matches
bool hashMatches = settings.hardwareHash.Equals(LLMUnitySetup.GetHardwareHash());
if (!hashMatches) return false;
// Check if the version matches
bool versionMatches = settings.version.Equals(LLMVersion.VERSION);
if (!versionMatches) return false;
return true;
}
public static LLMSerializedSettings Deserialize()
{
if (!HasServerCommand())
{
return new LLMSerializedSettings();
}
else
{
string json = PlayerPrefs.GetString(PLAYER_PREFS_KEY);
return JsonUtility.FromJson<LLMSerializedSettings>(json);
}
}
}
}