-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
164 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
using UnityEngine; | ||
/// <summary> | ||
/// Provides a data structure for Rosalina settings. | ||
/// </summary> | ||
public class RosalinaSettings : ScriptableObject | ||
{ | ||
/// <summary> | ||
/// Gets the current Rosalina settings. | ||
/// </summary> | ||
public static RosalinaSettings Current => AssetDatabase.LoadAssetAtPath<RosalinaSettings>("Assets/Rosalina/RosalinaSettings.asset"); | ||
|
||
[SerializeField] | ||
private bool _isEnabled; | ||
|
||
[SerializeField] | ||
private string _defaultNamespace; | ||
|
||
/// <summary> | ||
/// Gets or sets a boolean value that indicates if Rosalina is enabled. | ||
/// </summary> | ||
public bool IsEnabled | ||
{ | ||
get => _isEnabled; | ||
set => _isEnabled = value; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the default namespace to use during code generation. | ||
/// </summary> | ||
public string DefaultNamespace | ||
{ | ||
get => _defaultNamespace; | ||
set => _defaultNamespace = value; | ||
} | ||
} | ||
|
||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#if UNITY_EDITOR | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
public class RosalinaSettingsProvider : SettingsProvider | ||
{ | ||
private RosalinaSettings _settings; | ||
|
||
public RosalinaSettingsProvider(string path, SettingsScope scopes, IEnumerable<string> keywords = null) | ||
: base(path, scopes, keywords) | ||
{ | ||
} | ||
|
||
public override void OnActivate(string searchContext, VisualElement rootElement) | ||
{ | ||
_settings = RosalinaSettings.Current != null ? RosalinaSettings.Current : CreateRosalinaSettingsAsset(); | ||
} | ||
|
||
public override void OnGUI(string searchContext) | ||
{ | ||
using (CreateSettingsWindowGUIScope()) | ||
{ | ||
EditorGUI.BeginChangeCheck(); | ||
|
||
_settings.IsEnabled = EditorGUILayout.Toggle("Is Enabled", _settings.IsEnabled); | ||
_settings.DefaultNamespace = EditorGUILayout.TextField("Default Namespace", _settings.DefaultNamespace); | ||
|
||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
EditorUtility.SetDirty(_settings); | ||
} | ||
} | ||
} | ||
|
||
private static RosalinaSettings CreateRosalinaSettingsAsset() | ||
{ | ||
string resourcePath = "Assets/Rosalina"; | ||
|
||
if (!AssetDatabase.IsValidFolder(resourcePath)) | ||
{ | ||
AssetDatabase.CreateFolder("Assets", "Rosalina"); | ||
} | ||
|
||
RosalinaSettings newSettings = ScriptableObject.CreateInstance<RosalinaSettings>(); | ||
AssetDatabase.CreateAsset(newSettings, $"{resourcePath}/RosalinaSettings.asset"); | ||
AssetDatabase.SaveAssets(); | ||
AssetDatabase.Refresh(); | ||
|
||
return RosalinaSettings.Current; | ||
} | ||
|
||
[SettingsProvider] | ||
public static SettingsProvider CreateRosalinaSettingsProvider() => new RosalinaSettingsProvider("Project/Rosalina", SettingsScope.Project); | ||
|
||
private static IDisposable CreateSettingsWindowGUIScope() | ||
{ | ||
var unityEditorAssembly = Assembly.GetAssembly(typeof(EditorWindow)); | ||
var type = unityEditorAssembly.GetType("UnityEditor.SettingsWindow+GUIScope"); | ||
|
||
return Activator.CreateInstance(type) as IDisposable; | ||
} | ||
} | ||
|
||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.