public override TaskResult Run(ITaskNode node) { Assert.IsFalse(string.IsNullOrEmpty(this.Name)); var go = node.Context.GetGameObject(); // TODO: Improve sensor discovery and cache in state. var sensorTx = go.transform.Find(this.Name); Assert.IsNotNull(sensorTx); switch (this.Action) { case ActionKind.Activate: sensorTx.gameObject.SetActive(true); break; case ActionKind.Deactivate: sensorTx.gameObject.SetActive(false); break; default: throw new InvalidOperationException(string.Format("Unsupported {0} value {1}", typeof(ActionKind), this.Action)); } return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { // TODO: Remove this as it isn't very clear it will happen. if (!this.level.IsStarted) { return(TaskResult.Pending); } var result = this.level.CheckRequiredObjectives(this.Category); switch (result) { case LevelObjectiveResult.Completed: return(TaskResult.Success); case LevelObjectiveResult.Failed: return(TaskResult.Failure); case LevelObjectiveResult.Pending: return(TaskResult.Pending); default: throw new InvalidOperationException(string.Format("Unsupported {0} value {1}", typeof(LevelObjectiveResult), result)); } }
public override TaskResult Run(ITaskNode node) { Debug.LogFormat("LevelControl: {0}", this.Action); var level = Indexed.GetSingle <ILevelSystem>(); switch (this.Action) { case ControlKind.Pause: level.PauseLevel(); break; case ControlKind.Resume: level.ResumeLevel(); break; case ControlKind.Start: level.StartLevel(); break; case ControlKind.Stop: level.StopLevel(); break; case ControlKind.ResetState: level.ResetState(); break; default: throw new InvalidOperationException(string.Format("Unsupported {0} value {1}", typeof(ControlKind), this.Action)); } return(TaskResult.Success); }
protected override ISlotController Listen(ITaskNode node) { var go = node.Context.GetGameObject(); return(this.signal.AddListener(go, data => { if (string.Equals(data.name, this.Name, StringComparison.OrdinalIgnoreCase)) { var shouldSignal = false; switch (this.Check) { case CheckKind.None: break; case CheckKind.Empty: shouldSignal = data.group.IsEmpty(this.Name); break; } if (shouldSignal) { this.OnSignalled(node); } } })); }
private void EditListViewItem(ListViewItem item, ITaskNode node) { item.Tag = node; if (node is RedirectTaskNode) { item.SubItems[1].Text = ((RedirectTaskNode)node).Url; } if (node is RefreshTaskNode) { } if (node is ManualTaskNode) { } if (node is ClickTaskNode) { item.SubItems[2].Text = ((ClickTaskNode)node).Element.ToString(); } if (node is FocusTaskNode) { item.SubItems[2].Text = ((FocusTaskNode)node).Element.ToString(); } if (node is InputTaskNode) { var input = (InputTaskNode)node; item.SubItems[2].Text = input.Element.ToString(); item.SubItems[3].Text = input.Text; } }
private void AddLog(ITaskNode taskNode, bool isSuccessfull = true) { Invoke(new Action(() => { var item = new ListViewItem(taskNode.ToString()); item.Tag = taskNode; listViewLog.Items.Add(item); if (!isSuccessfull) { DoFailLastLog(); } if (taskNode is ManualTaskNode) { var button = new Button(); button.Text = "完成"; button.Font = new Font("宋体", 9, GraphicsUnit.Point); listViewLog.Controls.Add(button); button.Location = new Point(listViewLog.Width - 42, item.Position.Y); button.Size = new Size(40, 20); button.Tag = taskNode; button.Click += (sender, e) => { ((ManualTaskNode)((Button)sender).Tag).IsFinished = true; listViewLog.Controls.Remove(button); }; //显示窗体 Show(); } })); }
public override TaskResult Run(ITaskNode node) { var state = (State)node.State; if (state.slot == null) { var sigCtx = node.Context.GetSignalContext(); state.slot = flagSignal.AddListener(sigCtx, data => { if (string.Equals(data.name, this.Flag, System.StringComparison.OrdinalIgnoreCase)) { // The callback can be executed even if the enclosing subtree is stopped, so we potentially schedule // an unnecessary iteration here. But we allow it because it won't be harmful, and there's no way of // pausing it without breaking the expected behaviour. // // TODO: Maybe supply a StopReason to the stop methods. this.scheduler.Schedule(node.Context); // We only want to process one raising of the flag, so pause until the task is re-run. state.slot.Pause(); } }); } // Resume for the signal slot so that we receive the next raising of the slot. if (state.slot.IsPaused) { state.slot.Resume(); } return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { Assert.IsFalse(string.IsNullOrEmpty(this.Group)); var go = node.Context.GetGameObject(); var detection = go.GetComponent <DetectionCache>(); Assert.IsNotNull(detection); var groups = go.GetComponent <GameObjectGroup>(); Assert.IsNotNull(groups); if (detection.StartedDetections.Count == 0) { return(TaskResult.Failure); } var detectedGo = detection.StartedDetections[0]; groups.Add(detectedGo, this.Group); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { Assert.IsFalse(string.IsNullOrEmpty(this.Profile)); var state = (State)node.State; if (string.IsNullOrEmpty(this.Group)) { this.damageSys.ApplyDamage(state.unit, this.Profile, state.unit); } else { var victims = state.groups.GetInGroup(this.Group); for (int i = 0; i < victims.Count; i++) { if (ObjectValidator.Validate(victims[i])) { var victim = victims[i].GetComponent <Unit>(); this.damageSys.ApplyDamage(state.unit, this.Profile, victim); } } victims.ReturnToPool(); } return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var ctx = node.Context; var go = ctx.GetGameObject(this.Target); var source = ctx.GetItem <IEnumerable <GameObject> >(this.Source).ToArray(); if (!source.Any()) { return(TaskResult.Failure); } GameObject closest = null; float closestDist = float.MaxValue; foreach (var srcGo in source) { var d = Vector3.Distance(go.transform.position, srcGo.transform.position); if (d < closestDist) { closest = srcGo; closestDist = d; } } if (closest == null) { throw new System.InvalidOperationException("Closest gameobject not found"); } ctx.SetItem(this.Assign, closest); return(TaskResult.Success); }
public virtual void Initialize(ITaskNode taskNode) { foreach (var task in this.GetChildren()) { taskNode.Enqueue(task); } }
public override TaskResult Run(ITaskNode node) { var ctx = node.Context; var go = ctx.GetGameObject(); if (!string.IsNullOrEmpty(this.Info)) { UnityEngine.Debug.Log(FormatMsg(this.Info, go), go); } if (!string.IsNullOrEmpty(this.Warn)) { UnityEngine.Debug.LogWarning(FormatMsg(this.Warn, go), go); } if (!string.IsNullOrEmpty(this.Error)) { UnityEngine.Debug.LogError(FormatMsg(this.Error, go), go); } #if UNITY_EDITOR if (this.Select) { Selection.activeGameObject = go; } #endif if (this.Break) { //UnityEngine.Debug.Log(string.Format("Breaking in task {0}", this)); UnityEngine.Debug.Break(); } return(TaskResult.Success); }
protected override void Initializing(ITaskNode node) { var go = node.Context.GetGameObject(); var state = (MoveState)node.State; state.Mover = go.GetComponent <Mover>(); }
public override TaskResult Run(ITaskNode node) { var ctx = node.Context; var targets = ctx.GetGameObjects(this.Target); var tagsToSet = MultiTags.Parse(this.Set); var tagsToUnset = MultiTags.Parse(this.Unset); foreach (var t in targets) { var multitags = t.GetComponent <MultiTags>(); if (multitags == null) { throw new InvalidOperationException(string.Format("Target gameobject {0} does not have a MultiTags component", t)); } foreach (var tag in tagsToSet) { multitags.AddTag(tag); } foreach (var tag in tagsToUnset) { multitags.RemoveTag(tag); } } return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var mover = node.Context.GetGameObject().GetComponent <Mover>(); switch (this.Action) { case ActionKind.None: break; case ActionKind.Play: mover.Driver.Play(); break; case ActionKind.Pause: mover.Driver.Pause(); break; case ActionKind.Cancel: mover.Driver.Cancel(); break; default: throw new InvalidOperationException(string.Format("Unknown move control action {0}", this.Action)); } return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var scoring = node.Context.GetComponent <Scoring>(); scoring.AddPoints(this.Key); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var level = Indexed.GetSingle <ILevelSystem>(); level.Configure(level.LevelNumber + 1); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var unit = node.Context.GetComponent <Unit>(); this.damageSys.CancelDamage(unit, this.Profile); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var firer = node.Context.GetGameObject().GetComponent <FireController>(); return(firer.IsFiring ? TaskResult.Pending : TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var detectionCache = node.Context.GetGameObject().GetComponent <DetectionCache>(); detectionCache.Cleanup(this.Started || this.All, this.Ended || this.All); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var targetable = node.Context.GetGameObject().GetComponent <Targetable>(); targetable.isTargetable = this.Value; return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var levelRating = Indexed.GetSingle <LevelRating>(); levelRating.Calculate(); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { var audioBoard = node.Context.GetComponent <AudioBoard>(); this.audioSystem.PlayClip(audioBoard, this.Key); return(TaskResult.Success); }
protected override void Initializing(ITaskNode node) { var state = (State)node.State; var go = node.Context.GetGameObject(); state.groups = go.GetComponent <GameObjectGroup>(); state.unit = go.GetComponent <Unit>(); }
public override TaskResult Run(ITaskNode node) { var spawner = node.Context.GetComponent <Spawner>(); var pos = node.Context.GetItem <Vector3>(Key); spawner.SpawnPosition = pos; return(TaskResult.Success); }
public void SetNode(ITaskNode node) { if (!(node is FocusTaskNode)) { throw new ArgumentException("参数“node”必须是 FocusTaskNode 类型。"); } elementControl1.SetElement(((FocusTaskNode)node).Element); }
public override TaskResult Run(ITaskNode node) { var go = node.Context.GetGameObject(); var unit = go.GetComponent <Unit>(); var damage = go.GetComponent <Damage>(); damage.profiles[0].targetDamage = unit.strength.Value; return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { Assert.IsFalse(string.IsNullOrEmpty(this.Group)); var go = node.Context.GetGameObject(); this.groups.Remove(go, this.Group); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { Assert.IsFalse(string.IsNullOrEmpty(this.Group)); var groups = node.Context.GetComponent <GameObjectGroup>(); groups.Remove(this.Group); return(TaskResult.Success); }
public override TaskResult Run(ITaskNode node) { Assert.IsFalse(string.IsNullOrEmpty(this.Driver)); var mover = node.Context.GetGameObject().GetComponent <Mover>(); mover.SetDriver(this.Driver); return(TaskResult.Success); }