// Use this for initialization void Start() { fsm = new FSM(); fsm.Create(5, 6); fsm.SetRelation((int)States.Idle, (int)States.GoToMine, (int)Events.HasGold); fsm.SetRelation((int)States.GoToMine, (int)States.Mining, (int)Events.MineReached); fsm.SetRelation((int)States.Mining, (int)States.GoToTown, (int)Events.MiningTimeOut); fsm.SetRelation((int)States.GoToTown, (int)States.DepositGold, (int)Events.TownReached); fsm.SetRelation((int)States.DepositGold, (int)States.Idle, (int)Events.GoldDeposited); fsm.SendEvent((int)States.Idle); workerConditions = new WorkerConditions(this); BTConditionNode hasGoldNode = new BTConditionNode(workerConditions.HasMaxGold); BTSequenceNode miningNode = new BTSequenceNode(); BTActionNode goToMineAction = new BTActionNode(GoToMine); BTActionNode miningAction = new BTActionNode(Mining); miningNode.AddChild(hasGoldNode); miningNode.AddChild(goToMineAction); miningNode.AddChild(miningAction); BTSequenceNode backToTownNode = new BTSequenceNode(); BTActionNode goToTownAction = new BTActionNode(GoToTown); BTActionNode depositGoldAction = new BTActionNode(DepositGold); backToTownNode.AddChild(goToTownAction); backToTownNode.AddChild(depositGoldAction); rootNode.AddChild(miningNode); rootNode.AddChild(backToTownNode); }
protected override void RecursivelyCreatChildren(Dictionary <string, BTEditorSprite> _sprites) { if (m_node != null) { BTConditionNode node = m_node as BTConditionNode; if (node.Child != null) { // create link string lineKey = BTEditorLine.GetKey(m_node, node.Child); if (!_sprites.ContainsKey(lineKey)) { BTEditorLine line = new BTEditorLine(m_treeViewer); line.ParentNode = m_node; line.ChildNode = node.Child; _sprites.Add(line.GetKey(), line); } // do for children RecursivelyCreateSprites(_sprites, node.Child, m_treeViewer); } } }
internal override int AutoRecursivelyLayout(Dictionary <string, BTEditorSprite> _sprites, Point _leftTop) { if (m_node != null) { // children BTConditionNode node = m_node as BTConditionNode; int x = _leftTop.X + m_bound.Width + HorizontalInterval; int y = _leftTop.Y; if (node.Child != null) { BTNode child = node.Child; string key = GetKey(child); if (_sprites.ContainsKey(key)) { BTEditorRectangle childNode = _sprites[key] as BTEditorRectangle; int height = childNode.AutoRecursivelyLayout(_sprites, new Point(x, y)); y += height + VerticalInterval; } else { Debug.Assert(false, "Cannot find sprite for node"); } } // self if (y != _leftTop.Y) { y -= VerticalInterval; } int needHeight = (m_bound.Height > (y - _leftTop.Y)) ? (m_bound.Height) : (y - _leftTop.Y); m_bound.X = _leftTop.X; m_bound.Y = _leftTop.Y + (needHeight - m_bound.Height) / 2; return(needHeight); } else { Debug.Assert(false, "Cannot find corresponding node"); return(0); } }