| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Models; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using UnityEngine; |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// This component is a descriptive name of the Entity. In the BuilderInWorld you can give an entity a descriptive name |
| | 12 | | /// Builder in World send a message to kernel to change the value of this component in order to assign a descriptive nam |
| | 13 | | /// </summary> |
| | 14 | | public class DCLName : BaseDisposable |
| | 15 | | { |
| | 16 | | [System.Serializable] |
| | 17 | | public class Model : BaseModel |
| | 18 | | { |
| | 19 | | public string value; |
| | 20 | | //TODO: This value is used for builder to manage the smart items, when the builder is no longer active we should |
| | 21 | | public string builderValue; |
| | 22 | |
|
| 0 | 23 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 24 | | } |
| | 25 | |
|
| 60 | 26 | | public DCLName() { model = new Model(); } |
| | 27 | |
|
| | 28 | | private string oldName; |
| | 29 | |
|
| 20 | 30 | | public override int GetClassId() { return (int) CLASS_ID.NAME; } |
| | 31 | |
|
| | 32 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 33 | | { |
| 20 | 34 | | Model modelToApply = (Model) newModel; |
| | 35 | |
|
| 20 | 36 | | model = modelToApply; |
| | 37 | |
|
| 42 | 38 | | foreach (IDCLEntity entity in attachedEntities) |
| | 39 | | { |
| 1 | 40 | | entity.OnNameChange?.Invoke(modelToApply); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | #if UNITY_EDITOR |
| 42 | 44 | | foreach (IDCLEntity decentralandEntity in this.attachedEntities) |
| | 45 | | { |
| 1 | 46 | | if (!string.IsNullOrEmpty(oldName)) |
| 0 | 47 | | decentralandEntity.gameObject.name.Replace(oldName, ""); |
| | 48 | |
|
| 1 | 49 | | decentralandEntity.gameObject.name += $"-{modelToApply.value}"; |
| | 50 | | } |
| | 51 | | #endif |
| 20 | 52 | | oldName = modelToApply.value; |
| 20 | 53 | | return null; |
| | 54 | | } |
| | 55 | |
|
| | 56 | | public void SetNewName(string value) |
| | 57 | | { |
| 1 | 58 | | Model newModel = new Model(); |
| 1 | 59 | | newModel.value = value; |
| 1 | 60 | | UpdateFromModel(newModel); |
| 1 | 61 | | } |
| | 62 | | } |