Skip to content

Commit

Permalink
feat: the Allow To Modify Mesh Shape property should remain unchang…
Browse files Browse the repository at this point in the history
…ed when loading a preset

close #294
  • Loading branch information
mob-sakai committed Jan 7, 2025
1 parent 238a17d commit f7175c0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Packages/src/Editor/UIEffectReplicaEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public class UIEffectReplicaEditor : Editor
private SerializedProperty _target;
private SerializedProperty _useTargetTransform;
private SerializedProperty _samplingScale;
private SerializedProperty _allowToModifyMeshShape;
private Editor _uiEffectEditor;

private void OnEnable()
{
_target = serializedObject.FindProperty("m_Target");
_useTargetTransform = serializedObject.FindProperty("m_UseTargetTransform");
_samplingScale = serializedObject.FindProperty("m_SamplingScale");
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
}

public override void OnInspectorGUI()
Expand All @@ -27,6 +29,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_target);
EditorGUILayout.PropertyField(_useTargetTransform);
EditorGUILayout.PropertyField(_samplingScale);
EditorGUILayout.PropertyField(_allowToModifyMeshShape);

if (_target.objectReferenceValue)
{
Expand Down
8 changes: 3 additions & 5 deletions Packages/src/Runtime/UIEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ public float samplingScale
? Mathf.Clamp(m_SamplingScale, 0.01f, 100)
: 1;

public override bool canModifyShape => m_AllowToModifyMeshShape;

/// <summary>
/// Transition filter for rendering.
/// </summary>
Expand Down Expand Up @@ -714,7 +716,7 @@ public bool allowToModifyMeshShape
set
{
if (m_AllowToModifyMeshShape == value) return;
context.allowToModifyMeshShape = m_AllowToModifyMeshShape = value;
m_AllowToModifyMeshShape = value;
SetVerticesDirty();
}
}
Expand Down Expand Up @@ -832,8 +834,6 @@ protected override void UpdateContext(UIEffectContext c)
c.gradationOffset = m_GradationOffset;
c.gradationScale = m_GradationScale;
c.gradationRotation = m_GradationRotation;

c.allowToModifyMeshShape = m_AllowToModifyMeshShape;
}

public override void ApplyContextToMaterial()
Expand Down Expand Up @@ -1013,8 +1013,6 @@ internal void CopyFrom(UIEffectContext c)
m_GradationScale = c.gradationScale;
m_GradationRotation = c.gradationRotation;

m_AllowToModifyMeshShape = c.allowToModifyMeshShape;

UpdateContext(context);
ApplyContextToMaterial();
SetVerticesDirty();
Expand Down
3 changes: 2 additions & 1 deletion Packages/src/Runtime/UIEffectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class UIEffectBase : UIBehaviour, IMeshModifier, IMaterialModifi
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
{
Expand Down Expand Up @@ -90,7 +91,7 @@ public virtual void ModifyMesh(VertexHelper vh)
{
if (!isActiveAndEnabled || context == null) return;

context.ModifyMesh(graphic, transitionRoot, vh);
context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape);
}

public virtual Material GetModifiedMaterial(Material baseMaterial)
Expand Down
23 changes: 9 additions & 14 deletions Packages/src/Runtime/UIEffectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ public class UIEffectContext
public float gradationRotation;
private List<float> _keyTimes;

public bool allowToModifyMeshShape;


public bool willModifyMaterial => samplingFilter != SamplingFilter.None
|| transitionFilter != TransitionFilter.None
|| toneFilter != ToneFilter.None
Expand Down Expand Up @@ -254,8 +251,6 @@ public void CopyFrom(UIEffectContext preset)
gradationOffset = preset.gradationOffset;
gradationScale = preset.gradationScale;
gradationRotation = preset.gradationRotation;

allowToModifyMeshShape = preset.allowToModifyMeshShape;
}

public void SetGradationDirty()
Expand Down Expand Up @@ -363,14 +358,14 @@ private static void SetKeyword(Material material, string[] keywords, int index)
}
}

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.
Expand Down Expand Up @@ -427,7 +422,7 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp
}

// Apply gradation.
ApplyGradation(verts, transitionRoot.rect, rectMatrix);
ApplyGradation(verts, transitionRoot.rect, rectMatrix, canModifyShape);

// Apply shadow.
ApplyShadow(transitionRoot, verts);
Expand All @@ -436,7 +431,7 @@ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelp
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;
Expand Down Expand Up @@ -476,7 +471,7 @@ private void ApplyGradation(List<UIVertex> verts, Rect rect, Matrix4x4 m)
GradientUtil.GetKeyTimes(grad, _keyTimes);
}

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

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

m = Matrix4x4.Rotate(Quaternion.Euler(0, 0, rot)) * m;
if (allowToModifyMeshShape)
if (canModifyShape)
{
var splitTimes = InternalListPool<float>.Rent();
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
Expand Down Expand Up @@ -555,9 +550,9 @@ private void ApplyShadow(RectTransform transitionRoot, List<UIVertex> verts)
}
}

private Vector2 GetExpandSize()
private Vector2 GetExpandSize(bool canModifyShape)
{
if (!allowToModifyMeshShape) return Vector2.zero;
if (!canModifyShape) return Vector2.zero;

var expandSize = Vector2.zero;
switch (samplingFilter)
Expand Down
5 changes: 5 additions & 0 deletions Packages/src/Runtime/UIEffectReplica.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class UIEffectReplica : UIEffectBase
[SerializeField]
protected float m_SamplingScale = 1f;

[SerializeField]
protected bool m_AllowToModifyMeshShape = true;

private UIEffect _currentTarget;
private Matrix4x4 _prevTransformHash;

Expand Down Expand Up @@ -55,6 +58,8 @@ public float samplingScale
? 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;

Expand Down

0 comments on commit f7175c0

Please sign in to comment.