-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVScrollEffect.cs
64 lines (54 loc) · 1.44 KB
/
UVScrollEffect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public class UVScrollEffect : BaseMeshEffect
{
[SerializeField] private Vector2 _scroll = new Vector2(1, 1);
[SerializeField] private bool _playEditor;
private Vector2 _scrollDelta;
protected override void OnEnable()
{
base.OnEnable();
#if UNITY_EDITOR
EditorApplication.update -= Repaint;
EditorApplication.update += Repaint;
#endif
}
protected override void OnDisable()
{
base.OnDisable();
#if UNITY_EDITOR
EditorApplication.update -= Repaint;
#endif
}
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive()) return;
if (!_playEditor || Application.isPlaying) return;
int vertCount = vh.currentVertCount;
_scrollDelta = _scroll * Time.time;
UIVertex vert = new UIVertex();
for (var i = 0; i < vertCount; i++)
{
vh.PopulateUIVertex(ref vert, i);
#if UNITY_2020_2_OR_NEWER
vert.uv0 += (Vector4)_scrollDelta;
#else
vert.uv0 += scrollDelta;
#endif
vh.SetUIVertex(vert, i);
}
}
private void Update()
{
graphic.SetVerticesDirty();
}
#if UNITY_EDITOR
private void Repaint()
{
if (!_playEditor || Application.isPlaying) return;
EditorApplication.QueuePlayerLoopUpdate();
graphic.SetVerticesDirty();
}
#endif
}