/// <summary> /// Draws gradient rectangle on texture /// </summary>t public static void DrawGradientRect(this Texture2D texture, int x, int y, int blockWidth, int blockHeight, Gradient gradient, Directions progressionDirection) { Func<int, int, Color> getColor; switch (progressionDirection) { case Directions.Left: getColor = (_x, _y) => gradient.Evaluate(1 - (float) _x/(float) blockWidth); break; case Directions.Right: getColor = (_x, _y) => gradient.Evaluate((float) _x/(float) blockWidth); break; case Directions.Down: getColor = (_x, _y) => gradient.Evaluate(1 - (float) _y/(float) blockHeight); break; case Directions.Up: getColor = (_x, _y) => gradient.Evaluate((float) _y/(float) blockHeight); break; default: Debug.LogError("Not supported direction: " + progressionDirection); return; } var colors = new Color[blockWidth*blockHeight]; for (int _y = 0; _y < blockHeight; _y++) { for (int _x = 0; _x < blockWidth; _x++) { colors[_x + _y*blockWidth] = getColor(_x, _y); } } texture.SetPixels(x, y, blockWidth, blockHeight, colors); }
private UnityEngine.Gradient MatrixToColormap(double[,] matrix) { UnityEngine.Gradient map = new UnityEngine.Gradient(); int rowCount = matrix.GetLength(0); GradientColorKey[] colorKey = new GradientColorKey[rowCount]; Color temp = new Color(); for (int i = 0; i < rowCount; i++) { temp.r = (float)matrix[i, 0]; temp.g = (float)matrix[i, 1]; temp.b = (float)matrix[i, 2]; colorKey[i].color = temp; colorKey[i].time = (float)i / rowCount; } GradientAlphaKey[] alphaKey = new GradientAlphaKey[2]; alphaKey[0].alpha = 1.0f; alphaKey[0].time = 0.0f; alphaKey[1].alpha = 0.0f; alphaKey[1].time = 1.0f; map.SetKeys(colorKey, alphaKey); return(map); }
private void FVmeshVertexColor(MatNode fv) { Vector3[] vertices = MatrixToVectorArray(fv.Fields["vertices"].GetValue <double[, ]>()); int[] faces = MatrixTo1DArray(fv.Fields["faces"].GetValue <int[, ]>()); double[,] col = fv.Fields["colors"].GetValue <double[, ]>(); _mesh = new Mesh(); _mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; _mesh.vertices = vertices; _mesh.triangles = faces; _mesh.RecalculateNormals(); UnityEngine.Gradient colMap = MatrixToColormap(fv.Fields["map"].GetValue <double[, ]>()); Color[] vertexColors = GetVertexColors(col, colMap, 0); _mesh.colors = vertexColors; double[,] temp = fv.Fields["opacity"].GetValue <double[, ]>(); float _opacity = (float)temp[0, 0]; if (_opacity < 1) { meshInstance = Instantiate(_vertexColorMeshPrefab, new Vector3(0, 0, 0), Quaternion.identity); meshInstance.GetComponent <Renderer>().material.SetFloat("_opacity", _opacity); } else { meshInstance = Instantiate(_opaqueVertexColorPrefab, new Vector3(0, 0, 0), Quaternion.identity); } meshInstance.transform.parent = transform; meshInstance.GetComponent <MeshFilter>().mesh = _mesh; //passing the mesh to the MeshFilteere so it can be displayed meshInstance.GetComponent <MeshCollider>().sharedMesh = _mesh; //adding _mesh to MeshCollider so it can be hit by raycasts (and do other collider physics) }
internal static void OnGUI() { if(!initialized) GetPreferences(); GUILayout.Label("Settings", z_GUI.headerTextStyle); rebuildNormals = EditorGUILayout.Toggle(gc_rebuildNormals, rebuildNormals); hideWireframe = EditorGUILayout.Toggle(gc_hideWireframe, hideWireframe); lockBrushSettings = EditorGUILayout.Toggle(gc_lockBrushSettings, lockBrushSettings); fullStrengthColor = EditorGUILayout.ColorField(gc_fullStrengthColor, fullStrengthColor); try { EditorGUI.BeginChangeCheck(); object out_gradient = z_ReflectionUtil.Invoke( null, typeof(EditorGUILayout), "GradientField", new System.Type[] { typeof(GUIContent), typeof(Gradient), typeof(GUILayoutOption[]) }, BindingFlags.NonPublic | BindingFlags.Static, new object[] { gc_BrushGradient, gradient, null }); gradient = (Gradient) out_gradient; if(EditorGUI.EndChangeCheck()) SetPreferences(); } catch { // internal editor gripe about something unimportant } }
private void Start() { if (!useShiftedGradient) { _effectGradient = new UnityEngine.Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(UserPrefsManager.leftColor, 0), new GradientColorKey(UserPrefsManager.rightColor, 1) } }; } else { float H, S, V; Color.RGBToHSV(UserPrefsManager.leftColor, out H, out S, out V); H = (H - 0.05f) % 1; Color newLeft = Color.HSVToRGB(H, S, V); float H2, S2, V2; Color.RGBToHSV(UserPrefsManager.rightColor, out H2, out S2, out V2); H2 = (H2 - 0.05f) % 1; Color newRight = Color.HSVToRGB(H2, S2, V2); _effectGradient = new UnityEngine.Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(newLeft, 0), new GradientColorKey(newRight, 1) } }; } }
static public int constructor(IntPtr l) { UnityEngine.Gradient o; o = new UnityEngine.Gradient(); pushObject(l, o); return(1); }
public GradientSerialization(System.Object value, string fieldName, bool arrayItem, NodeBase rootNode) { this.gradient = value as UnityEngine.Gradient; this.fieldName = fieldName; this.arrayItem = arrayItem; this.rootNode = rootNode; }
public static bool SaveGradientTexture(Gradient gradient, int width, string unityPath) { var ramp = CreateGradientTexture(gradient, width); var png = ramp.EncodeToPNG(); Object.DestroyImmediate(ramp); var systemPath = Application.dataPath + "/" + unityPath.Substring(7); File.WriteAllBytes(systemPath, png); AssetDatabase.ImportAsset(unityPath); var ti = AssetImporter.GetAtPath(unityPath) as TextureImporter; ti.wrapMode = TextureWrapMode.Clamp; ti.isReadable = true; #if UNITY_5_5_OR_NEWER ti.textureCompression = TextureImporterCompression.Uncompressed; ti.alphaSource = TextureImporterAlphaSource.None; #else ti.textureFormat = TextureImporterFormat.RGB24; #endif //Gradient data embedded in userData ti.userData = GradientToUserData(gradient); ti.SaveAndReimport(); return(true); }
public Texture2D GetCloudBase(UnityEngine.Gradient cloudGradient, int size, NoiseType type) { ModuleBase Generator = GetModule(type); //Billow Generator = new Billow( // 1f, // 2f, // 0.5f, // 6, // Random.Range(0, int.MaxValue), // QualityMode.Low); Noise2D map = new Noise2D(size, size / 2, Generator); map.GenerateSpherical( south, north, west, east); var tex = map.GetTexture(cloudGradient); tex.Apply(); return(tex); }
/// <summary> /// ColorTransition extension method for TransitionStep /// </summary> /// <returns></returns> public static ColorTransition ColorTransition(this TransitionStep transitionStep, UnityEngine.Gradient gradient, float delay = 0, float duration = 0.5f, TransitionStep.TransitionModeType transitionMode = TransitionStep.TransitionModeType.Specified, TransitionStep.TimeUpdateMethodType timeUpdateMethod = TransitionStep.TimeUpdateMethodType.GameTime, TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear, AnimationCurve animationCurve = null, bool runAtStart = false, Action <TransitionStep> onStart = null, Action <TransitionStep> onUpdate = null, Action <TransitionStep> onComplete = null) { var newTransitionStep = new ColorTransition(transitionStep.Target, gradient, delay, duration, transitionMode, timeUpdateMethod, tweenType, animationCurve, onStart, onUpdate, onComplete); newTransitionStep.AddToChain(transitionStep, runAtStart); return(newTransitionStep); }
static public int set_mode(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); UnityEngine.GradientMode v; v = (UnityEngine.GradientMode)LuaDLL.luaL_checkinteger(l, 2); self.mode = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int get_alphaKeys(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); pushValue(l, true); pushValue(l, self.alphaKeys); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int constructor(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.Gradient o; o = new UnityEngine.Gradient(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int Evaluate(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); System.Single a1; checkType(l, 2, out a1); var ret = self.Evaluate(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
/// <summary> /// Generate colors evely spaced out on a given gradient. /// </summary> /// <param name="colorCount"></param> /// <param name="gradient"></param> /// <param name="jitter"></param> /// <returns></returns> public static List<Color> GenerateColorsEvenGradient( int colorCount, Gradient gradient, float jitter) { return gradient.SampleEvenly(colorCount, jitter).ToList(); }
static public int SetKeys(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); UnityEngine.GradientColorKey[] a1; checkArray(l, 2, out a1); UnityEngine.GradientAlphaKey[] a2; checkArray(l, 3, out a2); self.SetKeys(a1, a2); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
private void DrawInternal(Rect rect, Gradient gradient) { if (gradient != null) { GradientEditor.DrawGradientWithBackground(rect, GradientPreviewCache.GetGradientPreview(gradient)); } }
public override object Read <T>(ES3Reader reader) { var instance = new UnityEngine.Gradient(); ReadInto <T>(reader, instance); return(instance); }
public void ApplyToUnityParticleSystem(UnityEngine.ParticleSystem ups, ParticleSystem ps) { var colorModule = ups.colorOverLifetime; var gradient = new UnityEngine.Gradient(); gradient.mode = UnityEngine.GradientMode.Blend; UnityEngine.GradientColorKey[] gck = new UnityEngine.GradientColorKey[keyFrameLifeTime.Count]; for (int i = 0; i < keyFrameLifeTime.Count; ++i) { gck[i].time = keyFrameLifeTime[i]; gck[i].color = new Color(r[i] / 255.0f, g[i] / 255.0f, b[i] / 255.0f); } UnityEngine.GradientAlphaKey[] gak; if (colorModule.enabled) { gak = colorModule.color.gradient.alphaKeys; } else { gak = new UnityEngine.GradientAlphaKey[2]; gak[0].time = 0.0f; gak[0].alpha = 1.0f; gak[1].time = 1.0f; gak[1].alpha = 1.0f; } gradient.SetKeys(gck, gak); colorModule.enabled = true; colorModule.color = new UnityEngine.ParticleSystem.MinMaxGradient(gradient); }
/// <summary> /// Write the specified value using the writer. /// </summary> /// <param name="value">Value.</param> /// <param name="writer">Writer.</param> public override void Write(object value, ISaveGameWriter writer) { UnityEngine.Gradient gradient = (UnityEngine.Gradient)value; writer.WriteProperty("colorKeys", gradient.colorKeys); writer.WriteProperty("alphaKeys", gradient.alphaKeys); writer.WriteProperty("mode", gradient.mode); }
static void Gradient_alphaKeys(JSVCall vc) { if (vc.bGet) { UnityEngine.Gradient _this = (UnityEngine.Gradient)vc.csObj; var result = _this.alphaKeys; var arrRet = result; for (int i = 0; arrRet != null && i < arrRet.Length; i++) { JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, arrRet[i]); JSApi.moveSaveID2Arr(i); } JSApi.setArrayS((int)JSApi.SetType.Rval, (arrRet != null ? arrRet.Length : 0), true); } else { UnityEngine.GradientAlphaKey[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.GradientAlphaKey[]>(() => { int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg); int length = JSApi.getArrayLength(jsObjID); var ret = new UnityEngine.GradientAlphaKey[length]; for (var i = 0; i < length; i++) { JSApi.getElement(jsObjID, i); ret[i] = (UnityEngine.GradientAlphaKey)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove); } return(ret); }); UnityEngine.Gradient _this = (UnityEngine.Gradient)vc.csObj; _this.alphaKeys = arg0; } }
/// <summary> /// Creates a gradient between two colors /// </summary> public static Gradient Gradient(Color from, Color to) { var g = new Gradient(); g.SetKeys(new[] {new GradientColorKey(from, 0), new GradientColorKey(to, 1)}, new[] {new GradientAlphaKey(from.a, 0), new GradientAlphaKey(to.a, 1)}); return g; }
public void DebugCreateTonsOfPresets() { int num = 150; string str = "Preset_"; for (int i = 0; i < num; i++) { List<GradientColorKey> list = new List<GradientColorKey>(); int num3 = Random.Range(3, 8); for (int j = 0; j < num3; j++) { list.Add(new GradientColorKey(new Color(Random.value, Random.value, Random.value), Random.value)); } List<GradientAlphaKey> list2 = new List<GradientAlphaKey>(); int num5 = Random.Range(3, 8); for (int k = 0; k < num5; k++) { list2.Add(new GradientAlphaKey(Random.value, Random.value)); } Gradient presetObject = new Gradient { colorKeys = list.ToArray(), alphaKeys = list2.ToArray() }; this.Add(presetObject, str + (i + 1)); } }
/// <summary> /// ColorTransition extension method for TransitionStep /// </summary> /// <returns></returns> public static ColorTransition ColorTransitionFromCurrent(this TransitionStep transitionStep, UnityEngine.Gradient gradient, float delay = 0, float duration = 0.5f, TransitionStep.TimeUpdateMethodType timeUpdateMethod = TransitionStep.TimeUpdateMethodType.GameTime, TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear, AnimationCurve animationCurve = null, bool runAtStart = false, Action <TransitionStep> onStart = null, Action <TransitionStep> onUpdate = null, Action <TransitionStep> onComplete = null) { var newTransitionStep = transitionStep.ColorTransition(gradient, delay, duration, TransitionStep.TransitionModeType.FromCurrent, timeUpdateMethod, tweenType, animationCurve, runAtStart, onStart, onUpdate, onComplete); return(newTransitionStep); }
public static bool Deserialize(string str, out Gradient gradient) { gradient = null; string[] arrays = str.Split('\n'); if(arrays.Length < 2) return false; string[] colors_str = arrays[0].Split('|'); string[] alphas_str = arrays[1].Split('|'); if(colors_str.Length < 2 || alphas_str.Length < 2) return false; List<GradientColorKey> colors = new List<GradientColorKey>(); List<GradientAlphaKey> alphas = new List<GradientAlphaKey>(); foreach(string s in colors_str) { string[] key = s.Split('&'); if(key.Length < 2) continue; Color value; float time; if(!TryParseColor(key[0], out value)) continue; if(!float.TryParse(key[1], out time)) continue; colors.Add( new GradientColorKey(value, time) ); } foreach(string s in alphas_str) { string[] key = s.Split('&'); if(key.Length < 2) continue; float alpha, time; if(!float.TryParse(key[0], out alpha)) continue; if(!float.TryParse(key[1], out time)) continue; alphas.Add( new GradientAlphaKey(alpha, time) ); } gradient = new Gradient(); gradient.SetKeys(colors.ToArray(), alphas.ToArray()); return true; }
public static void SetPixelsFromGradients(Texture2D texture, Gradient[] gradients, int width, int height) { // check color/alpha keys count across gradients int colorCount = gradients[0].colorKeys.Length; int alphaCount = gradients[0].alphaKeys.Length; for (int i = 1; i < gradients.Length; i++) { if (gradients[i].colorKeys.Length != colorCount) { Debug.LogError("[TCP2 Ramp Generator] Invalid Gradients: gradients need to have the same number of color/alpha keys to be interpolated properly."); return; } if (gradients[i].alphaKeys.Length != alphaCount) { Debug.LogError("[TCP2 Ramp Generator] Invalid Gradients: gradients need to have the same number of color/alpha keys to be interpolated properly."); return; } } int blockHeight = Mathf.FloorToInt(height / (float)(gradients.Length - 1)); var lerpGradient = new Gradient(); Color[] pixelsBuffer = new Color[width]; for (int y = 0; y < height; y++) { float l = (y % blockHeight) / (float)blockHeight; int rampIndex = Mathf.FloorToInt((y / (float)height) * (gradients.Length - 1)); int nextRampIndex = rampIndex + 1; var g1 = gradients[rampIndex]; var g2 = gradients[nextRampIndex]; var colorKeys = new GradientColorKey[g1.colorKeys.Length]; for (int i = 0; i < g1.colorKeys.Length; i++) { colorKeys[i] = new GradientColorKey( Color.Lerp(g1.colorKeys[i].color, g2.colorKeys[i].color, l), Mathf.Lerp(g1.colorKeys[i].time, g2.colorKeys[i].time, l) ); } var alphaKeys = new GradientAlphaKey[g1.alphaKeys.Length]; for (int i = 0; i < g1.alphaKeys.Length; i++) { alphaKeys[i] = new GradientAlphaKey( Mathf.Lerp(g1.alphaKeys[i].alpha, g2.alphaKeys[i].alpha, l), Mathf.Lerp(g1.alphaKeys[i].time, g2.alphaKeys[i].time, l) ); } lerpGradient.SetKeys(colorKeys, alphaKeys); var pixels = GetPixelsFromGradient(lerpGradient, width, 1, pixelsBuffer); texture.SetPixels(0, height - y - 1, width, 1, pixels); } texture.Apply(false); }
public static void RefreshPreview(Gradient gradient, Texture2D preview) { Color[] colors = new Color[512]; for (int index = 0; index < 256; ++index) colors[index] = colors[index + 256] = gradient.Evaluate((float) index / 256f); preview.SetPixels(colors); preview.Apply(); }
public static Texture2D CreateGradientTexture(Gradient gradient) { Texture2D preview = new Texture2D(256, 2, TextureFormat.ARGB32, false); preview.wrapMode = TextureWrapMode.Clamp; preview.hideFlags = HideFlags.HideAndDontSave; GradientEditor.RefreshPreview(gradient, preview); return preview; }
static public int set_alphaKeys(IntPtr l) { UnityEngine.Gradient o = (UnityEngine.Gradient)checkSelf(l); UnityEngine.GradientAlphaKey[] v; checkType(l, 2, out v); o.alphaKeys = v; return(0); }
protected override Color EvaluateValue(float toEvaluate) { if (Colors == null) { Colors = new UnityEngine.Gradient(); } return(Colors.Evaluate(toEvaluate)); }
private void Init(Gradient newGradient) { this.m_Gradient = newGradient; if (this.m_GradientEditor != null) { this.m_GradientEditor.Init(newGradient, 0); } base.Repaint(); }
public static bool CreateAndSaveNewGradientTexture(int width, string unityPath) { var gradient = new Gradient(); gradient.colorKeys = new[] { new GradientColorKey(Color.black, 0.45f), new GradientColorKey(Color.white, 0.55f) }; gradient.alphaKeys = new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }; return(SaveGradientTexture(gradient, width, unityPath)); }
private static Texture2D CreateGradientTexture(Gradient gradient, int width) { var height = 4; var ramp = new Texture2D(width, height, TextureFormat.RGB24, true, true); var colors = GetPixelsFromGradient(gradient, width, height); ramp.SetPixels(colors); ramp.Apply(true); return(ramp); }
public void Init(Gradient gradient, int numSteps) { this.m_Gradient = gradient; this.m_TextureDirty = true; this.m_NumSteps = numSteps; this.BuildArrays(); if (this.m_RGBSwatches.Count <= 0) return; this.m_SelectedSwatch = this.m_RGBSwatches[0]; }
private Color[] GetVertexColors(double[,] vertCol, UnityEngine.Gradient gradient, int idx) { Color[] colors = new Color[vertCol.GetLength(0)]; for (int i = 0; i < vertCol.GetLength(0); i++) { colors[i] = gradient.Evaluate((float)vertCol[i, idx]); } return(colors); }
static public int get_mode(IntPtr l) { try { UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); pushEnum(l, (int)self.mode); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int get_alphaKeys(IntPtr l) { try { UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); pushValue(l, self.alphaKeys); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int get_alphaKeys(IntPtr l) { try { UnityEngine.Gradient self = (UnityEngine.Gradient)checkSelf(l); pushValue(l, self.alphaKeys); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int constructor(IntPtr l) { try { UnityEngine.Gradient o; o = new UnityEngine.Gradient(); pushValue(l, o); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int constructor(IntPtr l) { try { UnityEngine.Gradient o; o=new UnityEngine.Gradient(); pushValue(l,true); pushValue(l,o); return 2; } catch(Exception e) { return error(l,e); } }
static int _CreateUnityEngine_ParticleSystem_MinMaxGradient(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 1 && TypeChecker.CheckTypes <UnityEngine.Color>(L, 1)) { UnityEngine.Color arg0 = ToLua.ToColor(L, 1); UnityEngine.ParticleSystem.MinMaxGradient obj = new UnityEngine.ParticleSystem.MinMaxGradient(arg0); ToLua.PushValue(L, obj); return(1); } else if (count == 1 && TypeChecker.CheckTypes <UnityEngine.Gradient>(L, 1)) { UnityEngine.Gradient arg0 = (UnityEngine.Gradient)ToLua.ToObject(L, 1); UnityEngine.ParticleSystem.MinMaxGradient obj = new UnityEngine.ParticleSystem.MinMaxGradient(arg0); ToLua.PushValue(L, obj); return(1); } else if (count == 2 && TypeChecker.CheckTypes <UnityEngine.Color, UnityEngine.Color>(L, 1)) { UnityEngine.Color arg0 = ToLua.ToColor(L, 1); UnityEngine.Color arg1 = ToLua.ToColor(L, 2); UnityEngine.ParticleSystem.MinMaxGradient obj = new UnityEngine.ParticleSystem.MinMaxGradient(arg0, arg1); ToLua.PushValue(L, obj); return(1); } else if (count == 2 && TypeChecker.CheckTypes <UnityEngine.Gradient, UnityEngine.Gradient>(L, 1)) { UnityEngine.Gradient arg0 = (UnityEngine.Gradient)ToLua.ToObject(L, 1); UnityEngine.Gradient arg1 = (UnityEngine.Gradient)ToLua.ToObject(L, 2); UnityEngine.ParticleSystem.MinMaxGradient obj = new UnityEngine.ParticleSystem.MinMaxGradient(arg0, arg1); ToLua.PushValue(L, obj); return(1); } else if (count == 0) { UnityEngine.ParticleSystem.MinMaxGradient obj = new UnityEngine.ParticleSystem.MinMaxGradient(); ToLua.PushValue(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: UnityEngine.ParticleSystem.MinMaxGradient.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public override void Replace(int index, object newPresetObject) { Gradient gradient = newPresetObject as Gradient; if (gradient == null) { Debug.LogError("Wrong type used in GradientPresetLibrary"); return; } Gradient gradient2 = new Gradient(); gradient2.alphaKeys = gradient.alphaKeys; gradient2.colorKeys = gradient.colorKeys; this.m_Presets[index].gradient = gradient2; }
public static int constructor(IntPtr l) { try { UnityEngine.Gradient o; o=new UnityEngine.Gradient(); pushValue(l,o); return 1; } catch(Exception e) { LuaDLL.luaL_error(l, e.ToString()); return 0; } }
public override void Add(object presetObject, string presetName) { Gradient gradient = presetObject as Gradient; if (gradient == null) { Debug.LogError("Wrong type used in GradientPresetLibrary"); return; } Gradient gradient2 = new Gradient(); gradient2.alphaKeys = gradient.alphaKeys; gradient2.colorKeys = gradient.colorKeys; this.m_Presets.Add(new GradientPresetLibrary.GradientPreset(gradient2, presetName)); }
static public int constructor(IntPtr l) { LuaDLL.lua_remove(l, 1); UnityEngine.Gradient o; if (matchType(l, 1)) { o = new UnityEngine.Gradient(); pushObject(l, o); return(1); } LuaDLL.luaL_error(l, "New object failed."); return(0); }
protected virtual void Reset() { Ramp = new Gradient(); Ramp.colorKeys = new GradientColorKey[] { new GradientColorKey(Color.black, 0f), new GradientColorKey(Color.white, 1f) }; Ramp.alphaKeys = new GradientAlphaKey[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }; UpdateGradientCache(); }
public override ModuleBase GetModule() { // check that has inputs if(type != COLORTYPE.COLOR) { for(int i = 0; i < inputs.Length; i++) { if(inputs[i] == null) { return null; } } } // get module switch(type) { case COLORTYPE.GRADIENT: if(gradient == null) { gradient = new Gradient(); if(gradientColorKeys != null) gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(gradientColorKeys); if(gradientAlphaKeys != null) gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(gradientAlphaKeys); } if(gradientColorKeys == null) gradientColorKeys = SerializableGradientColorKey.FromGradientColorKeys(gradient.colorKeys); if(gradientAlphaKeys == null) gradientAlphaKeys = SerializableGradientAlphaKey.FromGradientColorKeys(gradient.alphaKeys); module = new GradientModule(inputs[0].GetModule(), gradient); break; case COLORTYPE.ADD: module = new AddColorModule(inputs[0].GetModule(), inputs[1].GetModule()); break; case COLORTYPE.MULTIPLY: module = new MultiplyColorModule(inputs[0].GetModule(), inputs[1].GetModule()); break; case COLORTYPE.BLEND: module = new BlendColorModule(inputs[0].GetModule(), inputs[1].GetModule(), inputs[2].GetModule()); break; case COLORTYPE.COLOR: module = new ColorSource(color.ToColor()); break; case COLORTYPE.OVERLAY: module = new OverlayColorModule(inputs[0].GetModule(), inputs[1].GetModule()); break; } SetOutputOptions(); return this.module; }
public ColorNode(int x, int y) : base("Color Node", new SerializableRect(x, y, 200, 150)) { type = lastType = ColorNode.COLORTYPE.COLOR; gradient = new Gradient(); if(gradientColorKeys != null && gradientAlphaKeys != null) { gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(gradientColorKeys); gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(gradientAlphaKeys); } color = new SerializableColor(Color.black); SetInputs(); }
void Awake() { drawTexture = Texture2D.whiteTexture; // get an empty white texture gradient = PanelWaveform.GetColorGradient(startColor, endColor); // get a color gradient. if (audioSources.Count == 0) // if we haven't assigned any audio sources { if (this.GetComponent<AudioSource>() != null) // try to grab one from this gameobject { audioSources.Add(this.GetComponent<AudioSource>()); } else { Debug.LogError("Error! no audio sources attached to AudioSampler.css"); } } }
public override void Add(object presetObject, string presetName) { Gradient gradient = presetObject as Gradient; if (gradient == null) { Debug.LogError("Wrong type used in GradientPresetLibrary"); } else { Gradient preset = new Gradient { alphaKeys = gradient.alphaKeys, colorKeys = gradient.colorKeys }; this.m_Presets.Add(new GradientPreset(preset, presetName)); } }
/// <summary> /// Returns a gradient that represents a linear interpolation between two colors. /// </summary> /// <param name="color1"></param> /// <param name="color2"></param> /// <returns></returns> public static Gradient GetLerp(Color color1, Color color2) { var gradient = new Gradient(); var leftColorKey = new GradientColorKey(color1, 0); var rightColorKey = new GradientColorKey(color2, 1); var leftAlphaKey = new GradientAlphaKey(color1.a, 0); var rightAlphaKey = new GradientAlphaKey(color1.a, 1); gradient.SetKeys( new[]{leftColorKey, rightColorKey}, new[]{leftAlphaKey, rightAlphaKey}); return gradient; }
// Use this for initialization void Start () { padGradient = PanelWaveform.GetColorGradient (lineAttributes.startColor, lineAttributes.endColor); for(int i = 0; i < numLines; i++) { float val = (float)i/(numLines-1); lines.Add(NewLine(padGradient.Evaluate(val))); } CreatePad (); //just in case someone changes the private var. rippleLines can't be > numLines if( rippleWidth > numLines) { rippleWidth = numLines; } }
private void Generate() { gradient = RandomE.gradientHSV; var noiseOffset = new Vector2(Random.Range(0f, 100f), Random.Range(0f, 100f)); draft.colors.Clear(); for (int i = 0; i < draft.vertices.Count; i++) { var vertex = draft.vertices[i]; var x = scale*vertex.x/xSegments + noiseOffset.x; var y = scale*vertex.z/zSegments + noiseOffset.y; var noise = Mathf.PerlinNoise(x, y); draft.vertices[i] = new Vector3(vertex.x, noise, vertex.z); draft.colors.Add(gradient.Evaluate(noise)); } GetComponent<MeshFilter>().mesh = draft.ToMesh(); }
public static void Show(Gradient newGradient) { GUIView current = GUIView.current; if ((UnityEngine.Object) GradientPicker.s_GradientPicker == (UnityEngine.Object) null) { GradientPicker.s_GradientPicker = (GradientPicker) EditorWindow.GetWindow(typeof (GradientPicker), true, "Gradient Editor", false); Vector2 vector2_1 = new Vector2(360f, 224f); Vector2 vector2_2 = new Vector2(1900f, 3000f); GradientPicker.s_GradientPicker.minSize = vector2_1; GradientPicker.s_GradientPicker.maxSize = vector2_2; GradientPicker.s_GradientPicker.wantsMouseMove = true; GradientPicker.s_GradientPicker.ShowAuxWindow(); } else GradientPicker.s_GradientPicker.Repaint(); GradientPicker.s_GradientPicker.m_DelegateView = current; GradientPicker.s_GradientPicker.Init(newGradient); }
/// <summary>Tweens a 2D Toolkit Sprite's color using the given gradient /// (NOTE 1: only uses the colors of the gradient, not the alphas - NOTE 2: creates a Sequence, not a Tweener). /// Also stores the image as the tween's target so it can be used for filtered operations</summary> /// <param name="gradient">The gradient to use</param><param name="duration">The duration of the tween</param> public static Sequence DOGradientColor(this tk2dBaseSprite target, Gradient gradient, float duration) { Sequence s = DOTween.Sequence(); GradientColorKey[] colors = gradient.colorKeys; int len = colors.Length; for (int i = 0; i < len; ++i) { GradientColorKey c = colors[i]; if (i == 0 && c.time <= 0) { target.color = c.color; continue; } float colorDuration = i == len - 1 ? duration - s.Duration(false) // Verifies that total duration is correct : duration * (i == 0 ? c.time : c.time - colors[i - 1].time); s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear)); } return s; }
/// <summary> /// Gives a list of colors where that maximises distance on /// the gradient between consecutaive colors. /// </summary> /// <param name="colorCount"></param> /// <param name="gradient"></param> /// <returns></returns> public static List<Color> GenerateColorsGoldenRatioGradient(int colorCount, Gradient gradient) { var colors = new List<Color>(); var t = Random.value; for (int i = 0; i < colorCount; i++) { var newColor = gradient.Evaluate(t); colors.Add(newColor); t += GoldenRatioConjugate; t %= 1.0f; } return colors; }
public override void CreateModel(Transform parent) { GameObject model = Object.Instantiate(Resources.Load("ParticleSystem")) as GameObject; if (model != null) { var colorOverLifetimeModule = model.GetComponent<ParticleSystem>().colorOverLifetime; var gradient = new Gradient(); var gradientColorKeys = new GradientColorKey[] {new GradientColorKey(_startColor, 0f), new GradientColorKey(_endColor, 1f)}; var gradientAlphaKeys = new GradientAlphaKey[] {new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 0.8f), new GradientAlphaKey(0f, 1f)}; // only fade out in the last 20% of lifetime gradient.SetKeys(gradientColorKeys, gradientAlphaKeys); colorOverLifetimeModule.color = new ParticleSystem.MinMaxGradient(gradient); model.transform.SetParent(parent); model.transform.localPosition = LocalCoinPosition(); SetModel(model); } }
public Color EvaluateColor(double value) { if (_unityGradient == null) { var colorKeys = Stops .Select(i => i.TryConvertToColorKey(Min, Max)) .Where(i => i != null) .Select(i => i.Value) .ToArray(); var alphaKeys = Stops .Select(i => i.TryConvertToAlphaKey(Min, Max)) .Where(i => i != null) .Select(i => i.Value) .ToArray(); _unityGradient = new Gradient(); _unityGradient.SetKeys(colorKeys, alphaKeys); } return _unityGradient.Evaluate((float)((value - Min) / (Max - Min))); }
public static IEnumerable<Danmaku> Color(this IEnumerable<Danmaku> danmakus, Gradient colors, Func<Danmaku, bool> filter = null) { if (colors == null) throw new ArgumentNullException("colors"); return danmakus.ForEach(x => x.Color = colors.Random(), filter); }
/// <summary> /// Generates a textire from a gradient.. assumes the arrays values are nomalized between 0-1 /// </summary> /// <returns>a texture 2d the length and width of the heightmap, all pixels will be based on the gradient provided.</returns> public static Texture2D generateTextureFromSingleGradient(float[,] heightMap,Gradient colorGradient) { int width = heightMap.GetLength(0); int height = heightMap.GetLength(1); Color[] pixels = new Color[height * width]; bool debug = false; for(int y =0; y < height; y++) { for(int x =0; x < width; x++) { pixels[x + y * width] = colorGradient.Evaluate(heightMap[x,y]); if(debug == false) { debug = true; Debug.Log(pixels[x + y * width].a); } } } return buildTextureFromPixels(pixels,width,height); }