コード例 #1
0
    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 MonoTransformComparer();
        var tReferenceMono = new ReferenceTransformMono();


        Entities.ForEach((ref ObjectTransform pObjectEntity) =>
        {
            tReferenceMono.ObjectID = pObjectEntity.MonoBehaviorID;
            int tIndex = m_ReferenceMonos.BinarySearch(tReferenceMono, tMonoComparer);
            if (tIndex > -1)
            {
                m_ReferenceMonos[tIndex].ObjectTransformReference.position = pObjectEntity.Position;
                m_ReferenceMonos[tIndex].ObjectTransformReference.rotation =
                    Quaternion.LookRotation(pObjectEntity.Direction, Vector3.up);
            }
        });
    }