| | 1 | | using System.Collections; |
| | 2 | | using System.Net.Configuration; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Components |
| | 8 | | { |
| | 9 | | public class DCLTransform : IEntityComponent |
| | 10 | | { |
| | 11 | | [System.Serializable] |
| | 12 | | public class Model : BaseModel |
| | 13 | | { |
| 66 | 14 | | public Vector3 position = Vector3.zero; |
| 66 | 15 | | public Quaternion rotation = Quaternion.identity; |
| 66 | 16 | | public Vector3 scale = Vector3.one; |
| | 17 | |
|
| | 18 | | public override BaseModel GetDataFromJSON(string json) |
| | 19 | | { |
| 230 | 20 | | MessageDecoder.DecodeTransform(json, ref DCLTransform.model); |
| 230 | 21 | | return DCLTransform.model; |
| | 22 | | } |
| | 23 | | } |
| | 24 | |
|
| 1 | 25 | | public static Model model = new Model(); |
| | 26 | |
|
| 60 | 27 | | public void Cleanup() { } |
| | 28 | |
|
| 204 | 29 | | public string componentName { get; } = "Transform"; |
| 0 | 30 | | public IParcelScene scene { get; private set; } |
| 0 | 31 | | public IDCLEntity entity { get; private set; } |
| 0 | 32 | | public Transform GetTransform() => null; |
| | 33 | |
|
| | 34 | | public void Initialize(IParcelScene scene, IDCLEntity entity) |
| | 35 | | { |
| 204 | 36 | | this.scene = scene; |
| 204 | 37 | | this.entity = entity; |
| 204 | 38 | | } |
| | 39 | |
|
| | 40 | | public void UpdateFromJSON(string json) |
| | 41 | | { |
| 230 | 42 | | model.GetDataFromJSON(json); |
| 230 | 43 | | UpdateFromModel(model); |
| 230 | 44 | | } |
| | 45 | |
|
| | 46 | | public void UpdateFromModel(BaseModel model) |
| | 47 | | { |
| 262 | 48 | | DCLTransform.model = model as Model; |
| | 49 | |
|
| 262 | 50 | | if (entity.OnTransformChange != null) // AvatarShape interpolation hack |
| | 51 | | { |
| 1 | 52 | | entity.OnTransformChange.Invoke(DCLTransform.model); |
| 1 | 53 | | } |
| | 54 | | else |
| | 55 | | { |
| 261 | 56 | | entity.gameObject.transform.localPosition = DCLTransform.model.position; |
| 261 | 57 | | entity.gameObject.transform.localRotation = DCLTransform.model.rotation; |
| 261 | 58 | | entity.gameObject.transform.localScale = DCLTransform.model.scale; |
| | 59 | |
|
| 261 | 60 | | DCL.Environment.i.world.sceneBoundsChecker?.AddEntityToBeChecked(entity); |
| | 61 | | } |
| 261 | 62 | | } |
| | 63 | |
|
| 0 | 64 | | public IEnumerator ApplyChanges(BaseModel model) { return null; } |
| | 65 | |
|
| 0 | 66 | | public void RaiseOnAppliedChanges() { } |
| | 67 | |
|
| 0 | 68 | | public bool IsValid() => true; |
| 1 | 69 | | public BaseModel GetModel() => DCLTransform.model; |
| 0 | 70 | | public int GetClassId() => (int) CLASS_ID_COMPONENT.TRANSFORM; |
| | 71 | | } |
| | 72 | | } |