static void WriteSelectionNode(Transform monoDialogEvent) { SelectionNode talkNode = monoDialogEvent.gameObject.GetComponent <MonoSelectionNode> ().m_node; newWriterSelectionNode = new SelectionNode(talkNode.m_name); newWriterDialogEvent.m_nodeList.Add(newWriterSelectionNode); }
public override void VisitSelection(SelectionNode node) { Visit(node.Selections); foreach (var cost in node.Costs) { var value = Costs.TryGetValue(cost.TypeId !, out var retrieved) ? retrieved : 0; Costs[cost.TypeId !] = value + cost.Value;
public SelectionNode(int _x, int _y) { North = East = South = West = null; x = _x; y = _y; TileIndex = Program.TilesetPointToIndex(x, y); }
public AlphaBuilderContext <T> BuildSelectionNode <T>(AlphaBuilderContext <T> context, Expression <Func <T, bool> > conditionExpression) where T : class { using (_logger.BeginScope($"{nameof(BuildSelectionNode)}<{typeof(T).Name}>")) { var alphaCondition = new AlphaCondition <T>(conditionExpression); _logger.LogDebug($"Condition: {alphaCondition}"); IAlphaNode <T> alphaNode = context.CurrentNode; SelectionNode <T> selectionNode = alphaNode.GetChildNodes <SelectionNode <T> >() .FirstOrDefault(x => x.Condition.Equals(alphaCondition)); if (selectionNode == null) { using (_logger.BeginScope("Create")) { _logger.LogDebug($"Creating selection node: {typeof(T).Name}"); selectionNode = new SelectionNode <T>(_loggerFactory, alphaCondition); alphaNode.AddChild(selectionNode); } } return(new RuntimeAlphaBuilderContext <T>(context.Declaration, selectionNode)); } }
public ISelectionNode <T> BuildSelectionNode <T>(BuilderContext context, Expression <Func <T, bool> > conditionExpression) where T : class { using (_logger.BeginScope($"{nameof(BuildSelectionNode)}<{typeof(T).Name}>")) { var alphaCondition = new AlphaCondition <T>(conditionExpression); _logger.LogDebug($"Condition: {alphaCondition}"); var alphaNode = context.CurrentAlphaNode ?? BuildTypeNode <T>(context); SelectionNode <T> selectionNode = alphaNode.GetChildNodes <SelectionNode <T> >() .FirstOrDefault(x => x.Condition.Equals(alphaCondition)); if (selectionNode == null) { using (_logger.BeginScope("Create")) { _logger.LogDebug($"Creating selection node: {typeof(T).Name}"); selectionNode = new SelectionNode <T>(_loggerFactory, alphaCondition); alphaNode.AddChild(selectionNode); } } context.CurrentAlphaNode = selectionNode; context.AlphaSource = selectionNode.MemoryNode; return(selectionNode); } }
public ISelectionNode <T> BuildSelectionNode <T>(BuilderContext context, Expression <Func <T, bool> > conditionExpression) where T : class { using (_logger.BeginScope($"{nameof(BuildSelectionNode)}<{typeof(T).Name}>")) { var alphaCondition = new AlphaCondition <T>(conditionExpression); _logger.LogDebug($"Condition: {alphaCondition}"); if (context.CurrentAlphaNode == null) { throw new RuntimeBuilderException("CurrentAlphaNode must not be null"); } var selectionNode = context.CurrentAlphaNode.GetChildNodes <SelectionNode <T> >() .FirstOrDefault(x => x.Condition.Equals(alphaCondition)); if (selectionNode == null) { using (_logger.BeginScope("Create")) { selectionNode = new SelectionNode <T>(_loggerFactory, alphaCondition); context.CurrentAlphaNode.AddChild(selectionNode); } } context.CurrentAlphaNode = selectionNode; return(selectionNode); } }
public static void Traverse( SelectionNode root, bool realizeChildren, Action <TreeWalkNodeInfo> nodeAction) { var pendingNodes = new List <TreeWalkNodeInfo>(); var current = new IndexPath(null); pendingNodes.Add(new TreeWalkNodeInfo(root, current)); while (pendingNodes.Count > 0) { var nextNode = pendingNodes.Last(); pendingNodes.RemoveAt(pendingNodes.Count - 1); int count = realizeChildren ? nextNode.Node.DataCount : nextNode.Node.ChildrenNodeCount; for (int i = count - 1; i >= 0; i--) { var child = nextNode.Node.GetAt(i, realizeChildren); var childPath = nextNode.Path.CloneWithChildIndex(i); if (child != null) { pendingNodes.Add(new TreeWalkNodeInfo(child, childPath, nextNode.Node)); } } // Queue the children first and then perform the action. This way // the action can remove the children in the action if necessary nodeAction(nextNode); } }
private void OnEnable() { m_monoSelectionNode = target as MonoSelectionNode; m_selectionNode = m_monoSelectionNode.m_node; UpdateNodeTree(); }
public TreeWalkNodeInfo(SelectionNode node, IndexPath indexPath) { node = node ?? throw new ArgumentNullException(nameof(node)); Node = node; Path = indexPath; ParentNode = null; }
protected internal override void VisitSelectionNode(SchemaBuilder builder, SelectionNode node) { if (builder.IsVisited(node)) { return; } builder.AddNode(node, ReteNode.Create); base.VisitSelectionNode(builder, node); }
static void LoadSelection() { SelectionNode m_node = (SelectionNode)m_dialogEvent.m_nodeList [m_currentNode]; foreach (string s in m_node.m_selection.Keys) { m_select.Add(s); } }
protected internal override void VisitSelectionNode(SnapshotBuilder builder, SelectionNode node) { if (builder.IsVisited(node)) { return; } builder.AddNode(node, NodeInfo.Create); base.VisitSelectionNode(builder, node); }
internal static ReteNode Create(SelectionNode node) { var conditions = new[] { new KeyValuePair <string, LambdaExpression>("Condition", node.ExpressionElement.Expression) }; return(new ReteNode(node.Id, NodeType.Selection, outputType: node.NodeInfo.OutputType, expressions: conditions, rules: node.NodeInfo.Rules)); }
public override void Execute(TreeBuilder tree, FusionContext context) { var root = tree.Root; var selectionNode = new SelectionNode() { ChildNode = root }; tree.Root = selectionNode; }
public CategoryMock(BattleScribeXml.CategoryMock xml) : base(xml) { _categoryLink = new IdLink <ICategory>( XmlBackend.CategoryGuid, newGuid => XmlBackend.CategoryGuid = newGuid, () => XmlBackend.CategoryId); _selectionsNode = new SelectionNode(() => XmlBackend.Selections, this) { Controller = XmlBackend.Controller }; }
public static SelectionNode WithUpdatedNumberAndCosts(this SelectionNode node, int newCount) { if (newCount < 1) { throw new ArgumentException("Count must be greater than 0", nameof(newCount)); } if (node.Number == newCount) { // we assume same instance is OK if count doesn't change return(node); } var oldCount = node.Number; return(node.WithNumber(newCount) .ReplaceFluent(x => x.Costs, x => x.WithValue(x.Value / oldCount * newCount))); }
public static void TraverseIndexPath( SelectionNode root, IndexPath path, bool realizeChildren, Action <SelectionNode, IndexPath, int, int> nodeAction) { var node = root; for (int depth = 0; depth < path.GetSize(); depth++) { int childIndex = path.GetAt(depth); nodeAction(node, path, depth, childIndex); if (depth < path.GetSize() - 1) { node = node.GetAt(childIndex, realizeChildren) !; } } }
static public void PlaySelection() { UIManager.Instance().ClosePanel <UISelectPanel> (); Clear(); //检查的时候会自增,因此一开始先减去自增的数值 m_currentContent = -1; SelectionNode m_selectNode = (SelectionNode)m_dialogEvent.m_nodeList [m_currentNode]; Debug.Log("SelectedOption : " + m_selected); TalkNode m_node = m_selectNode.m_selection [m_selected]; m_content = m_node.m_talkContents; GetSpriteAsset(m_node.m_background, m_background); GetSpriteAsset(m_node.m_tachie, m_tachie); GameObject.Find("RigidBodyFPSController").GetComponent <UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController> ().mouseLook.SetCursorLock(false); UIManager.Instance().ShowPanel <UIDialogPanel> (); GameObject.Find("UIDialogPanel").GetComponent <UIDialogPanel> ().InitDialog(); }
//保存为xml public static void SaveXMLEvent() { DialogWriter dialogWriter = ProduceWriter(); //保存路径 path = Application.dataPath + "/OutputXml/" + dialogWriter.GetType() + ".xml"; FileInfo fi = new FileInfo(path); if (fi.Exists) { //fi.MoveTo ("./backup"); fi.Delete(); } List <DialogEvent> dialogEventLsit = dialogWriter.m_dialogEventList; XmlDocument doc = new XmlDocument(); XmlElement dialogWriterElem = doc.CreateElement("DialogWriter"); for (int i = 0; i < dialogEventLsit.Count; i++) { XmlElement eve = doc.CreateElement("Event"); DialogEvent dialogEvent = dialogEventLsit [i]; eve.SetAttribute("Name", dialogEvent.m_name); eve.SetAttribute("EvenOrder", dialogEvent.m_eventOrder.ToString()); for (int j = 0; j < dialogEvent.m_nodeList.Count; j++) { //判断是否为talk节点 if (dialogEvent.m_nodeList [j].m_dialogType == DialogNode.NodeType.Talk) { XmlElement node = doc.CreateElement("TalkNode"); TalkNode talkNode = (TalkNode)dialogEvent.m_nodeList [j]; node.SetAttribute("Name", talkNode.m_name); node.SetAttribute("NodeType", talkNode.m_dialogType.ToString()); for (int k = 0; k < talkNode.m_background.Count; k++) { //node.SetAttribute ("Background"+k, ); XmlElement background = doc.CreateElement("Background"); background.SetAttribute("Name", talkNode.m_background [k]); node.AppendChild(background); } for (int k = 0; k < talkNode.m_tachie.Count; k++) { XmlElement tachie = doc.CreateElement("Tachie"); tachie.SetAttribute("Name", talkNode.m_tachie [k]); node.AppendChild(tachie); //node.SetAttribute ("Tachie"+k, talkNode.m_tachie [k]); } for (int k = 0; k < talkNode.m_talkContents.Count; k++) { XmlElement content = doc.CreateElement("TalkContent"); TalkContent talkContent = talkNode.m_talkContents [k]; content.SetAttribute("Background", talkContent.m_backGround.ToString()); content.SetAttribute("Tachie", talkContent.m_tachie.ToString()); content.SetAttribute("Name", talkContent.m_name); content.SetAttribute("Content", talkContent.m_content); node.AppendChild(content); } eve.AppendChild(node); } else { XmlElement node = doc.CreateElement("SelectionNode"); SelectionNode selectionNode = (SelectionNode)dialogEvent.m_nodeList [j]; node.SetAttribute("Name", selectionNode.m_name); node.SetAttribute("NodeType", selectionNode.m_dialogType.ToString()); //分为两个select节点 foreach (string s in selectionNode.m_selection.Keys) { XmlElement select = doc.CreateElement("Select"); select.SetAttribute("Select", s); XmlElement talk = doc.CreateElement("TalkNode"); TalkNode talkNode = selectionNode.m_selection [s]; talk.SetAttribute("Name", talkNode.m_name); talk.SetAttribute("NodeType", talkNode.m_dialogType.ToString()); for (int k = 0; k < talkNode.m_background.Count; k++) { //node.SetAttribute ("Background"+k, ); XmlElement background = doc.CreateElement("Background"); background.SetAttribute("Name", talkNode.m_background [k]); talk.AppendChild(background); } for (int k = 0; k < talkNode.m_tachie.Count; k++) { XmlElement tachie = doc.CreateElement("Tachie"); tachie.SetAttribute("Name", talkNode.m_tachie [k]); talk.AppendChild(tachie); //node.SetAttribute ("Tachie"+k, talkNode.m_tachie [k]); } for (int k = 0; k < talkNode.m_talkContents.Count; k++) { XmlElement content = doc.CreateElement("TalkContent"); TalkContent talkContent = talkNode.m_talkContents [k]; content.SetAttribute("Background", talkContent.m_backGround.ToString()); content.SetAttribute("Tachie", talkContent.m_tachie.ToString()); content.SetAttribute("Name", talkContent.m_name); content.SetAttribute("Content", talkContent.m_content); talk.AppendChild(content); } select.AppendChild(talk); node.AppendChild(select); } eve.AppendChild(node); } } dialogWriterElem.AppendChild(eve); } doc.AppendChild(dialogWriterElem); doc.Save(path); }
protected internal virtual void VisitSelectionNode(TContext context, SelectionNode node) { VisitAlphaNode(context, node); }
public void Init(SelectionNode node) { m_node = node; }
internal static NodeInfo Create(SelectionNode node) { return(new NodeInfo(NodeType.Selection, string.Empty, node.Conditions.Select(c => c.ToString()), Empty)); }
protected internal virtual void VisitSelectionNode(TContext builder, SelectionNode node) { VisitAlphaNode(builder, node); }
public static void TraverseRangeRealizeChildren( SelectionNode root, IndexPath start, IndexPath end, Action <TreeWalkNodeInfo> nodeAction) { var pendingNodes = new List <TreeWalkNodeInfo>(); var current = start; // Build up the stack to account for the depth first walk up to the // start index path. TraverseIndexPath( root, start, true, (node, path, depth, childIndex) => { var currentPath = StartPath(path, depth); bool isStartPath = IsSubSet(start, currentPath); bool isEndPath = IsSubSet(end, currentPath); int startIndex = depth < start.GetSize() && isStartPath ? start.GetAt(depth) : 0; int endIndex = depth < end.GetSize() && isEndPath ? end.GetAt(depth) : node.DataCount - 1; for (int i = endIndex; i >= startIndex; i--) { var child = node.GetAt(i, realizeChild: true); if (child != null) { var childPath = currentPath.CloneWithChildIndex(i); pendingNodes.Add(new TreeWalkNodeInfo(child, childPath, node)); } } }); // From the start index path, do a depth first walk as long as the // current path is less than the end path. while (pendingNodes.Count > 0) { var info = pendingNodes.Last(); pendingNodes.RemoveAt(pendingNodes.Count - 1); int depth = info.Path.GetSize(); bool isStartPath = IsSubSet(start, info.Path); bool isEndPath = IsSubSet(end, info.Path); int startIndex = depth < start.GetSize() && isStartPath?start.GetAt(depth) : 0; int endIndex = depth < end.GetSize() && isEndPath?end.GetAt(depth) : info.Node.DataCount - 1; for (int i = endIndex; i >= startIndex; i--) { var child = info.Node.GetAt(i, realizeChild: true); if (child != null) { var childPath = info.Path.CloneWithChildIndex(i); pendingNodes.Add(new TreeWalkNodeInfo(child, childPath, info.Node)); } } nodeAction(info); if (info.Path.CompareTo(end) == 0) { // We reached the end index path. stop iterating. break; } } }
private void Start() { player = GameObject.FindGameObjectWithTag(Tags.Player).GetComponent <UserSoldier>(); gameManager = GameObject.FindGameObjectWithTag(Tags.GameController).GetComponent <GameManager>(); npc = GetComponent <NPCSoldier>(); npc.Damaged += Damaged; nextRadius = gameManager.nextRadius; SetCoverPos(transform.position); var notInSafeZoneCond = new ConditionNode(IsInSafeZone, false); var haveEnemyCond = new ConditionNode(HaveEnemyInSight, true); var beingShootCond = new ConditionNode(BeingShoot, true); var haveWeaponCond = new ConditionNode(HaveWeapon, true); var seekWeaponCond = new ConditionNode(SeekWeapon, true); var equipAction = new SetEquipmentAction(npc, true); var notEquipAction = new SetEquipmentAction(npc, false); var crouchAction = new SetCrouchAction(npc, true); var notCrouchAction = new SetCrouchAction(npc, false); var toSafeZoneAction = new MoveAction(npc, blackBoard, safeZoneKey); var goCoverAction = new MoveAction(npc, blackBoard, coverPosKey); var FallBackAction = new MoveAction(npc, blackBoard, fallBackPosKey); var goWeaponAction = new MoveAction(npc, blackBoard, weaponPosKey); var pickUpWeaponAction = new PickUpWeaponAction(npc, blackBoard, weaponKey); var shootAction = new ShootAction(npc, blackBoard, enemyPosKey); var turnToShooterAction = new TurnAction(npc, blackBoard, shooterPosKey); var idleAction = new IdleAction(npc); var combat = new SequenceNode(); combat.AddCondition(haveWeaponCond); combat.AddNode(equipAction); combat.AddNode(shootAction); var fallBack = new SequenceNode(); fallBack.AddNode(FallBackAction); haveEnemy = new SelectionNode(); haveEnemy.AddCondition(haveEnemyCond); haveEnemy.AddNode(combat); haveEnemy.AddNode(fallBack); var counter = new SequenceNode(); counter.AddCondition(haveWeaponCond); counter.AddNode(turnToShooterAction); beingShoot = new SelectionNode(); beingShoot.AddCondition(beingShootCond); beingShoot.AddNode(counter); beingShoot.AddNode(fallBack); toSafeZone = new SequenceNode(); toSafeZone.AddCondition(notInSafeZoneCond); toSafeZone.AddNode(notCrouchAction); toSafeZone.AddNode(notEquipAction); toSafeZone.AddNode(toSafeZoneAction); stayInCover = new SequenceNode(); stayInCover.AddCondition(haveWeaponCond); stayInCover.AddNode(goCoverAction); stayInCover.AddNode(crouchAction); stayInCover.AddNode(idleAction); seekWeapon = new SequenceNode(); seekWeapon.AddCondition(seekWeaponCond); seekWeapon.AddNode(goWeaponAction); seekWeapon.AddNode(pickUpWeaponAction); idle = new SelectionNode(); idle.AddNode(stayInCover); idle.AddNode(seekWeapon); root.AddNode(haveEnemy); root.AddNode(beingShoot); root.AddNode(toSafeZone); root.AddNode(idle); }
internal static NodeInfo Create(SelectionNode node) { return new NodeInfo(NodeType.Selection, string.Empty, node.Conditions.Select(c => c.ToString()), Empty, Empty); }
internal static NodeInfo Create(SelectionNode node) { return new NodeInfo(NodeType.Selection, string.Empty, new[] {node.Condition.ToString()}, Empty, Empty); }
internal static NodeInfo Create(SelectionNode node) { var conditions = new[] { node.Condition.ToString() }; return(new NodeInfo(NodeType.Selection, string.Empty, conditions, Empty, Empty)); }
//加载xm文件 public static DialogWriter LoadXMLEvent() { bool m_isTalkNode = true; if (Application.platform == RuntimePlatform.OSXPlayer) { Console.Log("sfdbdfsdgsfdgsfdds"); path = Application.dataPath + "/Resources/Data/StreamingAssets/dialogWriter.xml"; Console.Log(path); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { path = Application.dataPath + "/Raw/"; } else if (Application.platform == RuntimePlatform.Android) { path = "jar:file//" + Application.dataPath + "!/assets/"; } //} else if(Application.platform == RuntimePlatform.){ // path = Application.dataPath + "/StreamingAssets/"; //} XmlReader reader = new XmlTextReader(path); //提前设置的变量,用于保存读取文件时的各个子节点 DialogWriter newDialogWriter = null; DialogEvent newDialogEvent = null; TalkNode newTalkNode = null; SelectionNode newSelectionNode = null; TalkContent newTalkContent = null; string newSelect = ""; newDialogWriter = new DialogWriter(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == "DialogWriter") { if (newDialogWriter != null) { } //不会执行 } else if (reader.LocalName == "Event") { newDialogEvent = new DialogEvent(""); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Name") { newDialogEvent.m_name = reader.Value; } else if (reader.Name == "EventOrder") { newDialogEvent.m_eventOrder = int.Parse(reader.Value); } } if (newDialogWriter != null) { newDialogWriter.m_dialogEventList.Add(newDialogEvent); } } else if (reader.LocalName == "TalkNode") { newTalkNode = new TalkNode(""); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Name") { newTalkNode.m_name = reader.Value; } else if (reader.Name == "NodeType") { newTalkNode.m_dialogType = (DialogNode.NodeType)System.Enum.Parse(typeof(DialogNode.NodeType), reader.Value); } } //不是选择分支下的对话节点 if (m_isTalkNode) { if (newDialogEvent != null) { newDialogEvent.m_nodeList.Add(newTalkNode); } } else { if (newSelectionNode != null) { newSelectionNode.m_selection [newSelect] = newTalkNode; //每次都重新设为true m_isTalkNode = true; } } } else if (reader.LocalName == "Background") { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Name") { newTalkNode.m_background.Add(reader.Value); } } } else if (reader.LocalName == "Tachie") { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Name") { newTalkNode.m_tachie.Add(reader.Value); } } } else if (reader.LocalName == "TalkContent") { newTalkContent = new TalkContent(); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Background") { newTalkContent.m_backGround = int.Parse(reader.Value); } else if (reader.Name == "Tachie") { newTalkContent.m_tachie = int.Parse(reader.Value); } else if (reader.Name == "Name") { newTalkContent.m_name = reader.Value; } else if (reader.Name == "Content") { newTalkContent.m_content = reader.Value; } } if (newTalkNode != null) { newTalkNode.m_talkContents.Add(newTalkContent); } } else if (reader.LocalName == "SelectionNode") { newSelectionNode = new SelectionNode(""); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Name") { newSelectionNode.m_name = reader.Value; } } if (newDialogEvent != null) { newDialogEvent.m_nodeList.Add(newSelectionNode); } } else if (reader.LocalName == "Select") { m_isTalkNode = false; for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Select") { //把数值临时保存 newSelect = reader.Value; newSelectionNode.m_selection.Add(reader.Value, new TalkNode("")); } } } } } return(newDialogWriter); }