In order to support you taking your first steps with MatEdit we provide this "How to Start" guide.
Simply follow the given steps in order to create your custom material inspectors:
- Right-click the shader you want to enhance with a custom material inspector and select "Create > MatEdit > Create ShaderGUI"
- Open the editor script generated in the folder "Editor" relative to the shader file.
- Select the presented method under the SetScope() method call.
- Use any MatGUI method to create new fields for the material inspector.
If you plan to add it manually or in an already existing ShaderGUI follow the upcoming instructions instead:
- Create a new C# script and name it as you wish. It is recommended to call it relatable to your shader.
- Open the script in the script editor of your choice.
- Remove all MonoBehaviour related functions etc.
- Use “MB.MatEdit” and “UnityEditor”.
- Inherit from “ShaderGUI” and implement the method “OnGUI”
- At this point it is recommended to use “MatGUI.SetScope” to define the target of all upcoming operations.
- Use any MatGUI-Field method you want.
- To bind this GUI to the shader open your shader and insert before the last braces: CustomEditor “YourGUIScript”
Giving you a more user friendly and readable approach for GUI code is not the only task MatEdit tries to fulfill.
By using the special fields you can enable the user to change Color Gradients and Animation Curves directly in the material inspector. These fields generate a texture which can be read in the shader.
In order to guarantee the smooth functionality of MatEdit in future updates it is recommended to use the cg-inclusions provided with MatEdit. These cginc files can be placed manually in your shader's folder or can be used project wide by using the installation button in the about window. The cginc files provide a method for converting the textures back into Color Gradients or Animation Curves.