public BehaviorTreeControl( ) : base()
        {
            m_nodes = new List< BehaviorNodeControl >();

            m_nodeCache = new EditorNodeTypeCache();
            m_nodeCache.CacheAvailableNodes();

            AddDecorator( new Scrollbars() );
            m_canvas = ( GraphicsCanvas )AddDecorator( new GraphicsCanvas() );

            m_linkLine = ( BezierCurve )m_canvas.AddShape( new BezierCurve( Vector2.zero, Vector2.zero, Color.red, 1.0f, BezierCurve.TangentMode.AutoY, Vector2.zero, Vector2.zero ) );
            m_linkLine.Tangents = BezierCurve.TangentMode.AutoY;

            ContextMenuControl ctx = new ContextMenuControl();            
            foreach ( EditorCachedNode node in m_nodeCache.Cache )
            {
                ctx.Menu.AddItem( new GUIContent( node.displayName ), false, AddNode, node );
            }
            ctx.Positionless = true;
            AddChild( ctx );
        }
        public BehaviorNodeControl( EditorCachedNode node )
        {
            m_fieldControls = new Dictionary<string, Control>();
            m_node = node;            

            int     lines    = 0;

            foreach( EditorCachedNodeField field in node.fields )
            {
                Control fieldControl = null;
                int l = 0;

                // Create fields per type
                if ( field.type == typeof( int ) )
                {
                    fieldControl = AddChild( new IntField( default( int ), field.name ) );
                    l = 1;
                }
                else if ( field.type == typeof( float ) )
                {
                    fieldControl = AddChild( new FloatField( default( float ), field.name ) );
                    l = 1;
                }
                else if ( field.type == typeof( Vector2 ) )
                {
                    fieldControl = AddChild( new Vector2Field( default( Vector2 ), field.name ) );
                    l = 2;
                }
                else if ( field.type == typeof( Vector3 ) )
                {
                    fieldControl = AddChild( new Vector3Field( default( Vector3 ), field.name ) );
                    l = 2;
                }
                else if ( field.type == typeof( Vector4 ) )
                {
                    fieldControl = AddChild( new Vector4Field( default( Vector4 ), field.name ) );
                    l = 2;
                }
                else if ( field.type == typeof( string ) )
                {
                    fieldControl = AddChild( new TextField( "", field.name ) );
                    l = 1;
                }
                else if ( field.type == typeof( Rect ) )
                {
                    fieldControl = AddChild( new RectField( default( Rect ), field.name ) );
                    l = 3;
                }
                else if ( field.type == typeof( Color ) )
                {
                    fieldControl = AddChild( new ColorField( default( Color ), field.name ) );
                    l = 1;
                }
                else if ( field.type == typeof( Bounds ) )
                {
                    fieldControl = AddChild( new BoundsField( default( Bounds ), field.name ) );
                    l = 3;
                }
                else if ( field.type.IsEnum )
                {
                    fieldControl = AddChild( new EnumDropdown( ( System.Enum )Activator.CreateInstance( field.type ), field.name ) );
                    l = 1;
                }
                else if ( field.type == typeof( bool ) )
                {
                    fieldControl = AddChild( new Toggle( field.name, false, false ) );
                    l = 1;
                }
                else
                {
                    Debug.LogWarning( string.Format( "Unsupported field type `{0}({1})` encountered in node `{2}`", field.name, field.type, node.displayName ) );
                }

                if ( fieldControl != null )
                {
                    m_fieldControls.Add( field.name, fieldControl );

                    fieldControl
                    .SetPosition( INNER_PADDING, HEADER_SIZE + LINE_SIZE * lines )
                    .SetSize( BOX_WIDTH - INNER_PADDING - INNER_PADDING, LINE_SIZE );

                    lines += l;
                }
            }

            if ( m_node.nodeType != BehaviorTrees.BehaviorNodeAttribute.NodeType.Leaf )
            { 
                lines++;    // Add extra line of padding at the bottom
            }

            m_canvas = (GraphicsCanvas)AddDecorator( new GraphicsCanvas() );

            SetHeight( HEADER_SIZE + FOOTER_PADDING + LINE_SIZE * lines );

            // Create outputs
            m_outputs = new List<BehaviorNodeControl>();
            m_outputButtons = new List<Button>();
            m_outputLines   = new List<BezierCurve>();

            UpdateOutputs();
        }