Skip to content

Commit

Permalink
grad2
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Dec 14, 2024
1 parent 1b0ec9e commit f33cc97
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 49 deletions.
6 changes: 6 additions & 0 deletions Packages/src/Editor/UIEffectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class UIEffect2Editor : Editor
private SerializedProperty _gradationColor1;
private SerializedProperty _gradationColor2;
private SerializedProperty _gradationGradient;
private SerializedProperty _gradationOffset;
private SerializedProperty _gradationScale;

private bool _expandOthers;
private SerializedProperty _allowExtendVertex;
Expand Down Expand Up @@ -121,6 +123,8 @@ private void OnEnable()
_gradationColor1 = serializedObject.FindProperty("m_GradationColor1");
_gradationColor2 = serializedObject.FindProperty("m_GradationColor2");
_gradationGradient = serializedObject.FindProperty("m_GradationGradient");
_gradationOffset = serializedObject.FindProperty("m_GradationOffset");
_gradationScale = serializedObject.FindProperty("m_GradationScale");

_allowExtendVertex = serializedObject.FindProperty("m_AllowExtendVertex");
}
Expand Down Expand Up @@ -280,6 +284,8 @@ public void DrawProperties()
break;
}

EditorGUILayout.PropertyField(_gradationOffset);
EditorGUILayout.PropertyField(_gradationScale);
EditorGUI.indentLevel--;
}

Expand Down
39 changes: 39 additions & 0 deletions Packages/src/Runtime/UIEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ public class UIEffect : UIEffectBase
[SerializeField]
private Gradient m_GradationGradient = new Gradient();

[Range(-1, 1)]
[SerializeField]
protected float m_GradationOffset = 0;

[Range(0.1f, 5)]
[SerializeField]
protected float m_GradationScale = 1;

[SerializeField]
protected bool m_AllowExtendVertex = true;

Expand Down Expand Up @@ -611,6 +619,28 @@ public Gradient gradationGradient
}
}

public float gradationOffset
{
get => m_GradationOffset;
set
{
if (Mathf.Approximately(m_GradationOffset, value)) return;
context.gradationOffset = m_GradationOffset = value;
SetVerticesDirty();
}
}

public float gradationScale
{
get => m_GradationScale;
set
{
if (Mathf.Approximately(m_GradationScale, value)) return;
context.gradationScale = m_GradationScale = value;
SetVerticesDirty();
}
}

public bool allowExtendVertex
{
get => m_AllowExtendVertex;
Expand Down Expand Up @@ -711,6 +741,8 @@ protected override void UpdateContext(UIEffectContext c)
c.gradationColor1 = m_GradationColor1;
c.gradationColor2 = m_GradationColor2;
c.gradationGradient = m_GradationGradient;
c.gradationOffset = m_GradationOffset;
c.gradationScale = m_GradationScale;
c.allowExtendVertex = m_AllowExtendVertex;
}

Expand Down Expand Up @@ -745,6 +777,11 @@ public override void SetRate(float rate, UIEffectTweener.CullingMask mask)
{
transitionRate = rate;
}

if (gradationMode != GradationMode.None && 0 < (mask & UIEffectTweener.CullingMask.Gradiation))
{
gradationOffset = Mathf.Lerp(-1f, 1f, rate);
}
}

public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
Expand Down Expand Up @@ -865,6 +902,8 @@ internal void CopyFrom(UIEffectContext c)
m_GradationColor1 = c.gradationColor1;
m_GradationColor2 = c.gradationColor2;
m_GradationGradient = c.gradationGradient;
m_GradationOffset = c.gradationOffset;
m_GradationScale = c.gradationScale;

m_AllowExtendVertex = c.allowExtendVertex;

Expand Down
6 changes: 5 additions & 1 deletion Packages/src/Runtime/UIEffectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public class UIEffectContext
public Color gradationColor2;
public Gradient gradationGradient;
public bool allowExtendVertex;
public float gradationOffset;
public float gradationScale;

public bool willModifyMaterial => samplingFilter != SamplingFilter.None
|| transitionFilter != TransitionFilter.None
Expand Down Expand Up @@ -203,6 +205,8 @@ public void CopyFrom(UIEffectContext preset)
gradationColor1 = preset.gradationColor1;
gradationColor2 = preset.gradationColor2;
gradationGradient = preset.gradationGradient;
gradationOffset = preset.gradationOffset;
gradationScale = preset.gradationScale;

allowExtendVertex = preset.allowExtendVertex;
}
Expand Down Expand Up @@ -423,7 +427,7 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp

// Apply gradation.
GradientUtil.DoGradient(gradationMode, verts, gradationColor1, gradationColor2, gradationGradient,
transitionRoot.rect);
gradationOffset, gradationScale, transitionRoot.rect);

// Apply shadow.
switch (shadowMode)
Expand Down
3 changes: 2 additions & 1 deletion Packages/src/Runtime/UIEffectTweener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum CullingMask
Tone = 1 << 0,
Color = 1 << 1,
Sampling = 1 << 2,
Transition = 1 << 3
Transition = 1 << 3,
Gradiation = 1 << 5,
}

public enum UpdateMode
Expand Down
Loading

0 comments on commit f33cc97

Please sign in to comment.