Example #1
0
        internal void OnPointEventHandle(Event e, TaskContentBase content)
        {
            switch (e.type)
            {
            case EventType.MouseDown:
                if (e.button == 0)
                {
                    _leftWiredOrigin.x  += Anchor.x;
                    _leftWiredOrigin.y  += Anchor.y;
                    _rightWiredOrigin.x += Anchor.x;
                    _rightWiredOrigin.y += Anchor.y;

                    if (_leftWiredOrigin.Contains(e.mousePosition))
                    {
                        _isWired      = true;
                        _isWiredRight = false;
                    }
                    else if (_rightWiredOrigin.Contains(e.mousePosition))
                    {
                        _isWired      = true;
                        _isWiredRight = true;
                    }
                    else if (Anchor.Contains(e.mousePosition))
                    {
                        _isDraging  = true;
                        _isSelected = true;
                        GUI.changed = true;
                        GUI.FocusControl(null);
                    }
                    else
                    {
                        _isSelected    = false;
                        _isEditID      = false;
                        _isEditName    = false;
                        _isEditDetails = false;
                        GUI.changed    = true;
                    }
                }
                else if (e.button == 1)
                {
                    if (_isSelected)
                    {
                        _leftWiredOrigin.x  += Anchor.x;
                        _leftWiredOrigin.y  += Anchor.y;
                        _rightWiredOrigin.x += Anchor.x;
                        _rightWiredOrigin.y += Anchor.y;

                        if (_leftWiredOrigin.Contains(e.mousePosition))
                        {
                            GenericMenu gm    = new GenericMenu();
                            int         index = content.Points.IndexOf(this);
                            for (int i = 0; i < content.Points.Count; i++)
                            {
                                if (i != index)
                                {
                                    int  m       = i;
                                    bool isExist = content.IsExistDepend(index, m);
                                    gm.AddItem(new GUIContent(content.Points[m].Name), isExist, () =>
                                    {
                                        if (isExist)
                                        {
                                            content.DisconnectDepend(index, m);
                                        }
                                        else
                                        {
                                            content.ConnectDepend(index, m);
                                        }
                                    });
                                }
                            }
                            gm.ShowAsContext();
                        }
                        else if (_rightWiredOrigin.Contains(e.mousePosition))
                        {
                            GenericMenu gm    = new GenericMenu();
                            int         index = content.Points.IndexOf(this);
                            for (int i = 0; i < content.Points.Count; i++)
                            {
                                if (i != index)
                                {
                                    int  m       = i;
                                    bool isExist = content.IsExistDepend(m, index);
                                    gm.AddItem(new GUIContent(content.Points[m].Name), isExist, () =>
                                    {
                                        if (isExist)
                                        {
                                            content.DisconnectDepend(m, index);
                                        }
                                        else
                                        {
                                            content.ConnectDepend(m, index);
                                        }
                                    });
                                }
                            }
                            gm.ShowAsContext();
                        }
                        else if (Anchor.Contains(e.mousePosition))
                        {
                            RightClickMenu(content);
                            e.Use();
                        }
                    }
                }
                break;

            case EventType.MouseUp:
                int upIndex;
                if (ChoosePoint(Event.current.mousePosition, content, out upIndex))
                {
                    if (_isWired)
                    {
                        int originIndex = content.Points.IndexOf(this);
                        if (originIndex != upIndex)
                        {
                            if (_isWiredRight)
                            {
                                if (content.IsExistDepend(upIndex, originIndex))
                                {
                                    content.DisconnectDepend(upIndex, originIndex);
                                }
                                else
                                {
                                    content.ConnectDepend(upIndex, originIndex);
                                }
                            }
                            else
                            {
                                if (content.IsExistDepend(originIndex, upIndex))
                                {
                                    content.DisconnectDepend(originIndex, upIndex);
                                }
                                else
                                {
                                    content.ConnectDepend(originIndex, upIndex);
                                }
                            }
                        }
                    }
                }

                _isDraging = false;
                if (_isWired)
                {
                    _isWired    = false;
                    GUI.changed = true;
                }
                break;

            case EventType.MouseDrag:
                if (_isWired)
                {
                    GUI.changed = true;
                }
                else if (_isDraging)
                {
                    OnDrag(e.delta);
                    e.Use();
                    GUI.changed = true;
                }
                break;
            }
        }
        /// <summary>
        /// 事件处理
        /// </summary>
        internal void OnPointEventHandle(Event e, TaskContentAsset asset, TaskContentBase content, HTFFunc <string, string> getWord)
        {
            switch (e.type)
            {
            case EventType.MouseDown:
                if (e.button == 0)
                {
                    _leftWiredOrigin.x  += Anchor.x;
                    _leftWiredOrigin.y  += Anchor.y;
                    _rightWiredOrigin.x += Anchor.x;
                    _rightWiredOrigin.y += Anchor.y;

                    if (_leftWiredOrigin.Contains(e.mousePosition))
                    {
                        _isWired      = true;
                        _isWiredRight = false;
                        e.Use();
                    }
                    else if (_rightWiredOrigin.Contains(e.mousePosition))
                    {
                        _isWired      = true;
                        _isWiredRight = true;
                        e.Use();
                    }
                    else if (Anchor.Contains(e.mousePosition))
                    {
                        IsDraging   = true;
                        IsSelected  = true;
                        GUI.changed = true;
                        GUI.FocusControl(null);
                        e.Use();
                    }
                    else
                    {
                        IsSelected  = false;
                        GUI.changed = true;
                    }
                }
                else if (e.button == 1)
                {
                    if (IsSelected)
                    {
                        _leftWiredOrigin.x  += Anchor.x;
                        _leftWiredOrigin.y  += Anchor.y;
                        _rightWiredOrigin.x += Anchor.x;
                        _rightWiredOrigin.y += Anchor.y;

                        if (_leftWiredOrigin.Contains(e.mousePosition))
                        {
                            GenericMenu gm    = new GenericMenu();
                            int         index = content.Points.IndexOf(this);
                            for (int i = 0; i < content.Points.Count; i++)
                            {
                                if (i != index)
                                {
                                    int  m       = i;
                                    bool isExist = content.IsExistDepend(index, m);
                                    gm.AddItem(new GUIContent(content.Points[m].Name), isExist, () =>
                                    {
                                        if (isExist)
                                        {
                                            content.DisconnectDepend(index, m);
                                        }
                                        else
                                        {
                                            content.ConnectDepend(index, m);
                                        }
                                        e.Use();
                                    });
                                }
                            }
                            gm.ShowAsContext();
                        }
                        else if (_rightWiredOrigin.Contains(e.mousePosition))
                        {
                            GenericMenu gm    = new GenericMenu();
                            int         index = content.Points.IndexOf(this);
                            for (int i = 0; i < content.Points.Count; i++)
                            {
                                if (i != index)
                                {
                                    int  m       = i;
                                    bool isExist = content.IsExistDepend(m, index);
                                    gm.AddItem(new GUIContent(content.Points[m].Name), isExist, () =>
                                    {
                                        if (isExist)
                                        {
                                            content.DisconnectDepend(m, index);
                                        }
                                        else
                                        {
                                            content.ConnectDepend(m, index);
                                        }
                                        e.Use();
                                    });
                                }
                            }
                            gm.ShowAsContext();
                        }
                        else if (Anchor.Contains(e.mousePosition))
                        {
                            GenericMenu gm = new GenericMenu();
                            gm.AddItem(new GUIContent(getWord("Edit Point Script")), false, () =>
                            {
                                MonoScript monoScript = MonoScript.FromScriptableObject(this);
                                AssetDatabase.OpenAsset(monoScript);
                                e.Use();
                            });
                            gm.AddItem(new GUIContent(getWord("Delete Point")), false, () =>
                            {
                                if (EditorUtility.DisplayDialog("Delete Task Point", "Are you sure you want to delete task point [" + Name + "]?", "Yes", "No"))
                                {
                                    DeletePoint(asset, content);
                                    GUI.changed = true;
                                    e.Use();
                                }
                            });
                            OnRightClickMenu(gm);
                            gm.ShowAsContext();
                        }
                    }
                }
                break;

            case EventType.MouseUp:
                if (_isWired)
                {
                    int chooseIndex;
                    if (ChoosePoint(e.mousePosition, content, out chooseIndex))
                    {
                        int originIndex = content.Points.IndexOf(this);
                        if (originIndex != chooseIndex)
                        {
                            if (_isWiredRight)
                            {
                                if (content.IsExistDepend(chooseIndex, originIndex))
                                {
                                    content.DisconnectDepend(chooseIndex, originIndex);
                                }
                                else
                                {
                                    content.ConnectDepend(chooseIndex, originIndex);
                                }
                            }
                            else
                            {
                                if (content.IsExistDepend(originIndex, chooseIndex))
                                {
                                    content.DisconnectDepend(originIndex, chooseIndex);
                                }
                                else
                                {
                                    content.ConnectDepend(originIndex, chooseIndex);
                                }
                            }
                        }
                        e.Use();
                    }

                    _isWired    = false;
                    GUI.changed = true;
                }
                IsDraging = false;
                break;

            case EventType.MouseDrag:
                if (_isWired)
                {
                    GUI.changed = true;
                }
                else if (IsDraging)
                {
                    OnDrag(e.delta);
                    GUI.changed = true;
                }
                break;

            case EventType.KeyDown:
                switch (e.keyCode)
                {
                case KeyCode.Delete:
                    if (IsSelected)
                    {
                        if (EditorUtility.DisplayDialog("Delete Task Point", "Are you sure you want to delete task point [" + Name + "]?", "Yes", "No"))
                        {
                            DeletePoint(asset, content);
                            GUI.changed = true;
                        }
                    }
                    break;
                }
                break;
            }
        }
Example #3
0
        internal int OnDependGUI(TaskContentBase taskContent)
        {
            int height = 0;

            GUILayout.BeginHorizontal();
            GUIContent gUIContent = EditorGUIUtility.IconContent("DotFrameDotted");

            gUIContent.tooltip = "Dependent task point";
            if (GUILayout.Button(gUIContent, "InvisibleButton", GUILayout.Width(20), GUILayout.Height(20)))
            {
                GenericMenu gm    = new GenericMenu();
                int         index = taskContent.Points.IndexOf(this);
                for (int i = 0; i < taskContent.Points.Count; i++)
                {
                    if (i != index)
                    {
                        int  m       = i;
                        bool isExist = taskContent.IsExistDepend(index, m);
                        gm.AddItem(new GUIContent(taskContent.Points[m].Name), isExist, () =>
                        {
                            if (isExist)
                            {
                                taskContent.DisconnectDepend(index, m);
                            }
                            else
                            {
                                taskContent.ConnectDepend(index, m);
                            }
                        });
                    }
                }
                gm.ShowAsContext();
            }
            GUILayout.FlexibleSpace();
            gUIContent.tooltip = "Be dependent task point";
            if (GUILayout.Button(gUIContent, "InvisibleButton", GUILayout.Width(20), GUILayout.Height(20)))
            {
                GenericMenu gm    = new GenericMenu();
                int         index = taskContent.Points.IndexOf(this);
                for (int i = 0; i < taskContent.Points.Count; i++)
                {
                    if (i != index)
                    {
                        int  m       = i;
                        bool isExist = taskContent.IsExistDepend(m, index);
                        gm.AddItem(new GUIContent(taskContent.Points[m].Name), isExist, () =>
                        {
                            if (isExist)
                            {
                                taskContent.DisconnectDepend(m, index);
                            }
                            else
                            {
                                taskContent.ConnectDepend(m, index);
                            }
                        });
                    }
                }
                gm.ShowAsContext();
            }
            GUILayout.EndHorizontal();

            height += 20;

            return(height);
        }