added code from unity

This commit is contained in:
Sebastian Bularca
2026-04-06 20:45:03 +02:00
parent 0075992205
commit 0f675b9981
56 changed files with 3448 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
{
"name": "Jovian.PopupSystem.Editor",
"rootNamespace": "Jovian.PopupSystem.Editor",
"references": [
"Jovian.PopupSystem"
],
"includePlatforms": ["Editor"],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e663435ad13b46d40a29802dab7e52f5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Jovian.PopupSystem.Editor {
[CustomPropertyDrawer(typeof(PopupCategory))]
public sealed class PopupCategoryDrawer : PropertyDrawer {
private static readonly string[] builtInIds = {
"Character",
"Item",
"Skill",
"General"
};
private const string customLabel = "Custom...";
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
var idProp = FindIdProperty(property);
if(idProp == null) {
return EditorGUIUtility.singleLineHeight;
}
var currentValue = idProp.stringValue ?? "";
var isCustom = Array.IndexOf(builtInIds, currentValue) < 0;
// Two lines when in custom mode: dropdown + text field
return isCustom
? EditorGUIUtility.singleLineHeight * 2 + 2
: EditorGUIUtility.singleLineHeight;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty(position, label, property);
var idProp = FindIdProperty(property);
if(idProp == null) {
EditorGUI.LabelField(position, label.text, "Cannot resolve PopupCategory id field");
EditorGUI.EndProperty();
return;
}
var currentValue = idProp.stringValue ?? "";
var builtInIndex = Array.IndexOf(builtInIds, currentValue);
var isCustom = builtInIndex < 0 && !string.IsNullOrEmpty(currentValue);
// Build display options: built-in entries + "Custom..."
var options = new List<string>(builtInIds);
options.Add(customLabel);
// Determine selected index
int selectedIndex;
if(builtInIndex >= 0) {
selectedIndex = builtInIndex;
}
else {
selectedIndex = options.Count - 1; // "Custom..."
}
// First line: dropdown
var dropdownRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
var newIndex = EditorGUI.Popup(dropdownRect, label.text, selectedIndex, options.ToArray());
if(newIndex != selectedIndex) {
if(newIndex < builtInIds.Length) {
idProp.stringValue = builtInIds[newIndex];
}
else {
// Switched to custom — seed with a placeholder if currently built-in
if(!isCustom) {
idProp.stringValue = "NewCategory";
}
}
}
// Second line: editable text field when custom
var finalIsCustom = newIndex >= builtInIds.Length || (newIndex == selectedIndex && isCustom);
if(finalIsCustom) {
var textRect = new Rect(
position.x + EditorGUIUtility.labelWidth + 2,
position.y + EditorGUIUtility.singleLineHeight + 2,
position.width - EditorGUIUtility.labelWidth - 2,
EditorGUIUtility.singleLineHeight);
var newValue = EditorGUI.TextField(textRect, idProp.stringValue);
if(newValue != idProp.stringValue) {
idProp.stringValue = newValue;
}
}
EditorGUI.EndProperty();
}
private static SerializedProperty FindIdProperty(SerializedProperty property) {
// readonly struct with [SerializeField] readonly string id
// Unity serializes this as "id" directly
var prop = property.FindPropertyRelative("id");
if(prop != null) {
return prop;
}
// Fallback: auto-property backing field pattern
return property.FindPropertyRelative("<id>k__BackingField");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9cc96a089d31fe14cbadf6c59ea0c9aa

View File

@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Jovian.PopupSystem.Editor {
/// <summary>
/// Custom PropertyDrawer for <see cref="PopupElementType"/>. Shows a dropdown with
/// built-in element types plus a "Custom..." option for free-text entry.
/// </summary>
[CustomPropertyDrawer(typeof(PopupElementType))]
public sealed class PopupElementTypeDrawer : PropertyDrawer {
private static readonly string[] builtInIds = {
"header",
"text",
"label_value_text",
"image",
"separator"
};
private const string customLabel = "Custom...";
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
var idProp = FindIdProperty(property);
if(idProp == null) {
return EditorGUIUtility.singleLineHeight;
}
var currentValue = idProp.stringValue ?? "";
var isCustom = Array.IndexOf(builtInIds, currentValue) < 0 && !string.IsNullOrEmpty(currentValue);
return isCustom
? EditorGUIUtility.singleLineHeight * 2 + 2
: EditorGUIUtility.singleLineHeight;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty(position, label, property);
var idProp = FindIdProperty(property);
if(idProp == null) {
EditorGUI.LabelField(position, label.text, "Cannot resolve PopupElementType id field");
EditorGUI.EndProperty();
return;
}
var currentValue = idProp.stringValue ?? "";
var builtInIndex = Array.IndexOf(builtInIds, currentValue);
var isCustom = builtInIndex < 0 && !string.IsNullOrEmpty(currentValue);
var options = new List<string>(builtInIds);
options.Add(customLabel);
int selectedIndex;
if(builtInIndex >= 0) {
selectedIndex = builtInIndex;
}
else {
selectedIndex = options.Count - 1;
}
var dropdownRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
var newIndex = EditorGUI.Popup(dropdownRect, label.text, selectedIndex, options.ToArray());
if(newIndex != selectedIndex) {
if(newIndex < builtInIds.Length) {
idProp.stringValue = builtInIds[newIndex];
}
else {
if(!isCustom) {
idProp.stringValue = "custom_element";
}
}
}
var finalIsCustom = newIndex >= builtInIds.Length || (newIndex == selectedIndex && isCustom);
if(finalIsCustom) {
var textRect = new Rect(
position.x + EditorGUIUtility.labelWidth + 2,
position.y + EditorGUIUtility.singleLineHeight + 2,
position.width - EditorGUIUtility.labelWidth - 2,
EditorGUIUtility.singleLineHeight);
var newValue = EditorGUI.TextField(textRect, idProp.stringValue);
if(newValue != idProp.stringValue) {
idProp.stringValue = newValue;
}
}
EditorGUI.EndProperty();
}
private static SerializedProperty FindIdProperty(SerializedProperty property) {
var prop = property.FindPropertyRelative("id");
if(prop != null) {
return prop;
}
return property.FindPropertyRelative("<id>k__BackingField");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9ea57be8755c60e4bbf156ac2b32c98c

View File

@@ -0,0 +1,80 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Jovian.PopupSystem.Editor {
public sealed class PopupSettingsProvider : SettingsProvider {
private PopupSettings settings;
private PopupSettingsProvider(string path, SettingsScope scope)
: base(path, scope) { }
private SerializedObject serializedSettings;
public override void OnActivate(string searchContext, UnityEngine.UIElements.VisualElement rootElement) {
var guids = AssetDatabase.FindAssets("t:PopupSettings");
if(guids.Length > 0) {
var path = AssetDatabase.GUIDToAssetPath(guids[0]);
settings = AssetDatabase.LoadAssetAtPath<PopupSettings>(path);
}
if(settings != null) {
serializedSettings = new SerializedObject(settings);
}
}
public override void OnGUI(string searchContext) {
if(settings == null) {
EditorGUILayout.HelpBox("No PopupSettings asset found. Create one via Assets > Create > Jovian > Popup System > Popup Settings.", MessageType.Warning);
return;
}
EditorGUILayout.Space(10);
EditorGUILayout.LabelField("Popup System Settings", EditorStyles.boldLabel);
EditorGUILayout.Space(5);
serializedSettings.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(serializedSettings.FindProperty("popupDelay"));
EditorGUILayout.PropertyField(serializedSettings.FindProperty("fadeDuration"));
EditorGUILayout.PropertyField(serializedSettings.FindProperty("defaultAnchorSide"));
EditorGUILayout.PropertyField(serializedSettings.FindProperty("screenEdgePadding"));
EditorGUILayout.PropertyField(serializedSettings.FindProperty("maxPopupWidth"));
EditorGUILayout.PropertyField(serializedSettings.FindProperty("sortingOrder"));
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Follow Mouse", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedSettings.FindProperty("followMouseOffset"));
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Input", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedSettings.FindProperty("touchHoldDuration"));
EditorGUILayout.PropertyField(serializedSettings.FindProperty("gamepadFocusTrigger"));
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Element Prefabs", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedSettings.FindProperty("elementPrefabs"), true);
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Priority", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedSettings.FindProperty("categoryPriorities"), true);
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Per-Category Overrides", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedSettings.FindProperty("categoryDelayOverrides"), true);
if(EditorGUI.EndChangeCheck()) {
serializedSettings.ApplyModifiedProperties();
EditorUtility.SetDirty(settings);
}
}
[SettingsProvider]
public static SettingsProvider CreateProvider() {
var provider = new PopupSettingsProvider("Project/Jovian/Popup System", SettingsScope.Project) {
keywords = new HashSet<string>(new[] { "popup", "tooltip", "hover", "delay" })
};
return provider;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 63a03b88ed78a934094ce61f9d127ec9