Hi guys. I wanted to ask how to assign a default shader to a script. The grayscale effect always uses the grayscale shader. The user does not have to set it anywhere. Every time grayscale is applied to the camera it uses the right shader. Now I have my custom Image Effect script that uses my custom shader. But every time I want to apply my shader to the camera I have to manually select an appropriate shader to the script. It sounds fine so far but I actually need to made some changes to the EditorGUILayout so I’m overwriting the editor with my own stuff. It would be perfect if I could make the shader be set automatically and the sellection box hidden from the user. If this is not possible how do I add shader selection box to my Editor GUI. Mind that I don’t have a variable called shader in my script. Here’s the script code :
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/HSL")]
public class HSLControl : ImageEffectBase
{
public float hue = 0.0f;
public float saturation = 0.0f;
public float lightness = 0.0f;
public float redSaturation = 0.0f;
public float greenSaturation = 0.0f;
public float blueSaturation = 0.0f;
// Called by camera to apply image effect
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
material.SetFloat("_Hue", hue);
material.SetFloat("_Saturation", saturation);
material.SetFloat("_Lightness", lightness);
material.SetFloat("_RedSaturation", redSaturation);
material.SetFloat("_GreenSaturation", greenSaturation);
material.SetFloat("_BlueSaturation", blueSaturation);
Graphics.Blit(source, destination, material);
}
}
And here is the editor code:
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(HSLControl))]
public class HSLControlEditor : Editor
{
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
((HSLControl)target).hue = EditorGUILayout.Slider("Hue", ((HSLControl)target).hue, 0.0f, 1.0f);
((HSLControl)target).saturation = EditorGUILayout.Slider("Saturation", ((HSLControl)target).saturation, -1.0f, 1.0f);
((HSLControl)target).lightness = EditorGUILayout.Slider("Lightness", ((HSLControl)target).lightness, -1.0f, 1.0f);
((HSLControl)target).redSaturation = EditorGUILayout.Slider("R Saturation", ((HSLControl)target).redSaturation, -1.0f, 1.0f);
((HSLControl)target).greenSaturation = EditorGUILayout.Slider("G Saturation", ((HSLControl)target).greenSaturation, -1.0f, 1.0f);
((HSLControl)target).blueSaturation = EditorGUILayout.Slider("B Saturation", ((HSLControl)target).blueSaturation, -1.0f, 1.0f);
if (GUI.changed)
{
EditorUtility.SetDirty((HSLControl)target);
}
}
}