mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14bf4da62b8434d7ca6e6a7e8b63e4ea
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43c4f102824e943cf859c0d6c966b9fa
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -232,15 +232,18 @@ namespace Coffee.UIEffects
|
||||
public float gradationRotation;
|
||||
private List<float> _keyTimes;
|
||||
|
||||
public bool willModifyMaterial => samplingFilter != SamplingFilter.None
|
||||
|| transitionFilter != TransitionFilter.None
|
||||
|| toneFilter != ToneFilter.None
|
||||
public bool willModifyMaterial => toneFilter != ToneFilter.None
|
||||
|| colorFilter != ColorFilter.None
|
||||
|| samplingFilter != SamplingFilter.None
|
||||
|| transitionFilter != TransitionFilter.None
|
||||
|| srcBlendMode != BlendMode.One
|
||||
|| dstBlendMode != BlendMode.OneMinusSrcAlpha
|
||||
|| shadowMode != ShadowMode.None
|
||||
|| edgeMode != EdgeMode.None;
|
||||
|
||||
public bool willModifyVertex => willModifyMaterial
|
||||
|| gradationMode != GradationMode.None;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
InternalListPool<float>.Return(ref _keyTimes);
|
||||
@@ -454,13 +457,15 @@ namespace Coffee.UIEffects
|
||||
|
||||
public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh, bool canModifyShape)
|
||||
{
|
||||
var count = vh.currentIndexCount;
|
||||
if (!willModifyVertex || count == 0) return;
|
||||
|
||||
var effectProxy = GraphicProxy.Find(graphic);
|
||||
var isText = effectProxy.IsText(graphic);
|
||||
effectProxy.OnPreModifyMesh(graphic);
|
||||
|
||||
var verts = s_WorkingVertices;
|
||||
var expandSize = effectProxy.ModifyExpandSize(graphic, GetExpandSize(canModifyShape));
|
||||
var count = vh.currentIndexCount;
|
||||
|
||||
// Get the rectangle to calculate the normalized position.
|
||||
vh.GetUIVertexStream(verts);
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace Coffee.UIEffects
|
||||
// When the text is changed, add it to the changed list
|
||||
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(obj =>
|
||||
{
|
||||
if (obj is TextMeshProUGUI textMeshProUGUI)
|
||||
if (obj is TextMeshProUGUI textMeshProUGUI && textMeshProUGUI.isActiveAndEnabled)
|
||||
{
|
||||
s_ChangedInstances.Add(textMeshProUGUI);
|
||||
}
|
||||
@@ -211,17 +211,14 @@ namespace Coffee.UIEffects
|
||||
|
||||
private static void ModifyMesh(TextMeshProUGUI textMeshProUGUI)
|
||||
{
|
||||
if (!textMeshProUGUI.TryGetComponent<UIEffectBase>(out var effect)) return;
|
||||
if (!effect || !effect.isActiveAndEnabled) return;
|
||||
|
||||
s_RegisteredInstances.Add(textMeshProUGUI);
|
||||
|
||||
if (!s_Mesh)
|
||||
{
|
||||
s_Mesh = new Mesh();
|
||||
s_Mesh.MarkDynamic();
|
||||
}
|
||||
|
||||
s_RegisteredInstances.Add(textMeshProUGUI);
|
||||
var effect = textMeshProUGUI.GetComponent<UIEffectBase>();
|
||||
var target = effect is UIEffect uiEffect
|
||||
? uiEffect
|
||||
: effect is UIEffectReplica parentReplica
|
||||
@@ -229,7 +226,10 @@ namespace Coffee.UIEffects
|
||||
: null;
|
||||
var subMeshes = InternalListPool<TMP_SubMeshUI>.Rent();
|
||||
var modifiers = InternalListPool<IMeshModifier>.Rent();
|
||||
var subModifiers = InternalListPool<IMeshModifier>.Rent();
|
||||
textMeshProUGUI.GetComponentsInChildren(subMeshes, 1);
|
||||
textMeshProUGUI.GetComponents(modifiers);
|
||||
|
||||
for (var i = 0; i < textMeshProUGUI.textInfo.meshInfo.Length; i++)
|
||||
{
|
||||
var meshInfo = textMeshProUGUI.textInfo.meshInfo[i];
|
||||
@@ -237,7 +237,6 @@ namespace Coffee.UIEffects
|
||||
meshInfo.mesh.CopyTo(s_VertexHelper, meshInfo.vertexCount, meshInfo.vertexCount * 6 / 4);
|
||||
if (i == 0)
|
||||
{
|
||||
textMeshProUGUI.GetComponents(modifiers);
|
||||
foreach (var modifier in modifiers)
|
||||
{
|
||||
modifier.ModifyMesh(s_VertexHelper);
|
||||
@@ -248,18 +247,27 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
else if (i - 1 < subMeshes.Count)
|
||||
{
|
||||
var subMeshUI = GetSubMeshUI(subMeshes, meshInfo.material, i - 1);
|
||||
if (!target || !subMeshUI) break;
|
||||
|
||||
var replica = subMeshUI.GetOrAddComponent<UIEffectReplica>();
|
||||
replica.target = target;
|
||||
|
||||
subMeshUI.GetComponents(modifiers);
|
||||
foreach (var modifier in modifiers)
|
||||
{
|
||||
if (modifier is UIEffectBase) continue;
|
||||
modifier.ModifyMesh(s_VertexHelper);
|
||||
}
|
||||
|
||||
var subMeshUI = GetSubMeshUI(subMeshes, meshInfo.material, i - 1);
|
||||
if (!subMeshUI) break;
|
||||
|
||||
if (target)
|
||||
{
|
||||
var replica = subMeshUI.GetOrAddComponent<UIEffectReplica>();
|
||||
replica.target = target;
|
||||
|
||||
subMeshUI.GetComponents(subModifiers);
|
||||
foreach (var modifier in subModifiers)
|
||||
{
|
||||
modifier.ModifyMesh(s_VertexHelper);
|
||||
}
|
||||
}
|
||||
|
||||
s_VertexHelper.FillMesh(s_Mesh);
|
||||
subMeshUI.canvasRenderer.SetMesh(s_Mesh);
|
||||
}
|
||||
@@ -269,8 +277,9 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
InternalListPool<IMeshModifier>.Return(ref modifiers);
|
||||
InternalListPool<TMP_SubMeshUI>.Return(ref subMeshes);
|
||||
InternalListPool<IMeshModifier>.Return(ref modifiers);
|
||||
InternalListPool<IMeshModifier>.Return(ref subModifiers);
|
||||
s_Mesh.Clear(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Coffee.UIEffects
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Graphic))]
|
||||
[AddComponentMenu("")]
|
||||
public class UIFlip : ObsoleteMonoBehaviour
|
||||
{
|
||||
[Tooltip("Flip horizontally.")]
|
||||
[SerializeField]
|
||||
private bool m_Horizontal = false;
|
||||
|
||||
[Tooltip("Flip vertically.")]
|
||||
[SerializeField]
|
||||
private bool m_Veritical = false;
|
||||
|
||||
public bool horizontal
|
||||
{
|
||||
get => m_Horizontal;
|
||||
set
|
||||
{
|
||||
if (m_Horizontal == value) return;
|
||||
m_Horizontal = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool vertical
|
||||
{
|
||||
get => m_Veritical;
|
||||
set
|
||||
{
|
||||
if (m_Veritical == value) return;
|
||||
m_Veritical = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using Coffee.UIEffectInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Coffee.UIEffects
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Graphic))]
|
||||
public class UIFlip : UIBehaviour, IMeshModifier
|
||||
{
|
||||
[Tooltip("Flip horizontally.")]
|
||||
[SerializeField]
|
||||
private bool m_Horizontal = false;
|
||||
|
||||
[FormerlySerializedAs("m_Veritical")]
|
||||
[Tooltip("Flip vertically.")]
|
||||
[SerializeField]
|
||||
private bool m_Vertical = false;
|
||||
|
||||
private Graphic _graphic;
|
||||
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this <see cref="Coffee.UIEffects.UIFlip"/> should be flipped horizontally.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value>
|
||||
public bool horizontal
|
||||
{
|
||||
get => m_Horizontal;
|
||||
set
|
||||
{
|
||||
if (m_Horizontal == value) return;
|
||||
m_Horizontal = value;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this <see cref="Coffee.UIEffects.UIFlip"/> should be flipped vertically.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value>
|
||||
public bool vertical
|
||||
{
|
||||
get => m_Vertical;
|
||||
set
|
||||
{
|
||||
if (m_Vertical == value) return;
|
||||
m_Vertical = value;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
public void SetVerticesDirty()
|
||||
{
|
||||
if (graphic)
|
||||
{
|
||||
graphic.SetVerticesDirty();
|
||||
GraphicProxy.Find(graphic).SetVerticesDirty(graphic, enabled);
|
||||
Misc.QueuePlayerLoopUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void ModifyMesh(Mesh mesh)
|
||||
{
|
||||
}
|
||||
|
||||
public void ModifyMesh(VertexHelper vh)
|
||||
{
|
||||
if (!isActiveAndEnabled || !graphic || !graphic.IsActive() || (!horizontal && !vertical)) return;
|
||||
|
||||
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(m_Horizontal ? -pos.x : pos.x, m_Vertical ? -pos.y : pos.y);
|
||||
vh.SetUIVertex(vt, i);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnValidate()
|
||||
{
|
||||
SetVerticesDirty();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user