Skip to content

Commit 96d06ed

Browse files
author
András Kurai
committed
add settings
1 parent 0c584d1 commit 96d06ed

File tree

5 files changed

+110
-10
lines changed

5 files changed

+110
-10
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 3cdd186d920f45adb2925f11fda1bdd8, type: 3}
13+
m_Name: ResourceGenerator
14+
m_EditorClassIdentifier:
15+
_baseNamespace: UnityResourceGenerator.Sample
16+
_className: ResourcePaths
17+
_folderPath: UnityResourceGenerator.Sample
18+
_logInfo: 0
19+
_logError: 1

UnityResourceGenerator/Assets/ResourceGenerator.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityResourceGenerator/Assets/UnityResourceGenerator/Editor/ResourceFileMenu.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using UnityEditor;
34
using UnityEngine;
45
using UnityResourceGenerator.Editor.Generation;
@@ -7,22 +8,21 @@ namespace UnityResourceGenerator.Editor
78
{
89
public static class ResourceFileMenu
910
{
10-
[MenuItem("Tools / Generate Resources")]
11+
[MenuItem("Tools / Generate Resources Paths")]
1112
public static void GenerateResources()
1213
{
13-
const string baseNamespace = "UnityResourceGenerator.Sample";
14-
const string className = "ResourcePaths";
15-
const string folderPath = "UnityResourceGenerator.Sample";
14+
var settings = ResourceGeneratorSettings.GetOrCreateSettings();
15+
1616
var assetsFolder = Application.dataPath;
1717

1818
var context = new ResourceContext
1919
(
2020
assetsFolder,
21-
folderPath,
22-
baseNamespace,
23-
className,
24-
Debug.Log,
25-
Debug.LogError
21+
settings.FolderPath,
22+
settings.BaseNamespace,
23+
settings.ClassName,
24+
settings.LogInfo ? Debug.Log : LogEmpty,
25+
settings.LogError ? Debug.LogError : LogEmpty
2626
);
2727

2828
var fileContent = ResourceFileGenerator.CreateResourceFile(context);
@@ -42,5 +42,7 @@ public static void GenerateResources()
4242
File.WriteAllText(filePath, fileContent);
4343
context.Info($"Created resource file at: {filePath}");
4444
}
45+
46+
private static Action<string> LogEmpty => _ => { };
4547
}
4648
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Collections.Generic;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace UnityResourceGenerator.Editor
6+
{
7+
public sealed class ResourceGeneratorSettings : ScriptableObject
8+
{
9+
private const string SettingsPath = "Assets/ResourceGenerator.asset";
10+
11+
[SerializeField] private string _baseNamespace;
12+
[SerializeField] private string _className;
13+
14+
[SerializeField]
15+
[Tooltip("Relative path from the Assets folder")]
16+
private string _folderPath;
17+
18+
[SerializeField] private bool _logInfo;
19+
[SerializeField] private bool _logError;
20+
21+
public string FolderPath => _folderPath;
22+
public string BaseNamespace => _baseNamespace;
23+
public string ClassName => _className;
24+
public bool LogInfo => _logInfo;
25+
public bool LogError => _logError;
26+
27+
public static ResourceGeneratorSettings GetOrCreateSettings()
28+
{
29+
var settings = AssetDatabase.LoadAssetAtPath<ResourceGeneratorSettings>(SettingsPath);
30+
if (settings != null) return settings;
31+
32+
settings = CreateInstance<ResourceGeneratorSettings>();
33+
34+
settings._folderPath = string.Empty;
35+
settings._baseNamespace = "Resources";
36+
settings._className = "ResourcePaths";
37+
settings._logInfo = false;
38+
settings._logError = true;
39+
40+
AssetDatabase.CreateAsset(settings, SettingsPath);
41+
AssetDatabase.SaveAssets();
42+
43+
return settings;
44+
}
45+
46+
[SettingsProvider]
47+
public static SettingsProvider CreateSettingsProvider() =>
48+
new SettingsProvider("Project/ResourceGenerator", SettingsScope.Project)
49+
{
50+
label = "ResourceGenerator",
51+
guiHandler = searchContext =>
52+
{
53+
var settings = GetSerializedSettings();
54+
55+
EditorGUILayout.PropertyField(settings.FindProperty(nameof(_folderPath)), new GUIContent("Folder from Assets"));
56+
EditorGUILayout.PropertyField(settings.FindProperty(nameof(_baseNamespace)), new GUIContent("Namespace"));
57+
EditorGUILayout.PropertyField(settings.FindProperty(nameof(_className)), new GUIContent("Class name"));
58+
EditorGUILayout.PropertyField(settings.FindProperty(nameof(_logInfo)), new GUIContent("Log Infos"));
59+
EditorGUILayout.PropertyField(settings.FindProperty(nameof(_logError)), new GUIContent("Log Errors"));
60+
61+
settings.ApplyModifiedProperties();
62+
},
63+
keywords = new HashSet<string>(new[] { "Resource", "Path" }),
64+
};
65+
66+
public static SerializedObject GetSerializedSettings() => new SerializedObject(GetOrCreateSettings());
67+
}
68+
}

UnityResourceGenerator/Assets/UnityResourceGenerator/Editor/ResourceGeneratorSettings.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)