public void CreateCharacter(GameObject pReference) { EntityManager tEntityManager = World.Active.EntityManager; GameObject tObjectMono = Instantiate(pReference); EntityArchetype tArchetype = tEntityManager.CreateArchetype(typeof(ObjectTransform), typeof(ObjectAnimator)); Entity tEntity = tEntityManager.CreateEntity(tArchetype); tEntityManager.SetComponentData(tEntity, new ObjectTransform { Direction = new float3(0, 0, 1), Position = float3.zero, Velocity = 0.06f, MonoBehaviorID = tObjectMono.GetInstanceID() }); tEntityManager.SetComponentData(tEntity, new ObjectAnimator { MonoBehaviorID = tObjectMono.GetInstanceID(), Animation = Animation.Idle }); MonobehaviorTransformPresentation tMonoTranformPresentation = World.Active.GetOrCreateSystem <MonobehaviorTransformPresentation>(); ReferenceTransformMono tReferenceTranformMono = new ReferenceTransformMono { ObjectID = tObjectMono.GetInstanceID(), ObjectTransformReference = tObjectMono.transform }; tMonoTranformPresentation.m_ReferenceMonos.Add(tReferenceTranformMono); tMonoTranformPresentation.m_ReferenceMonos.Sort(new MonoTransformComparer()); MonobehaviorAnimationPresentation tMonoAnimatorPresentation = World.Active.GetOrCreateSystem <MonobehaviorAnimationPresentation>(); ReferenceAnimatorMono tReferenceAnimatorMono = new ReferenceAnimatorMono { ObjectID = tObjectMono.GetInstanceID(), ObjectAnimatorReference = tObjectMono.GetComponent <Animator>() }; tMonoAnimatorPresentation.m_ReferenceMonos.Add(tReferenceAnimatorMono); tMonoAnimatorPresentation.m_ReferenceMonos.Sort(new MonoAnimationComparer()); }
protected override void OnUpdate() { var tMonoComparer = new MonoAnimationComparer(); var tReferenceMono = new ReferenceAnimatorMono(); Entities.ForEach((ref ObjectAnimator pObjectEntity) => { tReferenceMono.ObjectID = pObjectEntity.MonoBehaviorID; int tIndex = m_ReferenceMonos.BinarySearch(tReferenceMono, tMonoComparer); if (tIndex > -1) { AnimatorClipInfo tCurrentClip = m_ReferenceMonos[tIndex].ObjectAnimatorReference.GetCurrentAnimatorClipInfo(0)[0]; if (String.Compare(tCurrentClip.clip.name, pObjectEntity.Animation.ToString(), StringComparison.Ordinal) != 0) { var tAnimatorControllerParams = m_ReferenceMonos[tIndex].ObjectAnimatorReference.parameters; for (var j = 0; j < tAnimatorControllerParams.Length; j++) { if (tAnimatorControllerParams[j].type == AnimatorControllerParameterType.Bool) { m_ReferenceMonos[tIndex].ObjectAnimatorReference.SetBool(tAnimatorControllerParams[j].name, false); } if (String.CompareOrdinal(tAnimatorControllerParams[j].name, pObjectEntity.Animation.ToString()) == 0) { if (tAnimatorControllerParams[j].type == AnimatorControllerParameterType.Bool) { m_ReferenceMonos[tIndex].ObjectAnimatorReference .SetBool(pObjectEntity.Animation.ToString(), true); } else if (tAnimatorControllerParams[j].type == AnimatorControllerParameterType.Trigger) { m_ReferenceMonos[tIndex].ObjectAnimatorReference .SetTrigger(pObjectEntity.Animation.ToString()); } } } } } }); }