| | 1 | | using System.Collections; |
| | 2 | | using DCL.Controllers; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Components |
| | 8 | | { |
| | 9 | | public class DCLTransform : IEntityComponent, IOutOfSceneBoundariesHandler |
| | 10 | | { |
| | 11 | | [System.Serializable] |
| | 12 | | public class Model : BaseModel |
| | 13 | | { |
| 82 | 14 | | public Vector3 position = Vector3.zero; |
| 82 | 15 | | public Quaternion rotation = Quaternion.identity; |
| 82 | 16 | | public Vector3 scale = Vector3.one; |
| | 17 | |
|
| | 18 | | public override BaseModel GetDataFromJSON(string json) |
| | 19 | | { |
| 242 | 20 | | DCLTransformUtils.DecodeTransform(json, ref DCLTransform.model); |
| 242 | 21 | | return DCLTransform.model; |
| | 22 | | } |
| | 23 | | } |
| | 24 | |
|
| 1 | 25 | | public static Model model = new Model(); |
| | 26 | |
|
| 178 | 27 | | public void Cleanup() { } |
| | 28 | |
|
| 231 | 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 | | { |
| 216 | 36 | | this.scene = scene; |
| 216 | 37 | | this.entity = entity; |
| 216 | 38 | | } |
| | 39 | |
|
| | 40 | | public void UpdateFromJSON(string json) |
| | 41 | | { |
| 242 | 42 | | model.GetDataFromJSON(json); |
| 242 | 43 | | UpdateFromModel(model); |
| 242 | 44 | | } |
| | 45 | |
|
| | 46 | | public void UpdateFromModel(BaseModel model) |
| | 47 | | { |
| 274 | 48 | | DCLTransform.model = model as Model; |
| | 49 | |
|
| 274 | 50 | | if (entity.OnTransformChange != null) // AvatarShape interpolation hack |
| | 51 | | { |
| 1 | 52 | | entity.OnTransformChange.Invoke(DCLTransform.model); |
| 1 | 53 | | } |
| | 54 | | else |
| | 55 | | { |
| 273 | 56 | | entity.gameObject.transform.localPosition = DCLTransform.model.position; |
| 273 | 57 | | entity.gameObject.transform.localRotation = DCLTransform.model.rotation; |
| 273 | 58 | | entity.gameObject.transform.localScale = DCLTransform.model.scale; |
| | 59 | |
|
| 273 | 60 | | entity.gameObject.transform.CapGlobalValuesToMax(); |
| | 61 | | } |
| 273 | 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; |
| 0 | 71 | | public void UpdateOutOfBoundariesState(bool enable) { } |
| | 72 | |
|
| | 73 | |
|
| | 74 | | } |
| | 75 | | } |