static IEnumerator FadeNow(FadeParams p) { Image go = p.image; Text t = p.txt; COL c0 = p.c0, c1 = p.c1; float duration = p.duration; //start colours. 0 to 1.0 float r = c0.r / 255.0f, g = c0.g / 255.0f, b = c0.b / 255.0f, a = c0.a / 255.0f; float dr, dg, db, da; //deltas:0 to 1.0 dr = (c1.r - c0.r) / 255.0f; dg = (c1.g - c0.g) / 255.0f; db = (c1.b - c0.b) / 255.0f; da = (c1.a - c0.a) / 255.0f; Color col = new Color(); //print ("col-start"); float timestart = Time.time; float timeend = timestart + duration; float timecur, percent; while (true) { timecur = Time.time; if (timecur > timeend) { break; } percent = (timecur - timestart) / duration; col.r = Mathf.Clamp(r + percent * dr, 0.0f, 1.0f); col.g = Mathf.Clamp(g + percent * dg, 0.0f, 1.0f); col.b = Mathf.Clamp(b + percent * db, 0.0f, 1.0f); col.a = Mathf.Clamp(a + percent * da, 0.0f, 1.0f); if (go != null) { go.color = col; } else { t.color = col; } yield return(new WaitForSeconds(0.01f)); } //final fix bcos time might have elapsed and fade didnt complete if (go != null) { go.color = c1.toColor(); } if (t != null) { t.color = c1.toColor(); } //print ("col-end" + (Time.time - timestart)); }
private void Update() { if ((this._timer < this.fadeDuration) && (this._toParams != null)) { this._timer += Time.deltaTime; FadeParams @params = FadeParams.Lerp(this._fromParams, this._toParams, Mathf.Clamp01(this._timer / this.fadeDuration)); bool flag = this._currentParams.value < 0.99; bool flag2 = @params.value < 0.99; if (flag2 && !flag) { for (int i = 0; i < this._renderer.materials.Length; i++) { this._renderer.materials[i].shader = this._fadingShader; } } else if (!flag2 && flag) { for (int j = 0; j < this._renderer.materials.Length; j++) { this._renderer.materials[j].shader = this._normalShader; } } this._currentParams = @params; this.ApplyFade(); } }
private void Start() { this._originalParams = new FadeParams(); this._originalParams.value = 1f; this._currentParams = this._originalParams; this._fromParams = this._originalParams; this._timer = 0f; this._renderer = base.GetComponent <Renderer>(); this._mpb = new MaterialPropertyBlock(); this._normalShader = Shader.Find(NORMAL_SHADER_PATH); this._fadingShader = Shader.Find(FADING_SHADER_PATH); }
private void FadeToParams(FadeParams targetParams) { this._timer = 0f; this._fromParams = this._currentParams; this._toParams = targetParams; }