mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
feat: add TransitionAutoSpeed property
You can use this property to loop the TransitionRate without tweener or animation.
This commit is contained in:
@@ -53,6 +53,7 @@ namespace Coffee.UIEffects.Editors
|
||||
private SerializedProperty _transitionColor;
|
||||
private SerializedProperty _transitionColorGlow;
|
||||
private SerializedProperty _transitionPatternReverse;
|
||||
private SerializedProperty _transitionAutoPlaySpeed;
|
||||
|
||||
private SerializedProperty _targetMode;
|
||||
private SerializedProperty _targetColor;
|
||||
@@ -126,6 +127,7 @@ namespace Coffee.UIEffects.Editors
|
||||
_transitionColor = serializedObject.FindProperty("m_TransitionColor");
|
||||
_transitionColorGlow = serializedObject.FindProperty("m_TransitionColorGlow");
|
||||
_transitionPatternReverse = serializedObject.FindProperty("m_TransitionPatternReverse");
|
||||
_transitionAutoPlaySpeed = serializedObject.FindProperty("m_TransitionAutoPlaySpeed");
|
||||
|
||||
_targetMode = serializedObject.FindProperty("m_TargetMode");
|
||||
_targetColor = serializedObject.FindProperty("m_TargetColor");
|
||||
@@ -253,6 +255,12 @@ namespace Coffee.UIEffects.Editors
|
||||
EditorGUILayout.PropertyField(_transitionColorGlow);
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(_transitionAutoPlaySpeed);
|
||||
if (0 < _transitionFilter.intValue && !Mathf.Approximately(0, _transitionAutoPlaySpeed.floatValue))
|
||||
{
|
||||
EditorApplication.QueuePlayerLoopUpdate();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,10 @@ namespace Coffee.UIEffects
|
||||
[SerializeField]
|
||||
protected bool m_TransitionPatternReverse = false;
|
||||
|
||||
[Range(-5, 5)]
|
||||
[SerializeField]
|
||||
protected float m_TransitionAutoPlaySpeed = 0f;
|
||||
|
||||
[SerializeField]
|
||||
protected TargetMode m_TargetMode = TargetMode.None;
|
||||
|
||||
@@ -515,6 +519,18 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public float transitionAutoPlaySpeed
|
||||
{
|
||||
get => m_TransitionAutoPlaySpeed;
|
||||
set
|
||||
{
|
||||
value = Mathf.Clamp(value, -5, 5);
|
||||
if (Mathf.Approximately(m_TransitionAutoPlaySpeed, value)) return;
|
||||
context.transitionAutoPlaySpeed = m_TransitionAutoPlaySpeed = value;
|
||||
SetMaterialDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public TargetMode targetMode
|
||||
{
|
||||
get => m_TargetMode;
|
||||
@@ -957,6 +973,7 @@ namespace Coffee.UIEffects
|
||||
c.transitionColor = m_TransitionColor;
|
||||
c.transitionColorGlow = m_TransitionColorGlow;
|
||||
c.transitionPatternReverse = m_TransitionPatternReverse;
|
||||
c.transitionAutoPlaySpeed = m_TransitionAutoPlaySpeed;
|
||||
|
||||
c.targetMode = m_TargetMode;
|
||||
c.targetColor = m_TargetColor;
|
||||
@@ -1094,6 +1111,7 @@ namespace Coffee.UIEffects
|
||||
m_TransitionColor = preset.m_TransitionColor;
|
||||
m_TransitionColorGlow = preset.m_TransitionColorGlow;
|
||||
m_TransitionPatternReverse = preset.m_TransitionPatternReverse;
|
||||
m_TransitionAutoPlaySpeed = preset.m_TransitionAutoPlaySpeed;
|
||||
|
||||
m_TargetMode = preset.m_TargetMode;
|
||||
m_TargetColor = preset.m_TargetColor;
|
||||
@@ -1165,6 +1183,7 @@ namespace Coffee.UIEffects
|
||||
m_TransitionColor = c.transitionColor;
|
||||
m_TransitionColorGlow = c.transitionColorGlow;
|
||||
m_TransitionPatternReverse = c.transitionPatternReverse;
|
||||
m_TransitionAutoPlaySpeed = c.transitionAutoPlaySpeed;
|
||||
|
||||
m_TargetMode = c.targetMode;
|
||||
m_TargetColor = c.targetColor;
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Coffee.UIEffects
|
||||
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_TransitionAutoPlaySpeed = Shader.PropertyToID("_TransitionAutoPlaySpeed");
|
||||
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");
|
||||
@@ -188,6 +189,7 @@ namespace Coffee.UIEffects
|
||||
public Color transitionColor = new Color(0f, 0.5f, 1.0f, 1.0f);
|
||||
public bool transitionColorGlow;
|
||||
public bool transitionPatternReverse;
|
||||
public float transitionAutoPlaySpeed;
|
||||
|
||||
public TargetMode targetMode = TargetMode.None;
|
||||
public Color targetColor = Color.white;
|
||||
@@ -269,6 +271,7 @@ namespace Coffee.UIEffects
|
||||
transitionColorFilter = preset.transitionColorFilter;
|
||||
transitionColorGlow = preset.transitionColorGlow;
|
||||
transitionPatternReverse = preset.transitionPatternReverse;
|
||||
transitionAutoPlaySpeed = preset.transitionAutoPlaySpeed;
|
||||
|
||||
targetMode = preset.targetMode;
|
||||
targetColor = preset.targetColor;
|
||||
@@ -343,6 +346,7 @@ namespace Coffee.UIEffects
|
||||
material.SetColor(s_TransitionColor, transitionColor);
|
||||
material.SetInt(s_TransitionColorGlow, transitionColorGlow ? 1 : 0);
|
||||
material.SetInt(s_TransitionPatternReverse, transitionPatternReverse ? 1 : 0);
|
||||
material.SetFloat(s_TransitionAutoPlaySpeed, transitionAutoPlaySpeed);
|
||||
|
||||
material.SetColor(s_TargetColor, targetColor);
|
||||
material.SetFloat(s_TargetRange, Mathf.Clamp01(targetRange));
|
||||
|
||||
@@ -72,6 +72,11 @@ float2 texel_size()
|
||||
return _MainTex_TexelSize.xy * _SamplingScale;
|
||||
}
|
||||
|
||||
float transition_rate()
|
||||
{
|
||||
return frac(_TransitionAutoPlaySpeed * _Time.y + _TransitionRate);
|
||||
}
|
||||
|
||||
float3 rgb_to_hsv(float3 c)
|
||||
{
|
||||
const float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
@@ -101,8 +106,8 @@ float transition_alpha(float2 uvLocal)
|
||||
return 1;
|
||||
#elif TRANSITION_PATTERN
|
||||
{
|
||||
const half scale = lerp(100, 10, _TransitionWidth);
|
||||
const half2 time = half2(-_TransitionRate * 2, 0);
|
||||
const half scale = lerp(100, 1, _TransitionWidth);
|
||||
const half2 time = half2(-transition_rate() * 2, 0);
|
||||
uv = uvLocal * _TransitionTex_ST.xy * scale + _TransitionTex_ST.zw + time;
|
||||
}
|
||||
#else
|
||||
@@ -112,7 +117,7 @@ float transition_alpha(float2 uvLocal)
|
||||
#endif
|
||||
|
||||
const float alpha = tex2D(_TransitionTex, uv).a;
|
||||
return (1 - alpha) * _TransitionReverse + alpha * (1 - _TransitionReverse);
|
||||
return _TransitionReverse ? 1 - alpha : alpha;
|
||||
}
|
||||
|
||||
|
||||
@@ -424,7 +429,7 @@ float2 move_transition_filter(const float4 uvMask, const float alpha)
|
||||
}
|
||||
#endif
|
||||
|
||||
const float factor = alpha - _TransitionRate * (1 + _TransitionWidth * 1.5) + _TransitionWidth;
|
||||
const float factor = alpha - transition_rate() * (1 + _TransitionWidth * 1.5) + _TransitionWidth;
|
||||
const float band = max(0, _TransitionWidth - factor);
|
||||
|
||||
#if TRANSITION_MELT
|
||||
@@ -444,11 +449,11 @@ half4 apply_transition_filter(half4 color, const float alpha, const float2 uvLoc
|
||||
{
|
||||
#if TRANSITION_FADE // Transition.Fade
|
||||
{
|
||||
color *= saturate(alpha + 1 - _TransitionRate * 2);
|
||||
color *= saturate(alpha + 1 - transition_rate() * 2);
|
||||
}
|
||||
#elif TRANSITION_CUTOFF // Transition.Cutoff
|
||||
{
|
||||
color *= step(0.001, alpha - _TransitionRate);
|
||||
color *= step(0.001, alpha - transition_rate());
|
||||
}
|
||||
#elif TRANSITION_PATTERN // Transition.Pattern
|
||||
{
|
||||
@@ -461,7 +466,7 @@ half4 apply_transition_filter(half4 color, const float alpha, const float2 uvLoc
|
||||
// Transition.Dissolve/Shiny/ShinyOnly/Melt
|
||||
#elif TRANSITION_DISSOLVE || TRANSITION_SHINY || TRANSITION_MASK || TRANSITION_MELT || TRANSITION_BURN
|
||||
{
|
||||
const float factor = alpha - _TransitionRate * (1 + _TransitionWidth) + _TransitionWidth;
|
||||
const float factor = alpha - transition_rate() * (1 + _TransitionWidth) + _TransitionWidth;
|
||||
const float softness = max(0.0001, _TransitionWidth * _TransitionSoftness);
|
||||
const fixed bandLerp = saturate((_TransitionWidth - factor) * 1 / softness);
|
||||
const fixed softLerp = saturate(factor * 2 / softness);
|
||||
|
||||
Reference in New Issue
Block a user