コード例 #1
0
        private void GUI_token(GUIStyle style, BTNode node, BTLTokenizer.Token token)
        {
            var label = token.content.Replace("\t", "   ");

            if (clickedTask != null && clickedTaskFade < Time.realtimeSinceStartup)
            {
                clickedTask = null;
            }


#if UNITY_EDITOR
            var task = node as BTTask;

            if (task != null && task.boundState != BoundState.Bound)
            {
                style = BTLSyntaxHighlight.style_failed;
            }

            if (task != null && task.boundState == BoundState.Bound && token.type == BTLTokenizer.TokenType.Word)
            {
                if (GUILayout.Button(label, style) && Event.current.button == 0)
                {
                    if (clickedTask == task)
                    {
                        GUIBTScript.OpenScript(task.boundObject as MonoBehaviour, task.boundMember);
                    }

                    clickedTask     = task;
                    clickedTaskFade = Time.realtimeSinceStartup + 0.5f;
                }
            }
            else
            {
                GUILayout.Label(label, style);
            }
#else
            GUILayout.Label(label, style);
#endif
        }
コード例 #2
0
        public void OnGUI()
        {
            var node = this;

            GUINode._current = this;

            // Recompute rects when edit state has changed.
            if (GUIBTScript.isEventSafe)
            {
                if (isEdited == false && _isEditedPrev)
                {
                    SetDirty();
                }

                if (isEdited && _isEditedPrev == false)
                {
                    GUIBTScript.SelectionClear();
                }

                _isEditedPrev = isEdited;
            }

            if (node.nodeType == NodeType.TaskList)
            {
                OnGUI_TaskListSelector();
            }
            else
            {
                if ((node.isSelected || node == GUIBTScript.cursorNode) && !isRectDirty && !isEdited)
                {
                    OnGUI_OneBlock();
                }
                else
                {
                    OnGUI_ColoredNode();
                }
            }

            // Edit parameter when left mouse click.
            bool isClicked = Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.button == 0;
            var  mpos      = Event.current.mousePosition;

            if (!isRectDirty && !GUIBTScript.isCTRLPressed && isClicked && GUIBTScript.mode == GUIBTScript.Mode.Normal)
            {
                bool isParameterClicked = false;
                for (int i = 0; i < parameters.Count; i++)
                {
                    var r            = parameterRects[i];
                    var isWithinRect = r.Contains(mpos);
                    parameters[i].isEdited = isWithinRect;

                    if (isWithinRect)
                    {
                        isParameterClicked = true;
                    }
                }

                if (this.rect.Contains(mpos) && !isParameterClicked)
                {
                    bool isDoubleClicked = Time.realtimeSinceStartup - lastClickTime < 0.4f;
                    lastClickTime = Time.realtimeSinceStartup;
                    if (isDoubleClicked && this.nodeType == NodeType.Task && this.label.ToLower() != "tree")
                    {
                        GUIBTScript.OpenScript(this);
                    }
                }
            }

            // On press Enter or Esc stop editing the parameter.
            if (Event.current.isKey && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Escape))
            {
                foreach (var p in parameters)
                {
                    if (p.isEdited)
                    {
                        p.isEdited = false;
                    }
                }
            }

            // Locate mouse position in rect.
            if (Event.current.type == EventType.Repaint)
            {
                if (rect.Contains(mpos))
                {
                    isMouseOver = true;

                    if (GUIBTScript.cursorNode != node)
                    {
                        GUIBTScript.cursorNode = node;
                        //GUIBTScript.current.redraw = true;
                    }

                    float f  = 0.3f;
                    var   w  = rect.width;
                    var   wb = w * f;
                    var   h  = rect.height;
                    var   hb = h * f;

                    if (mpos.y < rect.y + hb)
                    {
                        mouseHoverPosition = MouseHoverPosition.Above;
                    }
                    else
                    if (mpos.y > rect.y + h - hb && node.line.children.Count == 0)
                    {
                        mouseHoverPosition = MouseHoverPosition.Below;
                    }
                    else
                    if (mpos.x < rect.x + wb)
                    {
                        mouseHoverPosition = MouseHoverPosition.Left;
                    }
                    else
                    if (mpos.x > rect.x + w - wb)
                    {
                        mouseHoverPosition = MouseHoverPosition.Right;
                    }
                    else
                    if (nodeType == NodeType.Structural && node.line.nodes[0] == node)
                    {
                        mouseHoverPosition = MouseHoverPosition.Center;
                    }
                }
                else
                {
                    isMouseOver = false;
                }
            }
            else if (node != GUIBTScript.cursorNode)
            {
                mouseHoverPosition = MouseHoverPosition.None;
            }
        }