-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathDecorate.cs
70 lines (61 loc) · 1.72 KB
/
Decorate.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
#if UNITY_EDITOR
using UnityEngine;
using UnityEngine.UI;
namespace U3DExtends
{
[RequireComponent(typeof(RectTransform))]
[ExecuteInEditMode]
public class Decorate : MonoBehaviour
{
string spr_path = "";
[SerializeField]
[HideInInspector]
private Image _image;
Vector3 _lastPos = new Vector3(-1, -1);
Vector2 _lastSize = Vector2.zero;
public string SprPath
{
get { return spr_path; }
set
{
LoadSpr(value);
}
}
public void LoadSpr(string path)
{
InitComponent();
if (spr_path != path)
{
spr_path = path;
_image.sprite = UIEditorHelper.LoadSpriteInLocal(path);
_image.SetNativeSize();
gameObject.name = CommonHelper.GetFileNameByPath(path);
//Debug.Log("_image.sprite :" + (_image.sprite != null).ToString());
}
}
protected void Start()
{
InitComponent();
}
protected void InitComponent()
{
if (_image == null)
_image = GetComponent<Image>();
}
public bool IsChangedTrans()
{
RectTransform curTrans = transform as RectTransform;
if (curTrans.localPosition == _lastPos && curTrans.sizeDelta == _lastSize)
return false;
else
return true;
}
public void SaveTrans()
{
RectTransform rectTrans = transform as RectTransform;
_lastPos = rectTrans.localPosition;
_lastSize = rectTrans.sizeDelta;
}
}
}
#endif