2015-10-29 04:43:01 +08:00
|
|
|
|
/// Credit 00christian00
|
|
|
|
|
/// Sourced from - http://forum.unity3d.com/threads/any-way-to-show-part-of-an-image-without-using-mask.360085/#post-2332030
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
2016-05-31 05:47:46 +08:00
|
|
|
|
[AddComponentMenu("UI/Effects/Extensions/UISoftAdditiveEffect")]
|
2015-10-29 04:43:01 +08:00
|
|
|
|
[ExecuteInEditMode]
|
|
|
|
|
[RequireComponent(typeof(RectTransform))]
|
2016-05-31 05:47:46 +08:00
|
|
|
|
public class UISoftAdditiveEffect : MonoBehaviour
|
2015-10-29 04:43:01 +08:00
|
|
|
|
{
|
|
|
|
|
MaskableGraphic mGraphic;
|
|
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
SetMaterial();
|
|
|
|
|
}
|
2015-12-02 00:01:01 +08:00
|
|
|
|
|
2015-10-29 04:43:01 +08:00
|
|
|
|
public void SetMaterial()
|
|
|
|
|
{
|
|
|
|
|
mGraphic = this.GetComponent<MaskableGraphic>();
|
|
|
|
|
if (mGraphic != null)
|
|
|
|
|
{
|
2015-12-02 00:01:01 +08:00
|
|
|
|
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
|
|
|
|
{
|
|
|
|
|
//Applying default material with UI Image Crop shader
|
2020-10-24 02:10:51 +08:00
|
|
|
|
mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UISoftAdditive"));
|
2015-12-02 00:01:01 +08:00
|
|
|
|
}
|
2015-10-29 04:43:01 +08:00
|
|
|
|
}
|
2015-12-02 00:01:01 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Please attach component to a Graphical UI component");
|
|
|
|
|
}
|
2015-10-29 04:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
public void OnValidate()
|
|
|
|
|
{
|
|
|
|
|
SetMaterial();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|