Esempio n. 1
0
        public void Execute(int idx)
        {
            MyTransform transform = transforms[idx];
            CharaData   chara     = charas[idx];

            //移動処理
            transform.position += chara.velocity * deltaTime;
            //時間の追加
            chara.time += deltaTime;
            //
            Vector3 forwardFromCamera = ECSCharaSystem.GetVectorFromCamera(cameraPosition, transform.position, chara.velocity);
            int     direction         = AppAnimationInfo.GetDirection(forwardFromCamera);//<-カメラと、キャラクターの向きを考慮してどの向きを向くかを決定します

            chara.rectIndex = ((int)(chara.time * 25.0f)) % animationLength + (direction * animationLength);

            transforms[idx] = transform;
            charas[idx]     = chara;
        }
Esempio n. 2
0
        /// <summary>
        /// Update時に行う処理です
        /// </summary>
        protected override void OnUpdate()
        {
            var charaGroup = this.GetComponentGroup(typeof(MyTransform), typeof(CharaData));
            var entities   = charaGroup.GetEntityArray();
            var charas     = charaGroup.GetComponentDataArray <CharaData>();
            var transforms = charaGroup.GetComponentDataArray <MyTransform>();

            var   deleteEntities = new NativeList <Entity>(0, Allocator.Temp);
            float deltaTime      = Time.deltaTime;

            int     animationLength = animationInfo.animationLength;
            Vector3 cameraPosition  = Camera.main.transform.position;

            characterNum = charas.Length;
#if NON_JOB
            // 更新処理
            for (int i = 0; i < charas.Length; ++i)
            {
                // データ取得
                MyTransform transform = transforms[i];
                CharaData   chara     = charas[i];

                //移動処理
                transform.position += chara.velocity * deltaTime;
                //時間の追加
                chara.time += deltaTime;


                Vector3 forwardFromCamera = GetVectorFromCamera(cameraPosition, transform.position, chara.velocity);
                int     direction         = AppAnimationInfo.GetDirection(forwardFromCamera);//<-カメラと、キャラクターの向きを考慮してどの向きを向くかを決定します
                chara.rectIndex = ((int)(chara.time * 25.0f)) % animationLength + (direction * animationLength);

                // 書き戻し
                transforms[i] = transform;
                charas[i]     = chara;
            }
#else
            UpdateJob updateJob = new UpdateJob()
            {
                charas          = charas,
                transforms      = transforms,
                deltaTime       = deltaTime,
                animationLength = animationLength,
                cameraPosition  = cameraPosition
            };
            var jobHandle = Unity.Jobs.IJobParallelForExtensions.Schedule(updateJob, charas.Length, 10);
            jobHandle.Complete();
#endif

            for (int i = 0; i < charas.Length; ++i)
            {
                CharaData chara = charas[i];
                // 削除処理
                if (chara.time > 10.0f)
                {
                    deleteEntities.Add(entities[i]);
                }
            }

            // 描画処理
            zPrepassCommandBuffer.Clear();
            actualCommandBuffer.Clear();
            int drawNum = 0;
            for (int i = 0; i < charas.Length; ++i)
            {
                if (drawNum >= InstanceDrawNum)
                {
                    DrawCharacter(drawNum);
                    drawNum = 0;
                }
                instancedBufferForMatrics[drawNum] = CreateMatrix(transforms[i].position, cameraPosition);
                instancedBufferForRects[drawNum]   = animationVectorInfo[charas[i].rectIndex];
                ++drawNum;
            }
            DrawCharacter(drawNum);


            // 削除リストにあったEntityの削除
            for (int i = 0; i < deleteEntities.Length; ++i)
            {
                this.EntityManager.DestroyEntity(deleteEntities[i]);
            }
            deleteEntities.Dispose();
        }