/// <summary> /// setup all the orbs /// </summary> private void Awake() { for (int i = 0; i < Orbs.Length; ++i) { Orbs[i].GetComponent <Renderer>().material.color = UseLightTheme ? LightColor : DarkColor; Orbs[i].SetActive(false); FadeColors fade = Orbs[i].GetComponent <FadeColors>(); fade.ResetFade(0); } }
/// <summary> /// Animate the loader /// </summary> void Update() { if (IsPaused) { return; } float percentage = mTime / RevolutionSpeed; for (int i = 0; i < Orbs.Length; ++i) { GameObject orb = Orbs[i]; // get the revolution completion percentage float orbPercentage = percentage - AngleSpace / 360 * i; if (orbPercentage < 0) { orbPercentage = 1 + orbPercentage; } if (SmoothEaseInOut) { float linearSmoothing = 1 * (orbPercentage * (1 - SmoothRatio)); orbPercentage = QuartEaseInOut(0, 1, orbPercentage) * SmoothRatio + linearSmoothing; } // set the angle mAngle = 0 - (orbPercentage) * 360; if (mStartingLoader) { if (orbPercentage >= 0 && orbPercentage < 0.5f) { if (i == mStartingIndex) { orb.SetActive(true); if (i >= Orbs.Length - 1) { mStartingLoader = false; } mStartingIndex += 1; } } } // apply the values orb.transform.Rotate(Axis, mAngle); mRotatedPositionVector = Quaternion.AngleAxis(mAngle, Axis) * mPositionVector * Radius; orb.transform.localPosition = CenterPoint + mRotatedPositionVector; // check for looping and handle loop counts if (mCheckLoopPause != mLoopPause) { if (mLoopPause && orbPercentage > 0.25f) { if (i == mFadeIndex) { FadeColors fade = orb.GetComponent <FadeColors>(); fade.FadeOut(false); if (i >= Orbs.Length - 1) { mCheckLoopPause = mLoopPause; } mFadeIndex += 1; } } if (!mLoopPause && orbPercentage > 0.5f) { if (i == mFadeIndex) { FadeColors fade = orb.GetComponent <FadeColors>(); fade.FadeIn(false); if (i >= Orbs.Length - 1) { mCheckLoopPause = mLoopPause; } mFadeIndex += 1; } } } } mTime += Time.deltaTime; if (!mLoopPause) { if (mTime >= RevolutionSpeed) { mTime = mTime - RevolutionSpeed; mRevolutionsCount += 1; if (mRevolutionsCount >= Revolutions && Revolutions > 0) { mLoopPause = true; mFadeIndex = 0; mRevolutionsCount = 0; } } } else { if (mTime >= RevolutionSpeed) { mTime = 0; mRevolutionsCount += 1; if (mRevolutionsCount >= Revolutions * 0.25f) { mFadeIndex = 0; mLoopPause = false; mRevolutionsCount = 0; } } } }