mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
feat: add 'Flip' feature
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -226,6 +226,9 @@ namespace Coffee.UIEffects
|
||||
[SerializeField]
|
||||
protected RectTransform m_CustomRoot = null;
|
||||
|
||||
[SerializeField]
|
||||
protected Flip m_Flip = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Tone filter for rendering.
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<UIVertex> verts)
|
||||
private void ApplyShadow(List<UIVertex> 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<UIVertex> 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<UIVertex, UIVertex, UIVertex, float, UIVertex> onLerpVertex;
|
||||
|
||||
public static void Flip(List<UIVertex> 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<UIVertex> verts, int multiplier)
|
||||
{
|
||||
var capacity = Mathf.NextPowerOfTwo(verts.Count * multiplier);
|
||||
|
||||
Reference in New Issue
Block a user