mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
feat: add TransitionFilter.Pattern feature
This commit is contained in:
@@ -48,9 +48,11 @@ namespace Coffee.UIEffects.Editors
|
||||
private SerializedProperty _transitionKeepAspectRatio;
|
||||
private SerializedProperty _transitionWidth;
|
||||
private SerializedProperty _transitionSoftness;
|
||||
private SerializedProperty _transitionRange;
|
||||
private SerializedProperty _transitionColorFilter;
|
||||
private SerializedProperty _transitionColor;
|
||||
private SerializedProperty _transitionColorGlow;
|
||||
private SerializedProperty _transitionPatternReverse;
|
||||
|
||||
private SerializedProperty _targetMode;
|
||||
private SerializedProperty _targetColor;
|
||||
@@ -119,9 +121,11 @@ namespace Coffee.UIEffects.Editors
|
||||
_transitionKeepAspectRatio = serializedObject.FindProperty("m_TransitionKeepAspectRatio");
|
||||
_transitionWidth = serializedObject.FindProperty("m_TransitionWidth");
|
||||
_transitionSoftness = serializedObject.FindProperty("m_TransitionSoftness");
|
||||
_transitionRange = serializedObject.FindProperty("m_TransitionRange");
|
||||
_transitionColorFilter = serializedObject.FindProperty("m_TransitionColorFilter");
|
||||
_transitionColor = serializedObject.FindProperty("m_TransitionColor");
|
||||
_transitionColorGlow = serializedObject.FindProperty("m_TransitionColorGlow");
|
||||
_transitionPatternReverse = serializedObject.FindProperty("m_TransitionPatternReverse");
|
||||
|
||||
_targetMode = serializedObject.FindProperty("m_TargetMode");
|
||||
_targetColor = serializedObject.FindProperty("m_TargetColor");
|
||||
@@ -229,7 +233,17 @@ namespace Coffee.UIEffects.Editors
|
||||
EditorGUILayout.PropertyField(_transitionReverse, EditorGUIUtility.TrTempContent("Reverse"));
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
if (2 < _transitionFilter.intValue)
|
||||
if (_transitionFilter.intValue == (int)TransitionFilter.Pattern)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_transitionWidth, EditorGUIUtility.TrTempContent("Pattern Size"));
|
||||
EditorGUILayout.PropertyField(_transitionRange, EditorGUIUtility.TrTempContent("Pattern Range"));
|
||||
EditorGUILayout.PropertyField(_transitionPatternReverse,
|
||||
EditorGUIUtility.TrTempContent("Pattern Reverse"));
|
||||
prevColorFilter = (ColorFilter)_transitionColorFilter.intValue;
|
||||
EditorGUILayout.PropertyField(_transitionColorFilter);
|
||||
DrawColor(_transitionColorFilter, _transitionColor, prevColorFilter);
|
||||
}
|
||||
else if (2 < _transitionFilter.intValue)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_transitionWidth);
|
||||
EditorGUILayout.PropertyField(_transitionSoftness);
|
||||
|
||||
@@ -46,7 +46,8 @@ namespace Coffee.UIEffects
|
||||
Shiny = 4,
|
||||
Mask = 5,
|
||||
Melt = 6,
|
||||
Burn = 7
|
||||
Burn = 7,
|
||||
Pattern = 8
|
||||
}
|
||||
|
||||
public enum BlendType
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Coffee.UIEffectInternal
|
||||
{
|
||||
[Serializable]
|
||||
public struct MinMax01
|
||||
{
|
||||
[SerializeField]
|
||||
private float m_Min;
|
||||
|
||||
[SerializeField]
|
||||
private float m_Max;
|
||||
|
||||
public MinMax01(float min, float max)
|
||||
{
|
||||
m_Min = Mathf.Clamp01(Mathf.Min(min, max));
|
||||
m_Max = Mathf.Clamp01(Mathf.Max(min, max));
|
||||
}
|
||||
|
||||
public float min
|
||||
{
|
||||
get => m_Min;
|
||||
set
|
||||
{
|
||||
m_Min = Mathf.Clamp01(value);
|
||||
m_Max = Mathf.Max(value, m_Max);
|
||||
}
|
||||
}
|
||||
|
||||
public float max
|
||||
{
|
||||
get => m_Max;
|
||||
set
|
||||
{
|
||||
m_Max = Mathf.Clamp01(value);
|
||||
m_Min = Mathf.Min(value, m_Min);
|
||||
}
|
||||
}
|
||||
|
||||
public float average => (m_Max + m_Min) * 0.5f;
|
||||
|
||||
public bool Approximately(MinMax01 other)
|
||||
{
|
||||
return Mathf.Approximately(m_Min, other.m_Min) && Mathf.Approximately(m_Max, other.m_Max);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(MinMax01))]
|
||||
public class MinMaxRangeDrawer : PropertyDrawer
|
||||
{
|
||||
private const float k_NumWidth = 50;
|
||||
private const float k_Space = 5;
|
||||
private SerializedProperty _max;
|
||||
private SerializedProperty _min;
|
||||
|
||||
private static bool IsSingleLine(GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.wideMode || label == null || string.IsNullOrEmpty(label.text);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return IsSingleLine(label) ? 18 : 36;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, prop);
|
||||
|
||||
if (_min == null)
|
||||
{
|
||||
prop.Next(true);
|
||||
_min = prop.Copy();
|
||||
prop.Next(true);
|
||||
_max = prop.Copy();
|
||||
}
|
||||
|
||||
if (IsSingleLine(label))
|
||||
{
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
var indent = (EditorGUI.indentLevel + 1) * 15f;
|
||||
position = new Rect(position.x + indent, position.y + 18, position.width - indent, 16);
|
||||
}
|
||||
|
||||
var min = _min.floatValue;
|
||||
var max = _max.floatValue;
|
||||
if (Draw(position, ref min, ref max))
|
||||
{
|
||||
_min.floatValue = min;
|
||||
_max.floatValue = max;
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public static bool Draw(Rect position, ref float minValue, ref float maxValue)
|
||||
{
|
||||
var indentLevel = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var rect = new Rect(position.x, position.y, k_NumWidth, position.height);
|
||||
minValue = Mathf.Clamp(EditorGUI.FloatField(rect, minValue), 0, maxValue);
|
||||
|
||||
rect.x += rect.width + k_Space;
|
||||
rect.width = position.width - k_NumWidth * 2 - k_Space * 2;
|
||||
EditorGUI.MinMaxSlider(rect, ref minValue, ref maxValue, 0, 1);
|
||||
|
||||
rect.x += rect.width + k_Space;
|
||||
rect.width = k_NumWidth;
|
||||
maxValue = Mathf.Clamp(EditorGUI.FloatField(rect, maxValue), minValue, 1);
|
||||
|
||||
EditorGUI.indentLevel = indentLevel;
|
||||
return EditorGUI.EndChangeCheck();
|
||||
}
|
||||
|
||||
public static bool DrawLayout(GUIContent label, ref float minValue, ref float maxValue)
|
||||
{
|
||||
Rect position;
|
||||
if (IsSingleLine(label))
|
||||
{
|
||||
position = EditorGUILayout.GetControlRect(true, 18f);
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
}
|
||||
else
|
||||
{
|
||||
position = EditorGUILayout.GetControlRect(true, 36f);
|
||||
EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
var indent = (EditorGUI.indentLevel + 1) * 15f;
|
||||
position = new Rect(position.x + indent, position.y + 18, position.width - indent, 16);
|
||||
}
|
||||
|
||||
return Draw(position, ref minValue, ref maxValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dacf9fb8cdb9a4a62a74b629d84cabd3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -81,6 +81,9 @@ namespace Coffee.UIEffects
|
||||
[SerializeField]
|
||||
protected float m_TransitionSoftness = 0.2f;
|
||||
|
||||
[SerializeField]
|
||||
protected MinMax01 m_TransitionRange = new MinMax01(0, 1);
|
||||
|
||||
[SerializeField]
|
||||
protected ColorFilter m_TransitionColorFilter = ColorFilter.MultiplyAdditive;
|
||||
|
||||
@@ -90,6 +93,9 @@ namespace Coffee.UIEffects
|
||||
[SerializeField]
|
||||
protected bool m_TransitionColorGlow = false;
|
||||
|
||||
[SerializeField]
|
||||
protected bool m_TransitionPatternReverse = false;
|
||||
|
||||
[SerializeField]
|
||||
protected TargetMode m_TargetMode = TargetMode.None;
|
||||
|
||||
@@ -454,6 +460,17 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public MinMax01 transitionRange
|
||||
{
|
||||
get => m_TransitionRange;
|
||||
set
|
||||
{
|
||||
if (m_TransitionRange.Approximately(value)) return;
|
||||
context.transitionRange = m_TransitionRange = value;
|
||||
SetMaterialDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public ColorFilter transitionColorFilter
|
||||
{
|
||||
get => m_TransitionColorFilter;
|
||||
@@ -487,6 +504,17 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public bool transitionPatternReverse
|
||||
{
|
||||
get => m_TransitionPatternReverse;
|
||||
set
|
||||
{
|
||||
if (m_TransitionPatternReverse == value) return;
|
||||
context.transitionPatternReverse = m_TransitionPatternReverse = value;
|
||||
SetMaterialDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public TargetMode targetMode
|
||||
{
|
||||
get => m_TargetMode;
|
||||
@@ -924,9 +952,11 @@ namespace Coffee.UIEffects
|
||||
c.transitionKeepAspectRatio = m_TransitionKeepAspectRatio;
|
||||
c.transitionWidth = m_TransitionWidth;
|
||||
c.transitionSoftness = m_TransitionSoftness;
|
||||
c.transitionRange = m_TransitionRange;
|
||||
c.transitionColorFilter = m_TransitionColorFilter;
|
||||
c.transitionColor = m_TransitionColor;
|
||||
c.transitionColorGlow = m_TransitionColorGlow;
|
||||
c.transitionPatternReverse = m_TransitionPatternReverse;
|
||||
|
||||
c.targetMode = m_TargetMode;
|
||||
c.targetColor = m_TargetColor;
|
||||
@@ -1014,6 +1044,7 @@ namespace Coffee.UIEffects
|
||||
case TransitionFilter.None:
|
||||
case TransitionFilter.Shiny:
|
||||
case TransitionFilter.Mask:
|
||||
case TransitionFilter.Pattern:
|
||||
return true;
|
||||
default:
|
||||
return transitionRate < 1;
|
||||
@@ -1058,9 +1089,11 @@ namespace Coffee.UIEffects
|
||||
m_TransitionKeepAspectRatio = preset.m_TransitionKeepAspectRatio;
|
||||
m_TransitionWidth = preset.m_TransitionWidth;
|
||||
m_TransitionSoftness = preset.m_TransitionSoftness;
|
||||
m_TransitionRange = preset.m_TransitionRange;
|
||||
m_TransitionColorFilter = preset.m_TransitionColorFilter;
|
||||
m_TransitionColor = preset.m_TransitionColor;
|
||||
m_TransitionColorGlow = preset.m_TransitionColorGlow;
|
||||
m_TransitionPatternReverse = preset.m_TransitionPatternReverse;
|
||||
|
||||
m_TargetMode = preset.m_TargetMode;
|
||||
m_TargetColor = preset.m_TargetColor;
|
||||
@@ -1127,9 +1160,11 @@ namespace Coffee.UIEffects
|
||||
m_TransitionKeepAspectRatio = c.transitionKeepAspectRatio;
|
||||
m_TransitionWidth = c.transitionWidth;
|
||||
m_TransitionSoftness = c.transitionSoftness;
|
||||
m_TransitionRange = c.transitionRange;
|
||||
m_TransitionColorFilter = c.transitionColorFilter;
|
||||
m_TransitionColor = c.transitionColor;
|
||||
m_TransitionColorGlow = c.transitionColorGlow;
|
||||
m_TransitionPatternReverse = c.transitionPatternReverse;
|
||||
|
||||
m_TargetMode = c.targetMode;
|
||||
m_TargetColor = c.targetColor;
|
||||
|
||||
@@ -28,9 +28,11 @@ namespace Coffee.UIEffects
|
||||
private static readonly int s_TransitionTex_ST = Shader.PropertyToID("_TransitionTex_ST");
|
||||
private static readonly int s_TransitionWidth = Shader.PropertyToID("_TransitionWidth");
|
||||
private static readonly int s_TransitionSoftness = Shader.PropertyToID("_TransitionSoftness");
|
||||
private static readonly int s_TransitionRange = Shader.PropertyToID("_TransitionRange");
|
||||
private static readonly int s_TransitionColorFilter = Shader.PropertyToID("_TransitionColorFilter");
|
||||
private static readonly int s_TransitionColor = Shader.PropertyToID("_TransitionColor");
|
||||
private static readonly int s_TransitionColorGlow = Shader.PropertyToID("_TransitionColorGlow");
|
||||
private static readonly int s_TransitionPatternReverse = Shader.PropertyToID("_TransitionPatternReverse");
|
||||
private static readonly int s_TargetColor = Shader.PropertyToID("_TargetColor");
|
||||
private static readonly int s_TargetRange = Shader.PropertyToID("_TargetRange");
|
||||
private static readonly int s_TargetSoftness = Shader.PropertyToID("_TargetSoftness");
|
||||
@@ -87,7 +89,8 @@ namespace Coffee.UIEffects
|
||||
"TRANSITION_SHINY",
|
||||
"TRANSITION_MASK",
|
||||
"TRANSITION_MELT",
|
||||
"TRANSITION_BURN"
|
||||
"TRANSITION_BURN",
|
||||
"TRANSITION_PATTERN"
|
||||
};
|
||||
|
||||
private static readonly string[] s_TransitionColorKeywords =
|
||||
@@ -180,9 +183,11 @@ namespace Coffee.UIEffects
|
||||
public bool transitionKeepAspectRatio = true;
|
||||
public float transitionWidth = 0.2f;
|
||||
public float transitionSoftness = 0.2f;
|
||||
public MinMax01 transitionRange = new MinMax01(0, 1);
|
||||
public ColorFilter transitionColorFilter = ColorFilter.MultiplyAdditive;
|
||||
public Color transitionColor = new Color(0f, 0.5f, 1.0f, 1.0f);
|
||||
public bool transitionColorGlow;
|
||||
public bool transitionPatternReverse;
|
||||
|
||||
public TargetMode targetMode = TargetMode.None;
|
||||
public Color targetColor = Color.white;
|
||||
@@ -259,9 +264,11 @@ namespace Coffee.UIEffects
|
||||
transitionRotation = preset.transitionRotation;
|
||||
transitionWidth = preset.transitionWidth;
|
||||
transitionSoftness = preset.transitionSoftness;
|
||||
transitionRange = preset.transitionRange;
|
||||
transitionColor = preset.transitionColor;
|
||||
transitionColorFilter = preset.transitionColorFilter;
|
||||
transitionColorGlow = preset.transitionColorGlow;
|
||||
transitionPatternReverse = preset.transitionPatternReverse;
|
||||
|
||||
targetMode = preset.targetMode;
|
||||
targetColor = preset.targetColor;
|
||||
@@ -331,9 +338,11 @@ namespace Coffee.UIEffects
|
||||
transitionTexOffset.x, transitionTexOffset.y));
|
||||
material.SetFloat(s_TransitionWidth, Mathf.Clamp01(transitionWidth));
|
||||
material.SetFloat(s_TransitionSoftness, Mathf.Clamp01(transitionSoftness));
|
||||
material.SetVector(s_TransitionRange, new Vector2(transitionRange.min, transitionRange.max));
|
||||
material.SetInt(s_TransitionColorFilter, (int)transitionColorFilter);
|
||||
material.SetColor(s_TransitionColor, transitionColor);
|
||||
material.SetInt(s_TransitionColorGlow, transitionColorGlow ? 1 : 0);
|
||||
material.SetInt(s_TransitionPatternReverse, transitionPatternReverse ? 1 : 0);
|
||||
|
||||
material.SetColor(s_TargetColor, targetColor);
|
||||
material.SetFloat(s_TargetRange, Mathf.Clamp01(targetRange));
|
||||
|
||||
@@ -96,11 +96,21 @@ float inv_lerp(const float from, const float to, const float value)
|
||||
|
||||
float transition_alpha(float2 uvLocal)
|
||||
{
|
||||
float2 uv;
|
||||
#if TRANSITION_NONE
|
||||
return 1;
|
||||
#elif TRANSITION_PATTERN
|
||||
{
|
||||
const half scale = lerp(100, 10, _TransitionWidth);
|
||||
const half2 time = half2(-_TransitionRate * 2, 0);
|
||||
uv = uvLocal * _TransitionTex_ST.xy * scale + _TransitionTex_ST.zw + time;
|
||||
}
|
||||
#else
|
||||
{
|
||||
uv = uvLocal * _TransitionTex_ST.xy + _TransitionTex_ST.zw;
|
||||
}
|
||||
#endif
|
||||
|
||||
const float2 uv = uvLocal * _TransitionTex_ST.xy + _TransitionTex_ST.zw;
|
||||
const float alpha = tex2D(_TransitionTex, uv).a;
|
||||
return (1 - alpha) * _TransitionReverse + alpha * (1 - _TransitionReverse);
|
||||
}
|
||||
@@ -430,7 +440,7 @@ float2 move_transition_filter(const float4 uvMask, const float alpha)
|
||||
return 0;
|
||||
}
|
||||
|
||||
half4 apply_transition_filter(half4 color, const float alpha)
|
||||
half4 apply_transition_filter(half4 color, const float alpha, const float2 uvLocal, float edgeFactor)
|
||||
{
|
||||
#if TRANSITION_FADE // Transition.Fade
|
||||
{
|
||||
@@ -440,6 +450,14 @@ half4 apply_transition_filter(half4 color, const float alpha)
|
||||
{
|
||||
color *= step(0.001, alpha - _TransitionRate);
|
||||
}
|
||||
#elif TRANSITION_PATTERN // Transition.Pattern
|
||||
{
|
||||
const half4 patternColor = apply_transition_color_filter(half4(color.rgb, 1), half4(_TransitionColor.rgb * color.a, 1), _TransitionColor.a);
|
||||
int isPattern = min(inv_lerp(_TransitionRange.x, _TransitionRange.y, uvLocal.x), 0.995) < (_TransitionPatternReverse ? alpha : 1 - alpha);
|
||||
isPattern = _TransitionPatternReverse ? isPattern : 1 - isPattern;
|
||||
const float patternFactor = _PatternArea == 0 ? 1 : _PatternArea == 1 ? 1 - edgeFactor : edgeFactor;
|
||||
color.rgb = lerp(color.rgb, patternColor.rgb, patternFactor * isPattern);
|
||||
}
|
||||
// Transition.Dissolve/Shiny/ShinyOnly/Melt
|
||||
#elif TRANSITION_DISSOLVE || TRANSITION_SHINY || TRANSITION_MASK || TRANSITION_MELT || TRANSITION_BURN
|
||||
{
|
||||
@@ -539,7 +557,7 @@ half4 uieffect_internal(float2 uv, const float4 uvMask, const float2 uvLocal)
|
||||
uv += move_transition_filter(uvMask, alpha);
|
||||
half4 color = apply_sampling_filter(uv, uvMask, uvLocal);
|
||||
color = apply_tone_filter(color);
|
||||
color = apply_transition_filter(color, alpha);
|
||||
color = apply_transition_filter(color, alpha, uvLocal, edgeFactor);
|
||||
|
||||
if (-4 <= uvLocal.x + uvLocal.y)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user