Skip to content

Commit 548fd55

Browse files
committed
feat: tweener supports EdgeMode.Shiny
close #307
1 parent bbb1f96 commit 548fd55

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

Packages/src/Editor/UIEffectEditor.cs

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public class UIEffect2Editor : Editor
8585
private SerializedProperty _gradationRotation;
8686

8787
private SerializedProperty _edgeMode;
88+
private SerializedProperty _edgeShinyRate;
8889
private SerializedProperty _edgeWidth;
8990
private SerializedProperty _edgeColorFilter;
9091
private SerializedProperty _edgeColor;
@@ -154,6 +155,7 @@ private void OnEnable()
154155
_edgeWidth = serializedObject.FindProperty("m_EdgeWidth");
155156
_edgeColorFilter = serializedObject.FindProperty("m_EdgeColorFilter");
156157
_edgeColor = serializedObject.FindProperty("m_EdgeColor");
158+
_edgeShinyRate = serializedObject.FindProperty("m_EdgeShinyRate");
157159
_edgeShinyWidth = serializedObject.FindProperty("m_EdgeShinyWidth");
158160
_edgeShinyAutoPlaySpeed = serializedObject.FindProperty("m_EdgeShinyAutoPlaySpeed");
159161
_patternArea = serializedObject.FindProperty("m_PatternArea");
@@ -378,6 +380,7 @@ public void DrawProperties()
378380

379381
if ((EdgeMode)_edgeMode.intValue == EdgeMode.Shiny)
380382
{
383+
EditorGUILayout.PropertyField(_edgeShinyRate);
381384
EditorGUILayout.PropertyField(_edgeShinyWidth);
382385
EditorGUILayout.PropertyField(_edgeShinyAutoPlaySpeed);
383386

Packages/src/Runtime/UIEffect.cs

+24
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ public class UIEffect : UIEffectBase
194194
[SerializeField]
195195
protected Color m_EdgeColor = Color.white;
196196

197+
[Range(0, 1)]
198+
[SerializeField]
199+
protected float m_EdgeShinyRate = 0.5f;
200+
197201
[Range(0, 1)]
198202
[SerializeField]
199203
protected float m_EdgeShinyWidth = 0.5f;
@@ -736,6 +740,18 @@ public EdgeMode edgeMode
736740
}
737741
}
738742

743+
public float edgeShinyRate
744+
{
745+
get => m_EdgeShinyRate;
746+
set
747+
{
748+
value = Mathf.Clamp(value, 0, 1);
749+
if (Mathf.Approximately(m_EdgeShinyRate, value)) return;
750+
context.edgeShinyRate = m_EdgeShinyRate = value;
751+
SetMaterialDirty();
752+
}
753+
}
754+
739755
public float edgeWidth
740756
{
741757
get => m_EdgeWidth;
@@ -994,6 +1010,7 @@ protected override void UpdateContext(UIEffectContext c)
9941010
c.shadowColorGlow = m_ShadowColorGlow;
9951011

9961012
c.edgeMode = m_EdgeMode;
1013+
c.edgeShinyRate = m_EdgeShinyRate;
9971014
c.edgeWidth = m_EdgeWidth;
9981015
c.edgeColorFilter = m_EdgeColorFilter;
9991016
c.edgeColor = m_EdgeColor;
@@ -1052,6 +1069,11 @@ public override void SetRate(float rate, UIEffectTweener.CullingMask mask)
10521069
{
10531070
gradationRotation = Mathf.Lerp(0f, 360f, rate);
10541071
}
1072+
1073+
if (edgeMode == EdgeMode.Shiny && 0 < (mask & UIEffectTweener.CullingMask.EdgeShiny))
1074+
{
1075+
edgeShinyRate = rate;
1076+
}
10551077
}
10561078

10571079
public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
@@ -1132,6 +1154,7 @@ public void LoadPreset(UIEffect preset)
11321154
m_ShadowColorGlow = preset.m_ShadowColorGlow;
11331155

11341156
m_EdgeMode = preset.m_EdgeMode;
1157+
m_EdgeShinyRate = preset.m_EdgeShinyRate;
11351158
m_EdgeWidth = preset.m_EdgeWidth;
11361159
m_EdgeColorFilter = preset.m_EdgeColorFilter;
11371160
m_EdgeColor = preset.m_EdgeColor;
@@ -1205,6 +1228,7 @@ internal void CopyFrom(UIEffectContext c)
12051228
m_ShadowColorGlow = c.shadowColorGlow;
12061229

12071230
m_EdgeMode = c.edgeMode;
1231+
m_EdgeShinyRate = c.edgeShinyRate;
12081232
m_EdgeWidth = c.edgeWidth;
12091233
m_EdgeColorFilter = c.edgeColorFilter;
12101234
m_EdgeColor = c.edgeColor;

Packages/src/Runtime/UIEffectContext.cs

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class UIEffectContext
4040
private static readonly int s_ShadowColor = Shader.PropertyToID("_ShadowColor");
4141
private static readonly int s_ShadowBlurIntensity = Shader.PropertyToID("_ShadowBlurIntensity");
4242
private static readonly int s_ShadowColorGlow = Shader.PropertyToID("_ShadowColorGlow");
43+
private static readonly int s_EdgeShinyRate = Shader.PropertyToID("_EdgeShinyRate");
4344
private static readonly int s_EdgeWidth = Shader.PropertyToID("_EdgeWidth");
4445
private static readonly int s_EdgeColor = Shader.PropertyToID("_EdgeColor");
4546
private static readonly int s_EdgeShinyAutoPlaySpeed = Shader.PropertyToID("_EdgeShinyAutoPlaySpeed");
@@ -210,6 +211,7 @@ public class UIEffectContext
210211
public bool shadowColorGlow;
211212

212213
public EdgeMode edgeMode;
214+
public float edgeShinyRate;
213215
public float edgeWidth;
214216
public ColorFilter edgeColorFilter;
215217
public Color edgeColor;
@@ -292,6 +294,7 @@ public void CopyFrom(UIEffectContext preset)
292294
shadowColorGlow = preset.shadowColorGlow;
293295

294296
edgeMode = preset.edgeMode;
297+
edgeShinyRate = preset.edgeShinyRate;
295298
edgeWidth = preset.edgeWidth;
296299
edgeColorFilter = preset.edgeColorFilter;
297300
edgeColor = preset.edgeColor;
@@ -367,6 +370,7 @@ public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)
367370
material.SetColor(s_ShadowColor, shadowColor);
368371
material.SetInt(s_ShadowColorGlow, shadowColorGlow ? 1 : 0);
369372

373+
material.SetFloat(s_EdgeShinyRate, Mathf.Clamp01(edgeShinyRate));
370374
material.SetFloat(s_EdgeWidth, Mathf.Clamp01(edgeWidth));
371375
material.SetColor(s_EdgeColor, edgeColor);
372376
material.SetFloat(s_EdgeShinyWidth, Mathf.Clamp01(edgeShinyWidth));

Packages/src/Runtime/UIEffectTweener.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public enum CullingMask
1717
Sampling = 1 << 2,
1818
Transition = 1 << 3,
1919
GradiationOffset = 1 << 5,
20-
GradiationRotation = 1 << 6
20+
GradiationRotation = 1 << 6,
21+
EdgeShiny = 1 << 8
2122
}
2223

2324
public enum UpdateMode

Packages/src/Shaders/UIEffect.cginc

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ uniform const float _ShadowBlurIntensity;
2727
uniform const half4 _ShadowColor;
2828
uniform const int _ShadowColorGlow;
2929
uniform const float _EdgeWidth;
30+
uniform const float _EdgeShinyRate;
3031
uniform const float _EdgeShinyAutoPlaySpeed;
3132
uniform const float _EdgeShinyWidth;
3233
uniform const half4 _EdgeColor;
@@ -539,7 +540,7 @@ int is_edge_shiny(const float2 uvLocal)
539540
{
540541
#if EDGE_SHINY
541542
const float deg = atan2(uvLocal.y - 0.5, uvLocal.x - 0.5) / UNITY_PI;
542-
return frac(_Time.y * _EdgeShinyAutoPlaySpeed + deg) < _EdgeShinyWidth;
543+
return frac(_EdgeShinyRate + _Time.y * _EdgeShinyAutoPlaySpeed + deg) < _EdgeShinyWidth;
543544
#else
544545
return 1;
545546
#endif

0 commit comments

Comments
 (0)