| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using UnityEngine; |
| | 7 | | using Decentraland.Sdk.Ecs6; |
| | 8 | |
|
| | 9 | | namespace DCL.Components |
| | 10 | | { |
| | 11 | | public class AvatarAttachComponent : IEntityComponent |
| | 12 | | { |
| | 13 | | [Serializable] |
| | 14 | | public class Model : BaseModel |
| | 15 | | { |
| | 16 | | public string avatarId; |
| | 17 | | public int anchorPointId; |
| | 18 | |
|
| | 19 | | public override BaseModel GetDataFromJSON(string json) => |
| 1 | 20 | | Utils.SafeFromJson<Model>(json); |
| | 21 | |
|
| | 22 | | public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) |
| | 23 | | { |
| 0 | 24 | | if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.AttachToAvatar) |
| 0 | 25 | | return Utils.SafeUnimplemented<AvatarAttachComponent, Model>(expected: ComponentBodyPayload.PayloadO |
| | 26 | |
|
| 0 | 27 | | var pb = new Model(); |
| 0 | 28 | | if (pbModel.AttachToAvatar.HasAvatarId) pb.avatarId = pbModel.AttachToAvatar.AvatarId; |
| 0 | 29 | | if (pbModel.AttachToAvatar.HasAnchorPointId) pb.anchorPointId = (int)pbModel.AttachToAvatar.AnchorPointI |
| | 30 | |
|
| 0 | 31 | | return pb; |
| | 32 | | } |
| | 33 | | } |
| | 34 | |
|
| 0 | 35 | | IParcelScene IComponent.scene => handler.scene; |
| 0 | 36 | | IDCLEntity IEntityComponent.entity => handler.entity; |
| | 37 | |
|
| 4 | 38 | | string IComponent.componentName => "AvatarAttach"; |
| | 39 | |
|
| 1 | 40 | | private readonly AvatarAttachHandler handler = new AvatarAttachHandler(); |
| | 41 | |
|
| | 42 | | void IEntityComponent.Initialize(IParcelScene scene, IDCLEntity entity) |
| | 43 | | { |
| 1 | 44 | | handler.Initialize(scene, entity, Environment.i.platform.updateEventHandler); |
| 1 | 45 | | } |
| | 46 | |
|
| 0 | 47 | | bool IComponent.IsValid() => true; |
| | 48 | |
|
| 0 | 49 | | BaseModel IComponent.GetModel() => handler.model; |
| | 50 | |
|
| 1 | 51 | | int IComponent.GetClassId() => (int)CLASS_ID_COMPONENT.AVATAR_ATTACH; |
| | 52 | |
|
| | 53 | | void IComponent.UpdateFromPb(ComponentBodyPayload payload) |
| | 54 | | { |
| 0 | 55 | | handler.OnModelUpdated(handler.model.GetDataFromPb(payload) as Model); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | void IComponent.UpdateFromJSON(string json) |
| | 59 | | { |
| 1 | 60 | | handler.OnModelUpdated(json); |
| 1 | 61 | | } |
| | 62 | |
|
| | 63 | | void IComponent.UpdateFromModel(BaseModel newModel) |
| | 64 | | { |
| 0 | 65 | | handler.OnModelUpdated(newModel as Model); |
| 0 | 66 | | } |
| | 67 | |
|
| | 68 | | IEnumerator IComponent.ApplyChanges(BaseModel newModel) |
| | 69 | | { |
| 0 | 70 | | yield break; |
| | 71 | | } |
| | 72 | |
|
| 0 | 73 | | void IComponent.RaiseOnAppliedChanges() { } |
| | 74 | |
|
| 2 | 75 | | Transform IMonoBehaviour.GetTransform() => null; |
| | 76 | |
|
| 1 | 77 | | void ICleanable.Cleanup() => handler.Dispose(); |
| | 78 | | } |
| | 79 | | } |