EchoTrio
Loading...
Searching...
No Matches
SpriteSwitcher.cs
Go to the documentation of this file.
1
using
UnityEngine;
2
3
namespace
EchoTrio.UI
{
4
[RequireComponent(typeof(UnityEngine.UI.Image))]
5
public
class
SpriteSwitcher
: MonoBehaviour {
6
[SerializeField]
private
Sprite[]
sprites
=
new
Sprite[0];
7
[SerializeField]
private
int
index
= 0;
8
9
public
void
CycleSprite
() {
10
index
= (
index
+ 1) %
sprites
.Length;
11
GetComponent<UnityEngine.UI.Image>().sprite =
sprites
[
index
];
12
}
13
14
public
void
SetSprite
(
int
index
) {
15
this.index =
index
;
16
GetComponent<UnityEngine.UI.Image>().sprite =
sprites
[
index
];
17
}
18
19
private
void
OnValidate
() {
20
UnityEngine.UI.Image image = GetComponent<UnityEngine.UI.Image>();
21
if
(image !=
null
&&
sprites
[0] !=
null
) {
22
image.sprite =
sprites
[0];
23
}
else
{
24
image.sprite =
null
;
25
}
26
}
27
}
28
}
EchoTrio.UI.SpriteSwitcher
Definition:
SpriteSwitcher.cs:5
EchoTrio.UI.SpriteSwitcher.index
int index
Definition:
SpriteSwitcher.cs:7
EchoTrio.UI.SpriteSwitcher.sprites
Sprite[] sprites
Definition:
SpriteSwitcher.cs:6
EchoTrio.UI.SpriteSwitcher.OnValidate
void OnValidate()
Definition:
SpriteSwitcher.cs:19
EchoTrio.UI.SpriteSwitcher.SetSprite
void SetSprite(int index)
Definition:
SpriteSwitcher.cs:14
EchoTrio.UI.SpriteSwitcher.CycleSprite
void CycleSprite()
Definition:
SpriteSwitcher.cs:9
EchoTrio.UI
Definition:
Chatbox.cs:4
Assets
Scripts
UI
SpriteSwitcher.cs
Generated by
1.9.6