Skip to content

Commit f7175c0

Browse files
committed
feat: the Allow To Modify Mesh Shape property should remain unchanged when loading a preset
close #294
1 parent 238a17d commit f7175c0

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

Packages/src/Editor/UIEffectReplicaEditor.cs

+3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ public class UIEffectReplicaEditor : Editor
1212
private SerializedProperty _target;
1313
private SerializedProperty _useTargetTransform;
1414
private SerializedProperty _samplingScale;
15+
private SerializedProperty _allowToModifyMeshShape;
1516
private Editor _uiEffectEditor;
1617

1718
private void OnEnable()
1819
{
1920
_target = serializedObject.FindProperty("m_Target");
2021
_useTargetTransform = serializedObject.FindProperty("m_UseTargetTransform");
2122
_samplingScale = serializedObject.FindProperty("m_SamplingScale");
23+
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
2224
}
2325

2426
public override void OnInspectorGUI()
@@ -27,6 +29,7 @@ public override void OnInspectorGUI()
2729
EditorGUILayout.PropertyField(_target);
2830
EditorGUILayout.PropertyField(_useTargetTransform);
2931
EditorGUILayout.PropertyField(_samplingScale);
32+
EditorGUILayout.PropertyField(_allowToModifyMeshShape);
3033

3134
if (_target.objectReferenceValue)
3235
{

Packages/src/Runtime/UIEffect.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ public float samplingScale
294294
? Mathf.Clamp(m_SamplingScale, 0.01f, 100)
295295
: 1;
296296

297+
public override bool canModifyShape => m_AllowToModifyMeshShape;
298+
297299
/// <summary>
298300
/// Transition filter for rendering.
299301
/// </summary>
@@ -714,7 +716,7 @@ public bool allowToModifyMeshShape
714716
set
715717
{
716718
if (m_AllowToModifyMeshShape == value) return;
717-
context.allowToModifyMeshShape = m_AllowToModifyMeshShape = value;
719+
m_AllowToModifyMeshShape = value;
718720
SetVerticesDirty();
719721
}
720722
}
@@ -832,8 +834,6 @@ protected override void UpdateContext(UIEffectContext c)
832834
c.gradationOffset = m_GradationOffset;
833835
c.gradationScale = m_GradationScale;
834836
c.gradationRotation = m_GradationRotation;
835-
836-
c.allowToModifyMeshShape = m_AllowToModifyMeshShape;
837837
}
838838

839839
public override void ApplyContextToMaterial()
@@ -1013,8 +1013,6 @@ internal void CopyFrom(UIEffectContext c)
10131013
m_GradationScale = c.gradationScale;
10141014
m_GradationRotation = c.gradationRotation;
10151015

1016-
m_AllowToModifyMeshShape = c.allowToModifyMeshShape;
1017-
10181016
UpdateContext(context);
10191017
ApplyContextToMaterial();
10201018
SetVerticesDirty();

Packages/src/Runtime/UIEffectBase.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public abstract class UIEffectBase : UIBehaviour, IMeshModifier, IMaterialModifi
3232
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
3333
public virtual uint effectId => (uint)GetInstanceID();
3434
public virtual float actualSamplingScale => 1;
35+
public virtual bool canModifyShape => true;
3536

3637
public virtual UIEffectContext context
3738
{
@@ -90,7 +91,7 @@ public virtual void ModifyMesh(VertexHelper vh)
9091
{
9192
if (!isActiveAndEnabled || context == null) return;
9293

93-
context.ModifyMesh(graphic, transitionRoot, vh);
94+
context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape);
9495
}
9596

9697
public virtual Material GetModifiedMaterial(Material baseMaterial)

Packages/src/Runtime/UIEffectContext.cs

+9-14
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ public class UIEffectContext
184184
public float gradationRotation;
185185
private List<float> _keyTimes;
186186

187-
public bool allowToModifyMeshShape;
188-
189-
190187
public bool willModifyMaterial => samplingFilter != SamplingFilter.None
191188
|| transitionFilter != TransitionFilter.None
192189
|| toneFilter != ToneFilter.None
@@ -254,8 +251,6 @@ public void CopyFrom(UIEffectContext preset)
254251
gradationOffset = preset.gradationOffset;
255252
gradationScale = preset.gradationScale;
256253
gradationRotation = preset.gradationRotation;
257-
258-
allowToModifyMeshShape = preset.allowToModifyMeshShape;
259254
}
260255

261256
public void SetGradationDirty()
@@ -363,14 +358,14 @@ private static void SetKeyword(Material material, string[] keywords, int index)
363358
}
364359
}
365360

366-
public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh)
361+
public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh, bool canModifyShape)
367362
{
368363
var processor = ContextProcessor.FindProcessor(graphic);
369364
var isText = processor.IsText(graphic);
370365
processor.OnPreModifyMesh(graphic);
371366

372367
var verts = s_WorkingVertices;
373-
var expandSize = GetExpandSize();
368+
var expandSize = GetExpandSize(canModifyShape);
374369
var count = vh.currentIndexCount;
375370

376371
// Get the rectangle to calculate the normalized position.
@@ -427,7 +422,7 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp
427422
}
428423

429424
// Apply gradation.
430-
ApplyGradation(verts, transitionRoot.rect, rectMatrix);
425+
ApplyGradation(verts, transitionRoot.rect, rectMatrix, canModifyShape);
431426

432427
// Apply shadow.
433428
ApplyShadow(transitionRoot, verts);
@@ -436,7 +431,7 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp
436431
vh.AddUIVertexTriangleStream(verts);
437432
}
438433

439-
private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m)
434+
private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m, bool canModifyShape)
440435
{
441436
var a = gradationColor1;
442437
var b = gradationColor2;
@@ -476,7 +471,7 @@ private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m)
476471
GradientUtil.GetKeyTimes(grad, _keyTimes);
477472
}
478473

479-
if (allowToModifyMeshShape)
474+
if (canModifyShape)
480475
{
481476
var splitTimes = InternalListPool<float>.Rent();
482477
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
@@ -498,7 +493,7 @@ private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m)
498493
GradientUtil.GetKeyTimes(grad, _keyTimes);
499494
}
500495

501-
if (allowToModifyMeshShape)
496+
if (canModifyShape)
502497
{
503498
var splitTimes = InternalListPool<float>.Rent();
504499
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
@@ -521,7 +516,7 @@ private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m)
521516
}
522517

523518
m = Matrix4x4.Rotate(Quaternion.Euler(0, 0, rot)) * m;
524-
if (allowToModifyMeshShape)
519+
if (canModifyShape)
525520
{
526521
var splitTimes = InternalListPool<float>.Rent();
527522
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
@@ -555,9 +550,9 @@ private void ApplyShadow(RectTransform transitionRoot, List<UIVertex> verts)
555550
}
556551
}
557552

558-
private Vector2 GetExpandSize()
553+
private Vector2 GetExpandSize(bool canModifyShape)
559554
{
560-
if (!allowToModifyMeshShape) return Vector2.zero;
555+
if (!canModifyShape) return Vector2.zero;
561556

562557
var expandSize = Vector2.zero;
563558
switch (samplingFilter)

Packages/src/Runtime/UIEffectReplica.cs

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class UIEffectReplica : UIEffectBase
1212
[SerializeField]
1313
protected float m_SamplingScale = 1f;
1414

15+
[SerializeField]
16+
protected bool m_AllowToModifyMeshShape = true;
17+
1518
private UIEffect _currentTarget;
1619
private Matrix4x4 _prevTransformHash;
1720

@@ -55,6 +58,8 @@ public float samplingScale
5558
? Mathf.Clamp(m_SamplingScale, 0.01f, 100)
5659
: 1;
5760

61+
public override bool canModifyShape => m_AllowToModifyMeshShape;
62+
5863
public override uint effectId => target ? target.effectId : 0;
5964
public override UIEffectContext context => target && target.isActiveAndEnabled ? target.context : null;
6065

0 commit comments

Comments
 (0)