update
This commit is contained in:
@@ -22,6 +22,8 @@ using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Globalization;
|
||||
using System;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
|
||||
namespace Editor
|
||||
{
|
||||
@@ -33,8 +35,9 @@ namespace Editor
|
||||
private static EventModifiers loadModifier;
|
||||
private static KeyCode[] slotKeys = new KeyCode[9];
|
||||
|
||||
// Static constructor runs automatically when Unity loads or recompiles
|
||||
static CameraBookmarksTool()
|
||||
// Replaced static constructor with InitializeOnLoadMethod to avoid EditorPrefs exceptions
|
||||
[InitializeOnLoadMethod]
|
||||
static void Init()
|
||||
{
|
||||
LoadSettings();
|
||||
SceneView.duringSceneGui += OnSceneGUI;
|
||||
@@ -69,52 +72,130 @@ namespace Editor
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
public void CreateGUI()
|
||||
{
|
||||
GUILayout.Label("Shortcut Configuration", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space();
|
||||
VisualElement root = rootVisualElement;
|
||||
root.style.paddingTop = 15;
|
||||
root.style.paddingBottom = 15;
|
||||
root.style.paddingLeft = 15;
|
||||
root.style.paddingRight = 15;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Label title = new Label("Shortcut Configuration");
|
||||
title.style.fontSize = 20;
|
||||
title.style.unityFontStyleAndWeight = FontStyle.Bold;
|
||||
title.style.color = new StyleColor(new Color(0.3f, 0.7f, 1f));
|
||||
title.style.marginBottom = 15;
|
||||
root.Add(title);
|
||||
|
||||
// Modifier Keys Setup
|
||||
saveModifier = (EventModifiers)EditorGUILayout.EnumFlagsField("Save Modifier", saveModifier);
|
||||
loadModifier = (EventModifiers)EditorGUILayout.EnumFlagsField("Load Modifier", loadModifier);
|
||||
// Warning Box
|
||||
VisualElement warningBox = new VisualElement();
|
||||
warningBox.style.backgroundColor = new StyleColor(new Color(0.8f, 0.6f, 0.1f, 0.3f));
|
||||
warningBox.style.borderLeftWidth = 4;
|
||||
warningBox.style.borderLeftColor = new StyleColor(new Color(0.9f, 0.7f, 0.1f));
|
||||
warningBox.style.paddingTop = 10;
|
||||
warningBox.style.paddingBottom = 10;
|
||||
warningBox.style.paddingLeft = 10;
|
||||
warningBox.style.marginBottom = 15;
|
||||
warningBox.style.display = DisplayStyle.None;
|
||||
|
||||
Label warningLabel = new Label("Warning: Save and Load modifiers are the SAME! This will cause conflicts.");
|
||||
warningLabel.style.color = new StyleColor(new Color(0.9f, 0.8f, 0.5f));
|
||||
warningLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
||||
warningBox.Add(warningLabel);
|
||||
root.Add(warningBox);
|
||||
|
||||
if (saveModifier == loadModifier)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Warning: Save and Load modifiers are the SAME! This will cause conflicts.", MessageType.Warning);
|
||||
}
|
||||
// Modifiers Card
|
||||
VisualElement modifiersCard = CreateCard();
|
||||
EnumFlagsField saveField = new EnumFlagsField("Save Modifier", saveModifier);
|
||||
saveField.RegisterValueChangedCallback(evt => {
|
||||
saveModifier = (EventModifiers)evt.newValue;
|
||||
SaveSettings();
|
||||
warningBox.style.display = (saveModifier == loadModifier) ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
});
|
||||
modifiersCard.Add(saveField);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label("Slot Keys Assignment", EditorStyles.boldLabel);
|
||||
EnumFlagsField loadField = new EnumFlagsField("Load Modifier", loadModifier);
|
||||
loadField.RegisterValueChangedCallback(evt => {
|
||||
loadModifier = (EventModifiers)evt.newValue;
|
||||
SaveSettings();
|
||||
warningBox.style.display = (saveModifier == loadModifier) ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
});
|
||||
loadField.style.marginTop = 10;
|
||||
modifiersCard.Add(loadField);
|
||||
|
||||
warningBox.style.display = (saveModifier == loadModifier) ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
root.Add(modifiersCard);
|
||||
|
||||
// KeyCode Setup for 9 slots
|
||||
// Slots Section
|
||||
Label slotsTitle = new Label("Slot Keys Assignment");
|
||||
slotsTitle.style.fontSize = 16;
|
||||
slotsTitle.style.unityFontStyleAndWeight = FontStyle.Bold;
|
||||
slotsTitle.style.color = new StyleColor(new Color(0.8f, 0.8f, 0.8f));
|
||||
slotsTitle.style.marginTop = 15;
|
||||
slotsTitle.style.marginBottom = 10;
|
||||
root.Add(slotsTitle);
|
||||
|
||||
VisualElement slotsCard = CreateCard();
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Label($"Slot {i + 1}", GUILayout.Width(100));
|
||||
slotKeys[i] = (KeyCode)EditorGUILayout.EnumPopup(slotKeys[i]);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
int index = i;
|
||||
EnumField slotField = new EnumField($"Slot {i + 1}", slotKeys[i]);
|
||||
slotField.RegisterValueChangedCallback(evt => {
|
||||
slotKeys[index] = (KeyCode)evt.newValue;
|
||||
SaveSettings();
|
||||
});
|
||||
if (i > 0) slotField.style.marginTop = 8;
|
||||
slotsCard.Add(slotField);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
SaveSettings(); // Save immediately if anything changes
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.Space();
|
||||
root.Add(slotsCard);
|
||||
|
||||
// Reset Button
|
||||
if (GUILayout.Button("Reset to Default Settings", GUILayout.Height(30)))
|
||||
{
|
||||
Button resetBtn = new Button(() => {
|
||||
saveModifier = EventModifiers.Control;
|
||||
loadModifier = EventModifiers.Shift;
|
||||
for (int i = 0; i < 9; i++) slotKeys[i] = KeyCode.Alpha1 + i;
|
||||
|
||||
SaveSettings();
|
||||
GUI.FocusControl(null); // Remove focus to refresh UI correctly
|
||||
}
|
||||
|
||||
root.Clear();
|
||||
CreateGUI(); // Rebuild
|
||||
});
|
||||
resetBtn.text = "Reset to Default Settings";
|
||||
resetBtn.style.height = 40;
|
||||
resetBtn.style.marginTop = 20;
|
||||
resetBtn.style.backgroundColor = new StyleColor(new Color(0.7f, 0.3f, 0.3f));
|
||||
resetBtn.style.color = new StyleColor(Color.white);
|
||||
resetBtn.style.unityFontStyleAndWeight = FontStyle.Bold;
|
||||
resetBtn.style.borderTopLeftRadius = 6;
|
||||
resetBtn.style.borderTopRightRadius = 6;
|
||||
resetBtn.style.borderBottomLeftRadius = 6;
|
||||
resetBtn.style.borderBottomRightRadius = 6;
|
||||
root.Add(resetBtn);
|
||||
|
||||
root.Add(ScovySignature.CreateSignatureBox());
|
||||
}
|
||||
|
||||
private VisualElement CreateCard()
|
||||
{
|
||||
VisualElement card = new VisualElement();
|
||||
card.style.backgroundColor = new StyleColor(new Color(0.18f, 0.18f, 0.18f, 0.9f));
|
||||
card.style.borderTopLeftRadius = 8;
|
||||
card.style.borderTopRightRadius = 8;
|
||||
card.style.borderBottomLeftRadius = 8;
|
||||
card.style.borderBottomRightRadius = 8;
|
||||
card.style.paddingTop = 15;
|
||||
card.style.paddingBottom = 15;
|
||||
card.style.paddingLeft = 15;
|
||||
card.style.paddingRight = 15;
|
||||
|
||||
card.style.borderTopWidth = 1;
|
||||
card.style.borderBottomWidth = 1;
|
||||
card.style.borderLeftWidth = 1;
|
||||
card.style.borderRightWidth = 1;
|
||||
card.style.borderTopColor = new StyleColor(new Color(0.25f, 0.25f, 0.25f));
|
||||
card.style.borderBottomColor = new StyleColor(new Color(0.25f, 0.25f, 0.25f));
|
||||
card.style.borderLeftColor = new StyleColor(new Color(0.25f, 0.25f, 0.25f));
|
||||
card.style.borderRightColor = new StyleColor(new Color(0.25f, 0.25f, 0.25f));
|
||||
return card;
|
||||
}
|
||||
|
||||
static void OnSceneGUI(SceneView view)
|
||||
|
||||
Reference in New Issue
Block a user