private void GenericTintColorProperty(SerializedProperty colorProperty, float hue) { int state = colorProperty.FindPropertyRelative("minMaxState").intValue; switch (state) { //Constant Color case 0: colorProperty.FindPropertyRelative("maxColor").colorValue = HSLColor.FromRGBA(colorProperty.FindPropertyRelative("maxColor").colorValue).ColorWithHue(hue); break; //Gradient case 1: TintGradient(colorProperty.FindPropertyRelative("maxGradient"), hue); break; //Random between 2 Colors case 2: colorProperty.FindPropertyRelative("minColor").colorValue = HSLColor.FromRGBA(colorProperty.FindPropertyRelative("minColor").colorValue).ColorWithHue(hue); colorProperty.FindPropertyRelative("maxColor").colorValue = HSLColor.FromRGBA(colorProperty.FindPropertyRelative("maxColor").colorValue).ColorWithHue(hue); break; //Random between 2 Gradients case 3: TintGradient(colorProperty.FindPropertyRelative("maxGradient"), hue); TintGradient(colorProperty.FindPropertyRelative("minGradient"), hue); break; } }
private void GenericAddLightness(SerializedProperty colorProperty, float lightness) { int state = colorProperty.FindPropertyRelative("minMaxState").intValue; switch (state) { //Constant Color case 0: colorProperty.FindPropertyRelative("maxColor").colorValue = HSLColor.FromRGBA(colorProperty.FindPropertyRelative("maxColor").colorValue).ColorWithLightnessOffset(lightness); break; //Gradient case 1: AddLightnessGradient(colorProperty.FindPropertyRelative("maxGradient"), lightness); break; //Random between 2 Colors case 2: colorProperty.FindPropertyRelative("minColor").colorValue = HSLColor.FromRGBA(colorProperty.FindPropertyRelative("minColor").colorValue).ColorWithLightnessOffset(lightness); colorProperty.FindPropertyRelative("maxColor").colorValue = HSLColor.FromRGBA(colorProperty.FindPropertyRelative("maxColor").colorValue).ColorWithLightnessOffset(lightness); break; //Random between 2 Gradients case 3: AddLightnessGradient(colorProperty.FindPropertyRelative("maxGradient"), lightness); AddLightnessGradient(colorProperty.FindPropertyRelative("minGradient"), lightness); break; } }
private void AddLightnessGradient(SerializedProperty gradientProperty, float lightness) { gradientProperty.FindPropertyRelative("key0").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key0").colorValue).ColorWithLightnessOffset(lightness); gradientProperty.FindPropertyRelative("key1").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key1").colorValue).ColorWithLightnessOffset(lightness); gradientProperty.FindPropertyRelative("key2").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key2").colorValue).ColorWithLightnessOffset(lightness); gradientProperty.FindPropertyRelative("key3").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key3").colorValue).ColorWithLightnessOffset(lightness); gradientProperty.FindPropertyRelative("key4").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key4").colorValue).ColorWithLightnessOffset(lightness); gradientProperty.FindPropertyRelative("key5").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key5").colorValue).ColorWithLightnessOffset(lightness); gradientProperty.FindPropertyRelative("key6").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key6").colorValue).ColorWithLightnessOffset(lightness); gradientProperty.FindPropertyRelative("key7").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key7").colorValue).ColorWithLightnessOffset(lightness); }
private void TintGradient(SerializedProperty gradientProperty, float hue) { gradientProperty.FindPropertyRelative("key0").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key0").colorValue).ColorWithHue(hue); gradientProperty.FindPropertyRelative("key1").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key1").colorValue).ColorWithHue(hue); gradientProperty.FindPropertyRelative("key2").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key2").colorValue).ColorWithHue(hue); gradientProperty.FindPropertyRelative("key3").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key3").colorValue).ColorWithHue(hue); gradientProperty.FindPropertyRelative("key4").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key4").colorValue).ColorWithHue(hue); gradientProperty.FindPropertyRelative("key5").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key5").colorValue).ColorWithHue(hue); gradientProperty.FindPropertyRelative("key6").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key6").colorValue).ColorWithHue(hue); gradientProperty.FindPropertyRelative("key7").colorValue = HSLColor.FromRGBA(gradientProperty.FindPropertyRelative("key7").colorValue).ColorWithHue(hue); }
public void OnTrackBorderColorChanged(Color color) { Color differentColor = new Color(color.g, color.b, color.r); HSLColor skyColor = HSLColor.FromRGBA(differentColor); skyColor.l = 0.8f; this.targetSkyColor = skyColor.ToRGBA(); skyColor.l = 0.9f; this.targetAmbientColor = skyColor.ToRGBA(); this.sun.color = this.targetAmbientColor; }
//TINT COLORS ================================================================================================================================ private void tintColor() { if (!TintStartColor && !TintColorModule && !TintColorSpeedModule) { Debug.LogWarning("CartoonFX Easy Editor: You must toggle at least one of the three Color Modules to be able to tint anything!"); return; } float hue = HSLColor.FromRGBA(TintColorValue).h; foreach (GameObject go in Selection.gameObjects) { ParticleSystem[] systems; if (IncludeChildren) { systems = go.GetComponentsInChildren <ParticleSystem>(true); } else { systems = go.GetComponents <ParticleSystem>(); } foreach (ParticleSystem ps in systems) { SerializedObject psSerial = new SerializedObject(ps); if (TintStartColor) { GenericTintColorProperty(psSerial.FindProperty("InitialModule.startColor"), hue); } if (TintColorModule) { GenericTintColorProperty(psSerial.FindProperty("ColorModule.gradient"), hue); } if (TintColorSpeedModule) { GenericTintColorProperty(psSerial.FindProperty("ColorBySpeedModule.gradient"), hue); } psSerial.ApplyModifiedProperties(); } } }
void OnGUI() { GUILayout.BeginArea(new Rect(0, 0, this.position.width - 8, this.position.height)); GUILayout.Space(4); GUILayout.Label("CARTOON FX Easy Editor", EditorStyles.boldLabel); GUILayout.Label("Easily change properties of any Particle System!", EditorStyles.miniLabel); //---------------------------------------------------------------- EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); IncludeChildren = GUILayout.Toggle(IncludeChildren, new GUIContent("Include Children", "If checked, changes will affect every Particle Systems from each child of the selected GameObject(s)")); GUILayout.Space(90f); if (GUILayout.Button("Test Effect")) { foreach (GameObject go in Selection.gameObjects) { ParticleSystem[] systems = go.GetComponents <ParticleSystem>(); if (systems.Length == 0) { continue; } foreach (ParticleSystem system in systems) { system.Play(IncludeChildren); } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); //---------------------------------------------------------------- //Separator GUILayout.Box("", GUILayout.Width(this.position.width - 12), GUILayout.Height(3)); EditorGUI.BeginChangeCheck(); basicFoldout = EditorGUILayout.Foldout(basicFoldout, "BASIC PROPERTIES"); if (EditorGUI.EndChangeCheck()) { foldoutChanged = true; } if (basicFoldout) { //---------------------------------------------------------------- GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Scale Size", "Changes the size of the Particle System(s) and other values accordingly (speed, gravity, etc.)"), GUILayout.Width(120))) { applyScale(); } GUILayout.Label("Multiplier:", GUILayout.Width(110)); ScalingValue = EditorGUILayout.FloatField(ScalingValue); if (ScalingValue <= 0) { ScalingValue = 0.1f; } GUILayout.EndHorizontal(); //---------------------------------------------------------------- GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Set Duration", "Changes the duration of the Particle System(s) (if you want quicker or longer effects, 100% = default duration)"), GUILayout.Width(120))) { applyScaleLifetime(); } GUILayout.Label("Duration (%):", GUILayout.Width(110)); LTScalingValue = EditorGUILayout.FloatField(LTScalingValue); if (LTScalingValue < 0.1f) { LTScalingValue = 0.1f; } else if (LTScalingValue > 9999) { LTScalingValue = 9999; } GUILayout.EndHorizontal(); //---------------------------------------------------------------- GUILayout.Space(2); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Loop Effect", "Loop the effect (might not work properly on some effects such as explosions)"), EditorStyles.miniButtonLeft, GUILayout.Width(120))) { loopEffect(true); } if (GUILayout.Button(new GUIContent("Unloop Effect", "Remove looping from the effect"), EditorStyles.miniButtonRight, GUILayout.Width(120))) { loopEffect(false); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(2); //---------------------------------------------------------------- } //Separator GUILayout.Box("", GUILayout.Width(this.position.width - 12), GUILayout.Height(3)); // GUILayout.Space(4); EditorGUI.BeginChangeCheck(); colorFoldout = EditorGUILayout.Foldout(colorFoldout, "COLOR MANIPULATIONS"); if (EditorGUI.EndChangeCheck()) { foldoutChanged = true; } if (colorFoldout) { //---------------------------------------------------------------- GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Set Start Color(s)", "Changes the color(s) of the Particle System(s)\nSecond Color is used when Start Color is 'Random Between Two Colors'."), GUILayout.Width(120))) { applyColor(); } ColorValue = EditorGUILayout.ColorField(ColorValue); ColorValue2 = EditorGUILayout.ColorField(ColorValue2); AffectAlpha = GUILayout.Toggle(AffectAlpha, new GUIContent("Alpha", "If checked, the alpha value will also be changed")); GUILayout.EndHorizontal(); //---------------------------------------------------------------- GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Tint Colors", "Tints the colors of the Particle System(s), including gradients!\n(preserving their saturation and lightness)"), GUILayout.Width(120))) { tintColor(); } TintColorValue = EditorGUILayout.ColorField(TintColorValue); TintColorValue = HSLColor.FromRGBA(TintColorValue).VividColor(); GUILayout.EndHorizontal(); //---------------------------------------------------------------- /* * GUILayout.BeginHorizontal(); * GUILayout.Label("Add/Substract Lightness:"); * * LightnessStep = EditorGUILayout.IntField(LightnessStep, GUILayout.Width(30)); * if(LightnessStep > 99) LightnessStep = 99; * else if(LightnessStep < 1) LightnessStep = 1; * GUILayout.Label("%"); * * if(GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.Width(22))) * { * addLightness(true); * } * if(GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.Width(22))) * { * addLightness(false); * } * GUILayout.FlexibleSpace(); * GUILayout.EndHorizontal(); */ //---------------------------------------------------------------- GUILayout.Label("Color Modules to affect:"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = TintStartColor ? ColorSelected : Color.white; if (GUILayout.Button(new GUIContent("Start Color", "If checked, the \"Start Color\" value(s) will be affected."), EditorStyles.toolbarButton, GUILayout.Width(70))) { TintStartColor = !TintStartColor; } GUI.color = TintColorModule ? ColorSelected : Color.white; if (GUILayout.Button(new GUIContent("Color over Lifetime", "If checked, the \"Color over Lifetime\" value(s) will be affected."), EditorStyles.toolbarButton, GUILayout.Width(110))) { TintColorModule = !TintColorModule; } GUI.color = TintColorSpeedModule ? ColorSelected : Color.white; if (GUILayout.Button(new GUIContent("Color by Speed", "If checked, the \"Color by Speed\" value(s) will be affected."), EditorStyles.toolbarButton, GUILayout.Width(100))) { TintColorSpeedModule = !TintColorSpeedModule; } GUI.color = Color.white; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(4); //---------------------------------------------------------------- } //Separator GUILayout.Box("", GUILayout.Width(this.position.width - 12), GUILayout.Height(3)); // GUILayout.Space(6); //---------------------------------------------------------------- EditorGUI.BeginChangeCheck(); copyFoldout = EditorGUILayout.Foldout(copyFoldout, "COPY MODULES"); if (EditorGUI.EndChangeCheck()) { foldoutChanged = true; } if (copyFoldout) { GUILayout.Label("Copy properties from a Particle System to others!", EditorStyles.miniLabel); GUILayout.BeginHorizontal(); GUILayout.Label("Source Object:", GUILayout.Width(110)); sourceObject = (ParticleSystem)EditorGUILayout.ObjectField(sourceObject, typeof(ParticleSystem), true); GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Modules to Copy:"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("ALL", EditorStyles.miniButtonLeft, GUILayout.Width(120))) { for (int i = 0; i < b_modules.Length; i++) { b_modules[i] = true; } } if (GUILayout.Button("NONE", EditorStyles.miniButtonRight, GUILayout.Width(120))) { for (int i = 0; i < b_modules.Length; i++) { b_modules[i] = false; } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(4); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = b_modules[0] ? ColorSelected : Color.white; if (GUILayout.Button("Initial", EditorStyles.toolbarButton, GUILayout.Width(70))) { b_modules[0] = !b_modules[0]; } GUI.color = b_modules[1] ? ColorSelected : Color.white; if (GUILayout.Button("Emission", EditorStyles.toolbarButton, GUILayout.Width(70))) { b_modules[1] = !b_modules[1]; } GUI.color = b_modules[2] ? ColorSelected : Color.white; if (GUILayout.Button("Shape", EditorStyles.toolbarButton, GUILayout.Width(70))) { b_modules[2] = !b_modules[2]; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = b_modules[3] ? ColorSelected : Color.white; if (GUILayout.Button("Velocity", EditorStyles.toolbarButton, GUILayout.Width(70))) { b_modules[3] = !b_modules[3]; } GUI.color = b_modules[4] ? ColorSelected : Color.white; if (GUILayout.Button("Limit Velocity", EditorStyles.toolbarButton, GUILayout.Width(100))) { b_modules[4] = !b_modules[4]; } GUI.color = b_modules[5] ? ColorSelected : Color.white; if (GUILayout.Button("Force", EditorStyles.toolbarButton, GUILayout.Width(70))) { b_modules[5] = !b_modules[5]; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = b_modules[6] ? ColorSelected : Color.white; if (GUILayout.Button("Color over Lifetime", EditorStyles.toolbarButton, GUILayout.Width(120))) { b_modules[6] = !b_modules[6]; } GUI.color = b_modules[7] ? ColorSelected : Color.white; if (GUILayout.Button("Color by Speed", EditorStyles.toolbarButton, GUILayout.Width(120))) { b_modules[7] = !b_modules[7]; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = b_modules[8] ? ColorSelected : Color.white; if (GUILayout.Button("Size over Lifetime", EditorStyles.toolbarButton, GUILayout.Width(120))) { b_modules[8] = !b_modules[8]; } GUI.color = b_modules[9] ? ColorSelected : Color.white; if (GUILayout.Button("Size by Speed", EditorStyles.toolbarButton, GUILayout.Width(120))) { b_modules[9] = !b_modules[9]; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = b_modules[10] ? ColorSelected : Color.white; if (GUILayout.Button("Rotation over Lifetime", EditorStyles.toolbarButton, GUILayout.Width(120))) { b_modules[10] = !b_modules[10]; } GUI.color = b_modules[11] ? ColorSelected : Color.white; if (GUILayout.Button("Rotation by Speed", EditorStyles.toolbarButton, GUILayout.Width(120))) { b_modules[11] = !b_modules[11]; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = b_modules[12] ? ColorSelected : Color.white; if (GUILayout.Button("Collision", EditorStyles.toolbarButton, GUILayout.Width(100))) { b_modules[12] = !b_modules[12]; } GUI.color = b_modules[13] ? ColorSelected : Color.white; if (GUILayout.Button("Sub Emitters", EditorStyles.toolbarButton, GUILayout.Width(100))) { b_modules[13] = !b_modules[13]; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = b_modules[14] ? ColorSelected : Color.white; if (GUILayout.Button("Texture Animation", EditorStyles.toolbarButton, GUILayout.Width(110))) { b_modules[14] = !b_modules[14]; } GUI.color = b_modules[15] ? ColorSelected : Color.white; if (GUILayout.Button("Renderer", EditorStyles.toolbarButton, GUILayout.Width(90))) { b_modules[15] = !b_modules[15]; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUI.color = Color.white; GUILayout.Space(4); if (GUILayout.Button("Copy properties to selected Object(s)")) { bool foundPs = false; foreach (GameObject go in Selection.gameObjects) { ParticleSystem[] systems; if (IncludeChildren) { systems = go.GetComponentsInChildren <ParticleSystem>(true); } else { systems = go.GetComponents <ParticleSystem>(); } if (systems.Length == 0) { continue; } foundPs = true; foreach (ParticleSystem system in systems) { CopyModules(sourceObject, system); } } if (!foundPs) { Debug.LogWarning("CartoonFX Easy Editor: No Particle System found in the selected GameObject(s)!"); } } } //---------------------------------------------------------------- GUILayout.Space(8); //Resize window if (foldoutChanged && Event.current.type == EventType.Repaint) { foldoutChanged = false; Rect r = GUILayoutUtility.GetLastRect(); this.minSize = new Vector2(300, r.y + 8); this.maxSize = new Vector2(300, r.y + 8); this.position = new Rect(this.position.x, this.position.y, 300, r.y + 8); } GUILayout.EndArea(); }
public override void Update(float time, float deltaTime) { _lightness = HSLColor.FromRGBA(_value).l; }