| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.IO; |
| | 8 | | using System.Linq; |
| | 9 | | using UnityEngine; |
| | 10 | | using UnityGLTF; |
| | 11 | |
|
| | 12 | | namespace AvatarShape_Tests |
| | 13 | | { |
| | 14 | | public static class AvatarShapeTestHelpers |
| | 15 | | { |
| | 16 | | public static AvatarShape CreateAvatarShape(ParcelScene scene, string name, string fileName) |
| | 17 | | { |
| | 18 | | var model = GetTestAvatarModel(name, fileName); |
| | 19 | |
|
| | 20 | | return CreateAvatarShape(scene, model); |
| | 21 | | } |
| | 22 | |
|
| | 23 | | public static AvatarShape CreateAvatarShape(ParcelScene scene, AvatarModel model) |
| | 24 | | { |
| | 25 | | GLTFSceneImporter.budgetPerFrameInMilliseconds = float.MaxValue; |
| | 26 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 27 | | AvatarShape shape = TestHelpers.EntityComponentCreate<AvatarShape, AvatarModel>(scene, entity, model, CLASS_ |
| | 28 | | TestHelpers.SetEntityTransform(scene, entity, new Vector3(0, 0, 0), Quaternion.identity, Vector3.one); |
| | 29 | | return shape; |
| | 30 | | } |
| | 31 | |
|
| | 32 | | public static AvatarModel GetTestAvatarModel(string name, string fileName) |
| | 33 | | { |
| | 34 | | var avatarjson = File.ReadAllText(TestAssetsUtils.GetPathRaw() + "/Avatar/" + fileName); |
| | 35 | | AvatarModel model = JsonUtility.FromJson<AvatarModel>(avatarjson); |
| | 36 | | model.name = name; |
| | 37 | | return model; |
| | 38 | | } |
| | 39 | | } |
| | 40 | |
|
| | 41 | | class AvatarRenderer_Mock : AvatarRenderer |
| | 42 | | { |
| | 43 | | public static Dictionary<string, WearableController_Mock> GetWearableMockControllers(AvatarRenderer renderer) |
| | 44 | | { |
| | 45 | | var controllers = GetWearableControllers(renderer); |
| | 46 | | return controllers.ToDictionary(x => x.Key, x => new WearableController_Mock(x.Value)); |
| | 47 | | } |
| | 48 | |
|
| | 49 | | public static Dictionary<string, WearableController> GetWearableControllers(AvatarRenderer renderer) |
| | 50 | | { |
| | 51 | | var avatarRendererMock = new GameObject("Temp").AddComponent<AvatarRenderer_Mock>(); |
| | 52 | | avatarRendererMock.CopyFrom(renderer); |
| | 53 | |
|
| | 54 | | var result = |
| | 55 | | avatarRendererMock.wearableControllers.ToDictionary(x => x.Value.id, y => y.Value); |
| | 56 | |
|
| | 57 | | Destroy(avatarRendererMock.gameObject); |
| | 58 | |
|
| | 59 | | return result; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public static WearableController_Mock GetWearableController(AvatarRenderer renderer, string id) |
| | 63 | | { |
| | 64 | | var wearableControllers = GetWearableControllers(renderer); |
| | 65 | |
|
| | 66 | | if (!wearableControllers.ContainsKey(id)) |
| | 67 | | return null; |
| | 68 | |
|
| | 69 | | return new WearableController_Mock(wearableControllers[id]); |
| | 70 | | } |
| | 71 | |
|
| | 72 | | public static BodyShapeController_Mock GetBodyShapeController(AvatarRenderer renderer) |
| | 73 | | { |
| | 74 | | var bodyShapeController = GetBodyShape(renderer); |
| | 75 | | if (bodyShapeController == null) |
| | 76 | | return null; |
| | 77 | |
|
| | 78 | | return new BodyShapeController_Mock(bodyShapeController); |
| | 79 | | } |
| | 80 | |
|
| | 81 | | public static BodyShapeController GetBodyShape(AvatarRenderer renderer) |
| | 82 | | { |
| | 83 | | var avatarRendererMock = new GameObject("Temp").AddComponent<AvatarRenderer_Mock>(); |
| | 84 | | avatarRendererMock.CopyFrom(renderer); |
| | 85 | |
|
| | 86 | | var toReturn = avatarRendererMock.bodyShapeController; |
| | 87 | | Destroy(avatarRendererMock.gameObject); |
| | 88 | |
|
| | 89 | | return toReturn; |
| | 90 | | } |
| | 91 | |
|
| | 92 | | protected override void OnDestroy() { } //Override OnDestroy to prevent mock renderer from resetting the Avatar |
| | 93 | | } |
| | 94 | |
|
| | 95 | | class WearableController_Mock : WearableController |
| | 96 | | { |
| | 97 | | public WearableController_Mock(WearableItem wearableItem) : base(wearableItem) { } |
| | 98 | |
|
| | 99 | | public WearableController_Mock(WearableController original) : base(original) { } |
| | 100 | |
|
| | 101 | | public Renderer[] myAssetRenderers => assetRenderers; |
| | 102 | | public GameObject myAssetContainer => assetContainer; |
| | 103 | | public RendereableAssetLoadHelper myLoader => loader; |
| | 104 | | } |
| | 105 | |
|
| | 106 | | class BodyShapeController_Mock : BodyShapeController |
| | 107 | | { |
| 0 | 108 | | public BodyShapeController_Mock(WearableItem original) : base(original) { } |
| | 109 | |
|
| 0 | 110 | | public BodyShapeController_Mock(BodyShapeController original) : base(original) { } |
| | 111 | |
|
| 0 | 112 | | public Renderer[] myAssetRenderers => assetRenderers; |
| 0 | 113 | | public GameObject myAssetContainer => this.assetContainer; |
| | 114 | | } |
| | 115 | | } |