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