-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Eastrall/feature/manual-generation
Add manual generation support
- Loading branch information
Showing
72 changed files
with
1,240 additions
and
889 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
2 changes: 1 addition & 1 deletion
2
Editor/Scripts/Generator.meta → Editor/Scripts/Abstractions.meta
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,8 @@ | ||
#if UNITY_EDITOR | ||
|
||
internal interface IRosalinaCodeGeneartor | ||
{ | ||
RosalinaGenerationResult Generate(UIDocumentAsset document); | ||
} | ||
|
||
#endif |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
Editor/Scripts/Generator/Helpers.meta → Editor/Scripts/Editor.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
186 changes: 186 additions & 0 deletions
186
Editor/Scripts/Editor/RosalinaPropertiesEditorWindow.cs
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,186 @@ | ||
#if UNITY_EDITOR | ||
|
||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
public class RosalinaPropertiesEditorWindow : EditorWindow | ||
{ | ||
[SerializeField] | ||
private VisualTreeAsset _visualTreeAsset; | ||
private RosalinaFileSetting _fileSettings = null; | ||
|
||
public VisualElement Container { get; private set; } | ||
|
||
public VisualElement BasicSettingsContainer { get; private set; } | ||
|
||
public Toggle EnableFile { get; private set; } | ||
|
||
public EnumField GeneratorTypeSelector { get; private set; } | ||
|
||
public Button GenerateBindingsButton { get; private set; } | ||
|
||
public Button GenerateScriptButton { get; private set; } | ||
|
||
public Button ClearBindingsButton { get; private set; } | ||
|
||
private void OnEnable() | ||
{ | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
EnableFile.UnregisterValueChangedCallback(OnEnableFileChanged); | ||
GeneratorTypeSelector.UnregisterValueChangedCallback(OnGeneratorTypeSelectionChanged); | ||
GenerateBindingsButton.clicked -= OnGenerateBindings; | ||
GenerateScriptButton.clicked -= OnGenerateScripts; | ||
ClearBindingsButton.clicked -= OnClearBindings; | ||
} | ||
|
||
private void OnSelectionChange() | ||
{ | ||
bool isActive = Selection.activeObject != null && Selection.activeObject.GetType() == typeof(VisualTreeAsset); | ||
|
||
Container.SetEnabled(isActive); | ||
|
||
if (isActive) | ||
{ | ||
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); | ||
_fileSettings = RosalinaSettings.instance.GetFileSetting(assetPath); | ||
} | ||
else | ||
{ | ||
_fileSettings = null; | ||
} | ||
|
||
RefreshFileSettings(); | ||
} | ||
|
||
private void CreateGUI() | ||
{ | ||
rootVisualElement.Add(_visualTreeAsset.Instantiate()); | ||
|
||
Container = rootVisualElement.Q<VisualElement>("Container"); | ||
BasicSettingsContainer = rootVisualElement.Q<VisualElement>("BasicSettingsContainer"); | ||
EnableFile = rootVisualElement.Q<Toggle>("EnableFile"); | ||
GeneratorTypeSelector = rootVisualElement.Q<EnumField>("GeneratorTypeSelector"); | ||
GenerateBindingsButton = rootVisualElement.Q<Button>("GenerateBindingsButton"); | ||
GenerateScriptButton = rootVisualElement.Q<Button>("GenerateScriptButton"); | ||
ClearBindingsButton = rootVisualElement.Q<Button>("ClearBindingsButton"); | ||
|
||
OnSelectionChange(); | ||
EnableFile.RegisterValueChangedCallback(OnEnableFileChanged); | ||
GeneratorTypeSelector.RegisterValueChangedCallback(OnGeneratorTypeSelectionChanged); | ||
GenerateBindingsButton.clicked += OnGenerateBindings; | ||
GenerateScriptButton.clicked += OnGenerateScripts; | ||
ClearBindingsButton.clicked += OnClearBindings; | ||
} | ||
|
||
private void RefreshFileSettings() | ||
{ | ||
EnableFile.SetValueWithoutNotify(_fileSettings != null); | ||
BasicSettingsContainer.SetEnabled(_fileSettings != null); | ||
|
||
if (_fileSettings != null) | ||
{ | ||
GeneratorTypeSelector.value = _fileSettings.Type; | ||
} | ||
else | ||
{ | ||
GeneratorTypeSelector.value = null; | ||
} | ||
} | ||
|
||
private void OnEnableFileChanged(ChangeEvent<bool> @event) | ||
{ | ||
if (@event.newValue) | ||
{ | ||
_fileSettings = new RosalinaFileSetting | ||
{ | ||
Path = AssetDatabase.GetAssetPath(Selection.activeObject), | ||
Type = RosalinaGenerationType.Document | ||
}; | ||
RosalinaSettings.instance.Files.Add(_fileSettings); | ||
} | ||
else | ||
{ | ||
RosalinaSettings.instance.Files.Remove(_fileSettings); | ||
_fileSettings = null; | ||
} | ||
|
||
RefreshFileSettings(); | ||
OnSettingsChanged(); | ||
} | ||
|
||
private void OnGeneratorTypeSelectionChanged(ChangeEvent<Enum> @event) | ||
{ | ||
if (@event.newValue != null && @event.newValue != @event.previousValue) | ||
{ | ||
_fileSettings.Type = (RosalinaGenerationType)@event.newValue; | ||
|
||
RefreshFileSettings(); | ||
OnSettingsChanged(); | ||
} | ||
} | ||
|
||
private void OnGenerateBindings() | ||
{ | ||
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); | ||
var document = new UIDocumentAsset(assetPath); | ||
|
||
document.GenerateBindings(); | ||
AssetDatabase.Refresh(); | ||
} | ||
|
||
private void OnGenerateScripts() | ||
{ | ||
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); | ||
var document = new UIDocumentAsset(assetPath); | ||
|
||
bool bindingsGenerated = RosalinaScriptGeneratorUtilities.TryGenerateBindings(document); | ||
bool scriptGenerated = RosalinaScriptGeneratorUtilities.TryGenerateScript(document); | ||
|
||
if (bindingsGenerated || scriptGenerated) | ||
{ | ||
AssetDatabase.Refresh(); | ||
} | ||
} | ||
|
||
private void OnClearBindings() | ||
{ | ||
string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); | ||
var document = new UIDocumentAsset(assetPath); | ||
|
||
document.ClearBindings(); | ||
AssetDatabase.Refresh(); | ||
} | ||
|
||
private void OnSettingsChanged() | ||
{ | ||
RosalinaSettings.instance.Save(); | ||
} | ||
|
||
[MenuItem("Assets/Rosalina/Properties...", validate = true)] | ||
public static bool ShowWindowValidation() | ||
{ | ||
return RosalinaSettings.instance.IsEnabled && Selection.activeObject != null && Selection.activeObject.GetType() == typeof(VisualTreeAsset); | ||
} | ||
|
||
[MenuItem("Assets/Rosalina/Properties...", priority = 1200)] | ||
public static void ShowWindow() | ||
{ | ||
if (HasOpenInstances<RosalinaPropertiesEditorWindow>()) | ||
{ | ||
FocusWindowIfItsOpen<RosalinaPropertiesEditorWindow>(); | ||
return; | ||
} | ||
|
||
Type inspectorWindowType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow"); | ||
EditorWindow window = CreateWindow<RosalinaPropertiesEditorWindow>(inspectorWindowType); | ||
|
||
window.titleContent = new GUIContent("Rosalina", EditorGUIUtility.FindTexture("SettingsIcon")); | ||
} | ||
} | ||
|
||
#endif |
14 changes: 14 additions & 0 deletions
14
Editor/Scripts/Editor/RosalinaPropertiesEditorWindow.cs.meta
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,17 @@ | ||
<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"> | ||
<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;"> | ||
<ui:Label tabindex="-1" text="Basic settings" display-tooltip-when-elided="true" name="BasicSettingsTitleLabel" style="-unity-font-style: bold; font-size: 12px;" /> | ||
<ui:VisualElement name="FileSettingsContainer" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); margin-top: 8px;"> | ||
<ui:Toggle label="Enable" name="EnableFile" tooltip="Includes the current UXML file into the Rosalina code generation pipeline." /> | ||
<ui:VisualElement name="BasicSettingsContainer" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); margin-top: 0;"> | ||
<ui:EnumField label="Generator type" type="RosalinaGenerationType, com.eastylabs.rosalina" name="GeneratorTypeSelector" /> | ||
</ui:VisualElement> | ||
</ui:VisualElement> | ||
<ui:Label tabindex="-1" text="Tools" display-tooltip-when-elided="true" name="ToolsTitleLabel" style="-unity-font-style: bold; font-size: 12px; margin-top: 8px;" /> | ||
<ui:VisualElement name="ToolsContainer" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); margin-top: 8px;"> | ||
<ui:Button text="Generate bindings" display-tooltip-when-elided="true" name="GenerateBindingsButton" /> | ||
<ui:Button text="Generate script" display-tooltip-when-elided="true" name="GenerateScriptButton" /> | ||
<ui:Button text="Clear bindings" display-tooltip-when-elided="true" name="ClearBindingsButton" /> | ||
</ui:VisualElement> | ||
</ui:VisualElement> | ||
</ui:UXML> |
10 changes: 10 additions & 0 deletions
10
Editor/Scripts/Editor/RosalinaPropertiesEditorWindow.uxml.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.