Created
January 3, 2021 09:16
-
-
Save sarkahn/78ca665a858ddae16287f6d2047857bb to your computer and use it in GitHub Desktop.
ECS with UGUI Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Unity.Entities; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class PlayerHealthUIAuthoring : MonoBehaviour, IConvertGameObjectToEntity | |
{ | |
[SerializeField] | |
TMPro.TMP_Text _uiText; | |
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) | |
{ | |
dstManager.AddComponentData(entity, new PlayerHealthUI | |
{ | |
Text = _uiText | |
}); | |
} | |
} | |
public class PlayerHealthUI : IComponentData | |
{ | |
public TMPro.TMP_Text Text; | |
} | |
public struct Health : IComponentData | |
{ | |
public int Value; | |
} | |
public class UpdateHealthUISystem : SystemBase | |
{ | |
protected override void OnUpdate() | |
{ | |
Entities | |
.WithoutBurst() | |
.WithChangeFilter<Health>() | |
.ForEach((PlayerHealthUI healthUI, | |
in Health health) => | |
{ | |
healthUI.Text.text = health.Value.ToString(); | |
}).Run(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment