Exemple #1
0
        private void ShowMenu()
        {
            // add a new Node
            if (curEvent.type == EventType.MouseDown)
            {
                curSelect = windowList.Find((BaseWindow w) =>
                {
                    return(w.isClick(mousePosition));
                });

                if (curSelect != null)
                {
                    curSelect.rightMouseDraw(mousePosition);
                }
                else
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(addNode, false, () =>
                    {
                        windowList.Add(new NodeWindow(mousePosition, windowList));
                    });

                    menu.AddItem(addRouter, false, () =>
                    {
                        windowList.Add(new RouterWindow(mousePosition, windowList));
                    });
                    menu.ShowAsContext();
                }
            }
        }
        BaseWindow FindWindow(int id)
        {
            BaseWindow res = windowList.Find((BaseWindow w) =>
            {
                return(w.Id == id);
            });

            return(res);
        }
        protected void generateWindowData(NodeCanvasData windowData)
        {
            windowList  = new List <BaseWindow>();
            fixedWindow = new FixedWindow(windowData.shareData);

            foreach (var item in windowData.nodelist)
            {
                windowList.Add(new NodeWindow(item, windowList));
            }

            foreach (var item in windowData.routerlist)
            {
                windowList.Add(new RouterWindow(item, windowList));
            }

            //set next Node
            foreach (var item in windowList)
            {
                DataBase itemdata = windowData.Get(item.Id);

                if (itemdata.type == NodeType.Node)
                {
                    NodeData edata = itemdata as NodeData;

                    if (edata.next >= 0)
                    {
                        BaseWindow next = FindWindow(edata.next);

                        (item as NodeWindow).SetNext(next);
                    }
                }
                else
                {
                    RouterData   edata = itemdata as RouterData;
                    RouterWindow win   = item as RouterWindow;

                    //set default
                    if (edata.defaultEntity >= 0)
                    {
                        NodeWindow def = FindWindow <NodeWindow>(edata.defaultEntity);
                        win.SetDefault(def);
                    }

                    //set conditions
                    List <RouterWindowCondition> conditions = new List <RouterWindowCondition>();
                    foreach (var con in edata.conditions)
                    {
                        RouterWindowCondition rcon = new RouterWindowCondition();
                        rcon.className = con.className;
                        rcon.entity    = FindWindow <NodeWindow>(con.entity);
                        conditions.Add(rcon);
                    }
                    win.SetConditions(conditions);
                }
            }
        }
        T FindWindow <T>(int id)
            where T : BaseWindow
        {
            BaseWindow res = windowList.Find((BaseWindow w) =>
            {
                return(w.Id == id);
            });

            if (res == null)
            {
                return(null);
            }

            return(res as T);
        }
Exemple #5
0
 public void SetNext(BaseWindow entity)
 {
     next = entity;
 }
Exemple #6
0
        protected override void OnGUI()
        {
            if (EditorApplication.isCompiling)
            {
                ShowNotification(comiling);

                if (!EditorPrefs.HasKey(nodeAssetPath))
                {
                    EditorPrefs.SetString(nodeAssetPath, scriptable.path);
                }

                return;
            }

            if (EditorPrefs.HasKey(nodeAssetPath))
            {
                // once compiled
                string path = EditorPrefs.GetString(nodeAssetPath);
                EditorPrefs.DeleteKey(nodeAssetPath);

                scriptable = new ScriptableItem(path);

                Awake();

                Repaint();
            }

            if (windowList == null)
            {
                return;
            }

            curEvent      = Event.current;
            mousePosition = curEvent.mousePosition;

            if (curEvent.button == 1) // mouse right key
            {
                ShowMenu();
            }

            // mouse left key
            if (curEvent.button == 0 && curEvent.isMouse)
            {
                //a window is whether selected
                if (curEvent.type == EventType.MouseDown)
                {
                    curSelect = windowList.Find((BaseWindow w) =>
                    {
                        return(w.isClick(mousePosition));
                    });
                }
                else if (curEvent.type == EventType.MouseUp)
                {
                    curSelect = null;
                }

                if (curSelect != null)
                {
                    curSelect.leftMouseDraw(curEvent);
                }
                //else
                //{
                //    if (this.position.Contains(curEvent.mousePosition))
                //    {
                //        //drag the panel
                //        foreach (var item in windowList)
                //        {
                //            item.leftMouseDraw(curEvent);
                //        }
                //    }
                //}
            }

            base.OnGUI();
        }