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);
                }
            }
        }
Exemple #2
0
        void drawConditions()
        {
            for (int i = 0; i < conditions.Count; i++)
            {
                RouterWindowCondition rc = conditions[i];
                GUILayout.BeginHorizontal();

                string c           = rc.className;
                int    selectindex = allConditionClass.IndexOf(c);
                selectindex = EditorGUILayout.Popup(selectindex, allConditionClass.ToArray(), popupStyle);
                if (selectindex >= 0)
                {
                    conditions[i].className = allConditionClass[selectindex];
                }

                //删除
                GUI.color = Color.red;
                if (GUILayout.Button("-", buttonStyle))
                {
                    conditions.RemoveAt(i);
                    i--;
                    _size.y -= addHeight;
                }
                GUI.color = Color.white;

                //连接选择
                GUI.color = EditorGUIUtility.isProSkin ? Color.green : Color.grey;
                if (MyEditorLayout.Button("L", buttonStyle, out rect))
                {
                    GenericMenu menu = new GenericMenu();

                    menu.AddItem(newNode, false, () =>
                    {
                        var tempWindow = new NodeWindow(new Vector2(50, 50) + position, windowList);
                        windowList.Add(tempWindow);
                        rc.entity = tempWindow;
                    });

                    menu.AddSeparator("");

                    List <NodeWindow> selectionList = new List <NodeWindow>();
                    foreach (var item in windowList)
                    {
                        if (item.windowType == NodeType.Node)
                        {
                            selectionList.Add(item as NodeWindow);
                        }
                    }

                    foreach (var item in selectionList)
                    {
                        bool select = (rc.entity != null) && rc.entity.Id == item.Id;
                        menu.AddItem(new GUIContent(string.Format("[{0}][{1}] {2}", item.Id, item.windowType, item.Name)), select, () =>
                        {
                            if (select)
                            {
                                rc.entity = null;
                            }
                            else
                            {
                                rc.entity = item;
                            }
                        });
                    }

                    menu.ShowAsContext();
                }


                GUI.color = Color.white;

                if (rc.entity == null)
                {
                    linkStyle.normal.textColor = Color.gray;
                }
                else
                {
                    linkStyle.normal.textColor = EditorGUIUtility.isProSkin ? Color.green : Color.grey;
                }

                MyEditorLayout.Label("o", linkStyle, out rect);

                //有的时候 rect会为0,0,1,1
                if (rect.position != Vector2.zero)
                {
                    rc.drawPos.x = rect.position.x + rect.width;
                    rc.drawPos.y = rect.position.y + rect.height / 2;
                }

                GUILayout.EndHorizontal();
            }
        }
Exemple #3
0
        public override void draw()
        {
            base.draw();

            //画线

            #region condition list
            for (int i = 0; i < conditions.Count; i++)
            {
                RouterWindowCondition item = conditions[i];

                if (item.entity == null)
                {
                    continue;
                }

                if (!windowList.Contains(item.entity))
                {
                    item.entity = null;
                    continue;
                }

                if (item.drawPos == Vector2.zero)
                {
                    continue;
                }

                color = Color.white;

                if (Application.isPlaying && passed && runtimePassedConditionIndex == i)
                {
                    color = EditorGUIUtility.isProSkin ? Color.green : Color.grey;
                }

                DrawArrow(item.drawPos + position, item.entity.In, color);
            }
            #endregion

            #region default
            if (defaultEntity == null)
            {
                return;
            }

            if (!windowList.Contains(defaultEntity))
            {
                defaultEntity = null;
                return;
            }
            if (defaultPos == Vector2.zero)
            {
                return;
            }

            color = Color.white;

            if (Application.isPlaying && passed && runtimePassedConditionIndex == -1)
            {
                color = EditorGUIUtility.isProSkin ? Color.green : Color.grey;
            }

            DrawArrow(defaultPos + position, defaultEntity.In, color);
            #endregion
        }