/// <summary>
        /// 绘制工具栏
        /// </summary>
        /// <returns>绘制高度</returns>
        private int OnToolbarGUI(TaskContentAsset asset, TaskContentBase content)
        {
            int height = 0;

            GUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            GUIContent gUIContent = new GUIContent();

            gUIContent.image   = EditorGUIUtility.IconContent("d_editicon.sml").image;
            gUIContent.tooltip = "Edit Point Script";
            if (GUILayout.Button(gUIContent, "InvisibleButton", GUILayout.Width(20), GUILayout.Height(20)))
            {
                MonoScript monoScript = MonoScript.FromScriptableObject(this);
                AssetDatabase.OpenAsset(monoScript);
            }

            gUIContent.image   = EditorGUIUtility.IconContent("TreeEditor.Trash").image;
            gUIContent.tooltip = "Delete";
            if (GUILayout.Button(gUIContent, "InvisibleButton", GUILayout.Width(20), GUILayout.Height(20)))
            {
                if (EditorUtility.DisplayDialog("Delete Task Point", "Are you sure you want to delete task point [" + Name + "]?", "Yes", "No"))
                {
                    DeletePoint(asset, content);
                    GUI.changed = true;
                }
            }

            GUILayout.EndHorizontal();

            height += 20;

            return(height);
        }
        /// <summary>
        /// 删除任务点
        /// </summary>
        private void DeletePoint(TaskContentAsset asset, TaskContentBase content)
        {
            int index = content.Points.IndexOf(this);

            for (int i = 0; i < content.Depends.Count; i++)
            {
                TaskDepend depend = content.Depends[i];
                if (depend.OriginalPoint == index || depend.DependPoint == index)
                {
                    content.Depends.RemoveAt(i);
                    i -= 1;
                }
                else
                {
                    if (depend.OriginalPoint > index)
                    {
                        depend.OriginalPoint -= 1;
                    }
                    if (depend.DependPoint > index)
                    {
                        depend.DependPoint -= 1;
                    }
                }
            }

            content.Points.Remove(this);
            TaskContentAsset.DestroySerializeSubObject(this, asset);
        }
Exemplo n.º 3
0
        public static void ShowWindow(TaskContentAsset contentAsset)
        {
            TaskEditorWindow window = GetWindow <TaskEditorWindow>();

            window.titleContent.image = EditorGUIUtility.IconContent("AnimatorStateMachine Icon").image;
            window.titleContent.text  = "Task Editor";
            window._asset             = contentAsset;
            window.minSize            = new Vector2(800, 600);
            window.maxSize            = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
            window.Show();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 克隆任务点
        /// </summary>
        private void ClonePoint(TaskContentBase content, TaskPointBase point, Vector2 pos)
        {
            TaskPointBase taskPoint = point.Clone();

            taskPoint.Anchor = new Rect(pos.x, pos.y, 0, 0);
            taskPoint.GUID   = _contentAsset.TaskPointIDName + _contentAsset.TaskPointIDSign.ToString();
            _contentAsset.TaskPointIDSign += 1;
            content.Points.Add(taskPoint);

            TaskContentAsset.GenerateSerializeSubObject(taskPoint, _contentAsset);
        }
Exemplo n.º 5
0
        public static void ShowWindow(TaskEditorWindow taskEditorWindow, TaskContentAsset contentAsset)
        {
            TaskRegenIDWindow window = GetWindow <TaskRegenIDWindow>();

            window.titleContent.image = EditorGUIUtility.IconContent("d_editicon.sml").image;
            window.titleContent.text  = "Regen Task ID";
            window._taskEditorWindow  = taskEditorWindow;
            window._contentAsset      = contentAsset;
            window.minSize            = new Vector2(220, 160);
            window.maxSize            = new Vector2(220, 160);
            window.position           = new Rect(taskEditorWindow.position.x + 50, taskEditorWindow.position.y + 50, 200, 110);
            window.Show();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 新增任务点
        /// </summary>
        private void AddPoint(TaskContentBase content, Type type, Vector2 pos)
        {
            TaskPointAttribute attribute = type.GetCustomAttribute <TaskPointAttribute>();
            TaskPointBase      taskPoint = CreateInstance(type) as TaskPointBase;

            taskPoint.Anchor = new Rect(pos.x, pos.y, 0, 0);
            taskPoint.GUID   = _contentAsset.TaskPointIDName + _contentAsset.TaskPointIDSign.ToString();
            taskPoint.Name   = (attribute != null ? attribute.GetLastName() : "New Task Point ") + _contentAsset.TaskPointIDSign.ToString();
            _contentAsset.TaskPointIDSign += 1;
            content.Points.Add(taskPoint);

            TaskContentAsset.GenerateSerializeSubObject(taskPoint, _contentAsset);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 新增任务内容
        /// </summary>
        private void AddContent(Type type)
        {
            TaskContentAttribute attribute   = type.GetCustomAttribute <TaskContentAttribute>();
            TaskContentBase      taskContent = CreateInstance(type) as TaskContentBase;

            taskContent.GUID          = _contentAsset.TaskIDName + _contentAsset.TaskIDSign.ToString();
            taskContent.Name          = (attribute != null ? attribute.GetLastName() : "New Task  ") + _contentAsset.TaskIDSign.ToString();
            _contentAsset.TaskIDSign += 1;
            _contentAsset.Content.Add(taskContent);
            _taskContentList.index = _contentAsset.Content.Count - 1;
            _currentContent        = taskContent;

            TaskContentAsset.GenerateSerializeSubObject(taskContent, _contentAsset);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 删除任务内容
        /// </summary>
        private void DeleteContent(int taskIndex)
        {
            for (int i = 0; i < _contentAsset.Content[taskIndex].Points.Count; i++)
            {
                TaskContentAsset.DestroySerializeSubObject(_contentAsset.Content[taskIndex].Points[i], _contentAsset);
            }
            TaskContentAsset.DestroySerializeSubObject(_contentAsset.Content[taskIndex], _contentAsset);

            _contentAsset.Content[taskIndex].Depends.Clear();
            _contentAsset.Content[taskIndex].Points.Clear();
            _contentAsset.Content.RemoveAt(taskIndex);
            _taskContentList.index = -1;
            _currentContent        = null;
            HasChanged(_contentAsset);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 粘贴、克隆任务内容
        /// </summary>
        private void PasteCloneTaskContent(GenericMenu gm)
        {
            string assetPath = AssetDatabase.GetAssetPath(_contentAsset);

            TaskContentBase content = null;

            string[] buffers = GUIUtility.systemCopyBuffer.Split('|');
            if (buffers.Length == 3 && buffers[0] == "TaskContent")
            {
                if (buffers[1] == assetPath)
                {
                    content = _contentAsset.Content.Find((s) => { return(s.GUID == buffers[2]); });
                }
                else
                {
                    TaskContentAsset taskContentAsset = AssetDatabase.LoadAssetAtPath <TaskContentAsset>(buffers[1]);
                    if (taskContentAsset)
                    {
                        content = taskContentAsset.Content.Find((s) => { return(s.GUID == buffers[2]); });
                    }
                }
            }

            if (content == null)
            {
                gm.AddDisabledItem(new GUIContent(GetWord("Paste")));
            }
            else
            {
                gm.AddItem(new GUIContent(GetWord("Paste") + " " + content.Name), false, () =>
                {
                    CloneContent(content);
                });
            }

            if (_currentContent == null)
            {
                gm.AddDisabledItem(new GUIContent(GetWord("Clone")));
            }
            else
            {
                gm.AddItem(new GUIContent(GetWord("Clone")), false, () =>
                {
                    CloneContent(_currentContent);
                });
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 克隆任务内容
        /// </summary>
        private void CloneContent(TaskContentBase content)
        {
            TaskContentBase taskContent = content.Clone();

            taskContent.Points.Clear();
            for (int i = 0; i < content.Points.Count; i++)
            {
                ClonePoint(taskContent, content.Points[i], content.Points[i].Anchor.position);
            }
            taskContent.GUID          = _contentAsset.TaskIDName + _contentAsset.TaskIDSign.ToString();
            _contentAsset.TaskIDSign += 1;
            _contentAsset.Content.Add(taskContent);
            _taskContentList.index = _contentAsset.Content.Count - 1;
            _currentContent        = taskContent;

            TaskContentAsset.GenerateSerializeSubObject(taskContent, _contentAsset);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 打开窗口
        /// </summary>
        /// <param name="contentAsset">任务资源</param>
        public static void ShowWindow(TaskContentAsset contentAsset)
        {
            TaskEditorWindow window = GetWindow <TaskEditorWindow>();

            window.titleContent.image = EditorGUIUtility.IconContent("AnimatorStateMachine Icon").image;
            window.titleContent.text  = "Task Editor";
            window._contentAsset      = contentAsset;
            window._currentContent    = null;
            window._taskContentList   = null;
            if (!EditorApplication.isPlaying)
            {
                window.ReSet();
            }
            window.minSize = new Vector2(800, 600);
            window.maxSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
            window.Show();
        }
        /// <summary>
        /// 绘制编辑器GUI
        /// </summary>
        internal void OnEditorGUI(TaskContentAsset asset, HTFFunc <string, string> getWord, bool isLockID)
        {
            GUILayout.BeginVertical("ChannelStripBg", GUILayout.Width(_width), GUILayout.Height(_height));

            GUILayout.BeginHorizontal();
            GUILayout.Label(getWord("Task Content Property") + ":");
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            int height = 20;

            height += OnBaseGUI(getWord, isLockID);

            height += OnPropertyGUI();

            if (_height != height)
            {
                _height     = height;
                GUI.changed = true;
            }

            GUILayout.EndVertical();
        }
        /// <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;
            }
        }
        /// <summary>
        /// 绘制编辑器GUI
        /// </summary>
        internal void OnEditorGUI(TaskContentAsset asset, TaskContentBase content, HTFFunc <string, string> getWord, bool isLockID)
        {
            if (IsComplete)
            {
                GUI.backgroundColor = Color.green;
            }
            else if (!IsEnable)
            {
                GUI.backgroundColor = Color.gray;
            }
            else
            {
                GUI.backgroundColor = IsSelected ? Color.yellow : Color.white;
            }

            GUILayout.BeginArea(Anchor, ShowName, "Window");

            GUI.backgroundColor = Color.white;

            int height = 25;

            height += OnDependGUI(getWord);

            if (IsExpand)
            {
                height += OnToolbarGUI(asset, content);

                height += OnBaseGUI(getWord, isLockID);

                height += OnPropertyGUI();
            }
            else
            {
                height += OnCollapseGUI(getWord);
            }

            Anchor.width = _width;
            if ((int)Anchor.height != height)
            {
                Anchor.height = height;
                GUI.changed   = true;
            }

            GUILayout.EndArea();

            string     icon       = IsEnable ? "animationvisibilitytoggleon" : "animationvisibilitytoggleoff";
            GUIContent gUIContent = new GUIContent();

            gUIContent.image   = EditorGUIUtility.IconContent(icon).image;
            gUIContent.tooltip = IsEnable ? "Enable" : "Disable";
            if (GUI.Button(new Rect(Anchor.x + Anchor.width - 40, Anchor.y - 2, 20, 20), gUIContent, "InvisibleButton"))
            {
                IsEnable    = !IsEnable;
                GUI.changed = true;
            }

            gUIContent.image   = EditorGUIUtility.IconContent("LookDevPaneOption").image;
            gUIContent.tooltip = IsExpand ? "Expand" : "Collapse";
            if (GUI.Button(new Rect(Anchor.x + Anchor.width - 25, Anchor.y, 20, 20), gUIContent, "InvisibleButton"))
            {
                IsExpand    = !IsExpand;
                GUI.changed = true;
            }

            OnWiredGUI();
        }