| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.ECSRuntime; |
| | 3 | | using DCL.Models; |
| | 4 | |
|
| | 5 | | namespace DCL.ECSComponents |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// This class will handle the avatar shape for the global scenes and the scenes that use it |
| | 9 | | /// Take into account that this component uses a pool to manage the prefabs |
| | 10 | | /// </summary> |
| | 11 | | public class AvatarShapeComponentHandler : IECSComponentHandler<PBAvatarShape> |
| | 12 | | { |
| | 13 | | internal IAvatarShape avatar; |
| | 14 | | private readonly Pool pool; |
| | 15 | | private readonly PoolableObject poolableObject; |
| | 16 | |
|
| | 17 | | private bool isAvatarInitialized = false; |
| | 18 | |
|
| 3 | 19 | | public AvatarShapeComponentHandler(Pool pool) |
| | 20 | | { |
| 3 | 21 | | this.pool = pool; |
| 3 | 22 | | poolableObject = pool.Get(); |
| 3 | 23 | | avatar = poolableObject.gameObject.GetComponent<AvatarShape>(); |
| 3 | 24 | | } |
| | 25 | |
|
| | 26 | | public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) |
| | 27 | | { |
| 5 | 28 | | avatar.transform.SetParent(entity.gameObject.transform, false); |
| 5 | 29 | | } |
| | 30 | |
|
| | 31 | | public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity) |
| | 32 | | { |
| 4 | 33 | | if (avatar == null) |
| 1 | 34 | | return; |
| | 35 | |
|
| 3 | 36 | | avatar.Cleanup(); |
| 3 | 37 | | pool.Release(poolableObject); |
| 3 | 38 | | avatar = null; |
| 3 | 39 | | isAvatarInitialized = false; |
| 3 | 40 | | } |
| | 41 | |
|
| | 42 | | public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBAvatarShape model) |
| | 43 | | { |
| 2 | 44 | | if (!isAvatarInitialized) |
| | 45 | | { |
| 2 | 46 | | avatar.Init(); |
| 2 | 47 | | isAvatarInitialized = true; |
| | 48 | | } |
| 2 | 49 | | avatar.ApplyModel(scene,entity,model); |
| 2 | 50 | | } |
| | 51 | | } |
| | 52 | | } |