
Use the “ GetColor()” function to get the main color of the material.
color = newColor ī- By using the “ SetColor()” function: MeshRenderer rend = GetComponent() rend.material. In the same way with textures, to change the main color of a Material, you have also two options:Ī- By accessing the color property: Color newColor = Color.blue GetComponent().material. m_ ("_METALLICGLOSSMAP") ("_MetallicGlossMap", myTexture) You may need to use the “ EnableKeyword” function to enable a property keyword of the shader before calling “ SetTexture()” function. You can use the “ GetTexture()” function to get current main texture of the material. As it is your highlight shader effect, you can replace It by another different material if needed.For example, to change the main texture of a Material, you have two options:Ī- By accessing the mainTexture property: public Texture2D myTexture private void Start() The property bMaterial is the material attached to each button. Replace the Image/RawImage component on all your buttons with this CustomRawimage script component.return the material with Mask + Customs applied.
Public override Material GetModifiedMaterial( Material bMaterial)
Create a script ( CustomRawImage.cs) with the following code:. Attach a Mask component to the frame container. bMaterial will load our shader later in our script. Attach the Material to the Button component. Create a new Material called “CustomMaterial” which uses the Shader created above. Albedo comes from a texture tinted by color Half4 tmpTexColor = tex2D (_MainTex, IN.uv_MainTex) Void surf (Input IN, inout SurfaceOutput o) Create a shader which accepts custom parameters as the Highlight color. Create a frame (Canvas) and put your buttons inside. For example, to create a menu button with highlight effect (which has our custom shader) masked by a frame, follow these steps By doing this you can apply the mask first, to view which pixels are visible, and then send the custom values to the shader. To solve this problem, you have to extend the Image class ( UI.Image or UI.RawImage ) and override the method GetModifiedMaterial. Before rendering pixels on the screen however, the Mask component will call the method GetModifiedMaterial on each masked object and will use the default settings in your material. When you set the parameters using the setter functions (as SetColorArray ) they will be set momentarily. It ignores all custom parameters sent by your scripts as it applies the custom shader by scripting using defaults. Masks use a method called GetModifiedMaterial to calculate which pixels are masked using the Stencil buffer. This function automatically instantiates the materials and makes them unique to this. If the material is used by any other renderers, this will clone the shared material and start using it from now on. Modifying material will change the material for this object only. The shader seems to be ignoring my custom parameters sent by scripting when Masked. Returns the first instantiated Material assigned to the renderer. The shader behaves as expected in most cases, but when used with a masked UI component, the values from SetColorArray/SetColor/Set* are not being passed through to the shader.