コード例 #1
0
    /// <summary>
    /// 更新処理
    /// </summary>
    void Update()
    {
        // ここで発行したジョブの同期をします
        this.nextFrameSyncHandle.Complete();

        // キャラをパラパラ動かします
        // ここは MainThreadで
        UnityEngine.Profiling.Profiler.BeginSample("SetAllCharaRect");
        int animationLength = animationInfo.animationLength;

        for (int i = 0; i < characterNum; ++i)
        {
            int rectIndex = ((int)(i * 0.3f + Time.realtimeSinceStartup * 25.0f)) % animationLength;
            boardRenderers[i].SetRect(animationInfo.GetUvRect(rectIndex));
        }
        UnityEngine.Profiling.Profiler.EndSample();

        // 全キャラクターの移動処理を行います
        Vector3 cameraPosition = Camera.main.transform.position;

        cameraPosition.y = 0.5f;
        var characterMoveJob = new CharacterMoveJob()
        {
            deltaTime            = Time.deltaTime,
            realtimeSinceStartup = Time.realtimeSinceStartup,
            cameraPosition       = cameraPosition
        };

        nextFrameSyncHandle = characterMoveJob.Schedule(transformAccessArray);
        JobHandle.ScheduleBatchedJobs();
    }
コード例 #2
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        if (!CameraTransform)
        {
            return(inputDependencies);
        }

        // TODO: convert to use the cameraData entity
        Vector3    cameraPlanarForward  = Vector3.ProjectOnPlane(CameraTransform.forward, Vector3.up).normalized;
        Vector3    cameraPlanarRight    = Vector3.ProjectOnPlane(CameraTransform.right, Vector3.up).normalized;
        Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarForward, Vector3.up);

        PlayerInputsToCharacterInputsJob playerInputsToCharacterInputsJob = new PlayerInputsToCharacterInputsJob();

        playerInputsToCharacterInputsJob.CameraPlanarForwardDirection = cameraPlanarForward;
        playerInputsToCharacterInputsJob.CameraPlanarRightDirection   = cameraPlanarRight;
        playerInputsToCharacterInputsJob.CameraPlanarRotation         = cameraPlanarRotation;
        playerInputsToCharacterInputsJob.GameplayInputsFromEntity     = GetComponentDataFromEntity <GameplayInputs>();
        inputDependencies = playerInputsToCharacterInputsJob.Schedule(this, inputDependencies);

        CharacterMoveJob characterMoveSystemJob = new CharacterMoveJob();

        characterMoveSystemJob.deltaTime = Time.deltaTime;
        inputDependencies = characterMoveSystemJob.Schedule(this, inputDependencies);

        return(inputDependencies);
    }
コード例 #3
0
    /// <summary>
    /// 更新処理
    /// </summary>
    void Update()
    {
        Vector3 cameraPosition = Camera.main.transform.position;

        cameraPosition.y = 0.0f;

        nextFrameSyncHandle.Complete();
        // RayCastHitの作成
        float rayLength = Time.deltaTime * 3.0f;
        var   createRaycastCommandJob = new CreateRaycastJob()
        {
            rayLength       = rayLength,
            rayCastCommands = this.rayCastCommmands,
            velocities      = this.velocities
        };

        // キャラクターの移動Job
        var characterJob = new CharacterMoveJob()
        {
            velocities           = this.velocities,
            drawParameter        = this.drawParameter,
            rayCastResults       = rayCastResults,
            cameraPosition       = cameraPosition,
            deltaTime            = Time.deltaTime,
            realtimeSinceStartup = Time.realtimeSinceStartup,
            animationLength      = animationInfo.animationLength,
            animationRectInfo    = this.animationRectInfo
        };


        // raycast のJob化
        JobHandle rayCastJobHandle = RaycastCommand.ScheduleBatch(rayCastCommmands, rayCastResults, 1);

        JobHandle.ScheduleBatchedJobs();

        // Rectの指定
        for (int i = 0; i < characterNum; ++i)
        {
            boardRenderers[i].SetRect(drawParameter[i]);
        }
        var moveJobHandl = characterJob.Schedule(transformAccessArray, rayCastJobHandle);

        nextFrameSyncHandle = createRaycastCommandJob.Schedule(this.transformAccessArray, moveJobHandl);
        JobHandle.ScheduleBatchedJobs();
    }