public void OnViewPageDelete(ViewPageNode node)
        {
            var s = data.viewPages.SingleOrDefault(m => m.viewPage == node.viewPage);

            data.viewPages.Remove(s);
            isDirty = true;
        }
        private void CreateConnection(ViewStateNode viewStateNode, ViewPageNode viewPageNode)
        {
            viewStateNode.currentLinkedViewPageNode.Add(viewPageNode);
            viewPageNode.currentLinkedViewStateNode = viewStateNode;

            viewStateNode.OnNodeConnect(viewPageNode);
            viewPageNode.OnNodeConnect(viewStateNode);
        }
 void OnDisconnect(ViewPageNode viewPageNode)
 {
     viewPageNode.currentLinkedViewStateNode.currentLinkedViewPageNode.Remove(viewPageNode);
     viewPageNode.currentLinkedViewStateNode = null;
     viewPageNode.viewPage.viewState         = "";
 }
        public ViewPageNode AddViewPageNode(Vector2 position, bool isOverlay, ViewPage viewPage = null)
        {
            var node = new ViewPageNode(position, isOverlay, CheckCanMakeConnect,
                                        (vsn, vpn) =>
            {
                if (vsn != null)
                {
                    vsn.currentLinkedViewPageNode.Remove(vpn);
                }
            },
                                        viewPage
                                        );

            node.OnPreviewBtnClick += (m) =>
            {
                var bps = HasBreakPoint(m);
                if (bps.Length > 0)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent($"Preview with Default BreakPoint  "), false, () =>
                    {
                        dataReader.OnViewPagePreview(m, null);
                    });
                    foreach (var item in bps)
                    {
                        menu.AddItem(new GUIContent($"Preview with {item} BreakPoint  "), false, () =>
                        {
                            dataReader.OnViewPagePreview(m, new Dictionary <string, bool>
                            {
                                { item, true }
                            });
                        });
                    }
                    menu.ShowAsContext();
                }
                else
                {
                    dataReader.OnViewPagePreview(m, null);
                }

                string[] HasBreakPoint(ViewPage _viewPage)
                {
                    List <string> result = new List <string>();

                    foreach (var item in _viewPage.viewPageItems)
                    {
                        if (item.breakPointViewElementTransforms != null)
                        {
                            foreach (var bp in item.breakPointViewElementTransforms)
                            {
                                if (!result.Contains(bp.breakPointName))
                                {
                                    result.Add(bp.breakPointName);
                                }
                            }
                        }
                    }

                    var viewState = viewStateList.SingleOrDefault(x => x.viewState.name == _viewPage.viewState);

                    if (viewState != null)
                    {
                        foreach (var item in viewState.viewState.viewPageItems)
                        {
                            if (item.breakPointViewElementTransforms != null)
                            {
                                foreach (var bp in item.breakPointViewElementTransforms)
                                {
                                    if (!result.Contains(bp.breakPointName))
                                    {
                                        result.Add(bp.breakPointName);
                                    }
                                }
                            }
                        }
                    }
                    return(result.ToArray());
                }
            };
            node.OnNodeSelect += (m) =>
            {
                lastSelectNode = m;
                inspector.SetCurrentSelectItem(m);
            };
            node.OnNodeDelete += () =>
            {
                dataReader.OnViewPageDelete(node);
                viewPageList.Remove(node);
            };
            node.OnDisConnect = OnDisconnect;
            if (viewPage == null)
            {
                dataReader.OnViewPageAdd(node);
            }
            viewPageList.Add(node);
            return(node);
        }

        void CheckCanMakeConnect(ViewSystemNode currentClickNode)
        {
            switch (currentClickNode.nodeType)
            {
            case ViewSystemNode.NodeType.ViewState:
                selectedViewStateNode = (ViewStateNode)currentClickNode;
                //如果當前的 ViewPagePoint 不是 null
                if (selectedViewPageNode != null)
                {
                    if (selectedViewStateNode.currentLinkedViewPageNode.Count(m => m.nodeType != selectedViewPageNode.nodeType) > 0)
                    {
                        if (EditorUtility.DisplayDialog(
                                "Warring",
                                $"The target ViewState is already connect to one or more {selectedViewPageNode.nodeType} Page.\nSince ViewState can only connect to one type of ViewPage(FullPage or Overlay) you should remove all {selectedViewPageNode.nodeType} connection on ViewState to continue.\nOr press 'OK' the editor will help you do this stuff.",
                                "Go Ahead",
                                "I'll do it myself"))
                        {
                            //刪掉線
                            foreach (var pagenode in selectedViewStateNode.currentLinkedViewPageNode)
                            {
                                pagenode.viewPage.viewState         = string.Empty;
                                pagenode.currentLinkedViewStateNode = null;
                            }
                            selectedViewStateNode.currentLinkedViewPageNode.Clear();
                            CreateConnection();
                            ClearConnectionSelection();
                        }
                        else
                        {
                            ClearConnectionSelection();
                        }
                        return;
                    }

                    //檢查是不是已經有跟這個 ViewPageNode 節點連線過了
                    if (!selectedViewStateNode.currentLinkedViewPageNode.Contains(selectedViewPageNode) &&
                        selectedViewPageNode.currentLinkedViewStateNode == null
                        )
                    {
                        CreateConnection();
                        ClearConnectionSelection();
                    }
                    // 如果連線的節點跟原本的不同 刪掉舊的連線 然後建立新了
                    else if (selectedViewPageNode.currentLinkedViewStateNode != null)
                    {
                        //刪掉 ViewStateNode 裡的 ViewPageNode
                        selectedViewPageNode.currentLinkedViewStateNode.currentLinkedViewPageNode.Remove(selectedViewPageNode);

                        //刪掉線

                        CreateConnection();
                        ClearConnectionSelection();
                    }
                    else
                    {
                        ClearConnectionSelection();
                    }
                }
                break;

            //被聯線的是 FullPage
            case ViewSystemNode.NodeType.FullPage:
                selectedViewPageNode = (ViewPageNode)currentClickNode;
                if (selectedViewStateNode != null)
                {
                    if (selectedViewStateNode.currentLinkedViewPageNode.Count(m => m.nodeType != selectedViewPageNode.nodeType) > 0)
                    {
                        if (EditorUtility.DisplayDialog(
                                "Warring",
                                $"The target ViewPage is already connect to one or more {selectedViewPageNode.nodeType} Page.\nSince ViewState can only connect to one type of ViewPage(FullPage or Overlay) you should remove all {selectedViewPageNode.nodeType} connection on ViewState to continue.\nOr press 'OK' the editor will help you do this stuff.",
                                "Go Ahead",
                                "I'll do it myself"))
                        {
                            //刪掉線
                            foreach (var pagenode in selectedViewStateNode.currentLinkedViewPageNode)
                            {
                                pagenode.viewPage.viewState         = string.Empty;
                                pagenode.currentLinkedViewStateNode = null;
                            }
                            selectedViewStateNode.currentLinkedViewPageNode.Clear();

                            CreateConnection();
                            ClearConnectionSelection();
                        }
                        else
                        {
                            ClearConnectionSelection();
                        }

                        return;
                    }
                    //檢查是不是已經有跟這個 ViewStateNode 節點連線過了
                    if (selectedViewPageNode.currentLinkedViewStateNode == null)
                    {
                        CreateConnection();
                        ClearConnectionSelection();
                    }
                    // 如果連線的節點跟原本的不同 刪掉舊的連線 然後建立新了
                    else if (selectedViewPageNode.currentLinkedViewStateNode != selectedViewStateNode)
                    {
                        //刪掉 ViewStateNode 裡的 ViewPageNode
                        selectedViewPageNode.currentLinkedViewStateNode.currentLinkedViewPageNode.Remove(selectedViewPageNode);

                        CreateConnection();
                        ClearConnectionSelection();
                    }
                    else
                    {
                        ClearConnectionSelection();
                    }
                }
                break;

            //Overlay
            case ViewSystemNode.NodeType.Overlay:
                selectedViewPageNode = (ViewPageNode)currentClickNode;
                if (selectedViewStateNode != null)
                {
                    if (selectedViewStateNode.currentLinkedViewPageNode.Count(m => m.nodeType != selectedViewPageNode.nodeType) > 0)
                    {
                        if (EditorUtility.DisplayDialog(
                                "Warring",
                                $"The target ViewPage is already connect to one or more {selectedViewPageNode.nodeType} Page.\nSince ViewState can only connect to one type of ViewPage(FullPage or Overlay) you should remove all {selectedViewPageNode.nodeType} connection on ViewState to continue.\nOr press 'OK' the editor will help you do this stuff.",
                                "Go Ahead",
                                "I'll do it myself"))
                        {
                            //刪掉線
                            foreach (var pagenode in selectedViewStateNode.currentLinkedViewPageNode)
                            {
                                pagenode.viewPage.viewState         = string.Empty;
                                pagenode.currentLinkedViewStateNode = null;
                            }
                            selectedViewStateNode.currentLinkedViewPageNode.Clear();

                            CreateConnection();
                            ClearConnectionSelection();
                        }
                        else
                        {
                            ClearConnectionSelection();
                        }

                        return;
                    }
                    //檢查是不是已經有跟這個 ViewStateNode 節點連線過了
                    if (selectedViewPageNode.currentLinkedViewStateNode == null)
                    {
                        CreateConnection();
                        ClearConnectionSelection();
                    }
                    // 如果連線的節點跟原本的不同 刪掉舊的連線 然後建立新了
                    else if (selectedViewPageNode.currentLinkedViewStateNode != selectedViewStateNode)
                    {
                        //刪掉 ViewStateNode 裡的 ViewPageNode
                        selectedViewPageNode.currentLinkedViewStateNode.currentLinkedViewPageNode.Remove(selectedViewPageNode);

                        //刪掉線
                        CreateConnection();
                        ClearConnectionSelection();
                    }
                    else
                    {
                        ClearConnectionSelection();
                    }
                }
                break;
            }
        }
 public void OnViewPageAdd(ViewPageNode node)
 {
     data.viewPages.Add(new ViewSystemSaveData.ViewPageSaveData(new Vector2(node.rect.x, node.rect.y), node.viewPage));
     isDirty = true;
 }