Skip to content

Commit eadb477

Browse files
committed
feat: add EdgeMode feature
1 parent 33b1177 commit eadb477

File tree

5 files changed

+380
-32
lines changed

5 files changed

+380
-32
lines changed

Packages/src/Editor/UIEffectEditor.cs

+42
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ public class UIEffect2Editor : Editor
8181
private SerializedProperty _gradationScale;
8282
private SerializedProperty _gradationRotation;
8383

84+
private SerializedProperty _edgeMode;
85+
private SerializedProperty _edgeWidth;
86+
private SerializedProperty _edgeColorFilter;
87+
private SerializedProperty _edgeColor;
88+
private SerializedProperty _edgeShinyWidth;
89+
private SerializedProperty _edgeShinyAutoPlaySpeed;
90+
private SerializedProperty _patternArea;
91+
8492
private bool _expandOthers = true;
8593
private SerializedProperty _allowToModifyMeshShape;
8694

@@ -136,6 +144,14 @@ private void OnEnable()
136144
_shadowColor = serializedObject.FindProperty("m_ShadowColor");
137145
_shadowColorGlow = serializedObject.FindProperty("m_ShadowColorGlow");
138146

147+
_edgeMode = serializedObject.FindProperty("m_EdgeMode");
148+
_edgeWidth = serializedObject.FindProperty("m_EdgeWidth");
149+
_edgeColorFilter = serializedObject.FindProperty("m_EdgeColorFilter");
150+
_edgeColor = serializedObject.FindProperty("m_EdgeColor");
151+
_edgeShinyWidth = serializedObject.FindProperty("m_EdgeShinyWidth");
152+
_edgeShinyAutoPlaySpeed = serializedObject.FindProperty("m_EdgeShinyAutoPlaySpeed");
153+
_patternArea = serializedObject.FindProperty("m_PatternArea");
154+
139155
_gradationMode = serializedObject.FindProperty("m_GradationMode");
140156
_gradationColor1 = serializedObject.FindProperty("m_GradationColor1");
141157
_gradationColor2 = serializedObject.FindProperty("m_GradationColor2");
@@ -339,6 +355,32 @@ public void DrawProperties()
339355
EditorGUI.indentLevel--;
340356
}
341357

358+
// Edge Mode
359+
DrawSeparator();
360+
if (DrawHeaderPopup(_edgeMode))
361+
{
362+
EditorGUILayout.PropertyField(_edgeWidth);
363+
prevColorFilter = (ColorFilter)_edgeColorFilter.intValue;
364+
EditorGUILayout.PropertyField(_edgeColorFilter);
365+
DrawColor(_edgeColorFilter, _edgeColor, prevColorFilter);
366+
367+
if ((EdgeMode)_edgeMode.intValue == EdgeMode.Shiny)
368+
{
369+
EditorGUILayout.PropertyField(_edgeShinyWidth);
370+
EditorGUILayout.PropertyField(_edgeShinyAutoPlaySpeed);
371+
372+
if (!Mathf.Approximately(0, _edgeShinyAutoPlaySpeed.floatValue))
373+
{
374+
EditorApplication.QueuePlayerLoopUpdate();
375+
}
376+
}
377+
378+
if (_transitionFilter.intValue == (int)TransitionFilter.Pattern)
379+
{
380+
EditorGUILayout.PropertyField(_patternArea);
381+
}
382+
}
383+
342384
DrawSeparator();
343385
_expandOthers = EditorGUILayout.BeginFoldoutHeaderGroup(_expandOthers, "Others");
344386
if (_expandOthers)

Packages/src/Runtime/Enums.cs

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ public enum ShadowMode
7676
Mirror
7777
}
7878

79+
public enum EdgeMode
80+
{
81+
None = 0,
82+
Plain,
83+
Shiny
84+
}
85+
86+
public enum PatternArea
87+
{
88+
All = 0,
89+
Inner = 1,
90+
Edge = 2
91+
}
92+
7993
public enum GradationMode
8094
{
8195
None = 0,

Packages/src/Runtime/UIEffect.cs

+128
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@ public class UIEffect : UIEffectBase
171171
[SerializeField]
172172
protected bool m_AllowToModifyMeshShape = true;
173173

174+
[SerializeField]
175+
protected EdgeMode m_EdgeMode = EdgeMode.None;
176+
177+
[Range(0, 1)]
178+
[SerializeField]
179+
protected float m_EdgeWidth = 0.5f;
180+
181+
[SerializeField]
182+
protected ColorFilter m_EdgeColorFilter = ColorFilter.Replace;
183+
184+
[SerializeField]
185+
protected Color m_EdgeColor = Color.white;
186+
187+
[Range(0, 1)]
188+
[SerializeField]
189+
protected float m_EdgeShinyWidth = 0.5f;
190+
191+
[Range(-5, 5)]
192+
[SerializeField]
193+
protected float m_EdgeShinyAutoPlaySpeed = 1f;
194+
195+
[SerializeField]
196+
protected PatternArea m_PatternArea = PatternArea.Inner;
197+
174198
/// <summary>
175199
/// Tone filter for rendering.
176200
/// </summary>
@@ -657,6 +681,86 @@ public bool shadowGlow
657681
}
658682
}
659683

684+
public EdgeMode edgeMode
685+
{
686+
get => m_EdgeMode;
687+
set
688+
{
689+
if (m_EdgeMode == value) return;
690+
context.edgeMode = m_EdgeMode = value;
691+
SetMaterialDirty();
692+
}
693+
}
694+
695+
public float edgeWidth
696+
{
697+
get => m_EdgeWidth;
698+
set
699+
{
700+
value = Mathf.Clamp(value, 0, 1);
701+
if (Mathf.Approximately(m_EdgeWidth, value)) return;
702+
context.edgeWidth = m_EdgeWidth = value;
703+
SetMaterialDirty();
704+
}
705+
}
706+
707+
public ColorFilter edgeColorFilter
708+
{
709+
get => m_EdgeColorFilter;
710+
set
711+
{
712+
if (m_EdgeColorFilter == value) return;
713+
context.edgeColorFilter = m_EdgeColorFilter = value;
714+
SetMaterialDirty();
715+
}
716+
}
717+
718+
public Color edgeColor
719+
{
720+
get => m_EdgeColor;
721+
set
722+
{
723+
if (m_EdgeColor == value) return;
724+
context.edgeColor = m_EdgeColor = value;
725+
SetMaterialDirty();
726+
}
727+
}
728+
729+
public float edgeShinyWidth
730+
{
731+
get => m_EdgeShinyWidth;
732+
set
733+
{
734+
value = Mathf.Clamp(value, 0, 1);
735+
if (Mathf.Approximately(m_EdgeShinyWidth, value)) return;
736+
context.edgeShinyWidth = m_EdgeShinyWidth = value;
737+
SetMaterialDirty();
738+
}
739+
}
740+
741+
public float edgeShinyAutoPlaySpeed
742+
{
743+
get => m_EdgeShinyAutoPlaySpeed;
744+
set
745+
{
746+
value = Mathf.Clamp(value, -5, 5);
747+
if (Mathf.Approximately(m_EdgeShinyAutoPlaySpeed, value)) return;
748+
context.edgeShinyAutoPlaySpeed = m_EdgeShinyAutoPlaySpeed = value;
749+
SetMaterialDirty();
750+
}
751+
}
752+
753+
public PatternArea patternArea
754+
{
755+
get => m_PatternArea;
756+
set
757+
{
758+
if (m_PatternArea == value) return;
759+
context.patternArea = m_PatternArea = value;
760+
SetMaterialDirty();
761+
}
762+
}
763+
660764
public GradationMode gradationMode
661765
{
662766
get => m_GradationMode;
@@ -842,6 +946,14 @@ protected override void UpdateContext(UIEffectContext c)
842946
c.shadowColor = m_ShadowColor;
843947
c.shadowColorGlow = m_ShadowColorGlow;
844948

949+
c.edgeMode = m_EdgeMode;
950+
c.edgeWidth = m_EdgeWidth;
951+
c.edgeColorFilter = m_EdgeColorFilter;
952+
c.edgeColor = m_EdgeColor;
953+
c.edgeShinyWidth = m_EdgeShinyWidth;
954+
c.edgeShinyAutoPlaySpeed = m_EdgeShinyAutoPlaySpeed;
955+
c.patternArea = m_PatternArea;
956+
845957
c.gradationMode = m_GradationMode;
846958
c.gradationColor1 = m_GradationColor1;
847959
c.gradationColor2 = m_GradationColor2;
@@ -968,6 +1080,14 @@ public void LoadPreset(UIEffect preset)
9681080
m_ShadowColor = preset.m_ShadowColor;
9691081
m_ShadowColorGlow = preset.m_ShadowColorGlow;
9701082

1083+
m_EdgeMode = preset.m_EdgeMode;
1084+
m_EdgeWidth = preset.m_EdgeWidth;
1085+
m_EdgeColorFilter = preset.m_EdgeColorFilter;
1086+
m_EdgeColor = preset.m_EdgeColor;
1087+
m_EdgeShinyWidth = preset.m_EdgeShinyWidth;
1088+
m_EdgeShinyAutoPlaySpeed = preset.m_EdgeShinyAutoPlaySpeed;
1089+
m_PatternArea = preset.m_PatternArea;
1090+
9711091
m_GradationMode = preset.m_GradationMode;
9721092
m_GradationColor1 = preset.m_GradationColor1;
9731093
m_GradationColor2 = preset.m_GradationColor2;
@@ -1030,6 +1150,14 @@ internal void CopyFrom(UIEffectContext c)
10301150
m_ShadowColor = c.shadowColor;
10311151
m_ShadowColorGlow = c.shadowColorGlow;
10321152

1153+
m_EdgeMode = c.edgeMode;
1154+
m_EdgeWidth = c.edgeWidth;
1155+
m_EdgeColorFilter = c.edgeColorFilter;
1156+
m_EdgeColor = c.edgeColor;
1157+
m_EdgeShinyWidth = c.edgeShinyWidth;
1158+
m_EdgeShinyAutoPlaySpeed = c.edgeShinyAutoPlaySpeed;
1159+
m_PatternArea = c.patternArea;
1160+
10331161
m_GradationMode = c.gradationMode;
10341162
m_GradationColor1 = c.gradationColor1;
10351163
m_GradationColor2 = c.gradationColor2;

Packages/src/Runtime/UIEffectContext.cs

+63-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public class UIEffectContext
3737
private static readonly int s_ShadowColor = Shader.PropertyToID("_ShadowColor");
3838
private static readonly int s_ShadowBlurIntensity = Shader.PropertyToID("_ShadowBlurIntensity");
3939
private static readonly int s_ShadowColorGlow = Shader.PropertyToID("_ShadowColorGlow");
40+
private static readonly int s_EdgeWidth = Shader.PropertyToID("_EdgeWidth");
41+
private static readonly int s_EdgeColor = Shader.PropertyToID("_EdgeColor");
42+
private static readonly int s_EdgeShinyAutoPlaySpeed = Shader.PropertyToID("_EdgeShinyAutoPlaySpeed");
43+
private static readonly int s_EdgeShinyWidth = Shader.PropertyToID("_EdgeShinyWidth");
44+
private static readonly int s_PatternArea = Shader.PropertyToID("_PatternArea");
4045

4146
private static readonly string[] s_ToneKeywords =
4247
{
@@ -118,6 +123,26 @@ public class UIEffectContext
118123
"SHADOW_COLOR_CONTRAST"
119124
};
120125

126+
private static readonly string[] s_EdgeKeywords =
127+
{
128+
"",
129+
"EDGE_PLAIN",
130+
"EDGE_SHINY"
131+
};
132+
133+
private static readonly string[] s_EdgeColorKeywords =
134+
{
135+
"",
136+
"EDGE_COLOR_MULTIPLY",
137+
"EDGE_COLOR_ADDITIVE",
138+
"EDGE_COLOR_SUBTRACTIVE",
139+
"EDGE_COLOR_REPLACE",
140+
"EDGE_COLOR_MULTIPLY_LUMINANCE",
141+
"EDGE_COLOR_MULTIPLY_ADDITIVE",
142+
"EDGE_COLOR_HSV_MODIFIER",
143+
"EDGE_COLOR_CONTRAST"
144+
};
145+
121146
private static readonly Vector2[][] s_ShadowVectors = new[]
122147
{
123148
Array.Empty<Vector2>(), // None
@@ -177,6 +202,14 @@ public class UIEffectContext
177202
public Color shadowColor;
178203
public bool shadowColorGlow;
179204

205+
public EdgeMode edgeMode;
206+
public float edgeWidth;
207+
public ColorFilter edgeColorFilter;
208+
public Color edgeColor;
209+
public float edgeShinyWidth;
210+
public float edgeShinyAutoPlaySpeed;
211+
public PatternArea patternArea;
212+
180213
public GradationMode gradationMode;
181214
public Color gradationColor1;
182215
public Color gradationColor2;
@@ -192,7 +225,8 @@ public class UIEffectContext
192225
|| colorFilter != ColorFilter.None
193226
|| srcBlendMode != BlendMode.One
194227
|| dstBlendMode != BlendMode.OneMinusSrcAlpha
195-
|| shadowMode != ShadowMode.None;
228+
|| shadowMode != ShadowMode.None
229+
|| edgeMode != EdgeMode.None;
196230

197231
public void Reset()
198232
{
@@ -247,6 +281,14 @@ public void CopyFrom(UIEffectContext preset)
247281
shadowColor = preset.shadowColor;
248282
shadowColorGlow = preset.shadowColorGlow;
249283

284+
edgeMode = preset.edgeMode;
285+
edgeWidth = preset.edgeWidth;
286+
edgeColorFilter = preset.edgeColorFilter;
287+
edgeColor = preset.edgeColor;
288+
edgeShinyAutoPlaySpeed = preset.edgeShinyAutoPlaySpeed;
289+
edgeShinyWidth = preset.edgeShinyWidth;
290+
patternArea = preset.patternArea;
291+
250292
gradationMode = preset.gradationMode;
251293
gradationColor1 = preset.gradationColor1;
252294
gradationColor2 = preset.gradationColor2;
@@ -312,6 +354,12 @@ public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)
312354
material.SetColor(s_ShadowColor, shadowColor);
313355
material.SetInt(s_ShadowColorGlow, shadowColorGlow ? 1 : 0);
314356

357+
material.SetFloat(s_EdgeWidth, Mathf.Clamp01(edgeWidth));
358+
material.SetColor(s_EdgeColor, edgeColor);
359+
material.SetFloat(s_EdgeShinyWidth, Mathf.Clamp01(edgeShinyWidth));
360+
material.SetFloat(s_EdgeShinyAutoPlaySpeed, edgeShinyAutoPlaySpeed);
361+
material.SetInt(s_PatternArea, edgeMode != EdgeMode.None ? (int)patternArea : 0);
362+
315363
SetKeyword(material, s_ToneKeywords, (int)toneFilter);
316364
SetKeyword(material, s_ColorKeywords, (int)colorFilter);
317365
SetKeyword(material, s_SamplingKeywords, (int)samplingFilter);
@@ -323,11 +371,7 @@ public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)
323371
case TransitionFilter.Cutoff:
324372
SetKeyword(material, s_TransitionColorKeywords, (int)ColorFilter.None);
325373
break;
326-
case TransitionFilter.Dissolve:
327-
case TransitionFilter.Shiny:
328-
case TransitionFilter.Mask:
329-
case TransitionFilter.Melt:
330-
case TransitionFilter.Burn:
374+
default:
331375
SetKeyword(material, s_TransitionColorKeywords, (int)transitionColorFilter);
332376
break;
333377
}
@@ -342,6 +386,19 @@ public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)
342386
break;
343387
}
344388

389+
SetKeyword(material, s_EdgeKeywords, (int)edgeMode);
390+
391+
switch (edgeMode)
392+
{
393+
case EdgeMode.None:
394+
SetKeyword(material, s_EdgeColorKeywords, (int)ColorFilter.None);
395+
break;
396+
default:
397+
SetKeyword(material, s_EdgeColorKeywords, (int)edgeColorFilter);
398+
break;
399+
}
400+
401+
345402
SetKeyword(material, s_TargetKeywords, (int)targetMode);
346403

347404
Profiler.EndSample();

0 commit comments

Comments
 (0)