예제 #1
0
    private StateOfEditor this[string key]
    {
        get{
            StateOfEditor e;
            if (_expand.TryGetValue(key, out e))
            {
                return(e);
            }
            else
            {
                e = new StateOfEditor();
                _expand.Add(key, e);
            }
            return(e);
        }

        set{
            if (_expand.ContainsKey(key))
            {
                _expand [key] = value;
            }
            else
            {
                _expand.Add(key, value);
            }
        }
    }
예제 #2
0
    private StateOfEditor DrawNode(Rect rect, TreeNode node, StateOfEditor expanded, bool haveChild, bool isRuning, RunStatus?state)
    {
        Color color = isRuning ? Color.yellow : Color.black;


        Color bg  = Color.white;
        var   att = GetNodeAtt(node.GetType());

        if (lastClick == node)
        {
            color = Color.green;
        }
        var name = node.GetType().Name;

        if (att != null)
        {
            name = att.ShorName + ":" + node.name + (state == null?"":state.Value.ToString());
            bg   = GetColorByShortName(att.ShorName);
        }

        if (haveChild)
        {
            expanded.Expanded = EditorGLTools.DrawExpandBox(rect, name,
                                                            expanded.OnEdited?string.Empty:node.ToString(),
                                                            expanded.Expanded, color, bg, isRuning ? 2 : 1);
        }
        else
        {
            EditorGLTools.DrawTitleRect(rect, name,
                                        expanded.OnEdited?string.Empty:node.ToString(),
                                        color, bg, isRuning ? 2 : 1);
        }

        if (lastClick == node)
        {
            if (GUI.Button(new Rect(rect.xMax - 50, rect.y, 50, 20), expanded.OnEdited?"Close":"Edit"))
            {
                expanded.OnEdited = !expanded.OnEdited;
            }
        }
        else
        {
            expanded.OnEdited = false;
        }

        if (expanded.OnEdited)
        {
            GUILayout.BeginArea(new Rect(rect.x, rect.y + 25, rect.width - 2, rect.height - 25));
            expanded.scroll = GUILayout.BeginScrollView(expanded.scroll);
            GUILayout.BeginVertical(GUILayout.Width(rect.width - 25));
            PropertyDrawer.DrawObject(node);
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
            GUILayout.EndArea();
        }


        if (currentDrag == node)
        {
            return(new StateOfEditor());
        }

        if (Event.current.type == EventType.ContextClick)
        {
            if (rect.Contains(Event.current.mousePosition))
            {
                GenericMenu m = new GenericMenu();
                m.AddItem(new GUIContent("Delete"), false, DeleteNode, node);
                //m.AddSeparator ("");
                ProcessMenu(m, node);
                m.ShowAsContext();
                Event.current.Use();
            }
        }

        if (lastClick != node)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                if (rect.Contains(Event.current.mousePosition))
                {
                    SetLastClick(node);
                    Event.current.Use();
                }
            }
        }

        if (Event.current.type == EventType.MouseDrag)
        {
            if (rect.Contains(Event.current.mousePosition))
            {
                if (currentDrag != null)
                {
                    if (currentDrag != node)
                    {
                        HoverType t = HoverType.Middle;
                        if (node != root)
                        {
                            t = GetHoverType(rect, Event.current.mousePosition.y);
                        }
                        DragHover(rect, t);
                        Event.current.Use();
                    }
                    else
                    {
                        currentShowDrag = null;
                        Event.current.Use();
                    }
                }
                else
                {
                    BeginDrag(node);
                    Event.current.Use();
                }
            }
        }

        if (Event.current.type == EventType.mouseUp)
        {
            if (currentDrag != null && currentDrag != node)
            {
                if (rect.Contains(Event.current.mousePosition))
                {
                    var t = GetHoverType(rect, Event.current.mousePosition.y);
                    EndDrag(node, t);
                    Event.current.Use();
                }
            }
        }

        return(expanded);
    }