mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-20 00:36:44 +08:00
Merge branch 'cachedAttributes'
This commit is contained in:
commit
8f33f5ddf3
@ -45,7 +45,7 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
float spacePadding = 0;
|
float spacePadding = 0;
|
||||||
SpaceAttribute spaceAttribute;
|
SpaceAttribute spaceAttribute;
|
||||||
if(NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out spaceAttribute)) spacePadding = spaceAttribute.height;
|
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out spaceAttribute)) spacePadding = spaceAttribute.height;
|
||||||
|
|
||||||
// If property is an input, display a regular property field and put a port handle on the left side
|
// If property is an input, display a regular property field and put a port handle on the left side
|
||||||
if (port.direction == XNode.NodePort.IO.Input) {
|
if (port.direction == XNode.NodePort.IO.Input) {
|
||||||
@ -53,15 +53,15 @@ namespace XNodeEditor {
|
|||||||
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
|
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
|
||||||
XNode.Node.InputAttribute inputAttribute;
|
XNode.Node.InputAttribute inputAttribute;
|
||||||
bool instancePortList = false;
|
bool instancePortList = false;
|
||||||
if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out inputAttribute)) {
|
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out inputAttribute)) {
|
||||||
instancePortList = inputAttribute.instancePortList;
|
instancePortList = inputAttribute.instancePortList;
|
||||||
showBacking = inputAttribute.backingValue;
|
showBacking = inputAttribute.backingValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
|
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
|
||||||
bool useLayoutSpace = instancePortList
|
bool useLayoutSpace = instancePortList ||
|
||||||
|| showBacking == XNode.Node.ShowBackingValue.Never
|
showBacking == XNode.Node.ShowBackingValue.Never ||
|
||||||
|| (showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
|
(showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
|
||||||
if (spacePadding > 0 && useLayoutSpace) {
|
if (spacePadding > 0 && useLayoutSpace) {
|
||||||
GUILayout.Space(spacePadding);
|
GUILayout.Space(spacePadding);
|
||||||
spacePadding = 0;
|
spacePadding = 0;
|
||||||
@ -98,17 +98,16 @@ namespace XNodeEditor {
|
|||||||
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
|
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
|
||||||
XNode.Node.OutputAttribute outputAttribute;
|
XNode.Node.OutputAttribute outputAttribute;
|
||||||
bool instancePortList = false;
|
bool instancePortList = false;
|
||||||
if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out outputAttribute)) {
|
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out outputAttribute)) {
|
||||||
instancePortList = outputAttribute.instancePortList;
|
instancePortList = outputAttribute.instancePortList;
|
||||||
showBacking = outputAttribute.backingValue;
|
showBacking = outputAttribute.backingValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
|
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
|
||||||
bool useLayoutSpace = instancePortList
|
bool useLayoutSpace = instancePortList ||
|
||||||
|| showBacking == XNode.Node.ShowBackingValue.Never
|
showBacking == XNode.Node.ShowBackingValue.Never ||
|
||||||
|| (showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
|
(showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
|
||||||
if (spacePadding > 0 && useLayoutSpace)
|
if (spacePadding > 0 && useLayoutSpace) {
|
||||||
{
|
|
||||||
GUILayout.Space(spacePadding);
|
GUILayout.Space(spacePadding);
|
||||||
spacePadding = 0;
|
spacePadding = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,9 @@ namespace XNodeEditor {
|
|||||||
/// <summary>C#'s Script Icon [The one MonoBhevaiour Scripts have].</summary>
|
/// <summary>C#'s Script Icon [The one MonoBhevaiour Scripts have].</summary>
|
||||||
private static Texture2D scriptIcon = (EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D);
|
private static Texture2D scriptIcon = (EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D);
|
||||||
|
|
||||||
|
/// Saves Attribute from Type+Field for faster lookup. Resets on recompiles.
|
||||||
|
private static Dictionary<Type, Dictionary<string, Dictionary<Type, Attribute>>> typeAttributes = new Dictionary<Type, Dictionary<string, Dictionary<Type, Attribute>>>();
|
||||||
|
|
||||||
public static bool GetAttrib<T>(Type classType, out T attribOut) where T : Attribute {
|
public static bool GetAttrib<T>(Type classType, out T attribOut) where T : Attribute {
|
||||||
object[] attribs = classType.GetCustomAttributes(typeof(T), false);
|
object[] attribs = classType.GetCustomAttributes(typeof(T), false);
|
||||||
return GetAttrib(attribs, out attribOut);
|
return GetAttrib(attribs, out attribOut);
|
||||||
@ -45,6 +48,34 @@ namespace XNodeEditor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool GetCachedAttrib<T>(Type classType, string fieldName, out T attribOut) where T : Attribute {
|
||||||
|
Dictionary<string, Dictionary<Type, Attribute>> typeFields;
|
||||||
|
if (!typeAttributes.TryGetValue(classType, out typeFields)) {
|
||||||
|
typeFields = new Dictionary<string, Dictionary<Type, Attribute>>();
|
||||||
|
typeAttributes.Add(classType, typeFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<Type, Attribute> typeTypes;
|
||||||
|
if (!typeFields.TryGetValue(fieldName, out typeTypes)) {
|
||||||
|
typeTypes = new Dictionary<Type, Attribute>();
|
||||||
|
typeFields.Add(fieldName, typeTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
Attribute attr;
|
||||||
|
if (!typeTypes.TryGetValue(typeof(T), out attr)) {
|
||||||
|
if (GetAttrib<T>(classType, fieldName, out attribOut)) typeTypes.Add(typeof(T), attribOut);
|
||||||
|
else typeTypes.Add(typeof(T), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attr == null) {
|
||||||
|
attribOut = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribOut = attr as T;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Returns true if this can be casted to <see cref="Type"/></summary>
|
/// <summary> Returns true if this can be casted to <see cref="Type"/></summary>
|
||||||
public static bool IsCastableTo(this Type from, Type to) {
|
public static bool IsCastableTo(this Type from, Type to) {
|
||||||
if (to.IsAssignableFrom(from)) return true;
|
if (to.IsAssignableFrom(from)) return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user