-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathAtlasImage.cs
88 lines (78 loc) · 1.82 KB
/
AtlasImage.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;
namespace Coffee.UIExtensions
{
/// <summary>
/// Atlas image.
/// </summary>
public class AtlasImage : Image
{
[SerializeField] private string m_SpriteName;
[SerializeField] private SpriteAtlas m_SpriteAtlas;
private string _lastSpriteName = "";
/// <summary>Sprite Name. If there is no other sprite with the same name in the atlas, AtlasImage will display the default sprite.</summary>
public string spriteName
{
get { return m_SpriteName; }
set
{
if (m_SpriteName != value)
{
m_SpriteName = value;
SetAllDirty();
}
}
}
/// <summary>SpriteAtlas. Get and set atlas assets created by AtlasMaker.</summary>
public SpriteAtlas spriteAtlas
{
get { return m_SpriteAtlas; }
set
{
if (m_SpriteAtlas != value)
{
m_SpriteAtlas = value;
SetAllDirty();
}
}
}
/// <summary>
/// Sets the material dirty.
/// </summary>
public override void SetMaterialDirty()
{
// Changing sprites from Animation.
// If the "sprite" is changed by an animation or script, it will be reflected in the sprite name.
if (_lastSpriteName == spriteName && sprite)
{
m_SpriteName = sprite.name.Replace("(Clone)", "");
}
if (_lastSpriteName != spriteName)
{
_lastSpriteName = spriteName;
sprite = spriteAtlas ? spriteAtlas.GetSprite(spriteName) : null;
}
base.SetMaterialDirty();
}
protected AtlasImage()
: base()
{
}
/// <summary>
/// Raises the populate mesh event.
/// </summary>
/// <param name="toFill">To fill.</param>
protected override void OnPopulateMesh(VertexHelper toFill)
{
if (!overrideSprite)
{
toFill.Clear();
return;
}
base.OnPopulateMesh(toFill);
}
}
}