feat: the Allow To Modify Mesh Shape property should remain unchanged when loading a preset

close #294
This commit is contained in:
mob-sakai
2025-01-07 16:36:22 +09:00
parent 238a17d57d
commit f7175c0373
5 changed files with 22 additions and 20 deletions
@@ -12,6 +12,7 @@ namespace Coffee.UIEffects.Editors
private SerializedProperty _target;
private SerializedProperty _useTargetTransform;
private SerializedProperty _samplingScale;
private SerializedProperty _allowToModifyMeshShape;
private Editor _uiEffectEditor;
private void OnEnable()
@@ -19,6 +20,7 @@ namespace Coffee.UIEffects.Editors
_target = serializedObject.FindProperty("m_Target");
_useTargetTransform = serializedObject.FindProperty("m_UseTargetTransform");
_samplingScale = serializedObject.FindProperty("m_SamplingScale");
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
}
public override void OnInspectorGUI()
@@ -27,6 +29,7 @@ namespace Coffee.UIEffects.Editors
EditorGUILayout.PropertyField(_target);
EditorGUILayout.PropertyField(_useTargetTransform);
EditorGUILayout.PropertyField(_samplingScale);
EditorGUILayout.PropertyField(_allowToModifyMeshShape);
if (_target.objectReferenceValue)
{
+3 -5
View File
@@ -294,6 +294,8 @@ namespace Coffee.UIEffects
? Mathf.Clamp(m_SamplingScale, 0.01f, 100)
: 1;
public override bool canModifyShape => m_AllowToModifyMeshShape;
/// <summary>
/// Transition filter for rendering.
/// </summary>
@@ -714,7 +716,7 @@ namespace Coffee.UIEffects
set
{
if (m_AllowToModifyMeshShape == value) return;
context.allowToModifyMeshShape = m_AllowToModifyMeshShape = value;
m_AllowToModifyMeshShape = value;
SetVerticesDirty();
}
}
@@ -832,8 +834,6 @@ namespace Coffee.UIEffects
c.gradationOffset = m_GradationOffset;
c.gradationScale = m_GradationScale;
c.gradationRotation = m_GradationRotation;
c.allowToModifyMeshShape = m_AllowToModifyMeshShape;
}
public override void ApplyContextToMaterial()
@@ -1013,8 +1013,6 @@ namespace Coffee.UIEffects
m_GradationScale = c.gradationScale;
m_GradationRotation = c.gradationRotation;
m_AllowToModifyMeshShape = c.allowToModifyMeshShape;
UpdateContext(context);
ApplyContextToMaterial();
SetVerticesDirty();
+2 -1
View File
@@ -32,6 +32,7 @@ namespace Coffee.UIEffects
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
public virtual uint effectId => (uint)GetInstanceID();
public virtual float actualSamplingScale => 1;
public virtual bool canModifyShape => true;
public virtual UIEffectContext context
{
@@ -90,7 +91,7 @@ namespace Coffee.UIEffects
{
if (!isActiveAndEnabled || context == null) return;
context.ModifyMesh(graphic, transitionRoot, vh);
context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape);
}
public virtual Material GetModifiedMaterial(Material baseMaterial)
+9 -14
View File
@@ -184,9 +184,6 @@ namespace Coffee.UIEffects
public float gradationRotation;
private List<float> _keyTimes;
public bool allowToModifyMeshShape;
public bool willModifyMaterial => samplingFilter != SamplingFilter.None
|| transitionFilter != TransitionFilter.None
|| toneFilter != ToneFilter.None
@@ -254,8 +251,6 @@ namespace Coffee.UIEffects
gradationOffset = preset.gradationOffset;
gradationScale = preset.gradationScale;
gradationRotation = preset.gradationRotation;
allowToModifyMeshShape = preset.allowToModifyMeshShape;
}
public void SetGradationDirty()
@@ -363,14 +358,14 @@ namespace Coffee.UIEffects
}
}
public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh)
public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh, bool canModifyShape)
{
var processor = ContextProcessor.FindProcessor(graphic);
var isText = processor.IsText(graphic);
processor.OnPreModifyMesh(graphic);
var verts = s_WorkingVertices;
var expandSize = GetExpandSize();
var expandSize = GetExpandSize(canModifyShape);
var count = vh.currentIndexCount;
// Get the rectangle to calculate the normalized position.
@@ -427,7 +422,7 @@ namespace Coffee.UIEffects
}
// Apply gradation.
ApplyGradation(verts, transitionRoot.rect, rectMatrix);
ApplyGradation(verts, transitionRoot.rect, rectMatrix, canModifyShape);
// Apply shadow.
ApplyShadow(transitionRoot, verts);
@@ -436,7 +431,7 @@ namespace Coffee.UIEffects
vh.AddUIVertexTriangleStream(verts);
}
private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m)
private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m, bool canModifyShape)
{
var a = gradationColor1;
var b = gradationColor2;
@@ -476,7 +471,7 @@ namespace Coffee.UIEffects
GradientUtil.GetKeyTimes(grad, _keyTimes);
}
if (allowToModifyMeshShape)
if (canModifyShape)
{
var splitTimes = InternalListPool<float>.Rent();
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
@@ -498,7 +493,7 @@ namespace Coffee.UIEffects
GradientUtil.GetKeyTimes(grad, _keyTimes);
}
if (allowToModifyMeshShape)
if (canModifyShape)
{
var splitTimes = InternalListPool<float>.Rent();
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
@@ -521,7 +516,7 @@ namespace Coffee.UIEffects
}
m = Matrix4x4.Rotate(Quaternion.Euler(0, 0, rot)) * m;
if (allowToModifyMeshShape)
if (canModifyShape)
{
var splitTimes = InternalListPool<float>.Rent();
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
@@ -555,9 +550,9 @@ namespace Coffee.UIEffects
}
}
private Vector2 GetExpandSize()
private Vector2 GetExpandSize(bool canModifyShape)
{
if (!allowToModifyMeshShape) return Vector2.zero;
if (!canModifyShape) return Vector2.zero;
var expandSize = Vector2.zero;
switch (samplingFilter)
+5
View File
@@ -12,6 +12,9 @@ namespace Coffee.UIEffects
[SerializeField]
protected float m_SamplingScale = 1f;
[SerializeField]
protected bool m_AllowToModifyMeshShape = true;
private UIEffect _currentTarget;
private Matrix4x4 _prevTransformHash;
@@ -55,6 +58,8 @@ namespace Coffee.UIEffects
? Mathf.Clamp(m_SamplingScale, 0.01f, 100)
: 1;
public override bool canModifyShape => m_AllowToModifyMeshShape;
public override uint effectId => target ? target.effectId : 0;
public override UIEffectContext context => target && target.isActiveAndEnabled ? target.context : null;