mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-21 02:12:37 +08:00
Refactoring
This commit is contained in:
@@ -70,7 +70,7 @@ namespace Coffee.UIExtensions
|
||||
var comb = combinations[i];
|
||||
|
||||
EditorUtility.DisplayProgressBar("Genarate Effect Material", UIEffect.GetVariantName(shader, comb.tone, comb.color, comb.blur), (float)i / combinations.Length);
|
||||
UIEffect.GetOrCreateMaterialVariant(shader, comb.tone, comb.color, comb.blur);
|
||||
UIEffect.GetOrGenerateMaterialVariant(shader, comb.tone, comb.color, comb.blur);
|
||||
}
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Coffee.UIExtensions
|
||||
}
|
||||
else if (changed || !serializedObject.isEditingMultipleObjects)
|
||||
{
|
||||
spMaterial.objectReferenceValue = UIEffect.GetOrCreateMaterialVariant(Shader.Find(shaderName),
|
||||
spMaterial.objectReferenceValue = UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName),
|
||||
(UIEffect.ToneMode)spToneMode.intValue,
|
||||
(UIEffect.ColorMode)spColorMode.intValue,
|
||||
(UIEffect.BlurMode)spBlurMode.intValue
|
||||
|
||||
+62
-106
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.IO;
|
||||
@@ -32,8 +31,7 @@ namespace Coffee.UIExtensions
|
||||
/// <summary>
|
||||
/// How far is the blurring shadow from the graphic.
|
||||
/// </summary>
|
||||
[Range(0, 1)]
|
||||
public float shadowBlur = 0.25f;
|
||||
[Range(0, 1)] public float shadowBlur = 0.25f;
|
||||
|
||||
/// <summary>
|
||||
/// Shadow effect mode.
|
||||
@@ -57,7 +55,7 @@ namespace Coffee.UIExtensions
|
||||
}
|
||||
|
||||
//################################
|
||||
// Constant Members.
|
||||
// Constant or Static Members.
|
||||
//################################
|
||||
public const string shaderName = "UI/Hidden/UI-Effect";
|
||||
|
||||
@@ -87,24 +85,6 @@ namespace Coffee.UIExtensions
|
||||
Sub,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shadow effect mode.
|
||||
/// </summary>
|
||||
[Obsolete("ShadowMode has been deprecated. Use ShadowStyle instead (UnityUpgradable) -> ShadowStyle", true)]
|
||||
public enum ShadowMode
|
||||
{
|
||||
[Obsolete("ShadowMode.None has been deprecated. Use ShadowStyle.None instead (UnityUpgradable) -> ShadowStyle.None", true)]
|
||||
None = 0,
|
||||
[Obsolete("ShadowMode.Shadow has been deprecated. Use ShadowStyle.Shadow instead (UnityUpgradable) -> ShadowStyle.Shadow", true)]
|
||||
Shadow,
|
||||
[Obsolete("ShadowMode.Outline has been deprecated. Use ShadowStyle.Outline instead (UnityUpgradable) -> ShadowStyle.Outline", true)]
|
||||
Outline,
|
||||
[Obsolete("ShadowMode.Outline8 has been deprecated. Use ShadowStyle.Outline8 instead (UnityUpgradable) -> ShadowStyle.Outline8", true)]
|
||||
Outline8,
|
||||
[Obsolete("ShadowMode.Shadow3 has been deprecated. Use ShadowStyle.Shadow3 instead (UnityUpgradable) -> ShadowStyle.Shadow3", true)]
|
||||
Shadow3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shadow effect style.
|
||||
/// </summary>
|
||||
@@ -130,12 +110,25 @@ namespace Coffee.UIExtensions
|
||||
|
||||
|
||||
//################################
|
||||
// Static Members.
|
||||
// Serialize Members.
|
||||
//################################
|
||||
static readonly List<UIVertex> s_Verts = new List<UIVertex>();
|
||||
[SerializeField][Range(0, 1)] float m_ToneLevel = 1;
|
||||
[SerializeField][Range(0, 1)] float m_Blur = 0.25f;
|
||||
[SerializeField][Range(0, 1)] float m_ShadowBlur = 0.25f;
|
||||
[SerializeField] ShadowStyle m_ShadowStyle;
|
||||
[SerializeField] ToneMode m_ToneMode;
|
||||
[SerializeField] ColorMode m_ColorMode;
|
||||
[SerializeField] BlurMode m_BlurMode;
|
||||
[SerializeField] Color m_ShadowColor = Color.black;
|
||||
[SerializeField] Vector2 m_EffectDistance = new Vector2(1f, -1f);
|
||||
[SerializeField] bool m_UseGraphicAlpha = true;
|
||||
[SerializeField] Color m_EffectColor = Color.white;
|
||||
[SerializeField] Material m_EffectMaterial;
|
||||
[SerializeField] List<AdditionalShadow> m_AdditionalShadows = new List<AdditionalShadow>();
|
||||
|
||||
|
||||
//################################
|
||||
// Public or Serialize Members.
|
||||
// Public Members.
|
||||
//################################
|
||||
/// <summary>
|
||||
/// Graphic affected by the UIEffect.
|
||||
@@ -145,108 +138,68 @@ namespace Coffee.UIExtensions
|
||||
/// <summary>
|
||||
/// Tone effect level between 0(no effect) and 1(complete effect).
|
||||
/// </summary>
|
||||
public float toneLevel{ get { return m_ToneLevel; } set { m_ToneLevel = Mathf.Clamp(value, 0, 1); SetDirty(); } }
|
||||
|
||||
[SerializeField][Range(0, 1)] float m_ToneLevel = 1;
|
||||
public float toneLevel{ get { return m_ToneLevel; } set { m_ToneLevel = Mathf.Clamp(value, 0, 1); _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// How far is the blurring from the graphic.
|
||||
/// </summary>
|
||||
public float blur { get { return m_Blur; } set { m_Blur = Mathf.Clamp(value, 0, 2); SetDirty(); } }
|
||||
|
||||
[SerializeField][Range(0, 1)] float m_Blur = 0.25f;
|
||||
public float blur { get { return m_Blur; } set { m_Blur = Mathf.Clamp(value, 0, 2); _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// How far is the blurring shadow from the graphic.
|
||||
/// </summary>
|
||||
public float shadowBlur { get { return m_ShadowBlur; } set { m_ShadowBlur = Mathf.Clamp(value, 0, 2); SetDirty(); } }
|
||||
|
||||
[SerializeField][Range(0, 1)] float m_ShadowBlur = 0.25f;
|
||||
public float shadowBlur { get { return m_ShadowBlur; } set { m_ShadowBlur = Mathf.Clamp(value, 0, 2); _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Shadow effect mode.
|
||||
/// </summary>
|
||||
public ShadowStyle shadowStyle { get { return m_ShadowStyle; } set { m_ShadowStyle = value; SetDirty(); } }
|
||||
|
||||
[Obsolete("UIEffect.shadowMode is obsolete, use UIEffect.shadowStyle instead. (UnityUpgradable) -> shadowStyle")]
|
||||
public ShadowStyle shadowMode { get { return m_ShadowStyle; } set { m_ShadowStyle = value; SetDirty(); } }
|
||||
|
||||
[SerializeField][FormerlySerializedAs("m_ShadowMode")] ShadowStyle m_ShadowStyle;
|
||||
public ShadowStyle shadowStyle { get { return m_ShadowStyle; } set { m_ShadowStyle = value; _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Tone effect mode.
|
||||
/// </summary>
|
||||
public ToneMode toneMode { get { return m_ToneMode; } }
|
||||
|
||||
[SerializeField] ToneMode m_ToneMode;
|
||||
|
||||
/// <summary>
|
||||
/// Color effect mode.
|
||||
/// </summary>
|
||||
public ColorMode colorMode { get { return m_ColorMode; } }
|
||||
|
||||
[SerializeField] ColorMode m_ColorMode;
|
||||
|
||||
/// <summary>
|
||||
/// Blur effect mode.
|
||||
/// </summary>
|
||||
public BlurMode blurMode { get { return m_BlurMode; } }
|
||||
|
||||
[SerializeField] BlurMode m_BlurMode;
|
||||
|
||||
/// <summary>
|
||||
/// Color for the shadow effect.
|
||||
/// </summary>
|
||||
public Color shadowColor { get { return m_ShadowColor; } set { m_ShadowColor = value; SetDirty(); } }
|
||||
|
||||
[SerializeField] Color m_ShadowColor = Color.black;
|
||||
public Color shadowColor { get { return m_ShadowColor; } set { m_ShadowColor = value; _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// How far is the shadow from the graphic.
|
||||
/// </summary>
|
||||
public Vector2 effectDistance { get { return m_EffectDistance; } set { m_EffectDistance = value; SetDirty(); } }
|
||||
|
||||
[SerializeField] Vector2 m_EffectDistance = new Vector2(1f, -1f);
|
||||
public Vector2 effectDistance { get { return m_EffectDistance; } set { m_EffectDistance = value; _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Should the shadow inherit the alpha from the graphic?
|
||||
/// </summary>
|
||||
public bool useGraphicAlpha { get { return m_UseGraphicAlpha; } set { m_UseGraphicAlpha = value; SetDirty(); } }
|
||||
|
||||
[SerializeField] bool m_UseGraphicAlpha = true;
|
||||
public bool useGraphicAlpha { get { return m_UseGraphicAlpha; } set { m_UseGraphicAlpha = value; _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Color for the color effect.
|
||||
/// </summary>
|
||||
[Obsolete("UIEffect.color is obsolete, use UIEffect.effectColor instead. (UnityUpgradable) -> effectColor")]
|
||||
public Color color { get { return m_EffectColor; } set { m_EffectColor = value; SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Color for the color effect.
|
||||
/// </summary>
|
||||
public Color effectColor { get { return m_EffectColor; } set { m_EffectColor = value; SetDirty(); } }
|
||||
|
||||
[SerializeField][FormerlySerializedAs("m_Color")] Color m_EffectColor = Color.white;
|
||||
public Color effectColor { get { return m_EffectColor; } set { m_EffectColor = value; _SetDirty(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Effect material.
|
||||
/// </summary>
|
||||
public virtual Material effectMaterial { get { return m_EffectMaterial; } }
|
||||
|
||||
[SerializeField] Material m_EffectMaterial;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Additional Shadows.
|
||||
/// </summary>
|
||||
public List<AdditionalShadow> additionalShadows { get { return m_AdditionalShadows; } }
|
||||
|
||||
[SerializeField] List<AdditionalShadow> m_AdditionalShadows = new List<AdditionalShadow>();
|
||||
|
||||
|
||||
//################################
|
||||
// MonoBehaior Callbacks.
|
||||
//################################
|
||||
/// <summary>
|
||||
/// This function is called when the object becomes enabled and active.
|
||||
/// </summary>
|
||||
@@ -284,8 +237,8 @@ namespace Coffee.UIExtensions
|
||||
{
|
||||
// Pack some effect factors to 1 float.
|
||||
Vector2 factor = new Vector2(
|
||||
PackToFloat(toneLevel, 0, blur, 0),
|
||||
PackToFloat(effectColor.r, effectColor.g, effectColor.b, effectColor.a)
|
||||
_PackToFloat(toneLevel, 0, blur, 0),
|
||||
_PackToFloat(effectColor.r, effectColor.g, effectColor.b, effectColor.a)
|
||||
);
|
||||
|
||||
for (int i = 0; i < s_Verts.Count; i++)
|
||||
@@ -310,11 +263,11 @@ namespace Coffee.UIExtensions
|
||||
for (int i = additionalShadows.Count - 1; 0 <= i; i--)
|
||||
{
|
||||
AdditionalShadow shadow = additionalShadows[i];
|
||||
ApplyShadow(s_Verts, ref start, ref end, shadow.shadowMode, toneLevel, shadow.shadowBlur, shadow.effectDistance, shadow.shadowColor, shadow.useGraphicAlpha);
|
||||
_ApplyShadow(s_Verts, ref start, ref end, shadow.shadowMode, toneLevel, shadow.shadowBlur, shadow.effectDistance, shadow.shadowColor, shadow.useGraphicAlpha);
|
||||
}
|
||||
|
||||
// Shadow.
|
||||
ApplyShadow(s_Verts, ref start, ref end, shadowStyle, toneLevel, shadowBlur, effectDistance, shadowColor, useGraphicAlpha);
|
||||
_ApplyShadow(s_Verts, ref start, ref end, shadowStyle, toneLevel, shadowBlur, effectDistance, shadowColor, useGraphicAlpha);
|
||||
}
|
||||
|
||||
vh.Clear();
|
||||
@@ -339,7 +292,7 @@ namespace Coffee.UIExtensions
|
||||
|
||||
var mat = (0 == toneMode) && (0 == colorMode) && (0 == blurMode)
|
||||
? null
|
||||
: GetOrCreateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode);
|
||||
: GetOrGenerateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode);
|
||||
|
||||
if(m_EffectMaterial == mat && graphic.material == mat)
|
||||
return;
|
||||
@@ -354,7 +307,7 @@ namespace Coffee.UIExtensions
|
||||
public static Material GetMaterial(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
|
||||
{
|
||||
string variantName = GetVariantName(shader, tone, color, blur);
|
||||
return AssetDatabase.FindAssets("t:Material " + variantName)
|
||||
return AssetDatabase.FindAssets("t:Material " + Path.GetFileName(shader.name))
|
||||
.Select(x => AssetDatabase.GUIDToAssetPath(x))
|
||||
.SelectMany(x => AssetDatabase.LoadAllAssetsAtPath(x))
|
||||
.OfType<Material>()
|
||||
@@ -362,7 +315,7 @@ namespace Coffee.UIExtensions
|
||||
}
|
||||
|
||||
|
||||
public static Material GetOrCreateMaterialVariant(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
|
||||
public static Material GetOrGenerateMaterialVariant(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
|
||||
{
|
||||
if (!shader)
|
||||
return null;
|
||||
@@ -371,6 +324,7 @@ namespace Coffee.UIExtensions
|
||||
|
||||
if (!mat)
|
||||
{
|
||||
Debug.Log("Generate material : " + GetVariantName(shader, tone, color, blur));
|
||||
mat = new Material(shader);
|
||||
|
||||
if (0 < tone)
|
||||
@@ -429,51 +383,53 @@ namespace Coffee.UIExtensions
|
||||
}
|
||||
#endif
|
||||
|
||||
//################################
|
||||
// Internal Method.
|
||||
//################################
|
||||
/// <summary>
|
||||
/// Append shadow vertices.
|
||||
/// * It is similar to Shadow component implementation.
|
||||
/// </summary>
|
||||
static void ApplyShadow(List<UIVertex> verts, ref int start, ref int end, ShadowStyle mode, float toneLevel, float blur, Vector2 effectDistance, Color color, bool useGraphicAlpha)
|
||||
//################################
|
||||
// Private Members.
|
||||
//################################
|
||||
static readonly List<UIVertex> s_Verts = new List<UIVertex>();
|
||||
|
||||
/// <summary>
|
||||
/// Append shadow vertices.
|
||||
/// * It is similar to Shadow component implementation.
|
||||
/// </summary>
|
||||
static void _ApplyShadow(List<UIVertex> verts, ref int start, ref int end, ShadowStyle mode, float toneLevel, float blur, Vector2 effectDistance, Color color, bool useGraphicAlpha)
|
||||
{
|
||||
if (ShadowStyle.None == mode)
|
||||
return;
|
||||
|
||||
var factor = new Vector2(
|
||||
PackToFloat(toneLevel, 0, blur, 0),
|
||||
PackToFloat(color.r, color.g, color.b, 1)
|
||||
_PackToFloat(toneLevel, 0, blur, 0),
|
||||
_PackToFloat(color.r, color.g, color.b, 1)
|
||||
);
|
||||
|
||||
// Append Shadow.
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
|
||||
// Append Shadow3.
|
||||
if (ShadowStyle.Shadow3 == mode)
|
||||
{
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, 0, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, 0, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
}
|
||||
|
||||
// Append Outline.
|
||||
else if (ShadowStyle.Outline == mode)
|
||||
{
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
}
|
||||
|
||||
// Append Outline8.
|
||||
else if (ShadowStyle.Outline8 == mode)
|
||||
{
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, 0, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, 0, factor, color, useGraphicAlpha);
|
||||
ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, -effectDistance.x, 0, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, -effectDistance.y, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, effectDistance.x, 0, factor, color, useGraphicAlpha);
|
||||
_ApplyShadowZeroAlloc(s_Verts, ref start, ref end, 0, effectDistance.y, factor, color, useGraphicAlpha);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,7 +437,7 @@ namespace Coffee.UIExtensions
|
||||
/// Append shadow vertices.
|
||||
/// * It is similar to Shadow component implementation.
|
||||
/// </summary>
|
||||
static void ApplyShadowZeroAlloc(List<UIVertex> verts, ref int start, ref int end, float x, float y, Vector2 factor, Color color, bool useGraphicAlpha)
|
||||
static void _ApplyShadowZeroAlloc(List<UIVertex> verts, ref int start, ref int end, float x, float y, Vector2 factor, Color color, bool useGraphicAlpha)
|
||||
{
|
||||
// Check list capacity.
|
||||
var neededCapacity = verts.Count + end - start;
|
||||
@@ -516,7 +472,7 @@ namespace Coffee.UIExtensions
|
||||
/// <summary>
|
||||
/// Mark the UIEffect as dirty.
|
||||
/// </summary>
|
||||
void SetDirty()
|
||||
void _SetDirty()
|
||||
{
|
||||
if(graphic)
|
||||
graphic.SetVerticesDirty();
|
||||
@@ -526,7 +482,7 @@ namespace Coffee.UIExtensions
|
||||
/// Pack 4 low-precision [0-1] floats values to a float.
|
||||
/// Each value [0-1] has 64 steps(6 bits).
|
||||
/// </summary>
|
||||
static float PackToFloat(float x, float y, float z, float w)
|
||||
static float _PackToFloat(float x, float y, float z, float w)
|
||||
{
|
||||
const int PRECISION = (1 << 6) - 1;
|
||||
return (Mathf.FloorToInt(w * PRECISION) << 18)
|
||||
|
||||
@@ -21,6 +21,10 @@ namespace Coffee.UIExtensions
|
||||
, ISerializationCallbackReceiver
|
||||
#endif
|
||||
{
|
||||
|
||||
//################################
|
||||
// Constant or Static Members.
|
||||
//################################
|
||||
public const string shaderName = "UI/Hidden/UI-EffectCapture";
|
||||
|
||||
/// <summary>
|
||||
@@ -35,92 +39,128 @@ namespace Coffee.UIExtensions
|
||||
x8 = 8,
|
||||
}
|
||||
|
||||
|
||||
//################################
|
||||
// Serialize Members.
|
||||
//################################
|
||||
[SerializeField][Range(0, 1)] float m_ToneLevel = 1;
|
||||
[SerializeField][Range(0, 1)] float m_Blur = 0;
|
||||
[SerializeField] ToneMode m_ToneMode;
|
||||
[SerializeField] ColorMode m_ColorMode;
|
||||
[SerializeField] BlurMode m_BlurMode;
|
||||
[SerializeField] Color m_EffectColor = Color.white;
|
||||
[SerializeField] DesamplingRate m_DesamplingRate;
|
||||
[SerializeField] DesamplingRate m_ReductionRate;
|
||||
[SerializeField] FilterMode m_FilterMode = FilterMode.Bilinear;
|
||||
[SerializeField] Material m_EffectMaterial;
|
||||
|
||||
|
||||
//################################
|
||||
// Public Members.
|
||||
//################################
|
||||
/// <summary>
|
||||
/// Tone effect level between 0(no effect) and 1(complete effect).
|
||||
/// </summary>
|
||||
public float toneLevel { get { return m_ToneLevel; } set { m_ToneLevel = Mathf.Clamp(value, 0, 1); } }
|
||||
|
||||
[SerializeField]
|
||||
[Range(0, 1)]
|
||||
float m_ToneLevel = 1;
|
||||
|
||||
/// <summary>
|
||||
/// How far is the blurring from the graphic.
|
||||
/// </summary>
|
||||
public float blur { get { return m_Blur; } set { m_Blur = Mathf.Clamp(value, 0, 4); } }
|
||||
|
||||
[SerializeField]
|
||||
[Range(0, 1)]
|
||||
float m_Blur = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Tone effect mode.
|
||||
/// </summary>
|
||||
public ToneMode toneMode { get { return m_ToneMode; } set { m_ToneMode = value; } }
|
||||
|
||||
[SerializeField]
|
||||
ToneMode m_ToneMode;
|
||||
|
||||
/// <summary>
|
||||
/// Color effect mode.
|
||||
/// </summary>
|
||||
public ColorMode colorMode { get { return m_ColorMode; } set { m_ColorMode = value; } }
|
||||
|
||||
[SerializeField]
|
||||
ColorMode m_ColorMode;
|
||||
|
||||
/// <summary>
|
||||
/// Blur effect mode.
|
||||
/// </summary>
|
||||
public BlurMode blurMode { get { return m_BlurMode; } set { m_BlurMode = value; } }
|
||||
|
||||
[SerializeField]
|
||||
BlurMode m_BlurMode;
|
||||
|
||||
/// <summary>
|
||||
/// Color for the color effect.
|
||||
/// </summary>
|
||||
public Color effectColor { get { return m_EffectColor; } set { m_EffectColor = value; } }
|
||||
|
||||
[SerializeField]
|
||||
Color m_EffectColor = Color.white;
|
||||
/// <summary>
|
||||
/// Effect material.
|
||||
/// </summary>
|
||||
public virtual Material effectMaterial { get { return m_EffectMaterial; } }
|
||||
|
||||
/// <summary>
|
||||
/// Desampling rate of the generated RenderTexture.
|
||||
/// </summary>
|
||||
public DesamplingRate desamplingRate { get { return m_DesamplingRate; } set { m_DesamplingRate = value; } }
|
||||
|
||||
[SerializeField]
|
||||
DesamplingRate m_DesamplingRate;
|
||||
|
||||
/// <summary>
|
||||
/// Desampling rate of reduction buffer to apply effect.
|
||||
/// </summary>
|
||||
public DesamplingRate reductionRate { get { return m_ReductionRate; } set { m_ReductionRate = value; } }
|
||||
|
||||
[SerializeField]
|
||||
DesamplingRate m_ReductionRate;
|
||||
|
||||
/// <summary>
|
||||
/// FilterMode for capture.
|
||||
/// </summary>
|
||||
public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
|
||||
|
||||
[SerializeField]
|
||||
FilterMode m_FilterMode = FilterMode.Bilinear;
|
||||
|
||||
/// <summary>
|
||||
/// Effect material.
|
||||
/// </summary>
|
||||
public virtual Material effectMaterial { get { return m_EffectMaterial; } }
|
||||
|
||||
[SerializeField] Material m_EffectMaterial;
|
||||
|
||||
/// <summary>
|
||||
/// Captured texture.
|
||||
/// </summary>
|
||||
public RenderTexture capturedTexture { get { return _rt; } }
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when the MonoBehaviour will be destroyed.
|
||||
/// </summary>
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
_Release(true);
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback function when a UI element needs to generate vertices.
|
||||
/// </summary>
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
// When not displaying, clear vertex.
|
||||
if (texture == null || effectColor.a < 1 / 255f || canvasRenderer.GetAlpha() < 1 / 255f)
|
||||
vh.Clear();
|
||||
else
|
||||
base.OnPopulateMesh(vh);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
var obj = this;
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (Application.isPlaying || !obj)
|
||||
return;
|
||||
|
||||
var mat = (0 == toneMode) && (0 == colorMode) && (0 == blurMode)
|
||||
? null
|
||||
: UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode);
|
||||
|
||||
if (m_EffectMaterial == mat)
|
||||
return;
|
||||
|
||||
m_EffectMaterial = mat;
|
||||
EditorUtility.SetDirty(this);
|
||||
EditorApplication.delayCall += AssetDatabase.SaveAssets;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the desampling.
|
||||
/// </summary>
|
||||
@@ -226,60 +266,19 @@ namespace Coffee.UIExtensions
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release captured image.
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
_Release(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when the MonoBehaviour will be destroyed.
|
||||
/// </summary>
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
_Release(true);
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
var obj = this;
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (Application.isPlaying || !obj)
|
||||
return;
|
||||
|
||||
var mat = (0 == toneMode) && (0 == colorMode) && (0 == blurMode)
|
||||
? null
|
||||
: UIEffect.GetOrCreateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode);
|
||||
|
||||
if (m_EffectMaterial == mat)
|
||||
return;
|
||||
|
||||
m_EffectMaterial = mat;
|
||||
EditorUtility.SetDirty(this);
|
||||
EditorApplication.delayCall += AssetDatabase.SaveAssets;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Callback function when a UI element needs to generate vertices.
|
||||
/// </summary>
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
// When not displaying, clear vertex.
|
||||
if (texture == null || effectColor.a < 1 / 255f || canvasRenderer.GetAlpha() < 1 / 255f)
|
||||
vh.Clear();
|
||||
else
|
||||
base.OnPopulateMesh(vh);
|
||||
}
|
||||
|
||||
//################################
|
||||
// Private Members.
|
||||
//################################
|
||||
const CameraEvent kCameraEvent = CameraEvent.AfterEverything;
|
||||
Camera _camera;
|
||||
RenderTexture _rt;
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace Coffee.UIExtensions
|
||||
//################################
|
||||
// Constant or Static Members.
|
||||
//################################
|
||||
static readonly Vector2[] s_SplitedCharacterPosition = { Vector2.up, Vector2.one, Vector2.right, Vector2.zero };
|
||||
|
||||
/// <summary>
|
||||
/// Gradient direction.
|
||||
@@ -35,6 +34,7 @@ namespace Coffee.UIExtensions
|
||||
Split,
|
||||
}
|
||||
|
||||
|
||||
//################################
|
||||
// Serialize Members.
|
||||
//################################
|
||||
@@ -50,10 +50,10 @@ namespace Coffee.UIExtensions
|
||||
[SerializeField] ColorSpace m_ColorSpace = ColorSpace.Uninitialized;
|
||||
[SerializeField] bool m_IgnoreAspectRatio = true;
|
||||
|
||||
|
||||
//################################
|
||||
// Public Members.
|
||||
//################################
|
||||
|
||||
new public Graphic graphic { get { return base.graphic; } }
|
||||
|
||||
/// <summary>
|
||||
@@ -92,7 +92,7 @@ namespace Coffee.UIExtensions
|
||||
: m_Direction == Direction.Vertical ? 0
|
||||
: m_Rotation;
|
||||
}
|
||||
set { if (m_Rotation != value) { m_Rotation = value; graphic.SetVerticesDirty(); } }
|
||||
set { if (!Mathf.Approximately(m_Rotation, value)) { m_Rotation = value; graphic.SetVerticesDirty(); } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -207,6 +207,12 @@ namespace Coffee.UIExtensions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//################################
|
||||
// Private Members.
|
||||
//################################
|
||||
static readonly Vector2[] s_SplitedCharacterPosition = { Vector2.up, Vector2.one, Vector2.right, Vector2.zero };
|
||||
|
||||
/// <summary>
|
||||
/// Matrix2x3.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,7 +9,7 @@ PlayerSettings:
|
||||
targetDevice: 2
|
||||
useOnDemandResources: 0
|
||||
accelerometerFrequency: 60
|
||||
companyName: DefaultCompany
|
||||
companyName: Coffee
|
||||
productName: UIEffect
|
||||
defaultCursor: {fileID: 0}
|
||||
cursorHotspot: {x: 0, y: 0}
|
||||
@@ -88,7 +88,7 @@ PlayerSettings:
|
||||
16:10: 1
|
||||
16:9: 1
|
||||
Others: 1
|
||||
bundleIdentifier: com.Company.ProductName
|
||||
bundleIdentifier: com.coffee.uieffect
|
||||
bundleVersion: 1.0
|
||||
preloadedAssets: []
|
||||
metroEnableIndependentInputSource: 0
|
||||
|
||||
Reference in New Issue
Block a user