Thomas ICHÉ
6 年前
当前提交
5c52b390
共有 25 个文件被更改,包括 179 次插入 和 137 次删除
-
13NaughtyAttributes/Core/DrawConditionAttributes/HideIfAttribute.cs
-
15NaughtyAttributes/Core/DrawConditionAttributes/ShowIfAttribute.cs
-
13NaughtyAttributes/Core/DrawerAttributes/DisableIfAttribute.cs
-
15NaughtyAttributes/Core/DrawerAttributes/EnableIfAttribute.cs
-
4NaughtyAttributes/Editor/FieldDrawers/ShowNonSerializedFieldFieldDrawer.cs
-
2NaughtyAttributes/Editor/MethodDrawers/ButtonMethodDrawer.cs
-
4NaughtyAttributes/Editor/NativePropertyDrawers/ShowNativePropertyNativePropertyDrawer.cs
-
28NaughtyAttributes/Editor/PropertyDrawConditions/HideIfPropertyDrawCondition.cs
-
61NaughtyAttributes/Editor/PropertyDrawConditions/ShowIfPropertyDrawCondition.cs
-
41NaughtyAttributes/Editor/PropertyDrawers/DisableIfPropertyDrawer.cs
-
61NaughtyAttributes/Editor/PropertyDrawers/EnableIfPropertyDrawer.cs
-
2NaughtyAttributes/Editor/PropertyDrawers/MinMaxSliderPropertyDrawer.cs
-
2NaughtyAttributes/Editor/PropertyDrawers/ReorderableListPropertyDrawer.cs
-
2NaughtyAttributes/Editor/PropertyDrawers/ResizableTextAreaPropertyDrawer.cs
-
4NaughtyAttributes/Editor/PropertyDrawers/ShowAssetPreviewPropertyDrawer.cs
-
2NaughtyAttributes/Editor/PropertyDrawers/SliderPropertyDrawer.cs
-
2NaughtyAttributes/Editor/PropertyMetas/InfoBoxPropertyMeta.cs
-
2NaughtyAttributes/Editor/PropertyValidators/MaxValuePropertyValidator.cs
-
2NaughtyAttributes/Editor/PropertyValidators/MinValuePropertyValidator.cs
-
4NaughtyAttributes/Editor/PropertyValidators/RequiredPropertyValidator.cs
-
8NaughtyAttributes/Editor/PropertyValidators/ValidateInputPropertyValidator.cs
-
2NaughtyAttributes/Editor/Utility/EditorDrawUtility.cs
-
6Runtime/Managers/Implementations/GameSaveManager.cs
-
10NaughtyAttributes/Core/ConditionOperator.cs
-
11NaughtyAttributes/Core/ConditionOperator.cs.meta
|
|||
using System.Reflection; |
|||
public class HideIfPropertyDrawCondition : PropertyDrawCondition |
|||
public class HideIfPropertyDrawCondition : ShowIfPropertyDrawCondition |
|||
public override bool CanDrawProperty(SerializedProperty property) |
|||
{ |
|||
HideIfAttribute hideIfAttribute = PropertyUtility.GetAttribute<HideIfAttribute>(property); |
|||
UnityEngine.Object target = PropertyUtility.GetTargetObject(property); |
|||
|
|||
FieldInfo conditionField = ReflectionUtility.GetField(target, hideIfAttribute.ConditionName); |
|||
if (conditionField != null && |
|||
conditionField.FieldType == typeof(bool)) |
|||
{ |
|||
return !(bool)conditionField.GetValue(target); |
|||
} |
|||
|
|||
MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, hideIfAttribute.ConditionName); |
|||
if (conditionMethod != null && |
|||
conditionMethod.ReturnType == typeof(bool) && |
|||
conditionMethod.GetParameters().Length == 0) |
|||
{ |
|||
return !(bool)conditionMethod.Invoke(target, null); |
|||
} |
|||
|
|||
string warning = hideIfAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; |
|||
EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
} |
|
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
public class DisableIfPropertyDrawer : PropertyDrawer |
|||
public class DisableIfPropertyDrawer : EnableIfPropertyDrawer |
|||
public override void DrawProperty(SerializedProperty property) |
|||
{ |
|||
bool drawDisabled = false; |
|||
bool validCondition = false; |
|||
|
|||
DisableIfAttribute disableIfAttribute = PropertyUtility.GetAttribute<DisableIfAttribute>(property); |
|||
UnityEngine.Object target = PropertyUtility.GetTargetObject(property); |
|||
|
|||
FieldInfo conditionField = ReflectionUtility.GetField(target, disableIfAttribute.ConditionName); |
|||
if (conditionField != null && |
|||
conditionField.FieldType == typeof(bool)) |
|||
{ |
|||
drawDisabled = (bool)conditionField.GetValue(target); |
|||
validCondition = true; |
|||
} |
|||
|
|||
MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, disableIfAttribute.ConditionName); |
|||
if (conditionMethod != null && |
|||
conditionMethod.ReturnType == typeof(bool) && |
|||
conditionMethod.GetParameters().Length == 0) |
|||
{ |
|||
drawDisabled = (bool)conditionMethod.Invoke(target, null); |
|||
validCondition = true; |
|||
} |
|||
|
|||
if (validCondition) |
|||
{ |
|||
GUI.enabled = !drawDisabled; |
|||
EditorDrawUtility.DrawPropertyField(property); |
|||
GUI.enabled = true; |
|||
} |
|||
else |
|||
{ |
|||
string warning = disableIfAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; |
|||
EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: target); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
|
|||
namespace NaughtyAttributes |
|||
{ |
|||
public enum ConditionOperator |
|||
{ |
|||
And, |
|||
Or |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8da69fd2354ea264bb1c54362ee02938 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue