Skip to content

Commit b7f0642

Browse files
committed
feat: palette theming system with transition-based ColoredGraphic
1 parent 344648b commit b7f0642

154 files changed

Lines changed: 24832 additions & 168 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Linq;
2+
using PurrNet.UI;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace PurrNet.Editor.UI
7+
{
8+
[CustomEditor(typeof(AudioSessionPreset))]
9+
[CanEditMultipleObjects]
10+
public class AudioSessionPresetEditor : UnityEditor.Editor
11+
{
12+
public override void OnInspectorGUI()
13+
{
14+
DrawDefaultInspector();
15+
16+
EditorGUILayout.Space();
17+
18+
foreach (var t in targets)
19+
{
20+
var preset = (AudioSessionPreset)t;
21+
bool hasClips = preset.clips != null && preset.clips.Length > 0;
22+
var label = $"Test ({preset.name})";
23+
24+
using (new EditorGUI.DisabledScope(!hasClips))
25+
{
26+
if (GUILayout.Button(label, GUILayout.Height(24f)))
27+
preset.Play();
28+
}
29+
30+
if (!hasClips)
31+
EditorGUILayout.HelpBox($"{preset.name}: add at least one AudioClip to preview.", MessageType.Info);
32+
}
33+
}
34+
35+
[MenuItem("Assets/Create/PurrNet/PurrUI/AudioSessionPreset", false, 500)]
36+
static void CreateAudioSessionPreset()
37+
{
38+
var clips = Selection.objects.OfType<AudioClip>().ToArray();
39+
40+
var preset = CreateInstance<AudioSessionPreset>();
41+
if (clips.Length > 0)
42+
preset.clips = clips;
43+
44+
var folder = GetSelectionFolder();
45+
var defaultName = clips.Length == 1 ? clips[0].name : "NewAudioSessionPreset";
46+
var path = AssetDatabase.GenerateUniqueAssetPath($"{folder}/{defaultName}.asset");
47+
48+
ProjectWindowUtil.CreateAsset(preset, path);
49+
}
50+
51+
static string GetSelectionFolder()
52+
{
53+
foreach (var obj in Selection.objects)
54+
{
55+
var path = AssetDatabase.GetAssetPath(obj);
56+
if (string.IsNullOrEmpty(path))
57+
continue;
58+
59+
if (AssetDatabase.IsValidFolder(path))
60+
return path;
61+
62+
var folder = System.IO.Path.GetDirectoryName(path);
63+
if (!string.IsNullOrEmpty(folder))
64+
return folder.Replace('\\', '/');
65+
}
66+
67+
return "Assets";
68+
}
69+
}
70+
}

Assets/PurrUI/Editor/AudioSessionPresetEditor.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using PurrNet.UI;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace PurrNet.Editor.UI
6+
{
7+
[CustomPropertyDrawer(typeof(ColorInfo))]
8+
public class ColorInfoDrawer : PropertyDrawer
9+
{
10+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
11+
{
12+
using (new EditorGUI.PropertyScope(position, label, property))
13+
{
14+
var rect = EditorGUI.PrefixLabel(position, label);
15+
16+
var enabledProp = property.FindPropertyRelative("enabled");
17+
var colorProp = property.FindPropertyRelative("color");
18+
var contrastProp = property.FindPropertyRelative("contrast");
19+
20+
int previousIndent = EditorGUI.indentLevel;
21+
EditorGUI.indentLevel = 0;
22+
23+
const float enableWidth = 16f;
24+
const float toggleWidth = 80f;
25+
const float spacing = 4f;
26+
27+
var enableRect = new Rect(rect.x, rect.y, enableWidth, rect.height);
28+
var dropdownRect = new Rect(
29+
enableRect.xMax + spacing, rect.y,
30+
rect.width - enableWidth - toggleWidth - spacing * 2f, rect.height);
31+
var toggleRect = new Rect(rect.xMax - toggleWidth, rect.y, toggleWidth, rect.height);
32+
33+
EditorGUI.PropertyField(enableRect, enabledProp, GUIContent.none);
34+
35+
bool slotActive = !enabledProp.hasMultipleDifferentValues && enabledProp.boolValue;
36+
using (new EditorGUI.DisabledScope(!slotActive))
37+
{
38+
EditorGUI.PropertyField(dropdownRect, colorProp, GUIContent.none);
39+
40+
EditorGUI.BeginChangeCheck();
41+
EditorGUI.showMixedValue = contrastProp.hasMultipleDifferentValues;
42+
bool newContrast = EditorGUI.ToggleLeft(toggleRect, "Contrast", contrastProp.boolValue);
43+
EditorGUI.showMixedValue = false;
44+
if (EditorGUI.EndChangeCheck())
45+
contrastProp.boolValue = newContrast;
46+
}
47+
48+
EditorGUI.indentLevel = previousIndent;
49+
}
50+
}
51+
52+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
53+
{
54+
return EditorGUIUtility.singleLineHeight;
55+
}
56+
}
57+
}

Assets/PurrUI/Editor/ColorInfoDrawer.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using PurrNet.UI;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace PurrNet.Editor.UI
7+
{
8+
[CustomEditor(typeof(ColoredGraphic))]
9+
[CanEditMultipleObjects]
10+
public class ColoredGraphicEditor : UnityEditor.Editor
11+
{
12+
SerializedProperty _graphicProp;
13+
SerializedProperty _transitionDurationProp;
14+
SerializedProperty _colorProp;
15+
SerializedProperty _coloredInfosProp;
16+
17+
void OnEnable()
18+
{
19+
_graphicProp = serializedObject.FindProperty("_graphic");
20+
_transitionDurationProp = serializedObject.FindProperty("_transitionDuration");
21+
_colorProp = serializedObject.FindProperty("_color");
22+
_coloredInfosProp = serializedObject.FindProperty("_coloredInfos");
23+
}
24+
25+
public override void OnInspectorGUI()
26+
{
27+
serializedObject.Update();
28+
29+
EditorGUILayout.PropertyField(_graphicProp);
30+
EditorGUILayout.PropertyField(_transitionDurationProp);
31+
32+
if (_graphicProp.hasMultipleDifferentValues)
33+
{
34+
EditorGUILayout.HelpBox("Multi-selection has different Graphic targets — edit individually.", MessageType.Info);
35+
serializedObject.ApplyModifiedProperties();
36+
return;
37+
}
38+
39+
var graphic = _graphicProp.objectReferenceValue;
40+
41+
if (graphic == null)
42+
{
43+
EditorGUILayout.HelpBox("Assign a Graphic to color.", MessageType.Info);
44+
serializedObject.ApplyModifiedProperties();
45+
return;
46+
}
47+
48+
if (graphic is IColored colored)
49+
DrawMultiKey(colored);
50+
else
51+
EditorGUILayout.PropertyField(_colorProp, new GUIContent("Color"));
52+
53+
serializedObject.ApplyModifiedProperties();
54+
}
55+
56+
void DrawMultiKey(IColored colored)
57+
{
58+
var keys = colored.keys ?? Array.Empty<string>();
59+
60+
if (_coloredInfosProp.arraySize != keys.Length)
61+
_coloredInfosProp.arraySize = keys.Length;
62+
63+
if (keys.Length == 0)
64+
{
65+
EditorGUILayout.HelpBox("Target exposes no color keys.", MessageType.Info);
66+
return;
67+
}
68+
69+
for (int i = 0; i < keys.Length; i++)
70+
{
71+
var element = _coloredInfosProp.GetArrayElementAtIndex(i);
72+
var label = new GUIContent($"[{i}] {keys[i]}", $"Index {i} — use SetColor({i}, ...) at runtime.");
73+
EditorGUILayout.PropertyField(element, label, true);
74+
}
75+
}
76+
}
77+
}

Assets/PurrUI/Editor/ColoredGraphicEditor.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
481 Bytes
Loading

Assets/PurrUI/Editor/Icons/colors-icon.png.meta

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)