using TMPro; using Unity.Collections; using Unity.Entities; using UnityEngine; ///////////////////////////////////////////////////////////////////////////////// namespace Rukhanka.Samples { class UILabelSetter_AnimatorStateQuery: MonoBehaviour { public TextMeshProUGUI stateInfoLabel; public TextMeshProUGUI transitionInfoLabel; public TextMeshProUGUI sampleDescription; EntityManager em; EntityQuery animatorsQuery; ///////////////////////////////////////////////////////////////////////////////// void Start() { var worlds = World.All; foreach (var w in worlds) { if (RukhankaSystemsBootstrap.IsClientOrLocalSimulationWorld(w)) { em = w.EntityManager; break; } } var ecb0 = new EntityQueryBuilder(Allocator.Temp) .WithAll(); animatorsQuery = em.CreateEntityQuery(ecb0); #if !RUKHANKA_DEBUG_INFO sampleDescription.text += " Define RUKHANKA_DEBUG_INFO script symbol to view state and transition names."; #endif } ///////////////////////////////////////////////////////////////////////////////// void OnDestroy() { } ///////////////////////////////////////////////////////////////////////////////// void Update() { var animatedEntites = animatorsQuery.ToEntityArray(Allocator.Temp); if (animatedEntites.Length > 0) { var e = animatedEntites[0]; var aclc = em.GetBuffer(e); var a = new AnimatorStateQueryAspect(aclc); var stateInfo = a.GetLayerCurrentStateInfo(0); var transitionInfo = a.GetLayerCurrentTransitionInfo(0); #if RUKHANKA_DEBUG_INFO stateInfoLabel.text = $"Current State: name '{stateInfo.name}', hash '{stateInfo.hash}', and time '{stateInfo.normalizedTime:F2}'"; #else stateInfoLabel.text = $"Current State: hash '{stateInfo.hash}', and time '{stateInfo.normalizedTime:F2}'"; #endif if (transitionInfo.hash != 0) #if RUKHANKA_DEBUG_INFO transitionInfoLabel.text = $"Current Transition: name '{transitionInfo.name}', hash '{transitionInfo.hash}' and time '{transitionInfo.normalizedTime:F2}'"; #else transitionInfoLabel.text = $"Current Transition: hash '{transitionInfo.hash}' and time '{transitionInfo.normalizedTime:F2}'"; #endif else transitionInfoLabel.text = $"Not in transition"; } } } }