private void DrawHeader()
        {
            Rect titlePosition = GUILayoutUtility.GetRect(GUIContent.none, BTEditorStyle.RegionBackground, GUILayout.ExpandWidth(true), GUILayout.Height(15.0f));

            titlePosition.x     -= 19;
            titlePosition.y     -= 2;
            titlePosition.width += 28;

            Rect optionsButtonPosition = new Rect(titlePosition.xMax - 28.0f, titlePosition.y, 20.0f, 20.0f);

            DrawCategoryHeader(titlePosition, m_target.Title);
            if (GUI.Button(optionsButtonPosition, BTEditorStyle.OptionsIcon, EditorStyles.label))
            {
                GenericMenu menu = BTContextMenuFactory.CreateNodeInspectorContextMenu(m_target);
                menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
            }

            GUILayout.Space(2.5f);
            DrawSeparator();

            // show obsolete tip
            if (BTNodeObsoleteFactory.IsObsolete(m_target))
            {
                string tip = BTNodeObsoleteFactory.GetTipString(m_target);
                EditorGUILayout.HelpBox(tip, MessageType.Warning);
                GUILayout.Space(2.5f);
                DrawSeparator();
            }

            // show reference of class.
            string reference = BTNodeHelpBoxFactory.GetHelpString(m_target);

            if (!string.IsNullOrEmpty(reference))
            {
                EditorGUILayout.LabelField(reference, BTEditorStyle.HelpBox);
                GUILayout.Space(2.5f);
                DrawSeparator();
            }

            //m_target.Name = EditorGUILayout.TextField("Name", m_target.Name);
            EditorGUILayout.LabelField("Comment");
            m_target.Comment = EditorGUILayout.TextArea(m_target.Comment, BTEditorStyle.MultilineTextArea);

            if (m_graphNode.Parent != null && m_graphNode.Parent.Node is WeightedRandom)
            {
                EditorGUILayout.Space();
                m_target.Weight = EditorGUILayout.Slider("Weight", m_target.Weight, 0.0f, 1.0f);
            }

            GUILayout.Space(2.5f);
            DrawSeparator();
            EditorGUILayout.Space();
        }
Exemple #2
0
        protected void DrawDefaultProperties()
        {
            // show reference of class.
            string reference = BTNodeHelpBoxFactory.GetHelpString(m_target);

            if (!string.IsNullOrEmpty(reference))
            {
                EditorGUILayout.LabelField(reference, BTEditorStyle.HelpBox);
                //GUILayout.Space(2.5f);
                //DrawSeparator();
            }

            Type constraintType = m_target.GetType();
            var  fields         = from fi in constraintType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                  select fi;
            var properties = from pi in constraintType.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);
                    }
                }
            }
        }