Post by Admin on Jul 16, 2016 4:21:51 GMT
astro75 @astro75 Sep 10 2015 00:20
What is the best way to push unity Canvas UI events to Entitas?
astro75 @astro75 Sep 10 2015 01:07
This seems to work
public class UIEventsToEntitas : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
public Entity entity;
internal void Start() {
entity.Retain();
}
internal void OnDestroy() {
entity.Release();
}
public void OnPointerEnter(PointerEventData eventData) {
entity.ReplacePointerState(Enums.PointerState.OVER);
}
public void OnPointerExit(PointerEventData eventData) {
entity.ReplacePointerState(Enums.PointerState.NONE);
}
}
zyzyx @zyzyxdev Sep 10 2015 19:11
is this the correct way handling unity ui event? how do you use it?
Simon Schmid @sschmid Sep 10 2015 19:36
In my current project I don’t redirect them to Entitas. I only translate their effects, e.g. a button that regenerates health for coins, in OnButtonClicked I can do stuff like
pool.playerEntity.ReplaceHealth(pool.playerEntity.health.value + 100);
pool.ReplaceCoins(pool.coins.value - 50);
I currently just convert input from the Unity Input class to actual entities like in Match One InputController
What is the best way to push unity Canvas UI events to Entitas?
astro75 @astro75 Sep 10 2015 01:07
This seems to work
public class UIEventsToEntitas : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
public Entity entity;
internal void Start() {
entity.Retain();
}
internal void OnDestroy() {
entity.Release();
}
public void OnPointerEnter(PointerEventData eventData) {
entity.ReplacePointerState(Enums.PointerState.OVER);
}
public void OnPointerExit(PointerEventData eventData) {
entity.ReplacePointerState(Enums.PointerState.NONE);
}
}
zyzyx @zyzyxdev Sep 10 2015 19:11
is this the correct way handling unity ui event? how do you use it?
Simon Schmid @sschmid Sep 10 2015 19:36
In my current project I don’t redirect them to Entitas. I only translate their effects, e.g. a button that regenerates health for coins, in OnButtonClicked I can do stuff like
pool.playerEntity.ReplaceHealth(pool.playerEntity.health.value + 100);
pool.ReplaceCoins(pool.coins.value - 50);
I currently just convert input from the Unity Input class to actual entities like in Match One InputController