Skip to content

Commit

Permalink
Fix settings file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eastrall committed Jul 16, 2023
1 parent bc122a1 commit 9ed4c72
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Rosalina CHANGELOG

## 3.0.1 - 2023-07-16

### 🐛Bug fixes

* Fixed a bug preventing Rosalina's settings file creation.

## 3.0.0 - 2023-04-09

### 🚀 Enhancement

* Change editor extensions bindings to its own Editor folder
* Add clear and generate all bindings menu items
* Replace Roslyn Library with Rosyn dlls instead
* Add Rosalina settings to enable/disable the generator

## 2.0.0 - 2022-11-28

### 🚀 Enhancement
Expand Down
4 changes: 2 additions & 2 deletions Editor/Scripts/Settings/RosalinaSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using UnityEditor;
using UnityEngine;

/// <summary>
/// Provides a data structure for Rosalina settings.
/// </summary>
Expand All @@ -10,8 +11,7 @@ public class RosalinaSettings : ScriptableObject
/// <summary>
/// Gets the current Rosalina settings.
/// </summary>
public static RosalinaSettings Current => AssetDatabase.LoadAssetAtPath<RosalinaSettings>("Assets/Rosalina/RosalinaSettings.asset")
?? ScriptableObject.CreateInstance<RosalinaSettings>();
public static RosalinaSettings Current => RosalinaSettingsProvider.GetOrCreateSettings();

[SerializeField]
private bool _isEnabled;
Expand Down
24 changes: 17 additions & 7 deletions Editor/Scripts/Settings/RosalinaSettingsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEngine;
Expand All @@ -17,7 +18,7 @@ public RosalinaSettingsProvider(string path, SettingsScope scopes, IEnumerable<s

public override void OnActivate(string searchContext, VisualElement rootElement)
{
_settings = RosalinaSettings.Current != null ? RosalinaSettings.Current : CreateRosalinaSettingsAsset();
_settings = RosalinaSettings.Current;
}

public override void OnGUI(string searchContext)
Expand All @@ -35,21 +36,30 @@ public override void OnGUI(string searchContext)
}
}

public static RosalinaSettings CreateRosalinaSettingsAsset()
public static RosalinaSettings GetOrCreateSettings()
{
string resourcePath = "Assets/Rosalina";
string settingsFileName = "RosalinaSettings.asset";
string settingsFilePath = Path.Combine(resourcePath, settingsFileName);

if (!AssetDatabase.IsValidFolder(resourcePath))
{
AssetDatabase.CreateFolder("Assets", "Rosalina");
}

RosalinaSettings newSettings = ScriptableObject.CreateInstance<RosalinaSettings>();
AssetDatabase.CreateAsset(newSettings, $"{resourcePath}/RosalinaSettings.asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
if (File.Exists(settingsFilePath))
{
return AssetDatabase.LoadAssetAtPath<RosalinaSettings>(settingsFilePath);
}
else
{
RosalinaSettings newSettings = ScriptableObject.CreateInstance<RosalinaSettings>();
AssetDatabase.CreateAsset(newSettings, settingsFilePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

return RosalinaSettings.Current;
return newSettings;
}
}

[SettingsProvider]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.eastylabs.rosalina",
"version": "3.0.0",
"version": "3.0.1",
"type": "tool",
"displayName": "Rosalina",
"unity": "2021.3",
Expand Down

0 comments on commit 9ed4c72

Please sign in to comment.