Second commit
This commit is contained in:
commit
36840f3ad4
999 files changed
+61364
No files matched your search
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// This file is part of the Tremble package by Tiny Goose.
|
||||
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TinyGoose.Tremble.Editor
|
||||
{
|
||||
public abstract class BaseClassPickerDrawer<TClassType> : PropertyDrawer
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
// Consts
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
private const string INDENT_STRING = " ";
|
||||
private const string NONE_STRING = "(none)";
|
||||
|
||||
protected abstract string ClassNamePropertyName { get; }
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
// State
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
private List<Type> m_AllClasses;
|
||||
private int m_SelectedClass;
|
||||
|
||||
private bool m_Inited;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Lazy-load class catalog if needed
|
||||
if (!m_Inited)
|
||||
{
|
||||
m_Inited = true;
|
||||
GenerateClassCatalog();
|
||||
}
|
||||
|
||||
// Draw label & icon
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
// Generate class list
|
||||
string[] classDisplayNames = m_AllClasses.Select(t => GetHumanClassName(t)).ToArray();
|
||||
|
||||
// Calculate current index
|
||||
SerializedProperty classProperty = property.FindPropertyRelative(ClassNamePropertyName);
|
||||
int prevSelectedClass = m_AllClasses.FindIndex(c => c.FullName == classProperty.stringValue);
|
||||
if (prevSelectedClass == -1)
|
||||
{
|
||||
prevSelectedClass = 0;
|
||||
}
|
||||
|
||||
m_SelectedClass = EditorGUI.Popup(position, "", prevSelectedClass, classDisplayNames);
|
||||
|
||||
EditorGUI.BeginProperty(position, GUIContent.none, property);
|
||||
classProperty.stringValue = m_AllClasses[m_SelectedClass].FullName;
|
||||
EditorGUI.EndProperty();
|
||||
|
||||
// Draw icon overlay
|
||||
Rect iconRect = position;
|
||||
iconRect.width = position.height;
|
||||
iconRect.x += 2f;
|
||||
iconRect.y += 2f;
|
||||
iconRect.width -= 4f;
|
||||
iconRect.height -= 4f;
|
||||
|
||||
position.x += position.height;
|
||||
position.width -= position.height;
|
||||
|
||||
GUI.DrawTexture(iconRect, EditorGUIUtility.FindTexture("cs Script Icon"));
|
||||
}
|
||||
|
||||
private void GenerateClassCatalog()
|
||||
{
|
||||
List<Type> allClasses = TypeCache.GetTypesDerivedFrom(typeof(TClassType)).ToList();
|
||||
m_AllClasses = new(allClasses.Count + 1);
|
||||
|
||||
if (!typeof(TClassType).IsAbstract)
|
||||
{
|
||||
m_AllClasses.Add(typeof(TClassType));
|
||||
}
|
||||
m_AllClasses.AddRange(allClasses);
|
||||
}
|
||||
|
||||
private static string GetHumanClassName(Type type, bool indent = true)
|
||||
{
|
||||
string fullClassName = type.FullName;
|
||||
if (fullClassName == null)
|
||||
return indent ? (INDENT_STRING + NONE_STRING) : NONE_STRING;
|
||||
|
||||
int lastDot = fullClassName.LastIndexOf('.');
|
||||
|
||||
// If it ends in dot (?!) or has no dot - return class as-is
|
||||
if (lastDot == -1 || lastDot == fullClassName.Length - 1)
|
||||
return fullClassName;
|
||||
|
||||
string shortClassName = fullClassName.Substring(lastDot + 1);
|
||||
|
||||
if (shortClassName.StartsWithInvariant("Null", caseSensitive: true))
|
||||
{
|
||||
return indent ? (INDENT_STRING + NONE_STRING) : NONE_STRING;
|
||||
}
|
||||
|
||||
bool doneFirst = false;
|
||||
List<char> output = new(shortClassName.Length + 10);
|
||||
|
||||
foreach (char c in shortClassName)
|
||||
{
|
||||
if (Char.IsUpper(c) && doneFirst)
|
||||
{
|
||||
output.Add(' ');
|
||||
}
|
||||
|
||||
output.Add(c);
|
||||
doneFirst = true;
|
||||
}
|
||||
|
||||
string humanName = new(output.ToArray());
|
||||
return indent ? (INDENT_STRING + humanName) : humanName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b7aeb7420ec45cda02dea687dbd8e57
|
||||
timeCreated: 1710244772
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 277805
|
||||
packageName: Tremble - Map Importer
|
||||
packageVersion: 1.11.1
|
||||
assetPath: Assets/Tremble/Editor/EditorUI/Drawers/BaseClassPickerDrawer.cs
|
||||
uploadId: 939664
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// This file is part of the Tremble package by Tiny Goose.
|
||||
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
|
||||
//
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace TinyGoose.Tremble.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(MapProcessorClass), useForChildren: true)]
|
||||
public class MapProcessorClassDrawer : BaseClassPickerDrawer<MapProcessorBase>
|
||||
{
|
||||
protected override string ClassNamePropertyName => "m_MapClassName";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85a89c98c61044e08811ba3fb0fbe957
|
||||
timeCreated: 1707730234
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 277805
|
||||
packageName: Tremble - Map Importer
|
||||
packageVersion: 1.11.1
|
||||
assetPath: Assets/Tremble/Editor/EditorUI/Drawers/MapProcessorClassDrawer.cs
|
||||
uploadId: 939664
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// This file is part of the Tremble package by Tiny Goose.
|
||||
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
|
||||
//
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace TinyGoose.Tremble.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(WorldspawnScript), useForChildren: true)]
|
||||
public class WorldspawnScriptDrawer : BaseClassPickerDrawer<Worldspawn>
|
||||
{
|
||||
protected override string ClassNamePropertyName => "m_ScriptName";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 513c5345701d4a0894054ae3c25184fb
|
||||
timeCreated: 1710152511
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 277805
|
||||
packageName: Tremble - Map Importer
|
||||
packageVersion: 1.11.1
|
||||
assetPath: Assets/Tremble/Editor/EditorUI/Drawers/WorldspawnScriptDrawer.cs
|
||||
uploadId: 939664
|
||||
Reference in new issue
Block a user