Пример #1
0
        public override DataBase GetData()
        {
            RouterData data = new RouterData();

            data.id       = Id;
            data.name     = Name;
            data.position = position;

            foreach (var item in conditions)
            {
                RouterConditionData cond = new RouterConditionData();

                cond.className = item.className;

                if (item.entity != null)
                {
                    cond.entity = item.entity.Id;
                }

                data.conditions.Add(cond);
            }

            if (defaultEntity != null)
            {
                data.defaultEntity = defaultEntity.Id;
            }

            return(data);
        }
Пример #2
0
        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);
                }
            }
        }
        void addRouterPathMessage(RouterData router, int coditionIndex)
        {
            RouterPathMessage rpm = routerPathMessage.Find((RouterPathMessage m) =>
            {
                return(m.id == router.id);
            });

            if (rpm == null)
            {
                routerPathMessage.Add(new RouterPathMessage(router.id, coditionIndex));
            }
            else
            {
                rpm.conditionIndex = coditionIndex;
            }
        }
Пример #4
0
 public RouterWindow(RouterData itemData, List <BaseWindow> _windowList)
     : base(itemData, _windowList)
 {
     addHeight = buttonStyle.lineHeight + 8;
 }
        private void LateUpdate()
        {
            if (finished)
            {
                return;
            }

            if (moveNext)
            {
                return;
            }

            if (currentEntity == null)
            {
                return;
            }

            if (currentEntity.State == EntityState.Finished)
            {
#if UNITY_EDITOR
                if (!nodePathMessage.Contains(current.id))
                {
                    nodePathMessage.Add(current.id);
                }
#endif

                currentEntity.reset();
                moveNext = true;

                tempDataBase = nodeFlowData.Get(current.next);
                if (null == tempDataBase)
                {
                    current = null;
                }
                else if (tempDataBase.type == NodeType.Router)
                {
                    tempRouter  = tempDataBase as RouterData;
                    currentID   = tempRouter.id;
                    currentName = tempRouter.name;

                    try
                    {
                        for (int i = 0; i < tempRouter.conditions.Count; i++)
                        {
                            RouterConditionData item = tempRouter.conditions[i];

                            string key = string.Format("{0}+{1}", tempRouter.id, item.className);
                            if (!conditionMap.ContainsKey(key))
                            {
                                type = Type.GetType(item.className);

                                tempCondition = Activator.CreateInstance(type, shareData) as RouterCondition;

                                conditionMap.Add(key, tempCondition);
                            }

                            tempCondition = conditionMap[key];

                            if (!tempCondition.justify())
                            {
                                continue;
                            }

#if UNITY_EDITOR
                            addRouterPathMessage(tempRouter, i);
#endif

                            tempDataBase = nodeFlowData.Get(item.entity);
                            if (null == tempDataBase)
                            {
                                current = null;
                            }
                            else
                            {
                                current = tempDataBase as NodeData;
                            }
                            return;
                        }

#if UNITY_EDITOR
                        addRouterPathMessage(tempRouter, -1);
#endif

                        tempDataBase = nodeFlowData.Get(tempRouter.defaultEntity);
                        if (null == tempDataBase)
                        {
                            current = null;
                        }
                        else
                        {
                            current = tempDataBase as NodeData;
                        }
                    }
                    catch (Exception e)
                    {
                        error    = e.Message;
                        finished = true;
                        if (onFinish != null)
                        {
                            onFinish.Invoke(false);
                        }
                        throw;
                    }
                }
                else //NodeType.Node
                {
                    current = tempDataBase as NodeData;
                }
            }
        }