架构大更
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace NaughtyAttributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class EnumFlagsAttribute : DrawerAttribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace NaughtyAttributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class ExpandableAttribute : DrawerAttribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace NaughtyAttributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class ShowAssetPreviewAttribute : DrawerAttribute
|
||||
{
|
||||
public const int DefaultWidth = 64;
|
||||
public const int DefaultHeight = 64;
|
||||
|
||||
public int Width { get; private set; }
|
||||
public int Height { get; private set; }
|
||||
|
||||
public ShowAssetPreviewAttribute(int width = DefaultWidth, int height = DefaultHeight)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public int Width { get; private set; }
|
||||
public int Height { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace NaughtyAttributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class TagAttribute : DrawerAttribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "NaughtyAttributes.Core",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
"name": "NaughtyAttributes.Core",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace NaughtyAttributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class RequiredAttribute : ValidatorAttribute
|
||||
{
|
||||
public string Message { get; private set; }
|
||||
|
||||
public RequiredAttribute(string message = null)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public string Message { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"name": "NaughtyAttributes.Editor",
|
||||
"references": [
|
||||
"NaughtyAttributes.Core"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
"name": "NaughtyAttributes.Editor",
|
||||
"references": [
|
||||
"NaughtyAttributes.Core"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
||||
@@ -8,62 +8,48 @@ namespace NaughtyAttributes.Editor
|
||||
public sealed override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Check if visible
|
||||
bool visible = PropertyUtility.IsVisible(property);
|
||||
if (!visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var visible = PropertyUtility.IsVisible(property);
|
||||
if (!visible) return;
|
||||
|
||||
// Validate
|
||||
ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(property);
|
||||
var 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);
|
||||
var enabled = PropertyUtility.IsEnabled(property);
|
||||
|
||||
using (new EditorGUI.DisabledScope(disabled: !enabled))
|
||||
using (new EditorGUI.DisabledScope(!enabled))
|
||||
{
|
||||
OnGUI_Internal(rect, property, PropertyUtility.GetLabel(property));
|
||||
}
|
||||
|
||||
// Call OnValueChanged callbacks
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
PropertyUtility.CallOnValueChangedCallbacks(property);
|
||||
}
|
||||
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)
|
||||
public sealed override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
bool visible = PropertyUtility.IsVisible(property);
|
||||
if (!visible)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
var 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);
|
||||
return EditorGUI.GetPropertyHeight(property, true);
|
||||
}
|
||||
|
||||
protected float GetPropertyHeight(SerializedProperty property)
|
||||
{
|
||||
SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute<SpecialCaseDrawerAttribute>(property);
|
||||
if (specialCaseAttribute != null)
|
||||
{
|
||||
return specialCaseAttribute.GetDrawer().GetPropertyHeight(property);
|
||||
}
|
||||
var specialCaseAttribute = PropertyUtility.GetAttribute<SpecialCaseDrawerAttribute>(property);
|
||||
if (specialCaseAttribute != null) return specialCaseAttribute.GetDrawer().GetPropertyHeight(property);
|
||||
|
||||
return EditorGUI.GetPropertyHeight(property, includeChildren: true);
|
||||
return EditorGUI.GetPropertyHeight(property, true);
|
||||
}
|
||||
|
||||
public virtual float GetHelpBoxHeight()
|
||||
@@ -71,18 +57,19 @@ namespace NaughtyAttributes.Editor
|
||||
return EditorGUIUtility.singleLineHeight * 2.0f;
|
||||
}
|
||||
|
||||
public void DrawDefaultPropertyAndHelpBox(Rect rect, SerializedProperty property, string message, MessageType messageType)
|
||||
public void DrawDefaultPropertyAndHelpBox(Rect rect, SerializedProperty property, string message,
|
||||
MessageType messageType)
|
||||
{
|
||||
float indentLength = NaughtyEditorGUI.GetIndentLength(rect);
|
||||
Rect helpBoxRect = new Rect(
|
||||
var indentLength = NaughtyEditorGUI.GetIndentLength(rect);
|
||||
var helpBoxRect = new Rect(
|
||||
rect.x + indentLength,
|
||||
rect.y,
|
||||
rect.width - indentLength,
|
||||
GetHelpBoxHeight());
|
||||
|
||||
NaughtyEditorGUI.HelpBox(helpBoxRect, message, MessageType.Warning, context: property.serializedObject.targetObject);
|
||||
NaughtyEditorGUI.HelpBox(helpBoxRect, message, MessageType.Warning, property.serializedObject.targetObject);
|
||||
|
||||
Rect propertyRect = new Rect(
|
||||
var propertyRect = new Rect(
|
||||
rect.x,
|
||||
rect.y + GetHelpBoxHeight(),
|
||||
rect.width,
|
||||
@@ -91,4 +78,4 @@ namespace NaughtyAttributes.Editor
|
||||
EditorGUI.PropertyField(propertyRect, property, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "NaughtyAttributes.Test",
|
||||
"references": [
|
||||
"NaughtyAttributes.Core"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
"name": "NaughtyAttributes.Test",
|
||||
"references": [
|
||||
"NaughtyAttributes.Core"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NaughtyAttributes.Test
|
||||
@@ -7,13 +7,13 @@ namespace NaughtyAttributes.Test
|
||||
{
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
[Serializable]
|
||||
public class MyClass
|
||||
{
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
[Serializable]
|
||||
public struct MyStruct
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NaughtyAttributes.Test
|
||||
{
|
||||
//[CreateAssetMenu(fileName = "TestScriptableObjectA", menuName = "NaughtyAttributes/TestScriptableObjectA")]
|
||||
public class _TestScriptableObjectA : ScriptableObject
|
||||
{
|
||||
[Expandable]
|
||||
public List<_TestScriptableObjectB> listB;
|
||||
[Expandable] public List<_TestScriptableObjectB> listB;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,11 @@
|
||||
"version": "2.1.4",
|
||||
"unity": "2018.4",
|
||||
"description": "NaughtyAttributes is an extension for the Unity Inspector.",
|
||||
"keywords": [ "attribute", "inspector", "editor" ],
|
||||
"keywords": [
|
||||
"attribute",
|
||||
"inspector",
|
||||
"editor"
|
||||
],
|
||||
"category": "editor extensions",
|
||||
"dependencies": {},
|
||||
"samples": [
|
||||
|
||||
Reference in New Issue
Block a user