Skip to content

Commit c71f096

Browse files
authored
Merge pull request #27 from Eastrall/feature/manual-generation
Add manual generation support
2 parents 0d68679 + 038fc7e commit c71f096

File tree

72 files changed

+1240
-889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1240
-889
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Rosalina CHANGELOG
22

3+
## 4.0.0 - 2023-09-23
4+
5+
### 🚀 Enhancement
6+
7+
* Bindings/Script generators code cleaning
8+
* Added manual generation (#26) (PR #27)
9+
* Added UXML custom properties window for configuring how Rosalina should behave. (#26) (PR #27)
10+
* Change bindings initialization method to generic methods. (#26) (PR #27)
11+
* Add custom component support (#25) (PR #27)
12+
* Rosalina settings improvement
13+
314
## 3.0.1 - 2023-07-16
415

516
### 🐛Bug fixes

Editor/Scripts/Generator.meta Editor/Scripts/Abstractions.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#if UNITY_EDITOR
2+
3+
internal interface IRosalinaCodeGeneartor
4+
{
5+
RosalinaGenerationResult Generate(UIDocumentAsset document);
6+
}
7+
8+
#endif

Editor/Scripts/Generator/Helpers.meta Editor/Scripts/Editor.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#if UNITY_EDITOR
2+
3+
using System;
4+
using UnityEditor;
5+
using UnityEngine;
6+
using UnityEngine.UIElements;
7+
8+
public class RosalinaPropertiesEditorWindow : EditorWindow
9+
{
10+
[SerializeField]
11+
private VisualTreeAsset _visualTreeAsset;
12+
private RosalinaFileSetting _fileSettings = null;
13+
14+
public VisualElement Container { get; private set; }
15+
16+
public VisualElement BasicSettingsContainer { get; private set; }
17+
18+
public Toggle EnableFile { get; private set; }
19+
20+
public EnumField GeneratorTypeSelector { get; private set; }
21+
22+
public Button GenerateBindingsButton { get; private set; }
23+
24+
public Button GenerateScriptButton { get; private set; }
25+
26+
public Button ClearBindingsButton { get; private set; }
27+
28+
private void OnEnable()
29+
{
30+
}
31+
32+
private void OnDestroy()
33+
{
34+
EnableFile.UnregisterValueChangedCallback(OnEnableFileChanged);
35+
GeneratorTypeSelector.UnregisterValueChangedCallback(OnGeneratorTypeSelectionChanged);
36+
GenerateBindingsButton.clicked -= OnGenerateBindings;
37+
GenerateScriptButton.clicked -= OnGenerateScripts;
38+
ClearBindingsButton.clicked -= OnClearBindings;
39+
}
40+
41+
private void OnSelectionChange()
42+
{
43+
bool isActive = Selection.activeObject != null && Selection.activeObject.GetType() == typeof(VisualTreeAsset);
44+
45+
Container.SetEnabled(isActive);
46+
47+
if (isActive)
48+
{
49+
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
50+
_fileSettings = RosalinaSettings.instance.GetFileSetting(assetPath);
51+
}
52+
else
53+
{
54+
_fileSettings = null;
55+
}
56+
57+
RefreshFileSettings();
58+
}
59+
60+
private void CreateGUI()
61+
{
62+
rootVisualElement.Add(_visualTreeAsset.Instantiate());
63+
64+
Container = rootVisualElement.Q<VisualElement>("Container");
65+
BasicSettingsContainer = rootVisualElement.Q<VisualElement>("BasicSettingsContainer");
66+
EnableFile = rootVisualElement.Q<Toggle>("EnableFile");
67+
GeneratorTypeSelector = rootVisualElement.Q<EnumField>("GeneratorTypeSelector");
68+
GenerateBindingsButton = rootVisualElement.Q<Button>("GenerateBindingsButton");
69+
GenerateScriptButton = rootVisualElement.Q<Button>("GenerateScriptButton");
70+
ClearBindingsButton = rootVisualElement.Q<Button>("ClearBindingsButton");
71+
72+
OnSelectionChange();
73+
EnableFile.RegisterValueChangedCallback(OnEnableFileChanged);
74+
GeneratorTypeSelector.RegisterValueChangedCallback(OnGeneratorTypeSelectionChanged);
75+
GenerateBindingsButton.clicked += OnGenerateBindings;
76+
GenerateScriptButton.clicked += OnGenerateScripts;
77+
ClearBindingsButton.clicked += OnClearBindings;
78+
}
79+
80+
private void RefreshFileSettings()
81+
{
82+
EnableFile.SetValueWithoutNotify(_fileSettings != null);
83+
BasicSettingsContainer.SetEnabled(_fileSettings != null);
84+
85+
if (_fileSettings != null)
86+
{
87+
GeneratorTypeSelector.value = _fileSettings.Type;
88+
}
89+
else
90+
{
91+
GeneratorTypeSelector.value = null;
92+
}
93+
}
94+
95+
private void OnEnableFileChanged(ChangeEvent<bool> @event)
96+
{
97+
if (@event.newValue)
98+
{
99+
_fileSettings = new RosalinaFileSetting
100+
{
101+
Path = AssetDatabase.GetAssetPath(Selection.activeObject),
102+
Type = RosalinaGenerationType.Document
103+
};
104+
RosalinaSettings.instance.Files.Add(_fileSettings);
105+
}
106+
else
107+
{
108+
RosalinaSettings.instance.Files.Remove(_fileSettings);
109+
_fileSettings = null;
110+
}
111+
112+
RefreshFileSettings();
113+
OnSettingsChanged();
114+
}
115+
116+
private void OnGeneratorTypeSelectionChanged(ChangeEvent<Enum> @event)
117+
{
118+
if (@event.newValue != null && @event.newValue != @event.previousValue)
119+
{
120+
_fileSettings.Type = (RosalinaGenerationType)@event.newValue;
121+
122+
RefreshFileSettings();
123+
OnSettingsChanged();
124+
}
125+
}
126+
127+
private void OnGenerateBindings()
128+
{
129+
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
130+
var document = new UIDocumentAsset(assetPath);
131+
132+
document.GenerateBindings();
133+
AssetDatabase.Refresh();
134+
}
135+
136+
private void OnGenerateScripts()
137+
{
138+
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
139+
var document = new UIDocumentAsset(assetPath);
140+
141+
bool bindingsGenerated = RosalinaScriptGeneratorUtilities.TryGenerateBindings(document);
142+
bool scriptGenerated = RosalinaScriptGeneratorUtilities.TryGenerateScript(document);
143+
144+
if (bindingsGenerated || scriptGenerated)
145+
{
146+
AssetDatabase.Refresh();
147+
}
148+
}
149+
150+
private void OnClearBindings()
151+
{
152+
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
153+
var document = new UIDocumentAsset(assetPath);
154+
155+
document.ClearBindings();
156+
AssetDatabase.Refresh();
157+
}
158+
159+
private void OnSettingsChanged()
160+
{
161+
RosalinaSettings.instance.Save();
162+
}
163+
164+
[MenuItem("Assets/Rosalina/Properties...", validate = true)]
165+
public static bool ShowWindowValidation()
166+
{
167+
return RosalinaSettings.instance.IsEnabled && Selection.activeObject != null && Selection.activeObject.GetType() == typeof(VisualTreeAsset);
168+
}
169+
170+
[MenuItem("Assets/Rosalina/Properties...", priority = 1200)]
171+
public static void ShowWindow()
172+
{
173+
if (HasOpenInstances<RosalinaPropertiesEditorWindow>())
174+
{
175+
FocusWindowIfItsOpen<RosalinaPropertiesEditorWindow>();
176+
return;
177+
}
178+
179+
Type inspectorWindowType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow");
180+
EditorWindow window = CreateWindow<RosalinaPropertiesEditorWindow>(inspectorWindowType);
181+
182+
window.titleContent = new GUIContent("Rosalina", EditorGUIUtility.FindTexture("SettingsIcon"));
183+
}
184+
}
185+
186+
#endif

Editor/Scripts/Editor/RosalinaPropertiesEditorWindow.cs.meta

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
2+
<ui:VisualElement name="Container" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); padding-left: 12px; padding-right: 12px; padding-top: 12px; padding-bottom: 12px;">
3+
<ui:Label tabindex="-1" text="Basic settings" display-tooltip-when-elided="true" name="BasicSettingsTitleLabel" style="-unity-font-style: bold; font-size: 12px;" />
4+
<ui:VisualElement name="FileSettingsContainer" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); margin-top: 8px;">
5+
<ui:Toggle label="Enable" name="EnableFile" tooltip="Includes the current UXML file into the Rosalina code generation pipeline." />
6+
<ui:VisualElement name="BasicSettingsContainer" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); margin-top: 0;">
7+
<ui:EnumField label="Generator type" type="RosalinaGenerationType, com.eastylabs.rosalina" name="GeneratorTypeSelector" />
8+
</ui:VisualElement>
9+
</ui:VisualElement>
10+
<ui:Label tabindex="-1" text="Tools" display-tooltip-when-elided="true" name="ToolsTitleLabel" style="-unity-font-style: bold; font-size: 12px; margin-top: 8px;" />
11+
<ui:VisualElement name="ToolsContainer" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); margin-top: 8px;">
12+
<ui:Button text="Generate bindings" display-tooltip-when-elided="true" name="GenerateBindingsButton" />
13+
<ui:Button text="Generate script" display-tooltip-when-elided="true" name="GenerateScriptButton" />
14+
<ui:Button text="Clear bindings" display-tooltip-when-elided="true" name="ClearBindingsButton" />
15+
</ui:VisualElement>
16+
</ui:VisualElement>
17+
</ui:UXML>

Editor/Scripts/Editor/RosalinaPropertiesEditorWindow.uxml.meta

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)