Esempio n. 1
0
        protected void DrawDefaultProperties()
        {
            Type serviceType = m_target.GetType();
            var  fields      = from fi in serviceType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                               select fi;
            var properties = from pi in serviceType.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);
                    }
                }
            }
        }
Esempio n. 2
0
        private void DrawTransitions()
        {
            Vector2            nodeSize   = BTEditorStyle.GetNodeSize(m_node);
            Rect               position   = new Rect(NodePosition + BTEditorCanvas.Current.Position, nodeSize);
            BTEditorTreeLayout treeLayout = BTEditorStyle.TreeLayout;

            foreach (var child in m_children)
            {
                Vector2       childNodeSize = BTEditorStyle.GetNodeSize(child.Node);
                Rect          childPosition = new Rect(child.Node.Position + BTEditorCanvas.Current.Position, childNodeSize);
                RunningStatus childStatus   = BTEditorCanvas.Current.IsDebuging ? GetNodeStatus(child.Node) : RunningStatus.None;
                Color         color         = BTEditorStyle.GetTransitionColor(childStatus);
                Vector2       nodeCenter    = position.center;
                Vector2       childCenter   = childPosition.center;

                if (treeLayout == BTEditorTreeLayout.Vertical)
                {
                    if (Mathf.Approximately(nodeCenter.y, childCenter.y) || Mathf.Approximately(nodeCenter.x, childCenter.x))
                    {
                        BTEditorUtils.DrawLine(nodeCenter, childCenter, color);
                    }
                    else
                    {
                        BTEditorUtils.DrawLine(nodeCenter, nodeCenter + Vector2.up * (childCenter.y - nodeCenter.y) / 2, color);

                        BTEditorUtils.DrawLine(nodeCenter + Vector2.up * (childCenter.y - nodeCenter.y) / 2,
                                               childCenter + Vector2.up * (nodeCenter.y - childCenter.y) / 2, color);

                        BTEditorUtils.DrawLine(childCenter, childCenter + Vector2.up * (nodeCenter.y - childCenter.y) / 2, color);
                    }
                }
                else if (treeLayout == BTEditorTreeLayout.Horizontal)
                {
                    //BTEditorUtils.DrawBezier(nodeCenter, childCenter, color);
                    Vector2 nodeRight = new Vector2(position.center.x + nodeSize.x / 2, position.center.y);
                    Vector2 childLeft = new Vector2(childPosition.center.x - childNodeSize.x / 2, childPosition.center.y);
                    BTEditorUtils.DrawBezier(nodeRight, childLeft, color);
                }
                else
                {
                    BTEditorUtils.DrawLine(nodeCenter, childCenter, color);
                }
            }
        }
Esempio n. 3
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);
                    }
                }
            }
        }