| | 1 | | using System; |
| | 2 | | using DCL.CameraTool; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.ECSComponents |
| | 7 | | { |
| | 8 | | public static class ProtoConvertUtils |
| | 9 | | { |
| | 10 | | public static PBOnPointerUpResult GetPointerUpResultModel(ActionButton buttonId, string meshName, Ray ray, HitIn |
| | 11 | | { |
| 1 | 12 | | PBOnPointerUpResult result = new PBOnPointerUpResult(); |
| 1 | 13 | | result.Button = buttonId; |
| 1 | 14 | | result.Direction = UnityVectorToPBVector(ray.direction); |
| 1 | 15 | | result.Distance = hit.distance; |
| 1 | 16 | | result.Normal = UnityVectorToPBVector(hit.normal); |
| 1 | 17 | | result.Origin = UnityVectorToPBVector(ray.origin); |
| 1 | 18 | | result.Point = UnityVectorToPBVector(hit.point); |
| | 19 | |
|
| | 20 | | // This null check will disappear when we introduce optionals to the proto |
| 1 | 21 | | if(meshName == null) |
| 1 | 22 | | meshName = String.Empty; |
| 1 | 23 | | result.MeshName = meshName; |
| 1 | 24 | | return result; |
| | 25 | | } |
| | 26 | |
|
| | 27 | | public static PBOnPointerDownResult GetPointerDownResultModel(ActionButton buttonId, string meshName, Ray ray, H |
| | 28 | | { |
| 1 | 29 | | PBOnPointerDownResult result = new PBOnPointerDownResult(); |
| 1 | 30 | | result.Button = buttonId; |
| 1 | 31 | | result.Direction = UnityVectorToPBVector(ray.direction); |
| 1 | 32 | | result.Distance = hit.distance; |
| 1 | 33 | | result.Normal = UnityVectorToPBVector(hit.normal); |
| 1 | 34 | | result.Origin = UnityVectorToPBVector(ray.origin); |
| 1 | 35 | | result.Point = UnityVectorToPBVector(hit.point); |
| | 36 | |
|
| | 37 | | // This null check will disappear when we introduce optionals to the proto |
| 1 | 38 | | if(meshName == null) |
| 1 | 39 | | meshName = String.Empty; |
| 1 | 40 | | result.MeshName = meshName; |
| 1 | 41 | | return result; |
| | 42 | | } |
| | 43 | |
|
| | 44 | | public static Vector3 UnityVectorToPBVector(UnityEngine.Vector3 original) |
| | 45 | | { |
| 8 | 46 | | Vector3 vector = new Vector3(); |
| 8 | 47 | | vector.X = original.x; |
| 8 | 48 | | vector.Y = original.y; |
| 8 | 49 | | vector.Z = original.z; |
| 8 | 50 | | return vector; |
| | 51 | | } |
| | 52 | |
|
| | 53 | | public static UnityEngine.Vector3 PBVectorToUnityVector(Vector3 original) |
| | 54 | | { |
| 6 | 55 | | UnityEngine.Vector3 vector = new UnityEngine.Vector3(); |
| 6 | 56 | | vector.x = original.X; |
| 6 | 57 | | vector.y = original.Y; |
| 6 | 58 | | vector.z = original.Z; |
| 6 | 59 | | return vector; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public static CameraMode.ModeId PBCameraEnumToUnityEnum(CameraModeValue mode) |
| | 63 | | { |
| | 64 | | switch (mode) |
| | 65 | | { |
| | 66 | | case CameraModeValue.FirstPerson: |
| 4 | 67 | | return CameraMode.ModeId.FirstPerson; |
| | 68 | | case CameraModeValue.ThirdPerson: |
| 0 | 69 | | return CameraMode.ModeId.ThirdPerson; |
| | 70 | | default: |
| 0 | 71 | | return CommonScriptableObjects.cameraMode.Get(); |
| | 72 | | } |
| | 73 | | } |
| | 74 | |
|
| | 75 | | public static CameraModeValue UnityEnumToPBCameraEnum(CameraMode.ModeId mode) |
| | 76 | | { |
| | 77 | | switch (mode) |
| | 78 | | { |
| | 79 | | case CameraMode.ModeId.FirstPerson: |
| 0 | 80 | | return CameraModeValue.FirstPerson; |
| | 81 | | case CameraMode.ModeId.ThirdPerson: |
| | 82 | | default: |
| 0 | 83 | | return CameraModeValue.ThirdPerson; |
| | 84 | | } |
| | 85 | | } |
| | 86 | |
|
| | 87 | | public static Color ToUnityColor(this Color3 color) |
| | 88 | | { |
| 12 | 89 | | return new Color(color.R, color.G, color.B); |
| | 90 | | } |
| | 91 | | } |
| | 92 | | } |