/// <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;
 }
示例#2
0
 /// <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;
 }
示例#3
0
 /// <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;
 }
示例#4
0
 /// <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;
 }
示例#5
0
 /// <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;
 }
示例#7
0
        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);
        }
示例#8
0
        /// <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);
        }
示例#9
0
        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);
 }
示例#11
0
 /// <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;
 }
示例#12
0
 /// <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)
 {
 }
示例#13
0
 public float Update(IUpdateEventArgs args)
 {
     return(BehaviourComponent.Update(args));
 }
示例#14
0
 /// <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)
 {
 }
示例#15
0
 /// <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)
 {
 }
示例#16
0
 /// <summary>
 ///     Registers the given entity to this manager.
 /// </summary>
 /// <param name="entity"></param>
 public virtual void RegisterEntity(BehaviourComponent entity)
 {
     Entities.Add(entity);
 }
示例#17
0
 /// <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)
 {
 }
示例#18
0
 /// <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;
 }
示例#19
0
 /// <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)
 {
 }
示例#20
0
 /// <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)
 {
 }
示例#21
0
 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)
 {
 }
示例#23
0
 public void AddComponent(BehaviourComponent component)
 {
     component.internalRouter = internalRouter;
     Components.Add(component);
 }
示例#24
0
 /// <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)
 {
 }
示例#26
0
 /// <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)
 {
 }
示例#27
0
 /// <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)
 {
 }
示例#28
0
 /// <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;
 }
示例#29
0
 private XElement SerializeBehaviour(BehaviourComponent behaviour)
 {
     return(null);
 }