Exemplo n.º 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);
        }
        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;
                }
            }
        }