Beispiel #1
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            dstManager.AddComponentData(entity, new CopyTransformToGameObject());

            PlayerCameraFollowData cameraFollow = dstManager.GetComponentData <PlayerCameraFollowData>(entity);
            Rotation cameraRotation             = dstManager.GetComponentData <Rotation>(entity);

            cameraFollow.currentPivotRotation  = cameraFollow.targetPivotRotation = quaternion.Euler(0, math.radians(225), 0);
            cameraFollow.currentPositionOffset = cameraFollow.targetPositionOffset;
            cameraRotation.Value = cameraFollow.currentPivotRotation;

            dstManager.SetComponentData <PlayerCameraFollowData>(entity, cameraFollow);
            dstManager.SetComponentData <Rotation>(entity, cameraRotation);

            PlayerCameraOrientationSystem cameraOrientationSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <PlayerCameraOrientationSystem>();

            cameraOrientationSystem.FollowEntity = cameraFollow.followEntity;
        }
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <Rotation>               rotations         = chunk.GetNativeArray(this.rotationType);
                NativeArray <Translation>            translations      = chunk.GetNativeArray(this.translationType);
                NativeArray <PlayerCameraFollowData> cameraFollowDatas = chunk.GetNativeArray(this.cameraFollowDataType);

                for (int ci = 0, cn = chunk.Count; ci < cn; ci++)
                {
                    PlayerCameraFollowData cameraFollow      = cameraFollowDatas[ci];
                    Translation            cameraTranslation = translations[ci];
                    Rotation cameraRotation = rotations[ci];

                    // Set camera orientation

                    quaternion currentPivotRotation  = UnityEngine.Quaternion.Lerp(cameraFollow.currentPivotRotation, cameraFollow.targetPivotRotation, cameraFollow.rotationSmoothFactor * deltaTime);
                    float3     currentFollowPosition = math.lerp(cameraFollow.currentFollowPosition, this.followPosition, cameraFollow.positionSmoothFactor * deltaTime);

                    float3     basePositionOffset = new float3(0f, cameraFollow.height, cameraFollow.distance);
                    float3     targetPosition     = currentFollowPosition + math.mul(currentPivotRotation, basePositionOffset);
                    quaternion targetRotation     = quaternion.LookRotation(math.normalize(currentFollowPosition - targetPosition), math.up());

                    float3   currentPositionOffset = math.lerp(cameraFollow.currentPositionOffset, cameraFollow.targetPositionOffset, cameraFollow.positionSmoothFactor * deltaTime);
                    float3x3 rotationMatrix        = new float3x3(currentPivotRotation);
                    float3   worldOffset           = math.mul(rotationMatrix, currentPositionOffset);
                    targetPosition += worldOffset;

                    // Set data

                    cameraFollow.currentFollowPosition = currentFollowPosition;
                    cameraFollow.currentPivotRotation  = currentPivotRotation;
                    cameraFollow.currentPositionOffset = currentPositionOffset;

                    cameraTranslation.Value = targetPosition;
                    cameraRotation.Value    = targetRotation;

                    // Apply changes

                    cameraFollowDatas[ci] = cameraFollow;
                    translations[ci]      = cameraTranslation;
                    rotations[ci]         = cameraRotation;
                }
            }
Beispiel #3
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <PlayerCameraFollowData> cameraFollowDatas = chunk.GetNativeArray(this.cameraFollowDataType);

                for (int ci = 0, cn = chunk.Count; ci < cn; ci++)
                {
                    PlayerCameraFollowData cameraFollow = cameraFollowDatas[ci];

                    // Rotate left/right based on input

                    if (rotateLeftInput)
                    {
                        cameraFollow.targetPivotRotation = math.mul(cameraFollow.targetPivotRotation, quaternion.Euler(0, math.PI / 2, 0));
                    }
                    if (rotateRightInput)
                    {
                        cameraFollow.targetPivotRotation = math.mul(cameraFollow.targetPivotRotation, quaternion.Euler(0, -(math.PI / 2), 0));
                    }

                    // Apply changes

                    cameraFollowDatas[ci] = cameraFollow;
                }
            }