static public int Equals__Gradient(IntPtr l) { try { UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); UnityEngine.Gradient a1; checkType(l, 2, out a1); var ret = self.Equals(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
private static UnityEngine.Gradient Lerp(this UnityEngine.Gradient a, UnityEngine.Gradient b, float t, bool noAlpha, bool noColor) { keysTimes.Clear(); if (a == b || a.Equals(b)) { return(b); } GradientAlphaKey[] alphaKeys1 = a.alphaKeys; GradientColorKey[] colorKeys1 = a.colorKeys; GradientAlphaKey[] alphaKeys2 = b.alphaKeys; GradientColorKey[] colorKeys2 = b.colorKeys; if (alphaKeys1.Length == alphaKeys2.Length && colorKeys1.Length == colorKeys2.Length) { // full compare of all keys, save allocating memory if both gradients are equal bool equal = true; for (int i = 0; i < alphaKeys1.Length; i++) { if (alphaKeys1[i].alpha != alphaKeys2[i].alpha || alphaKeys1[i].time != alphaKeys2[i].time || colorKeys1[i].color != colorKeys2[i].color || colorKeys1[i].time != colorKeys2[i].time) { equal = false; break; } } if (equal) { return(b); } Gradient gradient = new Gradient(); GradientColorKey[] clrs = new GradientColorKey[colorKeys1.Length]; GradientAlphaKey[] alphas = new GradientAlphaKey[colorKeys1.Length]; for (int i = 0; i < colorKeys1.Length; i++) { clrs[i] = new GradientColorKey(Color.Lerp(colorKeys1[i].color, colorKeys2[i].color, t), Mathf.Lerp(colorKeys1[i].time, colorKeys2[i].time, t)); alphas[i] = new GradientAlphaKey(Mathf.Lerp(alphaKeys1[i].alpha, alphaKeys2[i].alpha, t), Mathf.Lerp(alphaKeys1[i].time, alphaKeys2[i].time, t)); } gradient.colorKeys = clrs; gradient.alphaKeys = alphas; return(gradient); } else { for (int i = 0; i < colorKeys1.Length; i++) { float k = colorKeys1[i].time; if (!keysTimes.Contains(k)) { keysTimes.Add(k); } } for (int i = 0; i < colorKeys2.Length; i++) { float k = colorKeys2[i].time; if (!keysTimes.Contains(k)) { keysTimes.Add(k); } } for (int i = 0; i < alphaKeys1.Length; i++) { float k = alphaKeys1[i].time; if (!keysTimes.Contains(k)) { keysTimes.Add(k); } } for (int i = 0; i < alphaKeys2.Length; i++) { float k = alphaKeys2[i].time; if (!keysTimes.Contains(k)) { keysTimes.Add(k); } } GradientColorKey[] clrs = new GradientColorKey[keysTimes.Count]; GradientAlphaKey[] alphas = new GradientAlphaKey[keysTimes.Count]; for (int i = 0; i < keysTimes.Count; i++) { float key = keysTimes[i]; var clr = Color.Lerp(a.Evaluate(key), b.Evaluate(key), t); clrs[i] = new GradientColorKey(clr, key); alphas[i] = new GradientAlphaKey(clr.a, key); } Gradient gradient = new Gradient(); gradient.SetKeys(clrs, alphas); return(gradient); } }