-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGradientImage.cs
62 lines (56 loc) · 1.63 KB
/
GradientImage.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
using UnityEngine;
namespace Gilzoide.GradientRect
{
[RequireComponent(typeof(CanvasRenderer))]
public class GradientImage : GradientRect
{
[Header("Texture")]
[SerializeField] protected Sprite _sprite;
/// <summary>Sprite used to draw Image.</summary>
/// <remarks>For now, the only fill supported is simple mode, no slicing nor tiling.</remarks>
public Sprite Sprite
{
get => _sprite;
set
{
if (_sprite == value)
{
return;
}
_sprite = value;
SetVerticesDirty();
SetMaterialDirty();
}
}
public override Texture mainTexture
{
get
{
if (_sprite == null)
{
if (material != null && material.mainTexture != null)
{
return material.mainTexture;
}
return s_WhiteTexture;
}
return _sprite.texture;
}
}
protected override Vector2 GetUVForNormalizedPosition(Vector2 position)
{
if (_sprite)
{
Vector4 outerUV = UnityEngine.Sprites.DataUtility.GetOuterUV(_sprite);
return new Vector2(
Mathf.Lerp(outerUV.x, outerUV.z, position.x),
Mathf.Lerp(outerUV.y, outerUV.w, position.y)
);
}
else
{
return position;
}
}
}
}