Exemplo n.º 1
0
        void DrawNodeWindowName()
        {
            NodeNameAttribute attr     = BTHelper.GetAttribute <NodeNameAttribute>(this.GetType());
            string            nodeName = attr == null?string.Format("<b>{0}</b>", Name) : attr.Name;

            GUILayout.Label(nodeName, BTStyle.STYLE_CENTERLABEL);
        }
Exemplo n.º 2
0
        private void DrawSelectNodeInfo()
        {
            if (mTree.FocusedGraph == null)
            {
                mInspectorRect.height = 0;
                GUILayout.BeginArea(Rect.zero);
                GUILayout.EndArea();
                return;
            }
            mInspectorRect.width = 320;
            mInspectorRect.x     = 10;
            mInspectorRect.y     = 50;
            GUISkin lastSkin = GUI.skin;

            GUI.Box(mInspectorRect, "", BTStyle.BVT_WindowShadow);

            NodeNameAttribute nameAttr = BTHelper.GetAttribute <NodeNameAttribute>(FocuseType);

            GUILayout.BeginArea(mInspectorRect, nameAttr != null ? nameAttr.Name : FocuseType.Name, new GUIStyle(BTStyle.BVT_Panel));
            GUILayout.Space(5);
            GUI.skin = null;

            if (BTSettings.ShowNodeInfo)
            {
                GUI.backgroundColor = new Color(0.8f, 0.8f, 1);
                NodeDescAttribute descAttr = BTHelper.GetAttribute <NodeDescAttribute>(FocuseType);
                EditorGUILayout.HelpBox(descAttr != null ? descAttr.Desc : string.Empty, MessageType.None, true);
                GUI.backgroundColor = Color.white;
                mTree.FocusedGraph.DrawNodeInspectorGUI();
            }

            GUILayout.Box("", GUILayout.Height(5), GUILayout.Width(mInspectorRect.width - 1));
            GUI.skin = lastSkin;
            if (Event.current.type == EventType.Repaint)
            {
                mInspectorRect.height = GUILayoutUtility.GetLastRect().yMax + 5;
            }
            GUILayout.EndArea();
        }
Exemplo n.º 3
0
        public virtual void DrawNodeInspectorGUI()
        {
            NodeComment = UnityEditor.EditorGUILayout.TextField("NodeComment", NodeComment);
            BTHelper.DrawSeparator();
            if (!AutoDrawNodeInspector)
            {
                return;
            }
            System.Reflection.FieldInfo[] fields = GetType().GetFields();
            for (int i = 0; i < fields.Length; i++)
            {
                System.Reflection.FieldInfo field = fields[i];
                if (field.IsDefined(typeof(NodeVariable), false))
                {
                    object v = field.GetValue(this);
                    Type   t = field.FieldType;

                    if (t.BaseType == typeof(Enum))
                    {
                        v = UnityEditor.EditorGUILayout.EnumPopup(field.Name, (Enum)v);
                    }
                    else if (t == typeof(int))
                    {
                        v = UnityEditor.EditorGUILayout.IntField(field.Name, (int)v);
                    }
                    else if (t == typeof(bool))
                    {
                        v = UnityEditor.EditorGUILayout.Toggle(field.Name, (bool)v);
                    }
                    else if (t == typeof(float))
                    {
                        v = UnityEditor.EditorGUILayout.FloatField(field.Name, (float)v);
                    }
                    else if (t == typeof(string))
                    {
                        v = UnityEditor.EditorGUILayout.TextField(field.Name, (string)v);
                    }
                    else if (t == typeof(UnityEngine.Object))
                    {
                        v = UnityEditor.EditorGUILayout.ObjectField(field.Name, (UnityEngine.Object)v, t, false);
                    }
                    else if (t == typeof(double))
                    {
                        v = UnityEditor.EditorGUILayout.DoubleField(field.Name, (double)v);
                    }
                    else if (t == typeof(Vector3))
                    {
                        v = UnityEditor.EditorGUILayout.Vector3Field(field.Name, (Vector3)v);
                    }
                    else if (t == typeof(Vector2))
                    {
                        v = UnityEditor.EditorGUILayout.Vector2Field(field.Name, (Vector2)v);
                    }
                    else if (t == typeof(AnimationCurve))
                    {
                        v = UnityEditor.EditorGUILayout.CurveField(field.Name, (AnimationCurve)v);
                    }
                    else if (t == typeof(Color))
                    {
                        v = UnityEditor.EditorGUILayout.ColorField(field.Name, (Color)v);
                    }
                    try
                    {
                        field.SetValue(this, v);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(ex.ToString());
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void DrawNodeGraphControls()
        {
            Event e = Event.current;

            if (e.button == 0 && e.type == EventType.MouseDown && mInspectorRect.Contains(e.mousePosition))
            {
                e.Use();
            }
            if (!mInspectorRect.Contains(e.mousePosition) &&
                !mBlackboardRect.Contains(e.mousePosition))
            {
                if (e.button == 0 && e.isMouse && e.type == EventType.MouseDown)
                {
                    mTree.FocusedNode = null;
                    return;
                }
                if (e.button == 1 && e.type == EventType.MouseDown)
                {
                    var pos = e.mousePosition + scrollPos;
                    BTHelper.ShowComponentsSelectionMenu(typeof(Node), (selectType) =>
                    {
                        Node graph            = mTree.AddGraph(selectType);
                        graph.NodeRect.center = pos;
                        mTree.FocusedNode     = graph;
                    });
                    e.Use();
                }
            }
            if (e.isKey && e.alt && e.keyCode == KeyCode.Q)
            {
                foreach (Node graph in mTree.AllNodes)
                {
                    graph.NodeRect.width  = Node.MinSize.x;
                    graph.NodeRect.height = Node.MinSize.y;
                }
                e.Use();
            }
            if (e.type == EventType.MouseUp || e.type == EventType.KeyUp)
            {
            }
            if (e.type == EventType.KeyDown && e.keyCode == KeyCode.F && GUIUtility.keyboardControl == 0)
            {
                if (BVTTree.AllNodes.Count > 0)
                {
                    FocusPosition(GetNodeBounds(BVTTree, viewRect, false).center);
                }
                else
                {
                    FocusPosition(VirtualCenter);
                }
            }
            if (e.type == EventType.MouseDown && e.button == 2 && e.clickCount == 2)
            {
                FocusPosition(ViewToCanvas(e.mousePosition));
            }
            if (e.type == EventType.ScrollWheel)
            {
                if (canvasRect.Contains(e.mousePosition))
                {
                    var zoomDelta = e.shift ? 0.1f : 0.25f;
                    ZoomAt(e.mousePosition, -e.delta.y > 0 ? zoomDelta : -zoomDelta);
                }
            }
            if ((e.button == 2 && e.type == EventType.MouseDrag && canvasRect.Contains(e.mousePosition)) ||
                ((e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.alt && e.isMouse))
            {
                Pan             += e.delta;
                smoothPan        = null;
                smoothZoomFactor = null;
                e.Use();
            }
            if (e.type == EventType.MouseDown && e.button == 2 && canvasRect.Contains(e.mousePosition))
            {
                mouseButton2Down = true;
            }
            if (e.type == EventType.MouseUp && e.button == 2)
            {
                mouseButton2Down = false;
            }
            if (mouseButton2Down == true)
            {
                EditorGUIUtility.AddCursorRect(new Rect(0, 0, Screen.width, Screen.height), MouseCursor.Pan);
            }
        }