protected void DrawDefaultProperties() { Type nodeType = m_target.GetType(); var fields = from fi in nodeType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) select fi; var properties = from pi in nodeType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) select pi; foreach (var field in fields) { BTPropertyAttribute propertyAttribute = Attribute.GetCustomAttribute(field, typeof(BTPropertyAttribute)) as BTPropertyAttribute; BTIgnoreAttribute ignoreAttribute = Attribute.GetCustomAttribute(field, typeof(BTIgnoreAttribute)) as BTIgnoreAttribute; BTHideInInspectorAttribute hideAttribute = Attribute.GetCustomAttribute(field, typeof(BTHideInInspectorAttribute)) as BTHideInInspectorAttribute; string label = BTEditorUtils.MakePrettyName(field.Name); if (ignoreAttribute != null || hideAttribute != null || (propertyAttribute == null && field.IsPrivate)) { continue; } if (field.FieldType == typeof(MemoryVar)) { DrawMemoryVarField(label, (MemoryVar)field.GetValue(m_target)); } else { object value = null; if (TryToDrawField(label, field.GetValue(m_target), field.FieldType, out value)) { field.SetValue(m_target, value); } } } foreach (var property in properties) { BTPropertyAttribute propertyAttribute = Attribute.GetCustomAttribute(property, typeof(BTPropertyAttribute)) as BTPropertyAttribute; BTIgnoreAttribute ignoreAttribute = Attribute.GetCustomAttribute(property, typeof(BTIgnoreAttribute)) as BTIgnoreAttribute; BTHideInInspectorAttribute hideAttribute = Attribute.GetCustomAttribute(property, typeof(BTHideInInspectorAttribute)) as BTHideInInspectorAttribute; var setterMethod = property.GetSetMethod(true); string label = BTEditorUtils.MakePrettyName(property.Name); if (setterMethod == null || ignoreAttribute != null || hideAttribute != null || (propertyAttribute == null && setterMethod.IsPrivate)) { continue; } if (property.PropertyType == typeof(MemoryVar)) { DrawMemoryVarField(label, (MemoryVar)property.GetValue(m_target, null)); } else { object value = null; if (TryToDrawField(label, property.GetValue(m_target, null), property.PropertyType, out value)) { property.SetValue(m_target, value, null); } } } }
/// <summary> /// Create a node from an existing behaviour. /// </summary> /// <param name="behaviour"></param> /// <returns></returns> public BonsaiNode CreateNode(BehaviourNode behaviour) { var node = CreateEditorNode(behaviour.GetType()); node.Behaviour = behaviour; return(node); }
// Does a quick calculation to see how many pixels the type name takes up. private static float calculateNameWidth(BehaviourNode node) { string typename = node.GetType().Name; string niceName = ObjectNames.NicifyVariableName(typename); var content = new GUIContent(niceName); Vector2 size = new GUIStyle().CalcSize(content); return(size.x + BonsaiNode.resizePaddingX); }
/// <summary> /// Links the source with the other node. /// </summary> /// <param name="source"></param> /// <param name="other"></param> /// <returns>True if the link was applied.</returns> public static bool ApplyLink(BehaviourNode source, BehaviourNode other) { var key = new LinkArguments(source.GetType(), other.GetType()); if (linkActions.TryGetValue(key, out LinkAction linker)) { linker(source, other); return(true); } return(false); }
public static void PrintTree(BehaviourNode tree, string indent, bool last) { Debug.Log(indent + "+- " + tree.GetType()); indent += last ? " " : "| "; if (tree.getNextNodes() != null) { for (int i = 0; i < tree.getNextNodes().Count; i++) { if (tree.getNextNodes()[i] != null) { PrintTree(tree.getNextNodes()[i], indent, i == tree.getNextNodes().Count - 1); } } } }
private Dictionary <string, FieldInfo> GetRuntimeFields(BehaviourNode target) { return(target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Where(f => f.GetCustomAttribute <ShowAtRuntimeAttribute>() != null) .ToDictionary(f => RuntimeFieldLabel(f), f => f)); }
private string NiceName() { return(ObjectNames.NicifyVariableName(behaviour.GetType().Name)); }