Ejemplo n.º 1
0
 public void KillEarly(bool killImmediate = false)
 {
     if (_killEarly && !killImmediate) return; //We are already speeding this pulse up. Only execute if requested to kill immediately.
     _killEarly = true;
     _killImmediate = killImmediate;
     for (int i = 0; i < transform.childCount; i++)
     {
         transform.GetChild(i).GetComponent<Pulse>().SpeedUp(_killImmediate);
     }
     if (_killImmediate)
     {
         StopAllCoroutines();
         VisualFxManager.ReturnVisualFxCanvas(gameObject);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// A new click was made before the current one was finished, so any existing ripple effects should quickly disappear.
 /// </summary>
 public void SpeedUp(bool killImmediate)
 {
     if (IsSpeedUpActive)
     {
         return;
     }
     IsSpeedUpActive = true;
     IsMouseDown     = false;
     if (killImmediate)
     {
         StopAllCoroutines();
         GetComponent <RawImage>().color          = new Color32(255, 255, 255, 0);
         GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0);
         VisualFxManager.ReturnPulseRing(gameObject);
     }
     lifetime             = maxLife; // Reset.
     currentLifetime      = speedUpLifetime;
     alphaAtTimeOfSpeedup = alpha;
 }
Ejemplo n.º 3
0
 private IEnumerator Pulse(Vector3 target)
 {
     if (IsMouseDown)
     {
         GameObject ring = VisualFxManager.PulseRings[0];
         Pulse pulse = ring.GetComponent<Pulse>();
         VisualFxManager.PulseRings.RemoveAt(0);
         ring.transform.SetParent(transform);
         ring.transform.position = target;
         ring.SetActive(true);
         pulse.Init(IsMouseDown, false);
         yield return null;
     }
     else
     {                
         // Trigger any "hold down mouse" pulses that are not animating.
         for (int i = 0; i < transform.childCount; i++)
         {
             transform.GetChild(i).GetComponent<Pulse>().Continue();
         }
         float thisDuration = VisualFxManager.PulseDuration;
         while (thisDuration >= 0)
         {
             GameObject ring = VisualFxManager.PulseRings[0];
             Pulse pulse = ring.GetComponent<Pulse>();
             VisualFxManager.PulseRings.RemoveAt(0);
             ring.transform.SetParent(transform);
             ring.transform.position = target;
             ring.SetActive(true);
             pulse.Init(IsMouseDown, _killEarly);
             yield return new WaitForSeconds(VisualFxManager.PulseInterval);
             thisDuration -= VisualFxManager.PulseInterval;
         }
         VisualFxManager.ReturnVisualFxCanvas(gameObject);
     }
 }
Ejemplo n.º 4
0
        private IEnumerator Grow()
        {
            // Calculate a max width & height value based on whichever is smaller, screen width or screen height.
            finalWidthAndHeight = Screen.width > Screen.height ? Screen.height / 5f : Screen.width / 5f;
            RawImage img = GetComponent <RawImage>();

            rect.localScale = new Vector3(1.5f, 1.5f, 1);
            float widthAndHeight = 0f;

            currentLifetime = lifetime;

            // If resuming after mousedown, continue where we left off, rather than resetting these to their initial values.
            if (WasMouseDown)
            {
                lifetime       = maxLife - VisualFxManager.PulseInterval + Time.deltaTime;
                widthAndHeight = rect.sizeDelta.x;
            }
            // Mouse is pressed. Quickly pulse to a certain distance and hold. Do not remove ring or grow further.
            else if (IsMouseDown)
            {
                lifetime            = VisualFxManager.PulseInterval;
                finalWidthAndHeight = precentageSizeOfRingWhenMouseIsBeingHeld * finalWidthAndHeight;
                currentLifetime     = precentageSizeOfRingWhenMouseIsBeingHeld * currentLifetime;
                widthAndHeight      = precentageSizeOfRingWhenMouseIsBeingHeld * finalWidthAndHeight;
            }

            while (currentLifetime >= 0)
            {
                float currentWidthAndHeight = finalWidthAndHeight * (widthAndHeight / finalWidthAndHeight);
                rect.sizeDelta = new Vector2(currentWidthAndHeight, currentWidthAndHeight); // Increase ring pulse size over time.

                if (!IsMouseDown)
                {
                    // Become transparent over time. If speeding up, smoothly and quickly adjust increasing alpha.
                    if (IsSpeedUpActive)
                    {
                        alpha = (int)(currentLifetime / speedUpLifetime * alphaAtTimeOfSpeedup) / 2;
                    }
                    else if (WasMouseDown)
                    {
                        alpha = (int)(currentLifetime / VisualFxManager.PulseInterval * 255);
                    }
                    else
                    {
                        alpha = (int)(currentLifetime / lifetime * 255);
                    }

                    img.color = new Color32(255, 255, 255, (byte)(alpha < 0 ? 0 : alpha));
                }

                // Grow ring size. Regardless of speeding up, we do not want the ripple to speed up. We only want the ring to disappear faster. Use lifetime instead of speedUpLifetime to achieve that.
                if (!IsMouseDown)
                {
                    widthAndHeight += Time.deltaTime / lifetime * finalWidthAndHeight;
                }
                currentLifetime -= Time.deltaTime;
                yield return(null);
            }

            WasMouseDown = false;
            if (!IsMouseDown)
            {
                VisualFxManager.ReturnPulseRing(gameObject);
            }
        }