-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExGlobalNavbarMenu.cs
65 lines (44 loc) · 1.67 KB
/
ExGlobalNavbarMenu.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI.Extensions;
using UnityAtoms.BaseAtoms;
public class ExGlobalNavbarMenu : SimpleMenu<ExGlobalNavbarMenu>
{
// Start is called before the first frame update
public RectTransform healthBar;
private float healthMaxWidth = 250;
[SerializeField]
private IntConstant MaxHealth;
[SerializeField]
private IntEvent HealthChangedEvent;
public Vector2 startSizeDelta;
void Start(){
startSizeDelta = healthBar.sizeDelta;
Debug.Log( startSizeDelta.ToString() );
healthMaxWidth = healthBar.rect.width;
HealthChangedEvent.Register(this.UpdateHealthBar);
}
void OnDestroy(){
HealthChangedEvent.Unregister(this.UpdateHealthBar);
}
private void UpdateHealthBar(int healthValue){
Debug.Log("ExGlobalNavbarMenu heard UpdateHealthBar with " + healthValue);
Debug.Log( healthBar.sizeDelta.ToString() );
Debug.Log( healthValue.ToString() + " / " + MaxHealth.Value.ToString() );
float multi = (float)healthValue / (float)MaxHealth.Value;
Debug.Log( multi.ToString() );
multi *= startSizeDelta.x;
Debug.Log( multi.ToString() );
//healthMaxWidth =
//.rect.width
//Rect m_rect = healthBar.rect;
//m_rect.width = ( );
healthBar.sizeDelta = new Vector2( multi , startSizeDelta.y );
}
// Update is called once per frame
public void OnPausePressed(){
Debug.Log("GlobalNavbarMenu :: OnPausePressed");
ExPauseMenu.Show();
}
}