Exemplo n.º 1
0
    public void PerformTrigger(TriggerOption tOption)
    {
        if (!procced && isActive)
        {
            procced = true;
            foreach (GameObject gameObj in targets)
            {
                if (preventPropigation)
                {
                    TriggerPropagator[] propagators = gameObj.GetComponents <TriggerPropagator>();
                    foreach (TriggerPropagator propigator in propagators)
                    {
                        propigator.procced = true;
                    }

                    gameObj.SendMessage("PerformTrigger", tOption, SendMessageOptions.DontRequireReceiver);

                    foreach (TriggerPropagator propigator in propagators)
                    {
                        propigator.procced = false;
                    }
                }
                else
                {
                    gameObj.SendMessage("PerformTrigger", tOption, SendMessageOptions.DontRequireReceiver);
                }
            }
            procced = false;
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// This is called when a trigger meets the conditions to change state.
 /// </summary>
 /// <param name="tOption"></param>
 public virtual void PerformTrigger(TriggerOption tOption)
 {
     if (isActive)
     {
         ApplyTriggerOption(tOption);
     }
 }
Exemplo n.º 3
0
        public Trigger(
            string identifier,
            Action <ITriggerMsg> call,
            TriggerOption opt,
            TriggerThreading threading)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier), nullEx);
            }
            if (call == null)
            {
                throw new ArgumentNullException(nameof(call));
            }
            if (identifier == string.Empty)
            {
                throw new ArgumentException(emptyEx, nameof(identifier));
            }
            if (Tools.ContainsWhitespace(identifier))
            {
                throw new ArgumentException(whiteEx, nameof(identifier));
            }

            Identifiers = new ReadOnlyCollection <string>(new[] { identifier });
            Call        = call;
            Option      = opt;
            Threading   = threading;
        }
 override public void PerformTrigger(TriggerOption tOption)
 {
     base.PerformTrigger(tOption);
     if (isActive)
     {
         ToggleGameObjects();
     }
 }
Exemplo n.º 5
0
        public Trigger(
            Action <ITriggerMsg> call,
            TriggerOption opt,
            TriggerThreading threading,
            params string[] identifiers)
        {
            if (call == null)
            {
                throw new ArgumentNullException(nameof(call));
            }
            if (identifiers == null)
            {
                throw new ArgumentNullException(nameof(identifiers));
            }
            if (identifiers.Length == 0)
            {
                throw new ArgumentException("Cannot be an empty collection.", nameof(identifiers));
            }

            // Create our own copy.
            var triggerIdents = new string[identifiers.Length];

            for (int i = 0; i < identifiers.Length; i++)
            {
                var id = identifiers[i];

                if (id == null)
                {
                    throw new ArgumentException(nullEx, nameof(identifiers));
                }
                if (id == string.Empty)
                {
                    throw new ArgumentException(emptyEx, nameof(identifiers));
                }
                if (Tools.ContainsWhitespace(id))
                {
                    throw new ArgumentException(whiteEx, nameof(identifiers));
                }

                // We need to check each element anyway, so use the loop the create our own copy
                // instead of using Array.Copy afterwards.
                triggerIdents[i] = id;
            }

            Identifiers = new ReadOnlyCollection <string>(triggerIdents);
            Call        = call;
            Option      = opt;
            Threading   = threading;
        }
Exemplo n.º 6
0
        //Switches states
        /// <summary>
        /// Switches the states of the performer based on the <see cref="TriggerOption"/>.
        /// </summary>
        /// <param name="option"></param>
        public void ApplyTriggerOption(TriggerOption option)
        {
            switch (option)
            {
            case TriggerOption.turnOff:
                state = false;
                break;

            case TriggerOption.turnOn:
                state = true;
                break;

            case TriggerOption.toggle:
                state = !state;
                break;

            default:
                Debug.LogError("Passed bad TriggerOption during PerformTrigger", gameObject);
                break;
            }
        }
Exemplo n.º 7
0
        bool FirePredicate(ITriggerMsg msg, TriggerOption opt)
        {
            bool fire = true;

            switch (opt)
            {
            case TriggerOption.ChannelOnly:
                if (msg.Channel == null)
                {
                    fire = false;
                }
                break;

            case TriggerOption.QueryOnly:
                if (msg.Channel != null)
                {
                    fire = false;
                }
                break;
            }

            return(fire && !throttle.Triggers(msg));
        }
Exemplo n.º 8
0
 public override void Visit(TriggerOption node) { this.action(node); }
 public override void ExplicitVisit(TriggerOption fragment)
 {
     _fragments.Add(fragment);
 }
 override public void PerformTrigger(TriggerOption tOption)
 {
     base.PerformTrigger(tOption);
     ToggleMaterial();
 }
Exemplo n.º 11
0
 public Trigger(string identifier, Action <ITriggerMsg> call, TriggerOption opt) :
     this(identifier, call, opt, TriggerThreading.Default)
 {
 }
Exemplo n.º 12
0
 public Trigger(Action <ITriggerMsg> call, TriggerOption opt, params string[] identifiers) :
     this(call, opt, TriggerThreading.Default, identifiers)
 {
 }