-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaidIcon.cs
67 lines (55 loc) · 1.83 KB
/
MaidIcon.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.Events;
namespace COM3D2.UndressUtil.Plugin
{
public class MaidIconClickEvent : UnityEvent<Maid> { };
public class MaidIcon : MonoBehaviour
{
public Maid maid { get; private set; }
UISprite frame;
UIButton button;
UITexture texture;
public MaidIconClickEvent Click { get; private set; } = new MaidIconClickEvent();
public void Setup(Maid maid)
{
this.maid = maid;
}
public void Awake() {
Log.LogVerbose("MaidIcon.Awake {0}", this);
var frameObj = gameObject.transform.Find("IconMask/Frame").gameObject;
frame = frameObj.GetComponent<UISprite>();
var iconObj = gameObject.transform.Find("IconMask/Icon").gameObject;
button = iconObj.AddComponent<UIButton>();
texture = iconObj.GetComponentInChildren<UITexture>();
Assert.IsNotNull(texture, "Cannot find iconObj.UITexture");
}
public void Start()
{
Log.LogVerbose("MaidIcon.Start {0}", this);
Assert.IsNotNull(this.maid, "maid not set");
texture.mainTexture = maid.GetThumIcon();
EventDelegate.Add(button.onClick, this.OnMaidIconClick);
}
public void OnMaidIconClick()
{
Click.Invoke(this.maid);
}
public void SetSelected(bool selected)
{
if (selected)
{
button.SetState(UIButtonColor.State.Disabled, false);
frame.color = Color.yellow;
}
else
{
button.SetState(UIButtonColor.State.Normal, false);
frame.color = Color.clear;
}
}
}
}