Skip to content

Instantly share code, notes, and snippets.

@mob-sakai
Created June 1, 2018 08:09
Show Gist options
  • Save mob-sakai/57341af242e28f55aa2b579981364559 to your computer and use it in GitHub Desktop.
Save mob-sakai/57341af242e28f55aa2b579981364559 to your computer and use it in GitHub Desktop.
Change texture for UIDissolve
using UnityEngine;
using UnityEngine.UI;
using Coffee.UIExtensions;
[RequireComponent(typeof(UIDissolve))]
public class ChangeDissolveTexture : MonoBehaviour, IMaterialModifier
{
//################################
// Serialize Members.
//################################
[SerializeField] Texture m_dissolveTexture;
//################################
// Public Members.
//################################
public Texture dissolveTexture
{
get { return m_dissolveTexture; }
set
{
if (m_dissolveTexture != value)
{
m_dissolveTexture = value;
UpdateTexture();
graphic.SetMaterialDirty();
}
}
}
public Graphic graphic { get { return _graphic ?? (_graphic = GetComponent<Graphic>()); } }
public Material GetModifiedMaterial(Material baseMaterial)
{
if (baseMaterial.shader.name == "UI/Hidden/UI-Effect-Dissolve" && m_dissolveTexture)
{
_material = new Material(baseMaterial);
UpdateTexture();
return _material;
}
return baseMaterial;
}
//################################
// Private Members.
//################################
Material _material;
Graphic _graphic;
void OnValidate()
{
UpdateTexture();
graphic.SetMaterialDirty();
}
void UpdateTexture()
{
if (_material)
{
_material.SetTexture("_NoiseTex", m_dissolveTexture);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment