Exemplo n.º 1
0
 void Start()
 {
     if (nullKey == null)
     {
         var go = new GameObject();
         go.name        = "Null Key";
         nullKey        = go.AddComponent <NullKeyComponent>();
         nullKey.entity = new BallObject(); // idk
     }
     if (startOn)
     {
         var nullDelayedA = new DelayedActivator(null);
         nullDelayedA.state      = ActivatorState.TURNING_OFF;
         nullDelayedA.changeTime = Time.time;
         AddActivator(null);
         delayedActivators[nullKey] = nullDelayedA;
     }
 }
Exemplo n.º 2
0
 private void AddActivatorDelay(EntityComponent key, EntityComponent newActivator, float time)
 {
     if (delayedActivators.ContainsKey(key))
     {
         // must be in TURNING_OFF state
         delayedActivators[key].state = ActivatorState.ON;
     }
     else
     {
         var delayedA = new DelayedActivator(newActivator);
         if (onTime == 0)
         {
             delayedA.state = ActivatorState.ON;
             AddActivator(newActivator);
         }
         else
         {
             delayedA.state      = ActivatorState.TURNING_ON;
             delayedA.changeTime = time;
         }
         delayedActivators[key] = delayedA;
     }
 }
Exemplo n.º 3
0
    void Update()
    {
        float           time        = Time.time;
        EntityComponent inputEntity = input.component;

        foreach (var keyValue in delayedActivators)
        {
            DelayedActivator delayedA = keyValue.Value;
            if (delayedA.state == ActivatorState.TURNING_ON)
            {
                if (time - delayedA.changeTime >= onTime)
                {
                    delayedA.state = ActivatorState.ON;
                    AddActivator(delayedA.activator);
                }
            }
            else if (delayedA.state == ActivatorState.TURNING_OFF)
            {
                if (time - delayedA.changeTime >= offTime)
                {
                    delayedActivatorsToRemove.Add(keyValue.Key);
                    RemoveActivator(delayedA.activator);
                }
            }
        }
        foreach (EntityComponent e in delayedActivatorsToRemove)
        {
            delayedActivators.Remove(e);
        }
        delayedActivatorsToRemove.Clear();

        if (inputEntity == null)
        {
            return;
        }

        foreach (EntityComponent newActivator in inputEntity.GetNewActivators())
        {
            if (newActivator == null) // null is reserved for the net cycle
            {
                continue;
            }
            AddActivatorDelay(newActivator, newActivator, time);
        }

        foreach (EntityComponent removedActivator in inputEntity.GetRemovedActivators())
        {
            if (removedActivator == null) // null is reserved for the net cycle
            {
                continue;
            }
            RemoveActivatorDelay(removedActivator, removedActivator, time);
        }

        // net cycle
        bool inputIsOn = inputEntity.IsOn();

        if (inputIsOn && !inputWasOn)
        {
            AddActivatorDelay(nullKey, null, time);
        }
        else if (inputWasOn && !inputIsOn)
        {
            RemoveActivatorDelay(nullKey, null, time);
        }
        inputWasOn = inputIsOn;
    }