Flatkit 추가 및 설정

This commit is contained in:
2026-01-25 11:27:33 +09:00
parent 05233497e7
commit cf16910a32
1938 changed files with 408633 additions and 244 deletions

View File

@@ -0,0 +1,16 @@
using UnityEngine;
using UnityEditor;
namespace ExternPropertyAttributes.Editor
{
[CustomPropertyDrawer(typeof(AllowNestingAttribute))]
public class AllowNestingPropertyDrawer : PropertyDrawerBase
{
protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(rect, label, property);
EditorGUI.PropertyField(rect, property, label, true);
EditorGUI.EndProperty();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f731bdca659b2154db7e2dc33effc220
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,192 @@
using UnityEngine;
using UnityEditor;
namespace ExternPropertyAttributes.Editor
{
[CustomPropertyDrawer(typeof(ExpandableAttribute))]
public class ExpandablePropertyDrawer : PropertyDrawerBase
{
protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label)
{
System.Type propertyType = PropertyUtility.GetPropertyType(property);
if (typeof(ScriptableObject).IsAssignableFrom(propertyType))
{
ScriptableObject scriptableObject = property.objectReferenceValue as ScriptableObject;
if (scriptableObject == null)
{
return GetPropertyHeight(property);
}
if (property.isExpanded)
{
using (SerializedObject serializedObject = new SerializedObject(scriptableObject))
{
float totalHeight = EditorGUIUtility.singleLineHeight;
using (var iterator = serializedObject.GetIterator())
{
if (iterator.NextVisible(true))
{
do
{
SerializedProperty childProperty = serializedObject.FindProperty(iterator.name);
if (childProperty.name.Equals("m_Script", System.StringComparison.Ordinal))
{
continue;
}
bool visible = PropertyUtility.IsVisible(childProperty);
if (!visible)
{
continue;
}
float height = GetPropertyHeight(childProperty);
totalHeight += height;
}
while (iterator.NextVisible(false));
}
}
totalHeight += EditorGUIUtility.standardVerticalSpacing;
return totalHeight;
}
}
else
{
return GetPropertyHeight(property);
}
}
else
{
return GetPropertyHeight(property) + GetHelpBoxHeight();
}
}
protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(rect, label, property);
System.Type propertyType = PropertyUtility.GetPropertyType(property);
if (typeof(ScriptableObject).IsAssignableFrom(propertyType))
{
ScriptableObject scriptableObject = property.objectReferenceValue as ScriptableObject;
if (scriptableObject == null)
{
EditorGUI.PropertyField(rect, property, label, false);
}
else
{
// Draw a foldout
Rect foldoutRect = new Rect()
{
x = rect.x,
y = rect.y,
width = EditorGUIUtility.labelWidth,
height = EditorGUIUtility.singleLineHeight
};
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, toggleOnLabelClick: true);
// Draw the scriptable object field
float indentLength = ExternalCustomEditorGUI.GetIndentLength(rect);
float labelWidth = EditorGUIUtility.labelWidth - indentLength + ExternalCustomEditorGUI.HorizontalSpacing;
Rect propertyRect = new Rect()
{
x = rect.x + labelWidth,
y = rect.y,
width = rect.width - labelWidth,
height = EditorGUIUtility.singleLineHeight
};
EditorGUI.BeginChangeCheck();
property.objectReferenceValue = EditorGUI.ObjectField(propertyRect, GUIContent.none, property.objectReferenceValue, propertyType, false);
if (EditorGUI.EndChangeCheck())
{
property.serializedObject.ApplyModifiedProperties();
}
// Draw the child properties
if (property.isExpanded)
{
DrawChildProperties(rect, property);
}
}
}
else
{
string message = $"{typeof(ExpandableAttribute).Name} can only be used on scriptable objects";
DrawDefaultPropertyAndHelpBox(rect, property, message, MessageType.Warning);
}
EditorGUI.EndProperty();
}
private void DrawChildProperties(Rect rect, SerializedProperty property)
{
ScriptableObject scriptableObject = property.objectReferenceValue as ScriptableObject;
if (scriptableObject == null)
{
return;
}
Rect boxRect = new Rect()
{
x = 0.0f,
y = rect.y + EditorGUIUtility.singleLineHeight,
width = rect.width * 2.0f,
height = rect.height - EditorGUIUtility.singleLineHeight
};
GUI.Box(boxRect, GUIContent.none);
using (new EditorGUI.IndentLevelScope())
{
EditorGUI.BeginChangeCheck();
SerializedObject serializedObject = new SerializedObject(scriptableObject);
using (var iterator = serializedObject.GetIterator())
{
float yOffset = EditorGUIUtility.singleLineHeight;
if (iterator.NextVisible(true))
{
do
{
SerializedProperty childProperty = serializedObject.FindProperty(iterator.name);
if (childProperty.name.Equals("m_Script", System.StringComparison.Ordinal))
{
continue;
}
bool visible = PropertyUtility.IsVisible(childProperty);
if (!visible)
{
continue;
}
float childHeight = GetPropertyHeight(childProperty);
Rect childRect = new Rect()
{
x = rect.x,
y = rect.y + yOffset,
width = rect.width,
height = childHeight
};
ExternalCustomEditorGUI.PropertyField(childRect, childProperty, true);
yOffset += childHeight;
}
while (iterator.NextVisible(false));
}
}
if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3c1918a04454ee14a91bce2534050896
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
using UnityEditor;
using UnityEngine;
namespace ExternPropertyAttributes.Editor
{
[CustomPropertyDrawer(typeof(MinMaxSliderAttribute))]
public class MinMaxSliderPropertyDrawer : PropertyDrawerBase
{
protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label)
{
return (property.propertyType == SerializedPropertyType.Vector2)
? GetPropertyHeight(property)
: GetPropertyHeight(property) + GetHelpBoxHeight();
}
protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(rect, label, property);
MinMaxSliderAttribute minMaxSliderAttribute = (MinMaxSliderAttribute)attribute;
if (property.propertyType == SerializedPropertyType.Vector2)
{
EditorGUI.BeginProperty(rect, label, property);
float indentLength = ExternalCustomEditorGUI.GetIndentLength(rect);
float labelWidth = EditorGUIUtility.labelWidth + ExternalCustomEditorGUI.HorizontalSpacing;
float floatFieldWidth = EditorGUIUtility.fieldWidth;
float sliderWidth = rect.width - labelWidth - 2.0f * floatFieldWidth;
float sliderPadding = 5.0f;
Rect labelRect = new Rect(
rect.x,
rect.y,
labelWidth,
rect.height);
Rect sliderRect = new Rect(
rect.x + labelWidth + floatFieldWidth + sliderPadding - indentLength,
rect.y,
sliderWidth - 2.0f * sliderPadding + indentLength,
rect.height);
Rect minFloatFieldRect = new Rect(
rect.x + labelWidth - indentLength,
rect.y,
floatFieldWidth + indentLength,
rect.height);
Rect maxFloatFieldRect = new Rect(
rect.x + labelWidth + floatFieldWidth + sliderWidth - indentLength,
rect.y,
floatFieldWidth + indentLength,
rect.height);
// Draw the label
EditorGUI.LabelField(labelRect, label.text);
// Draw the slider
EditorGUI.BeginChangeCheck();
Vector2 sliderValue = property.vector2Value;
EditorGUI.MinMaxSlider(sliderRect, ref sliderValue.x, ref sliderValue.y, minMaxSliderAttribute.MinValue, minMaxSliderAttribute.MaxValue);
sliderValue.x = EditorGUI.FloatField(minFloatFieldRect, sliderValue.x);
sliderValue.x = Mathf.Clamp(sliderValue.x, minMaxSliderAttribute.MinValue, Mathf.Min(minMaxSliderAttribute.MaxValue, sliderValue.y));
sliderValue.y = EditorGUI.FloatField(maxFloatFieldRect, sliderValue.y);
sliderValue.y = Mathf.Clamp(sliderValue.y, Mathf.Max(minMaxSliderAttribute.MinValue, sliderValue.x), minMaxSliderAttribute.MaxValue);
if (EditorGUI.EndChangeCheck())
{
property.vector2Value = sliderValue;
}
EditorGUI.EndProperty();
}
else
{
string message = minMaxSliderAttribute.GetType().Name + " can be used only on Vector2 fields";
DrawDefaultPropertyAndHelpBox(rect, property, message, MessageType.Warning);
}
EditorGUI.EndProperty();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6706a615c0046cf4aa4f6f4ffae4f823
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,94 @@
using UnityEditor;
using UnityEngine;
namespace ExternPropertyAttributes.Editor
{
public abstract class PropertyDrawerBase : PropertyDrawer
{
public sealed override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
{
// Check if visible
bool visible = PropertyUtility.IsVisible(property);
if (!visible)
{
return;
}
// Validate
ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(property);
foreach (var validatorAttribute in validatorAttributes)
{
validatorAttribute.GetValidator().ValidateProperty(property);
}
// Check if enabled and draw
EditorGUI.BeginChangeCheck();
bool enabled = PropertyUtility.IsEnabled(property);
using (new EditorGUI.DisabledScope(disabled: !enabled))
{
OnGUI_Internal(rect, property, PropertyUtility.GetLabel(property));
}
// Call OnValueChanged callbacks
if (EditorGUI.EndChangeCheck())
{
PropertyUtility.CallOnValueChangedCallbacks(property);
}
}
protected abstract void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label);
sealed override public float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
bool visible = PropertyUtility.IsVisible(property);
if (!visible)
{
return 0.0f;
}
return GetPropertyHeight_Internal(property, label);
}
protected virtual float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, includeChildren: true);
}
protected float GetPropertyHeight(SerializedProperty property)
{
SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute<SpecialCaseDrawerAttribute>(property);
if (specialCaseAttribute != null)
{
return specialCaseAttribute.GetDrawer().GetPropertyHeight(property);
}
return EditorGUI.GetPropertyHeight(property, includeChildren: true);
}
public virtual float GetHelpBoxHeight()
{
return EditorGUIUtility.singleLineHeight * 2.0f;
}
public void DrawDefaultPropertyAndHelpBox(Rect rect, SerializedProperty property, string message, MessageType messageType)
{
float indentLength = ExternalCustomEditorGUI.GetIndentLength(rect);
Rect helpBoxRect = new Rect(
rect.x + indentLength,
rect.y,
rect.width - indentLength,
GetHelpBoxHeight());
ExternalCustomEditorGUI.HelpBox(helpBoxRect, message, MessageType.Warning, context: property.serializedObject.targetObject);
Rect propertyRect = new Rect(
rect.x,
rect.y + GetHelpBoxHeight(),
rect.width,
GetPropertyHeight(property));
EditorGUI.PropertyField(propertyRect, property, true);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 15bad6a367324ff438e9de75919e4b60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using UnityEditor;
namespace ExternPropertyAttributes.Editor
{
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyPropertyDrawer : PropertyDrawerBase
{
protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label)
{
return GetPropertyHeight(property);
}
protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(rect, label, property);
using (new EditorGUI.DisabledScope(disabled: true))
{
EditorGUI.PropertyField(rect, property, label, true);
}
EditorGUI.EndProperty();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 158ee71d6827f134595af325a6ec857a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,110 @@
using UnityEngine;
using UnityEditor;
namespace ExternPropertyAttributes.Editor
{
[CustomPropertyDrawer(typeof(ShowAssetPreviewAttribute))]
public class ShowAssetPreviewPropertyDrawer : PropertyDrawerBase
{
protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label)
{
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
Texture2D previewTexture = GetAssetPreview(property);
if (previewTexture != null)
{
return GetPropertyHeight(property) + GetAssetPreviewSize(property).y;
}
else
{
return GetPropertyHeight(property);
}
}
else
{
return GetPropertyHeight(property) + GetHelpBoxHeight();
}
}
protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(rect, label, property);
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
Rect propertyRect = new Rect()
{
x = rect.x,
y = rect.y,
width = rect.width,
height = EditorGUIUtility.singleLineHeight
};
EditorGUI.PropertyField(propertyRect, property, label);
Texture2D previewTexture = GetAssetPreview(property);
if (previewTexture != null)
{
Rect previewRect = new Rect()
{
x = rect.x + ExternalCustomEditorGUI.GetIndentLength(rect),
y = rect.y + EditorGUIUtility.singleLineHeight,
width = rect.width,
height = GetAssetPreviewSize(property).y
};
GUI.Label(previewRect, previewTexture);
}
}
else
{
string message = property.name + " doesn't have an asset preview";
DrawDefaultPropertyAndHelpBox(rect, property, message, MessageType.Warning);
}
EditorGUI.EndProperty();
}
private Texture2D GetAssetPreview(SerializedProperty property)
{
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
if (property.objectReferenceValue != null)
{
Texture2D previewTexture = AssetPreview.GetAssetPreview(property.objectReferenceValue);
return previewTexture;
}
return null;
}
return null;
}
private Vector2 GetAssetPreviewSize(SerializedProperty property)
{
Texture2D previewTexture = GetAssetPreview(property);
if (previewTexture == null)
{
return Vector2.zero;
}
else
{
int targetWidth = ShowAssetPreviewAttribute.DefaultWidth;
int targetHeight = ShowAssetPreviewAttribute.DefaultHeight;
ShowAssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttribute<ShowAssetPreviewAttribute>(property);
if (showAssetPreviewAttribute != null)
{
targetWidth = showAssetPreviewAttribute.Width;
targetHeight = showAssetPreviewAttribute.Height;
}
int width = Mathf.Clamp(targetWidth, 0, previewTexture.width);
int height = Mathf.Clamp(targetHeight, 0, previewTexture.height);
return new Vector2(width, height);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91ee7a4a8e531d841b7d36be94da45d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: