去掉obi,使用自写绳索

This commit is contained in:
2026-02-23 20:51:03 +08:00
parent cb636f862d
commit 91e2309eeb
2011 changed files with 2593 additions and 190578 deletions

View File

@@ -1,45 +0,0 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class ChildrenOnly : MultiPropertyAttribute
{
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
float height = 0;
SerializedProperty it = property;
int depth = it.depth;
it.NextVisible(true);
do
{
EditorGUI.PropertyField(new Rect(position.x,position.y+height,position.width,EditorGUIUtility.singleLineHeight),it,true);
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}while (it.NextVisible(false) && it.depth != depth);
}
internal override float? GetPropertyHeight(SerializedProperty property, GUIContent label)
{
float height = -EditorGUIUtility.standardVerticalSpacing;
SerializedProperty it = property;
int depth = it.depth;
it.NextVisible(true);
do
{
height += EditorGUI.GetPropertyHeight(it, label) + EditorGUIUtility.standardVerticalSpacing;
}while (it.NextVisible(false) && it.depth != depth);
return height;
}
#endif
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 37995b0258e3041208a4b13bd6feb31c
timeCreated: 1511965883
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,26 +0,0 @@
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
#if UNITY_EDITOR
[System.AttributeUsage(System.AttributeTargets.Field)]
public class DisplayAs : MultiPropertyAttribute
{
string name;
public DisplayAs(string name)
{
this.name = name;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position,property,new GUIContent(name),true);
}
}
#endif
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: dd2e6690a4e514f0b93596b416ea6e1a
timeCreated: 1515069828
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,25 +0,0 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class Indent : MultiPropertyAttribute
{
#if UNITY_EDITOR
internal override void OnPreGUI(Rect position, SerializedProperty property)
{
EditorGUI.indentLevel++;
}
internal override void OnPostGUI(Rect position, SerializedProperty property)
{
EditorGUI.indentLevel--;
}
#endif
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: a02d36b0684b3461fad08bed56e9798c
timeCreated: 1511529530
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,56 +0,0 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Reflection;
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class InspectorButtonAttribute : PropertyAttribute
{
public static float kDefaultButtonWidth = 80;
public readonly string MethodName;
private float _buttonWidth = kDefaultButtonWidth;
public float ButtonWidth
{
get { return _buttonWidth; }
set { _buttonWidth = value; }
}
public InspectorButtonAttribute(string MethodName)
{
this.MethodName = MethodName;
}
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(InspectorButtonAttribute))]
public class InspectorButtonPropertyDrawer : PropertyDrawer
{
private MethodInfo _eventMethodInfo = null;
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
{
InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;
Rect buttonRect = new Rect(position.x + (position.width - inspectorButtonAttribute.ButtonWidth) * 0.5f, position.y, inspectorButtonAttribute.ButtonWidth, position.height);
if (GUI.Button(buttonRect, label.text))
{
System.Type eventOwnerType = prop.serializedObject.targetObject.GetType();
string eventName = inspectorButtonAttribute.MethodName;
if (_eventMethodInfo == null)
_eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (_eventMethodInfo != null)
_eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
else
Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
}
}
}
#endif
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: bada34fec41c44b4b90af1fe27ca7a95
timeCreated: 1440029519
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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
}
}

View File

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

View File

@@ -1,41 +0,0 @@
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class MinMaxAttribute : MultiPropertyAttribute
{
float min;
float max;
public MinMaxAttribute(float min, float max)
{
this.min = min;
this.max = max;
}
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType == SerializedPropertyType.Vector2){
float minValue = property.vector2Value.x;
float maxValue = property.vector2Value.y;
EditorGUI.MinMaxSlider(position, label, ref minValue, ref maxValue, min, max);
var vec = Vector2.zero;
vec.x = minValue;
vec.y = maxValue;
property.vector2Value = vec;
}else{
EditorGUI.LabelField(position, label.text, "Use MinMaxAttribute with Vector2.");
}
}
#endif
}
}

View File

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

View File

@@ -1,29 +0,0 @@
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class MultiDelayed : MultiPropertyAttribute
{
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Now draw the property as a Slider or an IntSlider based on whether it's a float or integer.
if (property.propertyType == SerializedPropertyType.Float)
EditorGUI.DelayedFloatField(position, property, label);
else if (property.propertyType == SerializedPropertyType.Integer)
EditorGUI.DelayedIntField(position, property, label);
else if (property.propertyType == SerializedPropertyType.String)
EditorGUI.DelayedTextField(position, property, label);
else
EditorGUI.LabelField(position, label.text, "Use MultiRange with float or int.");
}
#endif
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 17d0e7e43f7f844aba84497d6385c920
timeCreated: 1511969575
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,97 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public abstract class MultiPropertyAttribute : PropertyAttribute
{
#if UNITY_EDITOR
public IOrderedEnumerable<object> stored = null;
public virtual void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position,property,label,true);
}
internal virtual void OnPreGUI(Rect position, SerializedProperty property){}
internal virtual void OnPostGUI(Rect position, SerializedProperty property){}
internal virtual bool IsVisible(SerializedProperty property){return true;}
internal virtual float? GetPropertyHeight( SerializedProperty property, GUIContent label){return null;}
#endif
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(MultiPropertyAttribute),true)]
public class MultiPropertyDrawer : PropertyDrawer
{
private MultiPropertyAttribute RetrieveAttributes()
{
MultiPropertyAttribute mAttribute = attribute as MultiPropertyAttribute;
// Get the attribute list, sorted by "order".
if (mAttribute.stored == null)
{
mAttribute.stored = fieldInfo.GetCustomAttributes(typeof(MultiPropertyAttribute), false).OrderBy(s => ((PropertyAttribute)s).order);
}
return mAttribute;
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
MultiPropertyAttribute mAttribute = RetrieveAttributes();
// If the attribute is invisible, regain the standard vertical spacing.
foreach (MultiPropertyAttribute attr in mAttribute.stored)
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);
// Check if any of the attributes wants to modify height:
foreach (object atr in mAttribute.stored)
{
if (atr as MultiPropertyAttribute != null)
{
var tempheight = ((MultiPropertyAttribute)atr).GetPropertyHeight(property, label);
if (tempheight.HasValue)
{
height = tempheight.Value;
break;
}
}
}
return height;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
MultiPropertyAttribute mAttribute = RetrieveAttributes();
// Calls to IsVisible. If it returns false for any attribute, the property will not be rendered.
foreach (MultiPropertyAttribute attr in mAttribute.stored)
if (!attr.IsVisible(property)) return;
// Calls to OnPreRender before the last attribute draws the UI.
foreach (MultiPropertyAttribute attr in mAttribute.stored)
attr.OnPreGUI(position,property);
// The last attribute is in charge of actually drawing something:
((MultiPropertyAttribute)mAttribute.stored.Last()).OnGUI(position,property,label);
// Calls to OnPostRender after the last attribute draws the UI. These are called in inverse order.
foreach (MultiPropertyAttribute attr in mAttribute.stored.Reverse())
attr.OnPostGUI(position,property);
}
}
#endif
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 71f4de68ec5de40edbf3e4f24c49ba18
timeCreated: 1511952779
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,34 +0,0 @@
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class MultiRange : MultiPropertyAttribute
{
float min;
float max;
public MultiRange(float min, float max)
{
this.min = min;
this.max = max;
}
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Now draw the property as a Slider or an IntSlider based on whether it's a float or integer.
if (property.propertyType == SerializedPropertyType.Float)
EditorGUI.Slider(position, property, min, max, label);
else if (property.propertyType == SerializedPropertyType.Integer)
EditorGUI.IntSlider(position, property, (int)min, (int)max, label);
else
EditorGUI.LabelField(position, label.text, "Use MultiRange with float or int.");
}
#endif
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: ab2178abf0a6343e19742febdd9784e3
timeCreated: 1511954360
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,168 +0,0 @@
using System;
using System.Reflection;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class SerializeProperty : PropertyAttribute
{
public string PropertyName { get; private set; }
public SerializeProperty(string propertyName)
{
PropertyName = propertyName;
}
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(SerializeProperty))]
public class SerializePropertyAttributeDrawer : PropertyDrawer
{
private PropertyInfo propertyFieldInfo = null;
private object target = null;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (target == null)
target = GetSource(property);
// Find the property field using reflection, in order to get access to its getter/setter.
if (propertyFieldInfo == null)
propertyFieldInfo = target.GetType().GetProperty(((SerializeProperty)attribute).PropertyName,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (propertyFieldInfo != null)
{
// Retrieve the value using the property getter:
object value = propertyFieldInfo.GetValue(target,null);
// Draw the property:
EditorGUI.BeginProperty(position,label,property);
EditorGUI.BeginChangeCheck();
value = DrawProperty(position,property.propertyType,propertyFieldInfo.PropertyType,value,label);
// 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");
// Call property setter:
propertyFieldInfo.SetValue(t, value, null);
SetPropertyValue(property, propertyFieldInfo.PropertyType, value);
// Record prefab modification:
PrefabUtility.RecordPrefabInstancePropertyModifications(t);
}
}
EditorGUI.EndProperty();
}else
{
EditorGUI.LabelField(position,"Error: could not retrieve property.");
}
}
private object GetSource(SerializedProperty property)
{
object trgt = property.serializedObject.targetObject;
string[] data = property.propertyPath.Split('.');
if (data.Length == 1)
return trgt;
else{
for (int i = 0; i < data.Length-1;++i){
trgt = trgt.GetType().GetField(data[i]).GetValue(trgt);
}
}
return trgt;
}
private object DrawProperty(Rect position, SerializedPropertyType propertyType, Type type, object value, GUIContent label)
{
switch (propertyType)
{
case SerializedPropertyType.Integer:
return EditorGUI.IntField(position,label,(int)value);
case SerializedPropertyType.Boolean:
return EditorGUI.Toggle(position,label,(bool)value);
case SerializedPropertyType.Float:
return EditorGUI.FloatField(position,label,(float)value);
case SerializedPropertyType.String:
return EditorGUI.TextField(position,label,(string)value);
case SerializedPropertyType.Color:
return EditorGUI.ColorField(position,label,(Color)value);
case SerializedPropertyType.ObjectReference:
return EditorGUI.ObjectField(position,label,(UnityEngine.Object)value,type,true);
case SerializedPropertyType.ExposedReference:
return EditorGUI.ObjectField(position,label,(UnityEngine.Object)value,type,true);
case SerializedPropertyType.LayerMask:
return EditorGUI.LayerField(position,label,(int)value);
case SerializedPropertyType.Enum:
return EditorGUI.EnumPopup(position,label,(Enum)value);
case SerializedPropertyType.Vector2:
return EditorGUI.Vector2Field(position,label,(Vector2)value);
case SerializedPropertyType.Vector3:
return EditorGUI.Vector3Field(position,label,(Vector3)value);
case SerializedPropertyType.Vector4:
return EditorGUI.Vector4Field(position,label,(Vector4)value);
case SerializedPropertyType.Rect:
return EditorGUI.RectField(position,label,(Rect)value);
case SerializedPropertyType.AnimationCurve:
return EditorGUI.CurveField(position,label,(AnimationCurve)value);
case SerializedPropertyType.Bounds:
return EditorGUI.BoundsField(position,label,(Bounds)value);
default:
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
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 9b22b3eff389444b1b4ab3bc2d6402b6
timeCreated: 1511456560
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,63 +0,0 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Reflection;
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class VisibleIf : MultiPropertyAttribute
{
public string MethodName { get; private set; }
public bool Negate {get; private set;}
private MethodInfo eventMethodInfo = null;
private FieldInfo fieldInfo = null;
private PropertyInfo propertyInfo = null;
public VisibleIf(string methodName, bool negate = false)
{
this.MethodName = methodName;
this.Negate = negate;
}
#if UNITY_EDITOR
internal override bool IsVisible(SerializedProperty property)
{
return Visibility(property) == !Negate;
}
private bool Visibility(SerializedProperty property)
{
System.Type eventOwnerType = property.serializedObject.targetObject.GetType();
string eventName = MethodName;
// Try finding a method with the name provided:
if (eventMethodInfo == null)
eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
// 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)
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));
return true;
}
#endif
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: e52da649989a94da8b1a5d1e1fe5ff8a
timeCreated: 1511456085
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: