net.dreditor.customgamesettings 0.0.0-stage → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CustomGameSettings.cs +81 -0
- package/CustomGameSettings.cs.meta +11 -0
- package/DREditor.CustomSettings.asmdef +24 -0
- package/DREditor.CustomSettings.asmdef.meta +7 -0
- package/GameSettings.cs +50 -0
- package/GameSettings.cs.meta +11 -0
- package/GameSettingsManager.cs +151 -0
- package/GameSettingsManager.cs.meta +11 -0
- package/GameSettingsObject.cs +47 -0
- package/GameSettingsObject.cs.meta +11 -0
- package/ICustomGameSettingsHandler.cs +23 -0
- package/ICustomGameSettingsHandler.cs.meta +11 -0
- package/Samples/Game_Settings_Manager.prefab +52 -0
- package/Samples/Game_Settings_Manager.prefab.meta +7 -0
- package/Samples.meta +8 -0
- package/package.json +34 -6
- package/package.json.meta +7 -0
- package/README.md +0 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using System;
|
|
3
|
+
#if NEWTONSOFT_JSON
|
|
4
|
+
using Newtonsoft.Json;
|
|
5
|
+
#endif
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
namespace DREditor.CustomSettings
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
///
|
|
12
|
+
/// </summary>
|
|
13
|
+
[Serializable]
|
|
14
|
+
public class CustomGameSettings
|
|
15
|
+
{
|
|
16
|
+
/// <summary>
|
|
17
|
+
///
|
|
18
|
+
/// </summary>
|
|
19
|
+
[Tooltip("")]
|
|
20
|
+
public string ID = "";
|
|
21
|
+
|
|
22
|
+
/// <summary>
|
|
23
|
+
///
|
|
24
|
+
/// </summary>
|
|
25
|
+
[Tooltip("")]
|
|
26
|
+
[TextArea]
|
|
27
|
+
public string data = "";
|
|
28
|
+
|
|
29
|
+
public CustomGameSettings(string ID, string data)
|
|
30
|
+
{
|
|
31
|
+
this.ID = ID;
|
|
32
|
+
|
|
33
|
+
this.data = data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/// <summary>
|
|
38
|
+
///
|
|
39
|
+
/// </summary>
|
|
40
|
+
/// <typeparam name="T"></typeparam>
|
|
41
|
+
/// <param name="data"></param>
|
|
42
|
+
/// <returns></returns>
|
|
43
|
+
public static string JObjectSerialize<T>(T data) where T : ScriptableObject
|
|
44
|
+
{
|
|
45
|
+
string result;
|
|
46
|
+
#if NEWTONSOFT_JSON
|
|
47
|
+
result = JsonConvert.SerializeObject(data, Formatting.Indented,
|
|
48
|
+
new JsonSerializerSettings
|
|
49
|
+
{
|
|
50
|
+
Formatting = Formatting.Indented,
|
|
51
|
+
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
52
|
+
TypeNameHandling = TypeNameHandling.Auto
|
|
53
|
+
});
|
|
54
|
+
#else
|
|
55
|
+
result = JsonUtility.ToJson(data);
|
|
56
|
+
#endif
|
|
57
|
+
result = result.Replace("\r\n", "");
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// <summary>
|
|
63
|
+
///
|
|
64
|
+
/// </summary>
|
|
65
|
+
/// <typeparam name="T"></typeparam>
|
|
66
|
+
/// <param name="json"></param>
|
|
67
|
+
/// <returns></returns>
|
|
68
|
+
public static T JObjectDeserialize<T>(string json) where T : ScriptableObject
|
|
69
|
+
{
|
|
70
|
+
#if NEWTONSOFT_JSON
|
|
71
|
+
var instance = ScriptableObject.CreateInstance<T>();
|
|
72
|
+
|
|
73
|
+
JsonConvert.PopulateObject(json, instance);
|
|
74
|
+
|
|
75
|
+
return instance;
|
|
76
|
+
#else
|
|
77
|
+
return JsonUtility.FromJson<T>(json);
|
|
78
|
+
#endif
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "DREditor.CustomSettings",
|
|
3
|
+
"rootNamespace": "",
|
|
4
|
+
"references": [
|
|
5
|
+
"DREditor"
|
|
6
|
+
],
|
|
7
|
+
"includePlatforms": [],
|
|
8
|
+
"excludePlatforms": [],
|
|
9
|
+
"allowUnsafeCode": false,
|
|
10
|
+
"overrideReferences": true,
|
|
11
|
+
"precompiledReferences": [
|
|
12
|
+
"Newtonsoft.Json.dll"
|
|
13
|
+
],
|
|
14
|
+
"autoReferenced": true,
|
|
15
|
+
"defineConstraints": [],
|
|
16
|
+
"versionDefines": [
|
|
17
|
+
{
|
|
18
|
+
"name": "com.unity.nuget.newtonsoft-json",
|
|
19
|
+
"expression": "0.0.0",
|
|
20
|
+
"define": "NEWTONSOFT_JSON"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"noEngineReferences": false
|
|
24
|
+
}
|
package/GameSettings.cs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
|
|
6
|
+
namespace DREditor.CustomSettings
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
///
|
|
10
|
+
/// </summary>
|
|
11
|
+
[Serializable]
|
|
12
|
+
public class GameSettings
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
///
|
|
16
|
+
/// </summary>
|
|
17
|
+
[Tooltip("")]
|
|
18
|
+
public int frameRate = 60;
|
|
19
|
+
|
|
20
|
+
/// <summary>
|
|
21
|
+
///
|
|
22
|
+
/// </summary>
|
|
23
|
+
[Tooltip("")]
|
|
24
|
+
public int vSyncCount = 1;
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
///
|
|
28
|
+
/// </summary>
|
|
29
|
+
[Tooltip("")]
|
|
30
|
+
public List<CustomGameSettings> customSettings = new();
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
public GameSettings() { }
|
|
34
|
+
|
|
35
|
+
public GameSettings(int frameRate, int vSyncCount, List<CustomGameSettings> customSettings)
|
|
36
|
+
{
|
|
37
|
+
this.frameRate = frameRate;
|
|
38
|
+
|
|
39
|
+
this.vSyncCount = vSyncCount;
|
|
40
|
+
|
|
41
|
+
this.customSettings = customSettings;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// <summary>
|
|
45
|
+
///
|
|
46
|
+
/// </summary>
|
|
47
|
+
/// <param name="customSettings"></param>
|
|
48
|
+
public virtual void SetCustomSettings(List<CustomGameSettings> customSettings) => this.customSettings = customSettings;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.SaveManaging;
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Linq;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
namespace DREditor.CustomSettings
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
///
|
|
12
|
+
/// </summary>
|
|
13
|
+
[ClassHeader("")]
|
|
14
|
+
public class GameSettingsManager : MonoBehaviour
|
|
15
|
+
{
|
|
16
|
+
/// <summary>
|
|
17
|
+
///
|
|
18
|
+
/// </summary>
|
|
19
|
+
[Header("")]
|
|
20
|
+
[Divider]
|
|
21
|
+
[Tooltip("")]
|
|
22
|
+
[SerializeField] protected string gameSettingsFileName = "GameSettings";
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/// <summary>
|
|
26
|
+
///
|
|
27
|
+
/// </summary>
|
|
28
|
+
[Header("")]
|
|
29
|
+
[Divider]
|
|
30
|
+
[Tooltip("")]
|
|
31
|
+
[SerializeField] protected GameSettingsObject defaultGameSettings = null;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
///
|
|
36
|
+
/// </summary>
|
|
37
|
+
[Header("")]
|
|
38
|
+
[Divider]
|
|
39
|
+
[Tooltip("")]
|
|
40
|
+
[SerializeField] protected GameSettings currentGameSettings;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/// <summary>
|
|
44
|
+
///
|
|
45
|
+
/// </summary>
|
|
46
|
+
protected List<ICustomGameSettingsHandler> gameSettingsHandlers = new();
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/// <summary>
|
|
50
|
+
///
|
|
51
|
+
/// </summary>
|
|
52
|
+
protected virtual void Start()
|
|
53
|
+
{
|
|
54
|
+
gameSettingsHandlers = FindObjectsByType<MonoBehaviour>().OfType<ICustomGameSettingsHandler>().ToList();
|
|
55
|
+
|
|
56
|
+
Load(GetData());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
///
|
|
61
|
+
/// </summary>
|
|
62
|
+
/// <param name="data"></param>
|
|
63
|
+
protected virtual void Load(GameSettings data)
|
|
64
|
+
{
|
|
65
|
+
if (data == null)
|
|
66
|
+
{
|
|
67
|
+
UnityEngine.Debug.LogError($"{nameof(GameSettingsManager)}: Game Settings Data was Null!");
|
|
68
|
+
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
UnityEngine.Debug.Log($"{nameof(GameSettingsManager)}: Loading Game Settings");
|
|
73
|
+
|
|
74
|
+
currentGameSettings = data;
|
|
75
|
+
|
|
76
|
+
Application.targetFrameRate = currentGameSettings.frameRate;
|
|
77
|
+
|
|
78
|
+
QualitySettings.vSyncCount = currentGameSettings.vSyncCount;
|
|
79
|
+
|
|
80
|
+
foreach (var handler in gameSettingsHandlers)
|
|
81
|
+
handler.Load(currentGameSettings.customSettings);
|
|
82
|
+
|
|
83
|
+
UnityEngine.Debug.Log($"{nameof(GameSettingsManager)}: Game Settings Successfully Loaded");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/// <summary>
|
|
87
|
+
///
|
|
88
|
+
/// </summary>
|
|
89
|
+
/// <returns></returns>
|
|
90
|
+
protected virtual GameSettings GetData()
|
|
91
|
+
{
|
|
92
|
+
GameSettings settings;
|
|
93
|
+
|
|
94
|
+
try
|
|
95
|
+
{
|
|
96
|
+
settings = SaveSystem.ReadFromJSON<GameSettings>(gameSettingsFileName);
|
|
97
|
+
|
|
98
|
+
if (settings == null)
|
|
99
|
+
{
|
|
100
|
+
UnityEngine.Debug.Log($"ANALYSIS: {nameof(GameSettingsManager)}: " +
|
|
101
|
+
$"Game didn't have a Game Settings file, creating one.");
|
|
102
|
+
|
|
103
|
+
settings = new GameSettings();
|
|
104
|
+
|
|
105
|
+
SaveSystem.SaveToJSON(settings, gameSettingsFileName);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (settings.customSettings.Count != gameSettingsHandlers.Count)
|
|
109
|
+
{
|
|
110
|
+
UnityEngine.Debug.Log($"ANALYSIS: {nameof(GameSettingsManager)}: " +
|
|
111
|
+
$"Game had inconsistent Game Settings; recreating file.");
|
|
112
|
+
|
|
113
|
+
settings.SetCustomSettings(CreateGameSettings().customSettings);
|
|
114
|
+
|
|
115
|
+
SaveSystem.SaveToJSON(settings, gameSettingsFileName);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (Exception e)
|
|
119
|
+
{
|
|
120
|
+
UnityEngine.Debug.LogWarning($"ALERT: {nameof(GameSettingsManager)}: " +
|
|
121
|
+
$"An unknown error occurred while loading the game settings file: "
|
|
122
|
+
+ e.ToString());
|
|
123
|
+
|
|
124
|
+
settings = defaultGameSettings != null ? defaultGameSettings.ToGameSettings() : CreateGameSettings();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return settings;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// <summary>
|
|
131
|
+
///
|
|
132
|
+
/// </summary>
|
|
133
|
+
/// <returns></returns>
|
|
134
|
+
protected virtual GameSettings CreateGameSettings()
|
|
135
|
+
{
|
|
136
|
+
GameSettings gameSettings = new();
|
|
137
|
+
|
|
138
|
+
foreach (var handler in gameSettingsHandlers)
|
|
139
|
+
gameSettings.customSettings.Add(handler.Save());
|
|
140
|
+
|
|
141
|
+
return gameSettings;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
/// <summary>
|
|
146
|
+
///
|
|
147
|
+
/// </summary>
|
|
148
|
+
[BehaviourButton]
|
|
149
|
+
public void ForceApplyData() => Load(currentGameSettings);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
|
|
5
|
+
namespace DREditor.CustomSettings
|
|
6
|
+
{
|
|
7
|
+
/// <summary>
|
|
8
|
+
///
|
|
9
|
+
/// </summary>
|
|
10
|
+
[CreateAssetMenu(menuName = "DREditor/Game Settings/Custom Settings", fileName = "GameSettings")]
|
|
11
|
+
public class GameSettingsObject : ScriptableObject
|
|
12
|
+
{
|
|
13
|
+
/// <summary>
|
|
14
|
+
///
|
|
15
|
+
/// </summary>
|
|
16
|
+
[Header("")]
|
|
17
|
+
[Header("")]
|
|
18
|
+
|
|
19
|
+
[Space(10)]
|
|
20
|
+
|
|
21
|
+
[Header("")]
|
|
22
|
+
[Divider]
|
|
23
|
+
[Tooltip("")]
|
|
24
|
+
public int defaultFrameRate = 60;
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
///
|
|
28
|
+
/// </summary>
|
|
29
|
+
[Tooltip("")]
|
|
30
|
+
public int defaultVSyncCount = 1;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/// <summary>
|
|
34
|
+
///
|
|
35
|
+
/// </summary>
|
|
36
|
+
[Header("")]
|
|
37
|
+
[Divider]
|
|
38
|
+
[Tooltip("")]
|
|
39
|
+
public List<CustomGameSettings> defaultCustomSettings = new();
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/// <summary>
|
|
43
|
+
///
|
|
44
|
+
/// </summary>
|
|
45
|
+
public virtual GameSettings ToGameSettings() => new(defaultFrameRate, defaultVSyncCount, defaultCustomSettings);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
|
|
4
|
+
namespace DREditor.CustomSettings
|
|
5
|
+
{
|
|
6
|
+
/// <summary>
|
|
7
|
+
///
|
|
8
|
+
/// </summary>
|
|
9
|
+
public interface ICustomGameSettingsHandler
|
|
10
|
+
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
///
|
|
13
|
+
/// </summary>
|
|
14
|
+
/// <returns></returns>
|
|
15
|
+
CustomGameSettings Save();
|
|
16
|
+
|
|
17
|
+
/// <summary>
|
|
18
|
+
///
|
|
19
|
+
/// </summary>
|
|
20
|
+
/// <param name="customSettings"></param>
|
|
21
|
+
void Load(List<CustomGameSettings> customSettings);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
%YAML 1.1
|
|
2
|
+
%TAG !u! tag:unity3d.com,2011:
|
|
3
|
+
--- !u!1 &7115206499295573243
|
|
4
|
+
GameObject:
|
|
5
|
+
m_ObjectHideFlags: 0
|
|
6
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
7
|
+
m_PrefabInstance: {fileID: 0}
|
|
8
|
+
m_PrefabAsset: {fileID: 0}
|
|
9
|
+
serializedVersion: 6
|
|
10
|
+
m_Component:
|
|
11
|
+
- component: {fileID: 7115206499295573240}
|
|
12
|
+
- component: {fileID: 7115206499295573241}
|
|
13
|
+
m_Layer: 0
|
|
14
|
+
m_Name: Game_Settings_Manager
|
|
15
|
+
m_TagString: Untagged
|
|
16
|
+
m_Icon: {fileID: 0}
|
|
17
|
+
m_NavMeshLayer: 0
|
|
18
|
+
m_StaticEditorFlags: 0
|
|
19
|
+
m_IsActive: 1
|
|
20
|
+
--- !u!4 &7115206499295573240
|
|
21
|
+
Transform:
|
|
22
|
+
m_ObjectHideFlags: 0
|
|
23
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
24
|
+
m_PrefabInstance: {fileID: 0}
|
|
25
|
+
m_PrefabAsset: {fileID: 0}
|
|
26
|
+
m_GameObject: {fileID: 7115206499295573243}
|
|
27
|
+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
28
|
+
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
29
|
+
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
30
|
+
m_ConstrainProportionsScale: 0
|
|
31
|
+
m_Children: []
|
|
32
|
+
m_Father: {fileID: 0}
|
|
33
|
+
m_RootOrder: 0
|
|
34
|
+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
35
|
+
--- !u!114 &7115206499295573241
|
|
36
|
+
MonoBehaviour:
|
|
37
|
+
m_ObjectHideFlags: 0
|
|
38
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
39
|
+
m_PrefabInstance: {fileID: 0}
|
|
40
|
+
m_PrefabAsset: {fileID: 0}
|
|
41
|
+
m_GameObject: {fileID: 7115206499295573243}
|
|
42
|
+
m_Enabled: 1
|
|
43
|
+
m_EditorHideFlags: 0
|
|
44
|
+
m_Script: {fileID: 11500000, guid: 94e93c31ab64714488977b623906d58f, type: 3}
|
|
45
|
+
m_Name:
|
|
46
|
+
m_EditorClassIdentifier:
|
|
47
|
+
gameSettingsFileName: GameSettings
|
|
48
|
+
defaultGameSettings: {fileID: 0}
|
|
49
|
+
currentGameSettings:
|
|
50
|
+
frameRate: 60
|
|
51
|
+
vSyncCount: 1
|
|
52
|
+
customSettings: []
|
package/Samples.meta
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "net.dreditor.customgamesettings",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "net.dreditor.customgamesettings",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"displayName": "DREditor Custom Game Settings",
|
|
5
|
+
"description": "The beta for DREditor. A tool to create death game style projects without having to code.",
|
|
6
|
+
"unity": "6000.4",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"net.dreditor.core": "0.1.6"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Benjamin \"Sweden\" Jillson",
|
|
15
|
+
"email": "dreditortool@gmail.com",
|
|
16
|
+
"url": "https://dreditor.net"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"editor",
|
|
20
|
+
"tool",
|
|
21
|
+
"dreditor"
|
|
22
|
+
],
|
|
23
|
+
"samples": [
|
|
24
|
+
{
|
|
25
|
+
"displayName": "Samples",
|
|
26
|
+
"description": "",
|
|
27
|
+
"path": "Samples~"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"documentationUrl": "https://dreditor.net",
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"licensesUrl": "https://dreditor.net/docs/LICENSE.html",
|
|
33
|
+
"changelogUrl": "https://dreditor.net/docs/CHANGELOG.html"
|
|
34
|
+
}
|
package/README.md
DELETED