-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCAN_SimpleLabel.cs
69 lines (58 loc) · 1.66 KB
/
SCAN_SimpleLabel.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
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCAN_SimpleLabel - Script for controlling simple map icons
*
* Copyright (c)2014 David Grandy <david.grandy@gmail.com>;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System;
using UnityEngine;
using UnityEngine.UI;
namespace SCANsat.Unity.Unity
{
public class SCAN_SimpleLabel : MonoBehaviour
{
private Image icon;
private RectTransform rect;
private SimpleLabelInfo info;
public void Setup(SimpleLabelInfo label)
{
if (label == null)
return;
info = label;
rect = gameObject.AddComponent<RectTransform>();
rect.anchorMin = new Vector2(0, 0);
rect.anchorMax = new Vector2(0, 0);
rect.pivot = new Vector2(0.5f, 0.5f);
rect.localScale = new Vector3(1, 1, 1);
rect.localPosition = new Vector3(0, 0, 0);
rect.anchoredPosition3D = new Vector3(label.pos.x, label.pos.y, 0);
rect.sizeDelta = new Vector2(label.width, label.width);
icon = gameObject.AddComponent<Image>();
icon.sprite = label.image;
icon.color = label.color;
icon.raycastTarget = false;
icon.type = Image.Type.Sliced;
}
public void UpdateIcon(SimpleLabelInfo label)
{
if (icon == null || rect == null || label == null)
return;
if (gameObject.activeSelf && !label.show)
{
gameObject.SetActive(false);
return;
}
else if (!gameObject.activeSelf && label.show)
gameObject.SetActive(true);
if (icon.color != label.color)
icon.color = label.color;
rect.anchoredPosition = label.pos;
}
}
}