mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-21 18:42:37 +08:00
refactor: change allowExtendVertex to allowToModifyMeshShape
This commit is contained in:
@@ -68,7 +68,7 @@ namespace Coffee.UIEffects.Editors
|
||||
private SerializedProperty _gradationScale;
|
||||
|
||||
private bool _expandOthers;
|
||||
private SerializedProperty _allowExtendVertex;
|
||||
private SerializedProperty _allowToModifyMeshShape;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -129,7 +129,7 @@ namespace Coffee.UIEffects.Editors
|
||||
_gradationOffset = serializedObject.FindProperty("m_GradationOffset");
|
||||
_gradationScale = serializedObject.FindProperty("m_GradationScale");
|
||||
|
||||
_allowExtendVertex = serializedObject.FindProperty("m_AllowExtendVertex");
|
||||
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
@@ -314,7 +314,7 @@ namespace Coffee.UIEffects.Editors
|
||||
_expandOthers = EditorGUILayout.BeginFoldoutHeaderGroup(_expandOthers, "Others");
|
||||
if (_expandOthers)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_allowExtendVertex);
|
||||
EditorGUILayout.PropertyField(_allowToModifyMeshShape);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace Coffee.UIEffects
|
||||
protected float m_GradationScale = 1;
|
||||
|
||||
[SerializeField]
|
||||
protected bool m_AllowExtendVertex = true;
|
||||
protected bool m_AllowToModifyMeshShape = true;
|
||||
|
||||
/// <summary>
|
||||
/// Tone filter for rendering.
|
||||
@@ -696,13 +696,13 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public bool allowExtendVertex
|
||||
public bool allowToModifyMeshShape
|
||||
{
|
||||
get => m_AllowExtendVertex;
|
||||
get => m_AllowToModifyMeshShape;
|
||||
set
|
||||
{
|
||||
if (m_AllowExtendVertex == value) return;
|
||||
context.allowExtendVertex = m_AllowExtendVertex = value;
|
||||
if (m_AllowToModifyMeshShape == value) return;
|
||||
context.allowToModifyMeshShape = m_AllowToModifyMeshShape = value;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
}
|
||||
@@ -819,7 +819,8 @@ namespace Coffee.UIEffects
|
||||
c.gradationGradient = m_GradationGradient;
|
||||
c.gradationOffset = m_GradationOffset;
|
||||
c.gradationScale = m_GradationScale;
|
||||
c.allowExtendVertex = m_AllowExtendVertex;
|
||||
|
||||
c.allowToModifyMeshShape = m_AllowToModifyMeshShape;
|
||||
}
|
||||
|
||||
public override void ApplyContextToMaterial()
|
||||
@@ -993,7 +994,7 @@ namespace Coffee.UIEffects
|
||||
m_GradationOffset = c.gradationOffset;
|
||||
m_GradationScale = c.gradationScale;
|
||||
|
||||
m_AllowExtendVertex = c.allowExtendVertex;
|
||||
m_AllowToModifyMeshShape = c.allowToModifyMeshShape;
|
||||
|
||||
UpdateContext(context);
|
||||
ApplyContextToMaterial();
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace Coffee.UIEffects
|
||||
private List<float> _keyTimes;
|
||||
private List<float> _splitTimes;
|
||||
|
||||
public bool allowExtendVertex;
|
||||
public bool allowToModifyMeshShape;
|
||||
|
||||
|
||||
public bool willModifyMaterial => samplingFilter != SamplingFilter.None
|
||||
@@ -254,7 +254,7 @@ namespace Coffee.UIEffects
|
||||
gradationOffset = preset.gradationOffset;
|
||||
gradationScale = preset.gradationScale;
|
||||
|
||||
allowExtendVertex = preset.allowExtendVertex;
|
||||
allowToModifyMeshShape = preset.allowToModifyMeshShape;
|
||||
}
|
||||
|
||||
public void SetGradationDirty()
|
||||
@@ -470,10 +470,18 @@ namespace Coffee.UIEffects
|
||||
GradientUtil.GetKeyTimes(grad, _keyTimes);
|
||||
}
|
||||
|
||||
var splitTimes = InternalListPool<float>.Rent();
|
||||
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
|
||||
GradientUtil.DoHorizontalGradient(verts, grad, splitTimes, offset, scale, rect, m);
|
||||
InternalListPool<float>.Return(ref splitTimes);
|
||||
if (allowToModifyMeshShape)
|
||||
{
|
||||
var splitTimes = InternalListPool<float>.Rent();
|
||||
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
|
||||
GradientUtil.DoHorizontalGradient(verts, grad, splitTimes, offset, scale, rect, m);
|
||||
InternalListPool<float>.Return(ref splitTimes);
|
||||
}
|
||||
else
|
||||
{
|
||||
GradientUtil.DoHorizontalGradient(verts, grad, offset, scale, rect, m);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case GradationMode.VerticalGradient:
|
||||
@@ -484,10 +492,17 @@ namespace Coffee.UIEffects
|
||||
GradientUtil.GetKeyTimes(grad, _keyTimes);
|
||||
}
|
||||
|
||||
var splitTimes = InternalListPool<float>.Rent();
|
||||
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
|
||||
GradientUtil.DoVerticalGradient(verts, grad, splitTimes, offset, scale, rect, m);
|
||||
InternalListPool<float>.Return(ref splitTimes);
|
||||
if (allowToModifyMeshShape)
|
||||
{
|
||||
var splitTimes = InternalListPool<float>.Rent();
|
||||
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
|
||||
GradientUtil.DoVerticalGradient(verts, grad, splitTimes, offset, scale, rect, m);
|
||||
InternalListPool<float>.Return(ref splitTimes);
|
||||
}
|
||||
else
|
||||
{
|
||||
GradientUtil.DoVerticalGradient(verts, grad, offset, scale, rect, m);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -512,7 +527,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
private Vector2 GetExpandSize()
|
||||
{
|
||||
if (!allowExtendVertex) return Vector2.zero;
|
||||
if (!allowToModifyMeshShape) return Vector2.zero;
|
||||
|
||||
var expandSize = Vector2.zero;
|
||||
switch (samplingFilter)
|
||||
|
||||
@@ -47,6 +47,27 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoHorizontalGradient(List<UIVertex> verts, Gradient gradient, float offset, float scale,
|
||||
Rect rect, Matrix4x4 m)
|
||||
{
|
||||
var count = verts.Count;
|
||||
for (var i = 0; i < count; i ++)
|
||||
{
|
||||
var vt = verts[i];
|
||||
vt.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(vt.position).x, offset, scale);
|
||||
verts[i] = vt;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
static Color Evaluate(Gradient gradient, Rect rect, float t, float offset, float scale)
|
||||
{
|
||||
t = Mathf.InverseLerp(rect.xMin, rect.xMax, t); // 0-1
|
||||
t = Mathf.Repeat((t - offset * scale - (1 - scale) / 2) / scale, 1); // Revert
|
||||
return gradient.Evaluate(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoVerticalGradient(List<UIVertex> verts, Color a, Color b, float offset, float scale,
|
||||
Rect rect, Matrix4x4 m)
|
||||
{
|
||||
@@ -89,6 +110,27 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoVerticalGradient(List<UIVertex> verts, Gradient gradient, float offset, float scale,
|
||||
Rect rect, Matrix4x4 m)
|
||||
{
|
||||
var count = verts.Count;
|
||||
for (var i = 0; i < count; i ++)
|
||||
{
|
||||
var vt = verts[i];
|
||||
vt.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(vt.position).y, offset, scale);
|
||||
verts[i] = vt;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
static Color Evaluate(Gradient gradient, Rect rect, float t, float offset, float scale)
|
||||
{
|
||||
t = Mathf.InverseLerp(rect.yMin, rect.yMax, t); // 0-1
|
||||
t = Mathf.Repeat((t - offset * scale - (1 - scale) / 2) / scale, 1); // Revert
|
||||
return gradient.Evaluate(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoDiagonalGradientToRightBottom(List<UIVertex> verts, Color a, Color b, float offset,
|
||||
float scale, Rect rect, Matrix4x4 m)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user