修改水
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Obi{
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class LayerField : MultiPropertyAttribute
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
property.intValue = EditorGUI.LayerField(position, label, property.intValue);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 636fa558efd1441fdbf787bdda34c53a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -16,7 +16,7 @@ namespace Obi{
|
||||
|
||||
public virtual void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.PropertyField(position,property,label,true);
|
||||
EditorGUI.PropertyField(position,property,label);
|
||||
}
|
||||
|
||||
internal virtual void OnPreGUI(Rect position, SerializedProperty property){}
|
||||
@@ -53,9 +53,8 @@ namespace Obi{
|
||||
if (!attr.IsVisible(property))
|
||||
return -EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
// In case no attribute returns a modified height, return the property's default one:
|
||||
float height = EditorGUI.GetPropertyHeight(property, label, true);
|
||||
//base.GetPropertyHeight(property, label);
|
||||
// In case no attribute returns a modified height, return the property's default one:
|
||||
float height = base.GetPropertyHeight(property, label);
|
||||
|
||||
// Check if any of the attributes wants to modify height:
|
||||
foreach (object atr in mAttribute.stored)
|
||||
|
||||
@@ -48,18 +48,15 @@ namespace Obi{
|
||||
// If any changes were detected, call the property setter:
|
||||
if (EditorGUI.EndChangeCheck() && propertyFieldInfo != null)
|
||||
{
|
||||
foreach (var t in property.serializedObject.targetObjects)
|
||||
{
|
||||
// Record object state for undo:
|
||||
Undo.RecordObject(t, "Inspector");
|
||||
|
||||
// Record object state for undo:
|
||||
Undo.RecordObject(property.serializedObject.targetObject, "Inspector");
|
||||
|
||||
// Call property setter:
|
||||
propertyFieldInfo.SetValue(target,value,null);
|
||||
|
||||
// Call property setter:
|
||||
propertyFieldInfo.SetValue(t, value, null);
|
||||
SetPropertyValue(property, propertyFieldInfo.PropertyType, value);
|
||||
|
||||
// Record prefab modification:
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(t);
|
||||
}
|
||||
// Record prefab modification:
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(property.serializedObject.targetObject);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
|
||||
@@ -71,18 +68,18 @@ namespace Obi{
|
||||
|
||||
private object GetSource(SerializedProperty property)
|
||||
{
|
||||
object trgt = property.serializedObject.targetObject;
|
||||
object target = property.serializedObject.targetObject;
|
||||
string[] data = property.propertyPath.Split('.');
|
||||
|
||||
if (data.Length == 1)
|
||||
return trgt;
|
||||
return target;
|
||||
else{
|
||||
for (int i = 0; i < data.Length-1;++i){
|
||||
trgt = trgt.GetType().GetField(data[i]).GetValue(trgt);
|
||||
target = target.GetType().GetField(data[i]).GetValue(target);
|
||||
}
|
||||
}
|
||||
|
||||
return trgt;
|
||||
return target;
|
||||
}
|
||||
|
||||
private object DrawProperty(Rect position, SerializedPropertyType propertyType, Type type, object value, GUIContent label)
|
||||
@@ -123,46 +120,7 @@ namespace Obi{
|
||||
throw new NotImplementedException("Unimplemented propertyType "+propertyType+".");
|
||||
}
|
||||
}
|
||||
|
||||
private void SetPropertyValue(SerializedProperty property, Type type, object value)
|
||||
{
|
||||
switch (property.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
property.intValue = (int)value; break;
|
||||
case SerializedPropertyType.Boolean:
|
||||
property.boolValue = (bool)value; break;
|
||||
case SerializedPropertyType.Float:
|
||||
property.floatValue = (float)value; break;
|
||||
case SerializedPropertyType.String:
|
||||
property.stringValue = (string)value; break;
|
||||
case SerializedPropertyType.Color:
|
||||
property.colorValue = (Color)value; break;
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
property.objectReferenceValue = (UnityEngine.Object)value; break;
|
||||
case SerializedPropertyType.ExposedReference:
|
||||
property.exposedReferenceValue = (UnityEngine.Object)value; break;
|
||||
case SerializedPropertyType.LayerMask:
|
||||
property.intValue = (int)value; break;
|
||||
case SerializedPropertyType.Enum:
|
||||
property.enumValueIndex = (int)value; break;
|
||||
case SerializedPropertyType.Vector2:
|
||||
property.vector2Value = (Vector2)value; break;
|
||||
case SerializedPropertyType.Vector3:
|
||||
property.vector3Value = (Vector3)value; break;
|
||||
case SerializedPropertyType.Vector4:
|
||||
property.vector4Value = (Vector4)value; break;
|
||||
case SerializedPropertyType.Rect:
|
||||
property.rectValue = (Rect)value; break;
|
||||
case SerializedPropertyType.AnimationCurve:
|
||||
property.animationCurveValue = (AnimationCurve)value; break;
|
||||
case SerializedPropertyType.Bounds:
|
||||
property.boundsValue = (Bounds)value; break;
|
||||
default:
|
||||
throw new NotImplementedException("Unimplemented propertyType " + property.propertyType + ".");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -14,7 +14,6 @@ namespace Obi{
|
||||
|
||||
private MethodInfo eventMethodInfo = null;
|
||||
private FieldInfo fieldInfo = null;
|
||||
private PropertyInfo propertyInfo = null;
|
||||
|
||||
public VisibleIf(string methodName, bool negate = false)
|
||||
{
|
||||
@@ -40,19 +39,13 @@ namespace Obi{
|
||||
// If we could not find a method with that name, look for a field:
|
||||
if (eventMethodInfo == null && fieldInfo == null)
|
||||
fieldInfo = eventOwnerType.GetField(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
// or maybe a property
|
||||
if (eventMethodInfo == null && fieldInfo == null && propertyInfo == null)
|
||||
propertyInfo = eventOwnerType.GetProperty(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
if (eventMethodInfo != null)
|
||||
|
||||
if (eventMethodInfo != null)
|
||||
return (bool)eventMethodInfo.Invoke(property.serializedObject.targetObject, null);
|
||||
else if (fieldInfo != null)
|
||||
return (bool)fieldInfo.GetValue(property.serializedObject.targetObject);
|
||||
else if (propertyInfo != null)
|
||||
return (bool)propertyInfo.GetValue(property.serializedObject.targetObject);
|
||||
else
|
||||
Debug.LogWarning(string.Format("VisibleIf: Unable to find method, field or property {0} in {1}", eventName, eventOwnerType));
|
||||
else
|
||||
Debug.LogWarning(string.Format("VisibleIf: Unable to find method or field {0} in {1}", eventName, eventOwnerType));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user