add scriptable object examples
add editor window example add attribute + drawer example
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Data;
|
||||
using Events;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class HealthBar : MonoBehaviour
|
||||
{
|
||||
[Header("Events")]
|
||||
[SerializeField] private EventBroker eventBroker;
|
||||
|
||||
[Header("Values")]
|
||||
[SerializeField] private FloatValue maxHealth;
|
||||
[SerializeField] private FloatValue health;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private Image fillingImage;
|
||||
[SerializeField] private TextMeshProUGUI deadText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
fillingImage.type = Image.Type.Filled;
|
||||
fillingImage.fillMethod = Image.FillMethod.Horizontal;
|
||||
deadText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
eventBroker.PlayerDied += OnPlayerDied;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
eventBroker.PlayerDied -= OnPlayerDied;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
fillingImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,
|
||||
Mathf.Clamp01(health.Value / maxHealth.Value) * 200.0f);
|
||||
}
|
||||
|
||||
private void OnPlayerDied()
|
||||
{
|
||||
fillingImage.fillAmount = 0.0f;
|
||||
fillingImage.color = Color.red;
|
||||
deadText.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a98df6e31c94df993b83fcfbf7111e6
|
||||
timeCreated: 1749824203
|
||||
Reference in New Issue
Block a user