/// <summary> /// Checks an interrupt condition, executing the given behaviour only if the condition returns False /// -Returns Success if the given behaviour returns Success and the condition returns False /// -Returns Running if the given behaviour returns Running and the condition returns False /// -Returns Failure if the given behaviour returns Failure or the condition returns True /// /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur /// </summary> /// <param name="name">the name of the interruptible</param> /// <param name="behaviour"></param> /// <param name="interruptCondition"></param> /// <param name="onInterruptReturn"></param> public Interruptible(string name, BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn) { Name = name; _behaviourComponent = behaviour; _interruptCondition = interruptCondition; _onInterruptReturn = onInterruptReturn; }
/// <summary> /// executes the behavior after a given amount of time in miliseconds has passed /// </summary> /// <param name="name">the name of the timer</param> /// <param name="elapsedTimeFunction">function that returns elapsed time</param> /// <param name="timeToWait">maximum time to wait before executing behavior</param> /// <param name="behaviour">behavior to run</param> public Timer(string name, Func <int> elapsedTimeFunction, int timeToWait, BehaviourComponent behaviour) { Name = name; _elapsedTimeFunction = elapsedTimeFunction; _behaviourComponent = behaviour; _waitTime = timeToWait; }
/// <summary> /// Checks an interrupt condition, executing the given behaviour only if the condition returns False /// -Returns Success if the given behaviour returns Success and the condition returns False /// -Returns Running if the given behaviour returns Running and the condition returns False /// -Returns Failure if the given behaviour returns Failure or the condition returns True /// /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur /// </summary> /// <param name="name">the name of the interruptible</param> /// <param name="behaviour"></param> /// <param name="interruptCondition"></param> /// <param name="onInterruptReturn"></param> public Interruptible(string name, BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn) { Name = name; _behaviourComponent = behaviour; _interruptCondition = interruptCondition; _onInterruptReturn = onInterruptReturn; }
/// <summary> /// executes the behavior after a given amount of time in miliseconds has passed /// </summary> /// <param name="name">the name of the timer</param> /// <param name="elapsedTimeFunction">function that returns elapsed time</param> /// <param name="timeToWait">maximum time to wait before executing behavior</param> /// <param name="behaviour">behavior to run</param> public Timer(string name, Func<int> elapsedTimeFunction, int timeToWait, BehaviourComponent behaviour) { Name = name; _elapsedTimeFunction = elapsedTimeFunction; _behaviourComponent = behaviour; _waitTime = timeToWait; }
/// <summary> /// randomly executes the behavior /// </summary> /// <param name="name">the name of the random decorator</param> /// <param name="probability">probability of execution</param> /// <param name="randomFunction">function that determines probability to execute</param> /// <param name="behaviour">behavior to execute</param> public RandomDecorator(string name, float probability, Func <float> randomFunction, BehaviourComponent behaviour) { Name = name; _probability = probability; _rRandomFunction = randomFunction; _behaviourComponent = behaviour; }
/// <summary> /// randomly executes the behavior /// </summary> /// <param name="name">the name of the random decorator</param> /// <param name="probability">probability of execution</param> /// <param name="randomFunction">function that determines probability to execute</param> /// <param name="behaviour">behavior to execute</param> public RandomDecorator(string name, float probability, Func<float> randomFunction, BehaviourComponent behaviour) { Name = name; _probability = probability; _rRandomFunction = randomFunction; _behaviourComponent = behaviour; }
public void AddComponent(ComponentDescriptor componentDescriptor) { Type vmType = componentDescriptor.ComponentType; Type componentType = BehaviourViewModelFactory.GetBehaviourFromViewModelProxy(vmType); BehaviourComponent component = BehaviourFactory.CreateFromType(componentType, entityData); entityData.AddComponent(component); //Create a viewmodel proxy for our new component BehaviourViewModel vm = BehaviourViewModelFactory.GetViewModelProxy(component); ComponentAdded?.Invoke(vm); }
/// <summary> /// Deserializes a given XElement into an entity, with the optional parent /// </summary> /// <param name="element">The xml element to derserialize into an entity</param> /// <param name="parent">The parent of the entity if any</param> /// <remarks>The method uses recursion to deserialize any children</remarks> /// <returns>The Deserialized version of the entity provided in the XElement</returns> private Entity DeserializeSceneEntity(XElement element, Entity parent = null) { Entity entity = new Entity(parent); entity.Name = element.Attribute(nameof(entity.Name))?.Value; string guidAttribute = element.Attribute(nameof(entity.GUID))?.Value; Guid guid; if (guidAttribute != null && Guid.TryParse(guidAttribute, out guid)) { entity.GUID = guid; } else { entity.GUID = Guid.NewGuid(); } IEnumerable <XElement> behaviours = element.Element("Components")?.Elements(); if (behaviours != null) { foreach (XElement behaviourElement in behaviours) { BehaviourComponent behaviour = BehaviourFactory.CreateWithName(behaviourElement.Name.LocalName, entity); if (behaviour != null) { behaviour.Deserialize(behaviourElement); entity.Components.Add(behaviour); } } } IEnumerable <XElement> children = element.Element("Children")?.Elements(); if (children != null) { foreach (XElement childElement in children) { Entity childEntity = DeserializeSceneEntity(childElement, entity); entity.Children.Add(childEntity); } } return(entity); }
public override string ToString() { StringBuilder keyframeName = new StringBuilder(); if (Target is BehaviourComponent) { BehaviourComponent behaviour = (Target as BehaviourComponent); keyframeName.Append(behaviour.Parent.ToString()); keyframeName.Append(" : "); keyframeName.Append(behaviour.ToString()); } else { keyframeName.Append(Target.ToString()); } keyframeName.Append(" - "); keyframeName.Append(Property.Property.Name); return(keyframeName.ToString()); }
public static BehaviourViewModel GetViewModelProxy(BehaviourComponent behaviour) { try { Type vmType = null; //Check if we have a viewmodel for this behaviour if (behaviourVmMapping.TryGetValue(behaviour.GetType(), out vmType)) { //Create a new instance of this ViewModel //the only constructor parameter is the source behaviour this //viewmodel is wrapping object instance = Activator.CreateInstance(vmType, behaviour); BehaviourViewModel vm = instance as BehaviourViewModel; return(vm); } } catch (Exception e) { DebugUtil.LogWithLocation($"Error Occured Getting ViewModel for {behaviour.ToString()}"); } return(null); }
/// <summary> /// executes the behavior based on a counter /// -each time Counter is called the counter increments by 1 /// -Counter executes the behavior when it reaches the supplied maxCount /// </summary> /// <param name="name">the name of the counter</param> /// <param name="maxCount">max number to count to</param> /// <param name="behaviour">behavior to run</param> public Counter(string name, int maxCount, BehaviourComponent behaviour) { Name = name; _maxCount = maxCount; _behaviour = behaviour; }
/// <summary> /// inverts the given behavior /// -Returns Success on Failure or Error /// -Returns Failure on Success /// -Returns Running on Running /// </summary> /// <param name="behaviour"></param> public Inverter(BehaviourComponent behaviour) : this("", behaviour) { }
public float Update(IUpdateEventArgs args) { return(BehaviourComponent.Update(args)); }
/// <summary> /// executes the behavior based on a counter /// -each time Counter is called the counter increments by 1 /// -Counter executes the behavior when it reaches the supplied maxCount /// </summary> /// <param name="maxCount">max number to count to</param> /// <param name="behaviour">behavior to run</param> public Counter(int maxCount, BehaviourComponent behaviour) : this("", maxCount, behaviour) { }
/// <summary> /// Checks an interrupt condition, executing the given behaviour only if the condition returns False /// -Returns Success if the given behaviour returns Success and the condition returns False /// -Returns Running if the given behaviour returns Running and the condition returns False /// -Returns Failure if the given behaviour returns Failure or the condition returns True /// /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur /// </summary> /// <param name="behaviour"></param> /// <param name="interruptCondition"></param> /// <param name="onInterruptReturn"></param> public Interruptible(BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn) : this("", behaviour, interruptCondition, onInterruptReturn) { }
/// <summary> /// Registers the given entity to this manager. /// </summary> /// <param name="entity"></param> public virtual void RegisterEntity(BehaviourComponent entity) { Entities.Add(entity); }
/// <summary> /// executes the behavior after a given amount of time in miliseconds has passed /// </summary> /// <param name="elapsedTimeFunction">function that returns elapsed time</param> /// <param name="timeToWait">maximum time to wait before executing behavior</param> /// <param name="behaviour">behavior to run</param> public Timer(Func<int> elapsedTimeFunction, int timeToWait, BehaviourComponent behaviour) : this("", elapsedTimeFunction, timeToWait, behaviour) { }
/// <summary> /// inverts the given behavior /// -Returns Success on Failure or Error /// -Returns Failure on Success /// -Returns Running on Running /// </summary> /// <param name="name">the name of the inverter</param> /// <param name="behaviour"></param> public Inverter(string name, BehaviourComponent behaviour) { Name = name; _behaviourComponent = behaviour; }
/// <summary> /// executes the behavior after a given amount of time in miliseconds has passed /// </summary> /// <param name="elapsedTimeFunction">function that returns elapsed time</param> /// <param name="timeToWait">maximum time to wait before executing behavior</param> /// <param name="behaviour">behavior to run</param> public Timer(Func <int> elapsedTimeFunction, int timeToWait, BehaviourComponent behaviour) : this("", elapsedTimeFunction, timeToWait, behaviour) { }
/// <summary> /// inverts the given behavior /// -Returns Success on Failure or Error /// -Returns Failure on Success /// -Returns Running on Running /// </summary> /// <param name="behaviour"></param> public Inverter(BehaviourComponent behaviour) : this("", behaviour) { }
private void DeserializeBehaviour(BehaviourComponent behaviour, XElement behaviourData) { }
/// <summary> /// randomly executes the behavior /// </summary> /// <param name="probability">probability of execution</param> /// <param name="randomFunction">function that determines probability to execute</param> /// <param name="behaviour">behavior to execute</param> public RandomDecorator(float probability, Func<float> randomFunction, BehaviourComponent behaviour) : this("", probability, randomFunction, behaviour) { }
public void AddComponent(BehaviourComponent component) { component.internalRouter = internalRouter; Components.Add(component); }
/// <summary> /// inverts the given behavior /// -Returns Success on Failure or Error /// -Returns Failure on Success /// -Returns Running on Running /// </summary> /// <param name="name">the name of the inverter</param> /// <param name="behaviour"></param> public Inverter(string name, BehaviourComponent behaviour) { Name = name; _behaviourComponent = behaviour; }
/// <summary> /// Checks an interrupt condition, executing the given behaviour only if the condition returns False /// -Returns Success if the given behaviour returns Success and the condition returns False /// -Returns Running if the given behaviour returns Running and the condition returns False /// -Returns Failure if the given behaviour returns Failure or the condition returns True /// /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur /// </summary> /// <param name="behaviour"></param> /// <param name="interruptCondition"></param> /// <param name="onInterruptReturn"></param> public Interruptible(BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn) : this("", behaviour, interruptCondition, onInterruptReturn) { }
/// <summary> /// executes the behavior based on a counter /// -each time Counter is called the counter increments by 1 /// -Counter executes the behavior when it reaches the supplied maxCount /// </summary> /// <param name="maxCount">max number to count to</param> /// <param name="behaviour">behavior to run</param> public Counter(int maxCount, BehaviourComponent behaviour) : this("", maxCount, behaviour) { }
/// <summary> /// randomly executes the behavior /// </summary> /// <param name="probability">probability of execution</param> /// <param name="randomFunction">function that determines probability to execute</param> /// <param name="behaviour">behavior to execute</param> public RandomDecorator(float probability, Func <float> randomFunction, BehaviourComponent behaviour) : this("", probability, randomFunction, behaviour) { }
/// <summary> /// executes the behavior based on a counter /// -each time Counter is called the counter increments by 1 /// -Counter executes the behavior when it reaches the supplied maxCount /// </summary> /// <param name="name">the name of the counter</param> /// <param name="maxCount">max number to count to</param> /// <param name="behaviour">behavior to run</param> public Counter(string name, int maxCount, BehaviourComponent behaviour) { Name = name; _maxCount = maxCount; _behaviour = behaviour; }
private XElement SerializeBehaviour(BehaviourComponent behaviour) { return(null); }