| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Threading; |
| | 4 | | using Cysharp.Threading.Tasks; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace AvatarSystem |
| | 8 | | { |
| | 9 | | public class BaseAvatar : IBaseAvatar |
| | 10 | | { |
| 0 | 11 | | public IBaseAvatarRevealer avatarRevealer { get; set; } |
| | 12 | | private ILOD lod; |
| | 13 | | private Transform avatarRevealerContainer; |
| 22 | 14 | | private CancellationTokenSource transitionCts = new CancellationTokenSource(); |
| | 15 | |
|
| | 16 | | public GameObject armatureContainer; |
| 0 | 17 | | public SkinnedMeshRenderer meshRenderer { get; private set; } |
| | 18 | |
|
| 22 | 19 | | public BaseAvatar(Transform avatarRevealerContainer, GameObject armatureContainer, ILOD lod) |
| | 20 | | { |
| 22 | 21 | | this.avatarRevealerContainer = avatarRevealerContainer; |
| 22 | 22 | | this.armatureContainer = armatureContainer; |
| 22 | 23 | | this.lod = lod; |
| 22 | 24 | | } |
| | 25 | |
|
| | 26 | | public GameObject GetArmatureContainer() |
| | 27 | | { |
| 0 | 28 | | return armatureContainer; |
| | 29 | | } |
| | 30 | |
|
| | 31 | | public SkinnedMeshRenderer GetMainRenderer() |
| | 32 | | { |
| 0 | 33 | | return avatarRevealer.GetMainRenderer(); |
| | 34 | | } |
| | 35 | |
|
| | 36 | | public void Initialize() |
| | 37 | | { |
| 0 | 38 | | if (avatarRevealer == null) |
| | 39 | | { |
| 0 | 40 | | avatarRevealer = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("LoadingAvatar"), avatarRevea |
| 0 | 41 | | avatarRevealer.InjectLodSystem(lod); |
| 0 | 42 | | } |
| | 43 | | else |
| | 44 | | { |
| 0 | 45 | | avatarRevealer.Reset(); |
| | 46 | | } |
| | 47 | |
|
| 0 | 48 | | meshRenderer = avatarRevealer.GetMainRenderer(); |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | public async UniTask FadeOut(MeshRenderer targetRenderer, bool withTransition, CancellationToken cancellationTok |
| | 52 | | { |
| 1 | 53 | | if (avatarRevealerContainer == null) |
| 0 | 54 | | return; |
| | 55 | |
|
| 1 | 56 | | transitionCts ??= new CancellationTokenSource(); |
| 1 | 57 | | CancellationToken linkedCt = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, transitionCt |
| 1 | 58 | | linkedCt.ThrowIfCancellationRequested(); |
| | 59 | |
|
| 1 | 60 | | avatarRevealer.AddTarget(targetRenderer); |
| | 61 | | //If canceled, the final state of the avatar is handle inside StartAvatarRevealAnimation |
| 1 | 62 | | await avatarRevealer.StartAvatarRevealAnimation(withTransition, linkedCt); |
| | 63 | |
|
| 1 | 64 | | transitionCts?.Dispose(); |
| 1 | 65 | | transitionCts = null; |
| 1 | 66 | | } |
| | 67 | |
|
| | 68 | | public void CancelTransition() |
| | 69 | | { |
| 0 | 70 | | transitionCts?.Cancel(); |
| 0 | 71 | | transitionCts?.Dispose(); |
| 0 | 72 | | transitionCts = null; |
| 0 | 73 | | } |
| | 74 | |
|
| | 75 | | } |
| | 76 | | } |