diff --git a/Packages/src/Editor/UIEffectEditor.cs b/Packages/src/Editor/UIEffectEditor.cs
index 8042f84..b8fbedf 100644
--- a/Packages/src/Editor/UIEffectEditor.cs
+++ b/Packages/src/Editor/UIEffectEditor.cs
@@ -104,6 +104,7 @@ namespace Coffee.UIEffects.Editors
private SerializedProperty _allowToModifyMeshShape;
private SerializedProperty _customRoot;
+ private SerializedProperty _flip;
private static bool expandOthers
{
@@ -189,6 +190,7 @@ namespace Coffee.UIEffects.Editors
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
_customRoot = serializedObject.FindProperty("m_CustomRoot");
+ _flip = serializedObject.FindProperty("m_Flip");
}
public override void OnInspectorGUI()
@@ -426,6 +428,7 @@ namespace Coffee.UIEffects.Editors
EditorGUILayout.PropertyField(_samplingScale);
EditorGUILayout.PropertyField(_allowToModifyMeshShape);
EditorGUILayout.PropertyField(_customRoot);
+ EditorGUILayout.PropertyField(_flip);
}
}
diff --git a/Packages/src/Editor/UIEffectReplicaEditor.cs b/Packages/src/Editor/UIEffectReplicaEditor.cs
index f0094fe..fd7adf7 100644
--- a/Packages/src/Editor/UIEffectReplicaEditor.cs
+++ b/Packages/src/Editor/UIEffectReplicaEditor.cs
@@ -13,6 +13,7 @@ namespace Coffee.UIEffects.Editors
private SerializedProperty _useTargetTransform;
private SerializedProperty _samplingScale;
private SerializedProperty _allowToModifyMeshShape;
+ private SerializedProperty _flip;
private Editor _uiEffectEditor;
private void OnEnable()
@@ -21,6 +22,7 @@ namespace Coffee.UIEffects.Editors
_useTargetTransform = serializedObject.FindProperty("m_UseTargetTransform");
_samplingScale = serializedObject.FindProperty("m_SamplingScale");
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
+ _flip = serializedObject.FindProperty("m_Flip");
}
public override void OnInspectorGUI()
@@ -30,6 +32,7 @@ namespace Coffee.UIEffects.Editors
EditorGUILayout.PropertyField(_useTargetTransform);
EditorGUILayout.PropertyField(_samplingScale);
EditorGUILayout.PropertyField(_allowToModifyMeshShape);
+ EditorGUILayout.PropertyField(_flip);
if (_target.objectReferenceValue)
{
diff --git a/Packages/src/Runtime/Enums.cs b/Packages/src/Runtime/Enums.cs
index eca1520..d831946 100644
--- a/Packages/src/Runtime/Enums.cs
+++ b/Packages/src/Runtime/Enums.cs
@@ -1,4 +1,5 @@
-using UnityEngine.Rendering;
+using System;
+using UnityEngine.Rendering;
namespace Coffee.UIEffects
{
@@ -107,6 +108,15 @@ namespace Coffee.UIEffects
AngleGradient = 10
}
+ [Flags]
+ public enum Flip
+ {
+ Horizontal = 1 << 0,
+ Vertical = 1 << 1,
+ Effect = 1 << 2,
+ Shadow = 1 << 3
+ }
+
internal static class BlendTypeConverter
{
public static (BlendMode, BlendMode) Convert(this (BlendType type, BlendMode src, BlendMode dst) self)
diff --git a/Packages/src/Runtime/UIEffect.cs b/Packages/src/Runtime/UIEffect.cs
index a04b3a3..9dcdd05 100644
--- a/Packages/src/Runtime/UIEffect.cs
+++ b/Packages/src/Runtime/UIEffect.cs
@@ -226,6 +226,9 @@ namespace Coffee.UIEffects
[SerializeField]
protected RectTransform m_CustomRoot = null;
+ [SerializeField]
+ protected Flip m_Flip = 0;
+
///
/// Tone filter for rendering.
///
@@ -1235,6 +1238,17 @@ namespace Coffee.UIEffects
}
}
+ public override Flip flip
+ {
+ get => m_Flip;
+ set
+ {
+ if (m_Flip == value) return;
+ m_Flip = value;
+ SetVerticesDirty();
+ }
+ }
+
public override RectTransform transitionRoot => m_CustomRoot
? m_CustomRoot
: transform as RectTransform;
diff --git a/Packages/src/Runtime/UIEffectBase.cs b/Packages/src/Runtime/UIEffectBase.cs
index 9e8bb8f..af520fa 100644
--- a/Packages/src/Runtime/UIEffectBase.cs
+++ b/Packages/src/Runtime/UIEffectBase.cs
@@ -48,6 +48,12 @@ namespace Coffee.UIEffects
public virtual RectTransform transitionRoot => transform as RectTransform;
+ public virtual Flip flip
+ {
+ get => 0;
+ set { }
+ }
+
protected override void OnEnable()
{
_onBeforeCanvasRebuild ??= OnBeforeCanvasRebuild;
@@ -95,7 +101,7 @@ namespace Coffee.UIEffects
_canModifyMesh = CanModifyMesh();
if (_canModifyMesh)
{
- context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape);
+ context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape, flip);
}
}
diff --git a/Packages/src/Runtime/UIEffectContext.cs b/Packages/src/Runtime/UIEffectContext.cs
index a7f91f1..c6935ec 100644
--- a/Packages/src/Runtime/UIEffectContext.cs
+++ b/Packages/src/Runtime/UIEffectContext.cs
@@ -459,8 +459,12 @@ namespace Coffee.UIEffects
}
}
- public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh, bool canModifyShape)
+ public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh,
+ bool canModifyShape, Flip flip)
{
+ // Apply flip (without effect).
+ ApplyFlipWithoutEffect(vh, flip);
+
var count = vh.currentIndexCount;
if (!willModifyVertex || count == 0) return;
@@ -531,8 +535,11 @@ namespace Coffee.UIEffects
// Apply gradation.
ApplyGradation(verts, transitionRoot.rect, rectMatrix, canModifyShape);
+ // Apply flip (with effect).
+ ApplyFlipWithEffect(verts, flip);
+
// Apply shadow.
- ApplyShadow(transitionRoot, verts);
+ ApplyShadow(verts, transitionRoot, flip);
vh.Clear();
vh.AddUIVertexTriangleStream(verts);
@@ -647,23 +654,54 @@ namespace Coffee.UIEffects
}
}
- private void ApplyShadow(RectTransform transitionRoot, List verts)
+ private void ApplyShadow(List verts, RectTransform transitionRoot, Flip flip)
{
+ var distance = shadowDistance;
+ if (distance == Vector2.zero) return;
+
+ if ((flip & Flip.Shadow) != 0)
+ {
+ distance.x = (flip & Flip.Horizontal) != 0 ? -distance.x : distance.x;
+ distance.y = (flip & Flip.Vertical) != 0 ? -distance.y : distance.y;
+ }
+
switch (shadowMode)
{
case ShadowMode.Shadow:
case ShadowMode.Shadow3:
case ShadowMode.Outline:
case ShadowMode.Outline8:
- ShadowUtil.DoShadow(verts, s_ShadowVectors[(int)shadowMode], shadowDistance, shadowIteration,
+ ShadowUtil.DoShadow(verts, s_ShadowVectors[(int)shadowMode], distance, shadowIteration,
shadowFade);
break;
case ShadowMode.Mirror:
- ShadowUtil.DoMirror(verts, shadowDistance, shadowMirrorScale, shadowFade, transitionRoot);
+ ShadowUtil.DoMirror(verts, distance, shadowMirrorScale, shadowFade, transitionRoot);
break;
}
}
+ private static void ApplyFlipWithoutEffect(VertexHelper vh, Flip flip)
+ {
+ if ((flip & Flip.Effect) != 0) return;
+
+ var flipHorizontal = 0 != (flip & Flip.Horizontal);
+ var flipVertical = 0 != (flip & Flip.Vertical);
+ if (!flipHorizontal && !flipVertical) return;
+
+ UIVertexUtil.Flip(vh, flipHorizontal, flipVertical);
+ }
+
+ private static void ApplyFlipWithEffect(List verts, Flip flip)
+ {
+ if ((flip & Flip.Effect) == 0) return;
+
+ var flipHorizontal = 0 != (flip & Flip.Horizontal);
+ var flipVertical = 0 != (flip & Flip.Vertical);
+ if (!flipHorizontal && !flipVertical) return;
+
+ UIVertexUtil.Flip(verts, flipHorizontal, flipVertical);
+ }
+
private Vector2 GetExpandSize(bool canModifyShape)
{
if (!canModifyShape) return Vector2.zero;
diff --git a/Packages/src/Runtime/UIEffectReplica.cs b/Packages/src/Runtime/UIEffectReplica.cs
index 4b4006e..0ff5945 100644
--- a/Packages/src/Runtime/UIEffectReplica.cs
+++ b/Packages/src/Runtime/UIEffectReplica.cs
@@ -16,6 +16,9 @@ namespace Coffee.UIEffects
[SerializeField]
protected bool m_AllowToModifyMeshShape = true;
+ [SerializeField]
+ protected Flip m_Flip = 0;
+
private UIEffect _currentTarget;
public UIEffect target
@@ -54,6 +57,28 @@ namespace Coffee.UIEffects
}
}
+ public bool allowToModifyMeshShape
+ {
+ get => m_AllowToModifyMeshShape;
+ set
+ {
+ if (m_AllowToModifyMeshShape == value) return;
+ m_AllowToModifyMeshShape = value;
+ SetVerticesDirty();
+ }
+ }
+
+ public override Flip flip
+ {
+ get => m_Flip;
+ set
+ {
+ if (m_Flip == value) return;
+ m_Flip = value;
+ SetVerticesDirty();
+ }
+ }
+
public override float actualSamplingScale => Mathf.Clamp(m_SamplingScale, 0.01f, 100);
public override bool canModifyShape => m_AllowToModifyMeshShape;
diff --git a/Packages/src/Runtime/Utilities/UIVertexUtil.cs b/Packages/src/Runtime/Utilities/UIVertexUtil.cs
index 9845f95..36a5152 100644
--- a/Packages/src/Runtime/Utilities/UIVertexUtil.cs
+++ b/Packages/src/Runtime/Utilities/UIVertexUtil.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using Coffee.UIEffectInternal;
using UnityEngine;
+using UnityEngine.UI;
namespace Coffee.UIEffects
{
@@ -9,6 +10,31 @@ namespace Coffee.UIEffects
{
public static Func onLerpVertex;
+ public static void Flip(List verts, bool horizontal, bool vertical)
+ {
+ var count = verts.Count;
+ for (var i = 0; i < count; i++)
+ {
+ var vt = verts[i];
+ var pos = vt.position;
+ vt.position = new Vector3(horizontal ? -pos.x : pos.x, vertical ? -pos.y : pos.y);
+ verts[i] = vt;
+ }
+ }
+
+ public static void Flip(VertexHelper vh, bool horizontal, bool vertical)
+ {
+ var count = vh.currentVertCount;
+ var vt = default(UIVertex);
+ for (var i = 0; i < count; i++)
+ {
+ vh.PopulateUIVertex(ref vt, i);
+ var pos = vt.position;
+ vt.position = new Vector3(horizontal ? -pos.x : pos.x, vertical ? -pos.y : pos.y);
+ vh.SetUIVertex(vt, i);
+ }
+ }
+
public static void ExpandCapacity(List verts, int multiplier)
{
var capacity = Mathf.NextPowerOfTwo(verts.Count * multiplier);