Ejemplo n.º 1
0
 void StopTimer()
 {
     if (TimerCoroutine != null)
     {
         TimerCoroutine.Abort();
         TimerCoroutine = null;
     }
 }
    public override void Init()
    {
        // start a quick job
        ICoroutine quickWork = StartCoroutine(DoWork, 0.2);

        // Start up a couple of coroutines that will "work" for 10s
        ICoroutine worker1 = StartCoroutine(DoWork, 10.0);
        ICoroutine worker2 = StartCoroutine(DoWork, 10.0);

        worker1.Name = "WorkerOne"; // Default name would be "DoWork"
        worker2.Name = "WorkerTwo";

        // Wait for quickWork to have finished.
        WaitFor(quickWork);
        // quickWork.IsAlive will now be false

        // Abort worker1.
        worker1.Abort();
        // worker1.IsAlive will now be false
        // Note that it will never log "has finished"

        // Start up a coroutine that won't do anything until it gets a signal.
        ICoroutine signalWaiter = StartCoroutine(WaitUntilSignal);

        // Start a coroutine that will do some "work" then send a signal to signalWaiter.
        StartCoroutine(WorkThenSignal, 2.0, signalWaiter);

        WaitForAllCoroutines();
    }
Ejemplo n.º 3
0
    void ApplyImpulse()
    {
        if (_resetCoroutine != null)
        {
            _resetCoroutine.Abort();
            _resetCoroutine = null;
        }

        // Apply linear impulse force
        if (_applyLinearImpulse)
        {
            _rb.AddLinearImpulse(LinearImpulseDirection * LinearForce);
        }

        // Apply angular impulse force
        if (_applyAngularImpulse)
        {
            // Generate a new random angular impulse
            Vector angularImpulse = new Vector((float)_rng.NextDouble() * AngularVariance.X,
                                               (float)_rng.NextDouble() * AngularVariance.Y,
                                               (float)_rng.NextDouble() * AngularVariance.Z);

            // Apply the angular impulse if it is non-zero
            if (angularImpulse.LengthSquared() > 0.0f)
            {
                _rb.AddAngularImpulse(angularImpulse.Normalized() * AngularForce);
            }
        }

        if ((ResetTimeout > 0.0) && (_applyLinearImpulse || _applyAngularImpulse))
        {
            _resetCoroutine = StartCoroutine(ResetAfterTimeout);
        }
    }
Ejemplo n.º 4
0
 private void StopInterpolation()
 {
     if (interpolationCoroutine != null)
     {
         interpolationCoroutine.Abort();
         interpolationCoroutine = null;
     }
 }
Ejemplo n.º 5
0
 private void StopFadeCoroutine()
 {
     if (fadeCoroutine != null)
     {
         fadeCoroutine.Abort();
         fadeCoroutine = null;
     }
 }
Ejemplo n.º 6
0
 public void Dispose()
 {
     if (coroutine != null)
     {
         coroutine.Abort();
         coroutine = null;
         T temp = default(T);
         while (WaitQueue.Count > 0)
         {
             WaitQueue.Dequeue()(temp, true);
         }
     }
 }
Ejemplo n.º 7
0
        void Disable()
        {
            if (TimerSub != null)
            {
                TimerSub.Unsubscribe();
                TimerSub = null;
            }

            if (TimerCoroutine != null)
            {
                TimerCoroutine.Abort();
                TimerCoroutine = null;
            }
        }