/// <summary> /// Removes this event from the object, restoring autonomy if appropriate /// </summary> /// <returns>true if the event is successfully detached</returns> private RunStatus Detach(BehaviorObject obj) { // If we were the object's current event, restore autonomy (even if the // object has another pending event -- that event will just stop it) if (obj.CurrentEvent == this) { obj.FinishEvent(); obj.StartBehavior(); } // If we were a pending event, then the response depends if (obj.PendingEvent == this) { // Was the object terminating because of us? If so, wait until it's // done terminating, and then restart it if (obj.Status == BehaviorStatus.Terminating) { return(RunStatus.Running); } // If the object isn't terminating (anymore), restart it if it's // idle and then clear the pending event if (obj.Status == BehaviorStatus.Idle) { obj.StartBehavior(); } obj.PendingEvent = null; // Don't worry if another pending event swoops in and replaces us, // it'll handle the object whether its terminating, running, or idle } return(RunStatus.Success); }
/// <summary> /// if you want to control a behavior agent, use this function to free agent /// from event, but after that, you have to call stopbehavior to stop agent's own autonomy. /// And most importantly, you have to use an interactive behavior tree as the root of /// event behavior tree because nodes related to the controlled agent should change correspondingly. /// With normal tree root, Do not use this Function, otherwise the event BT will mess up with agent's own BT! /// </summary> /// <param name="obj"></param> internal void Drop(BehaviorObject obj) { if (this.participants.Contains(obj) == true) { this.Detach(obj); } }
/// <summary> /// Terminates the object's current activity and gets it ready to execute /// </summary> private RunStatus Acquire(BehaviorObject obj) { // Reality check, make sure we're still the pending event if (obj.PendingEvent != this) { return(RunStatus.Failure); } // Either kill the active event or suspend the agent RunStatus result; if (obj.CurrentEvent != null) { result = obj.CurrentEvent.Yield(obj); } else { result = obj.StopBehavior(); } // If the current event is finished, clear it out if (result == RunStatus.Success) { obj.ClearEvent(); } return(result); }
public void LoadBehavior(File file, string fileContent) { if (file.configurationID != ma2MaComManager.robotManager.currentConfigurationID) { ma2MaComManager.ma2UIComManager.uI2MaComDirector.statusBarDirector.SetTempTextMessage("Cannot load behavior: Wrong configuration."); return; } XmlSerializer serializer = new XmlSerializer(typeof(BehaviorObject)); XmlReaderSettings settings = new XmlReaderSettings(); // No settings need modifying here using (StringReader textReader = new StringReader(fileContent)) { using (XmlReader xmlReader = XmlReader.Create(textReader, settings)) { BehaviorObject bo = serializer.Deserialize(xmlReader) as BehaviorObject; ma2MaComManager.behaviorManager.currentBehaviorObject = bo; ma2MaComManager.ma2UIComManager.uI2MaComDirector.panelBehaviorDirector.ClearAllButtons(); foreach (RobotStateObject rso in bo.listOfRobotStateObjects) { rso.button = ma2MaComManager.ma2UIComManager.uI2MaComDirector.panelBehaviorDirector.AddButton(rso); } ma2MaComManager.behaviorManager.robotStateObjectIndex = 0; } } }
/// <summary> /// Gives up a participating object for use in another event /// </summary> protected virtual RunStatus Yield(BehaviorObject obj) { if (this.participants.Contains(obj) == true) { return(this.StopEvent()); } // We don't have that object anyway return(RunStatus.Success); }
protected override RunStatus Yield(BehaviorObject obj) { Debug.Log("CrowdBehaviorEvent: Yielding " + obj.ToString()); if (this.participants.Contains(obj)) { ForEach <T> root = (ForEach <T>) this.treeRoot; return(root.RemoveParticipant(this.behaviorObjToParticipant[obj])); } return(RunStatus.Success); }
public void InitializeModule() { g_NPCController = GetComponent <NPCController>(); g_BehaviorObject = new BehaviorAgent( new DecoratorLoop( new LeafAssert(() => true))); BehaviorManager.Instance.Register((IBehaviorUpdate)g_BehaviorObject); g_NPCController.Debug("NPCBehavior - Initialized: " + name); g_Initialized = true; }
/// <summary> /// Registers this event as an object's pending event /// </summary> private RunStatus Enroll(BehaviorObject obj) { // Are we already enrolled? if (obj.PendingEvent == this) { return(RunStatus.Success); } // Kill any pending event and just replace it RunStatus result = RunStatus.Success; if (obj.PendingEvent != null) { result = obj.PendingEvent.Yield(obj); } if (result == RunStatus.Success) { obj.PendingEvent = this; } return(result); }
/// <summary> /// Checks whether we're eligible for a given objects /// </summary> protected RunStatus CheckEligible(BehaviorObject obj) { // if (obj == null)// // Debug.Log("null object" + obj.ToString()); return obj.IsElegible(this); }
/// <summary> /// Removes this event from the object, restoring autonomy if appropriate /// </summary> /// <returns>true if the event is successfully detached</returns> private RunStatus Detach(BehaviorObject obj) { // If we were the object's current event, restore autonomy (even if the // object has another pending event -- that event will just stop it) if (obj.CurrentEvent == this) { obj.FinishEvent(); obj.StartBehavior(); } // If we were a pending event, then the response depends if (obj.PendingEvent == this) { // Was the object terminating because of us? If so, wait until it's // done terminating, and then restart it if (obj.Status == BehaviorStatus.Terminating) return RunStatus.Running; // If the object isn't terminating (anymore), restart it if it's // idle and then clear the pending event if (obj.Status == BehaviorStatus.Idle) obj.StartBehavior(); obj.PendingEvent = null; // Don't worry if another pending event swoops in and replaces us, // it'll handle the object whether its terminating, running, or idle } return RunStatus.Success; }
/// <summary> /// Terminates the object's current activity and gets it ready to execute /// </summary> private RunStatus Acquire(BehaviorObject obj) { // Reality check, make sure we're still the pending event if (obj.PendingEvent != this) return RunStatus.Failure; // Either kill the active event or suspend the agent RunStatus result; if (obj.CurrentEvent != null) result = obj.CurrentEvent.Yield(obj); else result = obj.StopBehavior(); // If the current event is finished, clear it out if (result == RunStatus.Success) obj.ClearEvent(); return result; }
/// <summary> /// Registers this event as an object's pending event /// </summary> private RunStatus Enroll(BehaviorObject obj) { // Are we already enrolled? if (obj.PendingEvent == this) return RunStatus.Success; // Kill any pending event and just replace it RunStatus result = RunStatus.Success; if (obj.PendingEvent != null) result = obj.PendingEvent.Yield(obj); if (result == RunStatus.Success) obj.PendingEvent = this; return result; }
/// <summary> /// Gives up a participating object for use in another event /// </summary> protected virtual RunStatus Yield(BehaviorObject obj) { if (this.participants.Contains(obj) == true) return this.StopEvent(); // We don't have that object anyway return RunStatus.Success; }
// Use this for initialization void Start() { currentBehaviorObject = new BehaviorObject(); }
protected virtual void Initialize(BehaviorObject obj) { this.InitializeState(); this.Register(); this.RegisterAffordances(); this.Behavior = obj; this.Behavior.StartBehavior(); }
/// <summary> /// Checks whether we're eligible for a given objects /// </summary> protected RunStatus CheckEligible(BehaviorObject obj) { return(obj.IsElegible(this)); }
protected void StartTree( Node root, BehaviorObject.StatusChangedEventHandler statusChanged = null) { }
/// <summary> /// Checks whether we're eligible for a given objects /// </summary> protected RunStatus CheckEligible(BehaviorObject obj) { return obj.IsElegible(this); }
protected override void Initialize(BehaviorObject obj) { base.Initialize(obj); this.character = this.GetComponent<CharacterMecanim>(); this.behavior = this.GetComponent<BehaviorMecanim>(); if (this.MarkerHead == null) this.MarkerHead = this.GetComponent<Animator>().GetBoneTransform( HumanBodyBones.Head); }
void Start() { g_BehaviorObject = new BehaviorObject(); }
/// <summary> /// Checks whether we're eligible for a given objects /// </summary> protected RunStatus CheckEligible(BehaviorObject obj) { // if (obj == null)// // Debug.Log("null object" + obj.ToString()); return(obj.IsElegible(this)); }