-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UXML file properties window editor
- Loading branch information
Showing
10 changed files
with
235 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
140 changes: 140 additions & 0 deletions
140
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,140 @@ | ||
#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; } | ||
|
||
private void OnEnable() | ||
{ | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
EnableFile.UnregisterValueChangedCallback(OnEnableFileChanged); | ||
GeneratorTypeSelector.UnregisterValueChangedCallback(OnGeneratorTypeSelectionChanged); | ||
} | ||
|
||
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"); | ||
|
||
OnSelectionChange(); | ||
EnableFile.RegisterValueChangedCallback(OnEnableFileChanged); | ||
GeneratorTypeSelector.RegisterValueChangedCallback(OnGeneratorTypeSelectionChanged); | ||
} | ||
|
||
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 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...")] | ||
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,11 @@ | ||
<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: 1; 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.eastlylabs.rosalina" name="GeneratorTypeSelector" /> | ||
</ui:VisualElement> | ||
</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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
Editor/Scripts/Inspector/RosalinaUxmlDocumentInspectorEditor.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,49 @@ | ||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
[CustomEditor(typeof(VisualTreeAsset), true)] | ||
[CanEditMultipleObjects] | ||
public class RosalinaUxmlDocumentInspectorEditor : Editor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
base.OnInspectorGUI(); | ||
|
||
VisualTreeAsset visualTreeAsset = (VisualTreeAsset)target; | ||
|
||
string assetPath = AssetDatabase.GetAssetPath(visualTreeAsset.GetInstanceID()); | ||
var file = RosalinaSettings.instance.GetFileSetting(assetPath); | ||
|
||
//EditorGUI.BeginDisabledGroup(false); | ||
EditorGUILayout.BeginVertical(); | ||
EditorGUI.BeginChangeCheck(); | ||
|
||
GUILayout.Space(20); | ||
EditorGUILayout.LabelField("Rosalina", EditorStyles.boldLabel); | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
EditorGUILayout.PrefixLabel("Enable"); | ||
bool test = EditorGUILayout.Toggle(file != null); | ||
EditorGUILayout.EndHorizontal(); | ||
|
||
if (file != null) | ||
{ | ||
EditorGUILayout.BeginHorizontal(); | ||
EditorGUILayout.PrefixLabel("Code generation type"); | ||
file.Type = (RosalinaGenerationType)EditorGUILayout.EnumPopup(file.Type); | ||
EditorGUILayout.EndHorizontal(); | ||
} | ||
|
||
EditorGUILayout.LinkButton("test"); | ||
|
||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
|
||
} | ||
EditorGUILayout.EndVertical(); | ||
//EditorGUI.EndDisabledGroup(); | ||
} | ||
} | ||
#endif |
2 changes: 1 addition & 1 deletion
2
...aEnableBindingsGenerationMenuItem.cs.meta → ...salinaUxmlDocumentInspectorEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
Editor/Scripts/MenuItems/RosalinaEnableBindingsGenerationMenuItem.cs
This file was deleted.
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