| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Models; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Components |
| | 7 | | { |
| | 8 | | public abstract class BaseComponent : MonoBehaviour, IEntityComponent, IDelayedComponent, IPoolLifecycleHandler, IPo |
| | 9 | | { |
| | 10 | | protected ComponentUpdateHandler updateHandler; |
| 0 | 11 | | public CustomYieldInstruction yieldInstruction => updateHandler.yieldInstruction; |
| 0 | 12 | | public Coroutine routine => updateHandler.routine; |
| 0 | 13 | | public bool isRoutineRunning => updateHandler.isRoutineRunning; |
| | 14 | |
|
| 0 | 15 | | public IParcelScene scene { get; set; } |
| | 16 | |
|
| 314 | 17 | | public IDCLEntity entity { get; set; } |
| | 18 | |
|
| 52 | 19 | | public IPoolableObject poolableObject { get; set; } |
| | 20 | |
|
| 0 | 21 | | public string componentName => "BaseComponent"; |
| | 22 | |
|
| | 23 | | protected BaseModel model; |
| | 24 | |
|
| 144 | 25 | | public void RaiseOnAppliedChanges() { } |
| | 26 | |
|
| | 27 | | public virtual void Initialize(IParcelScene scene, IDCLEntity entity) |
| | 28 | | { |
| 100 | 29 | | this.scene = scene; |
| 100 | 30 | | this.entity = entity; |
| | 31 | |
|
| 100 | 32 | | if (transform.parent != entity.gameObject.transform) |
| 100 | 33 | | transform.SetParent(entity.gameObject.transform, false); |
| 100 | 34 | | } |
| | 35 | |
|
| 276 | 36 | | public virtual void UpdateFromJSON(string json) { UpdateFromModel(model.GetDataFromJSON(json)); } |
| | 37 | |
|
| | 38 | | public virtual void UpdateFromModel(BaseModel newModel) |
| | 39 | | { |
| 147 | 40 | | model = newModel; |
| 147 | 41 | | updateHandler.ApplyChangesIfModified(model); |
| 147 | 42 | | } |
| | 43 | |
|
| | 44 | | public abstract IEnumerator ApplyChanges(BaseModel model); |
| | 45 | |
|
| | 46 | | protected void OnEnable() |
| | 47 | | { |
| 786 | 48 | | if (updateHandler == null) |
| 784 | 49 | | updateHandler = CreateUpdateHandler(); |
| 786 | 50 | | } |
| | 51 | |
|
| 1 | 52 | | public virtual BaseModel GetModel() => model; |
| | 53 | |
|
| 784 | 54 | | protected virtual ComponentUpdateHandler CreateUpdateHandler() { return new ComponentUpdateHandler(this); } |
| | 55 | |
|
| 147 | 56 | | public bool IsValid() { return this != null; } |
| | 57 | |
|
| 1404 | 58 | | public virtual void Cleanup() { updateHandler.Cleanup(); } |
| | 59 | |
|
| 4 | 60 | | public virtual void OnPoolRelease() { Cleanup(); } |
| | 61 | |
|
| | 62 | | public virtual void OnPoolGet() |
| | 63 | | { |
| 2 | 64 | | if (updateHandler == null) |
| 0 | 65 | | updateHandler = CreateUpdateHandler(); |
| 2 | 66 | | } |
| | 67 | |
|
| | 68 | | public abstract int GetClassId(); |
| | 69 | |
|
| 292 | 70 | | public Transform GetTransform() => transform; |
| | 71 | | } |
| | 72 | | } |