Created
June 1, 2018 08:09
-
-
Save mob-sakai/57341af242e28f55aa2b579981364559 to your computer and use it in GitHub Desktop.
Change texture for UIDissolve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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