Skip to content

Commit e3ce67a

Browse files
committed
fix: Fixed Settings view,
Merge branch 'main' of https://github.com/jahro-console/unity-package
2 parents 05c8062 + 7b229ed commit e3ce67a

File tree

5 files changed

+145
-48
lines changed

5 files changed

+145
-48
lines changed

Editor/View/JahroEditorView.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,28 @@ public void CreateGUI()
6969

7070
_projectSettings = JahroProjectSettings.LoadOrCreate();
7171

72+
_projectSettings.OnSettingsChanged += SaveProjectSettings;
73+
7274
SetWindowMode(WindowMode.LOADING);
7375

7476
CheckVersion();
7577
}
7678

79+
private void OnDestroy()
80+
{
81+
_projectSettings.OnSettingsChanged -= SaveProjectSettings;
82+
}
83+
84+
private void SaveProjectSettings()
85+
{
86+
if (_projectSettings != null)
87+
{
88+
EditorUtility.SetDirty(_projectSettings);
89+
AssetDatabase.SaveAssets();
90+
AssetDatabase.Refresh();
91+
}
92+
}
93+
7794
private async void CheckVersion()
7895
{
7996
try

Editor/View/SettingsView.cs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using UnityEngine;
22
using UnityEngine.UIElements;
3-
using JahroConsole.Core.Network;
43
using JahroConsole.Core.Data;
54
using System;
65
using UnityEditor.UIElements;
@@ -25,18 +24,15 @@ public class SettingsView
2524
private Button _projectOverviewButton;
2625
private Button _teamOverviewButton;
2726
private Button _accountSettingsButton;
28-
2927
private Toggle _jahroEnableToggle;
3028
private Toggle _autoDisableToggle;
3129
private EnumField _launchKeyField;
3230
private Toggle _keyboardShortcutsToggle;
3331
private Toggle _mobileTapAreaToggle;
3432
private Toggle _dublicateLogsToggle;
3533
private MaskField _assembliesField;
36-
3734
private List<string> _assembliesNames = new List<string>();
3835
private int _assembliesFlag;
39-
4036
public event Action OnResetApiKey;
4137

4238
public SettingsView(VisualElement root)
@@ -164,20 +160,18 @@ public void Initialize(KeyValidator.ValidateKeyResponse validation, JahroProject
164160
if (_projectSettings.ActiveAssemblies == null)
165161
{
166162
_projectSettings.ActiveAssemblies = new List<string>();
167-
}
168-
169-
if (_projectSettings.ActiveAssemblies.Count == 0 && _assembliesNames != null && _assembliesNames.Count > 0)
170-
{
171-
_projectSettings.ActiveAssemblies.AddRange(_assembliesNames);
172-
EditorUtility.SetDirty(_projectSettings);
163+
if (_assembliesNames != null && _assembliesNames.Count > 0)
164+
{
165+
_projectSettings.ActiveAssemblies = new List<string>(_assembliesNames);
166+
}
173167
}
174168

175169
UpdateAssemblySelection();
176170

177-
SetupDataBinding();
171+
SetupManualBinding();
178172
}
179173

180-
private void SetupDataBinding()
174+
private void SetupManualBinding()
181175
{
182176
if (_projectSettings == null) return;
183177

@@ -187,7 +181,6 @@ private void SetupDataBinding()
187181
_jahroEnableToggle.RegisterValueChangedCallback(evt =>
188182
{
189183
_projectSettings.JahroEnabled = evt.newValue;
190-
SaveProjectSettings();
191184
});
192185
}
193186

@@ -197,7 +190,6 @@ private void SetupDataBinding()
197190
_autoDisableToggle.RegisterValueChangedCallback(evt =>
198191
{
199192
_projectSettings.AutoDisableInRelease = evt.newValue;
200-
SaveProjectSettings();
201193
});
202194
}
203195

@@ -207,7 +199,6 @@ private void SetupDataBinding()
207199
_keyboardShortcutsToggle.RegisterValueChangedCallback(evt =>
208200
{
209201
_projectSettings.UseLaunchKeyboardShortcut = evt.newValue;
210-
SaveProjectSettings();
211202
});
212203
}
213204

@@ -217,7 +208,6 @@ private void SetupDataBinding()
217208
_mobileTapAreaToggle.RegisterValueChangedCallback(evt =>
218209
{
219210
_projectSettings.UseLaunchTapArea = evt.newValue;
220-
SaveProjectSettings();
221211
});
222212
}
223213

@@ -227,7 +217,6 @@ private void SetupDataBinding()
227217
_dublicateLogsToggle.RegisterValueChangedCallback(evt =>
228218
{
229219
_projectSettings.DuplicateToUnityConsole = evt.newValue;
230-
SaveProjectSettings();
231220
});
232221
}
233222

@@ -237,32 +226,37 @@ private void SetupDataBinding()
237226
_launchKeyField.RegisterValueChangedCallback(evt =>
238227
{
239228
_projectSettings.LaunchKey = (KeyCode)evt.newValue;
240-
SaveProjectSettings();
241229
});
242230
}
243231

244232
if (_assembliesField != null)
245233
{
246234
_assembliesField.RegisterValueChangedCallback(evt =>
247235
{
248-
if (_assembliesNames != null && _assembliesNames.Count > 0)
236+
if (_projectSettings != null && _assembliesNames != null && _assembliesNames.Count > 0)
249237
{
250238
_assembliesFlag = (int)evt.newValue;
251239

252-
_projectSettings.ActiveAssemblies.Clear();
240+
var newActiveAssemblies = new List<string>(_projectSettings.ActiveAssemblies);
253241

254242
for (int i = 0; i < _assembliesNames.Count; i++)
255243
{
244+
string name = _assembliesNames[i];
245+
bool active = newActiveAssemblies.Contains(name);
256246
int layer = 1 << i;
257247
bool selected = (_assembliesFlag & layer) != 0;
258248

259-
if (selected)
249+
if (!active && selected)
260250
{
261-
_projectSettings.ActiveAssemblies.Add(_assembliesNames[i]);
251+
newActiveAssemblies.Add(name);
252+
}
253+
else if (active && !selected)
254+
{
255+
newActiveAssemblies.Remove(name);
262256
}
263257
}
264258

265-
SaveProjectSettings();
259+
_projectSettings.ActiveAssemblies = newActiveAssemblies;
266260
}
267261
});
268262
}
@@ -301,13 +295,6 @@ public void Hide()
301295
_container.style.display = DisplayStyle.None;
302296
}
303297

304-
private void SaveProjectSettings()
305-
{
306-
if (_projectSettings != null)
307-
{
308-
EditorUtility.SetDirty(_projectSettings);
309-
AssetDatabase.SaveAssets();
310-
}
311-
}
298+
312299
}
313300
}

Runtime/Core/Context/JahroConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ public enum Environment
1010

1111
internal const Environment ENV = Environment.PROD;
1212

13-
public static readonly string CurrentVersion = "0.1.0-alpha.7";
13+
public static readonly string CurrentVersion = "0.1.0-alpha.9";
1414

1515
internal static readonly string RegisterUrl = "https://console.jahro.io";
1616

1717
public static readonly string ChangelogUrl = "https://jahro.io/changelog";
1818

1919
internal static readonly string DocumentationRoot = "https://docs.jahro.io/";
2020

21-
internal static readonly string DocumentationWatcherOverview = "https://docs.jahro.io/start-here/watcher";
21+
internal static readonly string DocumentationWatcherOverview = "https://jahro.io/docs/watcher";
2222

23-
internal static readonly string DocumentationCommandsOverview = "https://docs.jahro.io/start-here/commands";
23+
internal static readonly string DocumentationCommandsOverview = "https://jahro.io/docs/unity-commands";
2424

2525
internal static readonly string HostUrl = ENV == Environment.PROD ? "https://api.jahro.io/jahro-api" : "http://localhost:3000";
2626
}

Runtime/Core/Data/JahroProjectSettings.cs

Lines changed: 105 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33
using System.Linq;
4+
using System;
45

56
namespace JahroConsole.Core.Data
67
{
7-
88
public class JahroProjectSettings : ScriptableObject, IProjectSettings
99
{
1010
[SerializeField]
@@ -31,21 +31,116 @@ public class JahroProjectSettings : ScriptableObject, IProjectSettings
3131
[SerializeField]
3232
private bool _autoDisableInRelease;
3333

34-
public bool JahroEnabled { get => _jahroEnabled; set => _jahroEnabled = value; }
34+
public event Action OnSettingsChanged;
3535

36-
public bool UseLaunchKeyboardShortcut { get => _useLaunchKeyboardShortcut; set => _useLaunchKeyboardShortcut = value; }
36+
public bool JahroEnabled
37+
{
38+
get => _jahroEnabled;
39+
set
40+
{
41+
if (_jahroEnabled != value)
42+
{
43+
_jahroEnabled = value;
44+
NotifySettingsChanged();
45+
}
46+
}
47+
}
3748

38-
public bool UseLaunchTapArea { get => _useLaunchTapArea; set => _useLaunchTapArea = value; }
49+
public bool UseLaunchKeyboardShortcut
50+
{
51+
get => _useLaunchKeyboardShortcut;
52+
set
53+
{
54+
if (_useLaunchKeyboardShortcut != value)
55+
{
56+
_useLaunchKeyboardShortcut = value;
57+
NotifySettingsChanged();
58+
}
59+
}
60+
}
3961

40-
public KeyCode LaunchKey { get => _launchKey; set => _launchKey = value; }
62+
public bool UseLaunchTapArea
63+
{
64+
get => _useLaunchTapArea;
65+
set
66+
{
67+
if (_useLaunchTapArea != value)
68+
{
69+
_useLaunchTapArea = value;
70+
NotifySettingsChanged();
71+
}
72+
}
73+
}
4174

42-
public List<string> ActiveAssemblies { get => _activeAssemblies; set => _activeAssemblies = value; }
75+
public KeyCode LaunchKey
76+
{
77+
get => _launchKey;
78+
set
79+
{
80+
if (_launchKey != value)
81+
{
82+
_launchKey = value;
83+
NotifySettingsChanged();
84+
}
85+
}
86+
}
4387

44-
public bool DuplicateToUnityConsole { get => _duplicateToUnityConsole; set => _duplicateToUnityConsole = value; }
88+
public List<string> ActiveAssemblies
89+
{
90+
get => _activeAssemblies;
91+
set
92+
{
93+
if (_activeAssemblies != value)
94+
{
95+
_activeAssemblies = value;
96+
NotifySettingsChanged();
97+
}
98+
}
99+
}
45100

46-
public string APIKey { get => _APIKey; set => _APIKey = value; }
101+
public bool DuplicateToUnityConsole
102+
{
103+
get => _duplicateToUnityConsole;
104+
set
105+
{
106+
if (_duplicateToUnityConsole != value)
107+
{
108+
_duplicateToUnityConsole = value;
109+
NotifySettingsChanged();
110+
}
111+
}
112+
}
47113

48-
public bool AutoDisableInRelease { get => _autoDisableInRelease; set => _autoDisableInRelease = value; }
114+
public string APIKey
115+
{
116+
get => _APIKey;
117+
set
118+
{
119+
if (_APIKey != value)
120+
{
121+
_APIKey = value;
122+
NotifySettingsChanged();
123+
}
124+
}
125+
}
126+
127+
public bool AutoDisableInRelease
128+
{
129+
get => _autoDisableInRelease;
130+
set
131+
{
132+
if (_autoDisableInRelease != value)
133+
{
134+
_autoDisableInRelease = value;
135+
NotifySettingsChanged();
136+
}
137+
}
138+
}
139+
140+
private void NotifySettingsChanged()
141+
{
142+
OnSettingsChanged?.Invoke();
143+
}
49144

50145
public static bool isSettingsFileExists()
51146
{
@@ -67,15 +162,14 @@ public static JahroProjectSettings CreateDefault()
67162
{
68163
var settings = ScriptableObject.CreateInstance<JahroProjectSettings>();
69164
settings._APIKey = "";
70-
settings.JahroEnabled = true;
165+
settings._jahroEnabled = true;
71166
settings._useLaunchKeyboardShortcut = true;
72167
settings._useLaunchTapArea = true;
73168
settings._activeAssemblies = new List<string>();
74169
settings._duplicateToUnityConsole = false;
75170
settings._launchKey = KeyCode.BackQuote;
76171
settings._autoDisableInRelease = false;
77172

78-
79173
#if UNITY_EDITOR
80174
var assemblies = UnityEditor.Compilation.CompilationPipeline.GetAssemblies(UnityEditor.Compilation.AssembliesType.Player)
81175
.Where(assembly =>
@@ -92,6 +186,5 @@ public static JahroProjectSettings CreateDefault()
92186
#endif
93187
return settings;
94188
}
95-
96189
}
97190
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "io.jahro.console",
3-
"version": "0.1.0-alpha.7",
3+
"version": "0.1.0-alpha.9",
44
"displayName": "Jahro",
55
"description": "Jahro is a powerful and easy-to-use Unity debugging console and runtime tool. Effortlessly execute commands, monitor variables in real-time, capture logs, and sync snapshots to analyze your game like never before. Perfect for developers who want a smarter way to debug, test, and optimize their Unity projects!",
6-
"unity": "2019.1",
6+
"unity": "2021.1",
77
"unityRelease": "0b5",
88
"dependencies": {},
99
"keywords": [

0 commit comments

Comments
 (0)