Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnSur committed Jan 5, 2024
1 parent 333e993 commit fca9302
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using UnityEngine;
using UnityEngine.UIElements;

namespace CompilationButton
namespace QuickEye.Utility.Editor.AssemblyReloading
{
[InitializeOnLoad]
public static class AssemblyReloadToggle
Expand All @@ -11,7 +11,6 @@ public static class AssemblyReloadToggle
private const string UIAssetsDirectory = "Packages/com.quickeye.utility/Editor/AssemblyReloading/UI Assets/";

private const string UxmlPath = UIAssetsDirectory + "ExtendedStatusBar.uxml";
//private const string StyleSheetPath = UIAssetsDirectory + "ExtendedStatusBar.style.uss";
private const string StyleSheetPathDark = UIAssetsDirectory + "ExtendedStatusBar.style.dark.uss";
private const string StyleSheetPathLight = UIAssetsDirectory + "ExtendedStatusBar.style.light.uss";

Expand All @@ -23,30 +22,23 @@ private static bool UserAssemblyLock

static AssemblyReloadToggle()
{
StatusBarExtender.StatusBarCreated += AddCompilationButton;
StatusBarExtender.StatusBarCreated += InitializeExtendedStatusBar;
}

private static void AddCompilationButton(VisualElement rootVisualElement)
private static void InitializeExtendedStatusBar(VisualElement rootVisualElement)
{
var extTemplate = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UxmlPath);
var themeStyleSheetPath = EditorGUIUtility.isProSkin ? StyleSheetPathDark : StyleSheetPathLight;
var extStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(themeStyleSheetPath);

rootVisualElement.styleSheets.Add(extStyleSheet);

var originalBar = rootVisualElement.Q<IMGUIContainer>(null, "status-bar");

extTemplate.CloneTree(rootVisualElement);
var extBarContainer = rootVisualElement.Q(null, "ext-status-bar");
extBarContainer.RegisterCallback<GeometryChangedEvent>(e =>
{
originalBar.style.right = extBarContainer.layout.width;
});
var extBarContainer = AddExtendedStatusBar(rootVisualElement);
RegisterBarSizeCorrection(rootVisualElement, extBarContainer);
rootVisualElement.Add(extBarContainer);
var compilationToggle = rootVisualElement.Q<Toggle>("compilation-toggle");
compilationToggle.value = UserAssemblyLock;
UpdateButtonTooltip(compilationToggle);
compilationToggle.RegisterValueChangedCallback(e =>
var assemblyToggle = extBarContainer.Q<Toggle>("compilation-toggle");
SetupAssemblyToggle(assemblyToggle);
}

private static void SetupAssemblyToggle(Toggle assemblyToggle)
{
assemblyToggle.value = UserAssemblyLock;
UpdateButtonTooltip(assemblyToggle);
assemblyToggle.RegisterValueChangedCallback(e =>
{
if (UserAssemblyLock == e.newValue)
return;
Expand All @@ -61,11 +53,32 @@ private static void AddCompilationButton(VisualElement rootVisualElement)
EditorUtility.RequestScriptReload();
}
UpdateButtonTooltip(compilationToggle);
UpdateButtonTooltip(assemblyToggle);
Debug.Log($"UserAssemblyLock: {UserAssemblyLock}");
});
}

private static VisualElement AddExtendedStatusBar(VisualElement rootVisualElement)
{
var extTemplate = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UxmlPath);
var themeStyleSheetPath = EditorGUIUtility.isProSkin ? StyleSheetPathDark : StyleSheetPathLight;
var extStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(themeStyleSheetPath);

rootVisualElement.styleSheets.Add(extStyleSheet);
extTemplate.CloneTree(rootVisualElement);
var extBarContainer = rootVisualElement.Q(null, "ext-status-bar");
return extBarContainer;
}

private static void RegisterBarSizeCorrection(VisualElement rootVisualElement, VisualElement extBarContainer)
{
var originalBar = rootVisualElement.Q<IMGUIContainer>(null, "status-bar");
extBarContainer.RegisterCallback<GeometryChangedEvent>(e =>
{
originalBar.style.right = extBarContainer.layout.width;
});
}

private static void UpdateButtonTooltip(Toggle toggle)
{
toggle.tooltip = toggle.value ? "Assembly reload disabled" : "Assembly reload enabled";
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using UnityEngine;
using UnityEngine.UIElements;

namespace CompilationButton
namespace QuickEye.Utility.Editor.AssemblyReloading
{
internal static class StatusBarExtender
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.status-bar {
background-color: rgb(165, 165, 165);
}

.compilation-toggle .unity-toggle__input {
background-image: url('project://database/Packages/com.quickeye.utility/Editor/AssemblyReloading/UI%20Assets/Icons/d_Assembly.png?fileID=2800000&guid=decdd61434639419fbf956cba10f94e6&type=3#d_Assembly');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.status-bar {
background-color: rgb(165, 165, 165);
}

.compilation-toggle .unity-toggle__input {
background-image: url('project://database/Packages/com.quickeye.utility/Editor/AssemblyReloading/UI%20Assets/Icons/Assembly.png?fileID=2800000&guid=4f12038a75ad3433a9d84aceecd2a40a&type=3#Assembly');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.status-bar {
height: 20px;
}

.ext-status-bar {
align-self: flex-end;
}
Expand Down

0 comments on commit fca9302

Please sign in to comment.