/// <summary> /// Constructs a new BehaviorObject capable of participating in events /// </summary> /// <param name="root">The root node of the tree</param> /// <param name="statusChanged">An OnStatusChanged delegate for receiving /// status change events</param> public BehaviorObject() { this.CurrentEvent = null; this.PendingEvent = null; this.Status = BehaviorStatus.Idle; this.Register(); }
private void FireTransitionEvent <T>(BehaviorEvent <T> args, TransitionEventDelegate <T> transitionEventDelegate, string viewName) where T : IViewModel, new() { var transitionEvent = new TransitionEvent <T>(args) { ViewModel = args.ViewModel, ViewReference = viewName, PreviousViewReference = this.CurrentViewReference }; transitionEventDelegate(transitionEvent); if (viewName != null) { this.CurrentViewReference = viewName; } this.ScriptManager = ScriptManager.GetCurrent(this.Page); if (this.ScriptManager != null && this.ScriptManager.IsInAsyncPostBack && this.ScriptManager.EnableHistory && string.IsNullOrEmpty(viewName) == false) { this.ScriptManager.AddHistoryPoint(new NameValueCollection { { "pv", transitionEvent.PreviousViewReference } }, transitionEvent.PreviousViewReference); } }
/// <summary> /// Returns true if and only if the candidate event is higher /// priority than both the running and next pending event, if any /// </summary> internal RunStatus IsElegible(BehaviorEvent candidate) { // Debug.Log("start"); if (this.CurrentEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0) { // Debug.Log("fail 1"); // Debug.Log("candidate " + candidate.Priority + " " + this.CurrentEvent.Priority); return(RunStatus.Failure); } if (this.pendingEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0) { //Debug.Log("fail 2 " + candidate.Priority + " " + this.pendingEvent.Priority + " "); return(RunStatus.Failure); } // Debug.Log("success"); return(RunStatus.Success); }
void Update() { if (Input.GetButtonDown("Fire2")) { Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit); BehaviorEvent.Run(new Sequence(Node_GoTo(position)), this); } }
void Update() { if (Input.GetKeyDown(KeyCode.R) == true) { BehaviorEvent.Run( this.ConversationTree(), Wanderer, Friend); } }
protected bool FireBehaviorEvent <T>(BehaviorEventHandler <T> handler, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { if (behaviorEvent == null) { return(false); } return(handler != null && handler(this as IBehaviorEventSender <T>, behaviorEvent)); }
protected void InvokeEvent(BehaviorEvent evt) { BehaviorComponent[] agents = evt.Agents; for (int i = 0; i < agents.Count(); i++) { agents[i].Suspended = true; this.idleAgents.Remove(agents[i]); } this.activeEvents.Add(evt); evt.Start(); }
private void EventStatusChanged( BehaviorEvent sender, EventStatus newStatus) { if (newStatus == EventStatus.Finished) { this.SendFreeObjects(sender.Token.Get<uint[]>()); this.SendRecommendationRequest(); this.paused = true; } }
// Use this for initialization void Start() { participants = findBAgent(); Behavior = new BehaviorEvent((Token toke) => this.BuildTreeRoot(), this.participants); //participants = findBAcrowd(); //Crowd = new CrowdBehaviorEvent<AdamBehaviorTree>((AdamBehaviorTree tree, object token)=>this.BuildTreeRoot(),this.participants); currentStoryID = StoryID.mainstoryarc; adam1Freed = false; }
/// <summary> /// Constructs a new BehaviorAgent responsible for taking care of a tree /// </summary> /// <param name="root">The root node of the tree</param> /// <param name="statusChanged">An OnStatusChanged delegate for receiving /// status change events</param> public BehaviorAgent(Node root, OnStatusChanged statusChanged) { this.treeRoot = root; this.pendingEvent = null; this.statusChanged = statusChanged; this.AgentStatus = Status.Idle; if (BehaviorManager.Instance == null) { Debug.LogError(this + ": No BehaviorManager!"); } else { BehaviorManager.RegisterReceiver(this); } }
/// <summary> /// Returns true if and only if the candidate event is higher /// priority than both the running and next pending event, if any /// </summary> internal RunStatus IsElegible(BehaviorEvent candidate) { if (this.CurrentEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0) { return(RunStatus.Failure); } if (this.pendingEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0) { return(RunStatus.Failure); } return(RunStatus.Success); }
/// <summary> /// Returns true if and only if the candidate event is higher /// priority than both the running and next pending event, if any /// </summary> public bool EventElegible(BehaviorEvent candidate) { if (this.CurrentEvent != null && BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0) { return(false); } if (this.pendingEvent != null && BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0) { return(false); } return(true); }
public void StartEvent(Node behavior, bool interruptible = false, IHasBehaviorObject[] agents = null) { if (Enabled) { if (interruptible) { float priority = 1f; if (InEvent) { priority = g_BehaviorObject.CurrentEvent.Priority + 0.1f; } } agents = agents == null ? new IHasBehaviorObject[] { this } : agents; BehaviorEvent ev = new BehaviorEvent(doEvent => behavior, agents); ev.StartEvent(InEvent ? g_BehaviorObject.CurrentPriority + 1f : 1f); } }
/// <summary> /// Notification that our pending event has become our current event /// </summary> public void EventStarted() { if (this.CurrentEvent != null) { throw new ApplicationException( this + ".EventStarted(): Clearing active event"); } else if (this.AgentStatus != Status.Idle) { throw new ApplicationException( this + ".EventStarted(): Starting evt on busy agent"); } this.CurrentEvent = this.pendingEvent; this.pendingEvent = null; this.AgentStatus = Status.InEvent; }
/// <summary> /// Notification that our pending event has become our current event /// </summary> internal void LaunchEvent() { if (this.CurrentEvent != null) { throw new ApplicationException( this + ".EventStarted(): Clearing active event"); } else if (this.Status != BehaviorStatus.Idle) { throw new ApplicationException( this + ".EventStarted(): Starting evt on busy agent"); } this.CurrentEvent = this.pendingEvent; this.pendingEvent = null; this.Status = BehaviorStatus.InEvent; }
void Update() { if (Input.GetButtonDown("Fire1")) { RaycastHit hit; Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit); if (hit.transform.parent != null && hit.transform.parent.gameObject.name == "Food Stand") { BehaviorEvent.Run(this.Eat(hit.transform.parent), player); } else if (hit.transform.gameObject.name == "Soil") { Debug.Log(player.Agent.AgentStatus); //if() BehaviorEvent.Run(this.Dig(hit.transform), player); } } }
public void Update() { // Skip user input if we are replaying. if (ReplayManager.Instance.mIsReplaying) { return; } foreach (KeyValuePair<ControlSignal, Behavior> key_behavior in mBehaviors) { ControlSignal controlSignal = key_behavior.Key; float signal = controlSignal.PollSignal(); Behavior behavior = key_behavior.Value; bool shouldRecord = behavior.Operate(signal); if (shouldRecord) { BehaviorEvent behavior_event = new BehaviorEvent(behavior.GenerateRecordedBehavior(), signal); ReplayManager.Instance.AddEvent(behavior_event); } } }
public bool SendBehaviorEvent <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { var success = false; foreach (var fireBehaviorEventDelegate in this.FireBehaviorEventDelegates) { if (fireBehaviorEventDelegate.Invoke(behaviorEvent)) { success = true; } } if (success == false) { var @base = this.Parent as ViewBase; if (@base != null) { success = @base.SendBehaviorEvent(behaviorEvent); } } return(success); }
/// <summary> /// Notification that our pending event has become our current event /// </summary> internal void LaunchEvent() { if (this.CurrentEvent != null) throw new ApplicationException( this + ".EventStarted(): Clearing active event"); else if (this.Status != BehaviorStatus.Idle) throw new ApplicationException( this + ".EventStarted(): Starting evt on busy agent"); this.CurrentEvent = this.pendingEvent; this.pendingEvent = null; this.Status = BehaviorStatus.InEvent; }
/// <summary> /// Returns true if and only if the candidate event is higher /// priority than both the running and next pending event, if any /// </summary> internal RunStatus IsElegible(BehaviorEvent candidate) { if (this.CurrentEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0) return RunStatus.Failure; if (this.pendingEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0) return RunStatus.Failure; return RunStatus.Success; }
protected virtual void OnBeforeBehaviorLookup <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { }
public static int ComparePriority(BehaviorEvent a, BehaviorEvent b) { // Debug.Log(a.Priority + " " + b.Priority); return Comparer<float>.Default.Compare(a.Priority, b.Priority); }
protected virtual void OnBehaviorEvent <T>(IExecutableBehavior <T> executableBehavior, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { executableBehavior.Execute(behaviorEvent); }
private void TransitionView <T>(ICanChangeMyVisibility sender, string viewName, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { this.TransitionView(sender, viewName); this.FireTransitionEvent(behaviorEvent, this.OnTransitionEvent, viewName); //if (sender is IBehaviorEventSender<T>) this.CurrentViewReference = viewName; }
public virtual void OnAfterTransition <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { }
public bool _ <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { return(this.SendBehaviorEvent(behaviorEvent)); }
/// <summary> /// Void methods are self contained behaviors of an agent /// </summary> /// <param name="code"></param> public void Behavior_DoTimedGesture(GESTURE_CODE code) { BehaviorEvent be = new BehaviorEvent(doEvent => NPCBehavior_DoTimedGesture(code), new IHasBehaviorObject[] { this }); be.StartEvent(1f); }
public static int ComparePriority(BehaviorEvent a, BehaviorEvent b) { return(Comparer <float> .Default.Compare(a.Priority, b.Priority)); }
public static int ComparePriority(BehaviorEvent a, BehaviorEvent b) { return Comparer<float>.Default.Compare(a.Priority, b.Priority); }
protected abstract void OnEventCompleted(BehaviorEvent evt);
public static int ComparePriority(BehaviorEvent a, BehaviorEvent b) { // Debug.Log(a.Priority + " " + b.Priority); return(Comparer <float> .Default.Compare(a.Priority, b.Priority)); }
protected virtual void OnAfterBehaviorEvent <T>(IBehaviorEventSender <T> sender, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { }
private bool OnBehaviorEventFired <T>(IBehaviorEventSender <T> sender, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { this.OnBeforeBehaviorLookup(behaviorEvent); if (this.Behaviors.ContainsKey(behaviorEvent.BehaviorReference) == false) { return(false); } var behavior = this.Behaviors[behaviorEvent.BehaviorReference] as IExecutableBehavior <T>; if (behavior == null) { return(false); } behavior.BehaviorContext = this; this.OnBeforeBehaviorEvent(sender, behaviorEvent); try { this.OnBehaviorEvent(behavior, behaviorEvent); } catch (Exception ex) { this.OnErrorBehaviorEvent(ex); return(false); } this.OnAfterBehaviorEvent(sender, behaviorEvent); string viewName = null; if (this.BehaviorBinding.ContainsKey(behaviorEvent.BehaviorReference)) { viewName = this.BehaviorBinding[behaviorEvent.BehaviorReference]; } this.OnBeforeTransitionEvent(viewName, behavior); var view = sender as ViewBase; if (view != null) { view.BehaviorContext = this; } this.TransitionView(view, viewName, behaviorEvent); if (viewName == null && sender is ViewBase) { this.BindingViewModel(sender as ViewBase, behaviorEvent.ViewModel); } else if (viewName != null) { var next = this.GetNextView(viewName); if (next != null) { this.BindingViewModel(next, behaviorEvent.ViewModel); next.OnAfterTransition(behaviorEvent); foreach (var sub in next.Controls.OfType <ViewBase>()) { sub.BehaviorContext = next.BehaviorContext; sub.OnAfterTransition(behaviorEvent); } } } this.OnAfterTransitionEvent(viewName, behavior); return(true); }
public bool FireBehaviorEvent <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new() { return(this.OnBehaviorEventFired(null, behaviorEvent)); }
public void StartEvent(Node behavior) { BehaviorEvent ev = new BehaviorEvent(doEvent => behavior, new IHasBehaviorObject[] { this }); ev.StartEvent(InEvent ? g_BehaviorObject.CurrentPriority + 1f : 1f); }
/// <summary> /// Returns true if and only if the candidate event is higher /// priority than both the running and next pending event, if any /// </summary> internal RunStatus IsElegible(BehaviorEvent candidate) { // Debug.Log("start"); if (this.CurrentEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0) { // Debug.Log("fail 1"); // Debug.Log("candidate " + candidate.Priority + " " + this.CurrentEvent.Priority); return RunStatus.Failure; } if (this.pendingEvent != null && pendingEvent != candidate && BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0) { //Debug.Log("fail 2 " + candidate.Priority + " " + this.pendingEvent.Priority + " "); return RunStatus.Failure; } // Debug.Log("success"); return RunStatus.Success; }