| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Models; |
| | 5 | | using System; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | public interface IEntityInformationController |
| | 9 | | { |
| | 10 | | event Action<Vector3> OnPositionChange; |
| | 11 | | event Action<Vector3> OnRotationChange; |
| | 12 | | event Action<Vector3> OnScaleChange; |
| | 13 | | event Action<BIWEntity, string> OnNameChange; |
| | 14 | | event Action<BIWEntity> OnSmartItemComponentUpdate; |
| | 15 | | event Action OnDisable; |
| | 16 | |
|
| | 17 | | void Initialize(IEntityInformationView view); |
| | 18 | | void Dispose(); |
| | 19 | | void PositionChanged(Vector3 pos); |
| | 20 | | void RotationChanged(Vector3 rot); |
| | 21 | | void ScaleChanged(Vector3 scale); |
| | 22 | | void NameChanged(BIWEntity entity, string name); |
| | 23 | | void ToggleDetailsInfo(); |
| | 24 | | void ToggleBasicInfo(); |
| | 25 | | void StartChangingName(); |
| | 26 | | void EndChangingName(); |
| | 27 | | void SetEntity(BIWEntity entity, IParcelScene currentScene); |
| | 28 | | void Enable(); |
| | 29 | | void Disable(); |
| | 30 | | void UpdateInfo(BIWEntity entity); |
| | 31 | | void UpdateEntitiesSelection(int numberOfSelectedEntities); |
| | 32 | | void SetTransparencyMode(bool isOn); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public class EntityInformationController : IEntityInformationController |
| | 36 | | { |
| | 37 | | private const string TRIS_TEXT_FORMAT = "{0} TRIS"; |
| | 38 | | private const string MATERIALS_TEXT_FORMAT = "{0} MATERIALS"; |
| | 39 | | private const string TEXTURES_TEXT_FORMAT = "{0} TEXTURES"; |
| | 40 | | private const float TRANSPARENCY_MODE_ALPHA_VALUE = 0.5f; |
| | 41 | |
|
| | 42 | | public event Action<Vector3> OnPositionChange; |
| | 43 | | public event Action<Vector3> OnRotationChange; |
| | 44 | | public event Action<Vector3> OnScaleChange; |
| | 45 | | public event Action<BIWEntity, string> OnNameChange; |
| | 46 | | public event Action<BIWEntity> OnSmartItemComponentUpdate; |
| | 47 | | public event Action OnDisable; |
| | 48 | |
|
| | 49 | | internal IEntityInformationView entityInformationView; |
| | 50 | | internal IParcelScene parcelScene; |
| | 51 | | internal AssetPromise_Texture loadedThumbnailPromise; |
| | 52 | | internal bool isChangingName = false; |
| | 53 | | internal BIWEntity currentEntity; |
| | 54 | |
|
| | 55 | | public void Initialize(IEntityInformationView entityInformationView) |
| | 56 | | { |
| 21 | 57 | | this.entityInformationView = entityInformationView; |
| | 58 | |
|
| 21 | 59 | | if (entityInformationView.position != null) |
| 0 | 60 | | entityInformationView.position.OnChanged += PositionChanged; |
| | 61 | |
|
| 21 | 62 | | if (entityInformationView.rotation != null) |
| 0 | 63 | | entityInformationView.rotation.OnChanged += RotationChanged; |
| | 64 | |
|
| 21 | 65 | | if (entityInformationView.scale != null) |
| 0 | 66 | | entityInformationView.scale.OnChanged += ScaleChanged; |
| | 67 | |
|
| 21 | 68 | | entityInformationView.OnNameChange += NameChanged; |
| 21 | 69 | | entityInformationView.OnStartChangingName += StartChangingName; |
| 21 | 70 | | entityInformationView.OnEndChangingName += EndChangingName; |
| 21 | 71 | | entityInformationView.OnDisable += Disable; |
| 21 | 72 | | entityInformationView.OnUpdateInfo += UpdateInfo; |
| 21 | 73 | | } |
| | 74 | |
|
| | 75 | | public void Dispose() |
| | 76 | | { |
| 22 | 77 | | if (entityInformationView == null) |
| 1 | 78 | | return; |
| | 79 | |
|
| 21 | 80 | | if (entityInformationView.position != null) |
| 0 | 81 | | entityInformationView.position.OnChanged -= PositionChanged; |
| | 82 | |
|
| 21 | 83 | | if (entityInformationView.rotation != null) |
| 0 | 84 | | entityInformationView.rotation.OnChanged -= RotationChanged; |
| | 85 | |
|
| 21 | 86 | | if (entityInformationView.scale != null) |
| 0 | 87 | | entityInformationView.scale.OnChanged -= ScaleChanged; |
| | 88 | |
|
| 21 | 89 | | entityInformationView.OnNameChange -= NameChanged; |
| 21 | 90 | | entityInformationView.OnUpdateInfo -= UpdateInfo; |
| 21 | 91 | | entityInformationView.OnStartChangingName -= StartChangingName; |
| 21 | 92 | | entityInformationView.OnEndChangingName -= EndChangingName; |
| 21 | 93 | | entityInformationView.OnDisable -= Disable; |
| 21 | 94 | | } |
| | 95 | |
|
| 2 | 96 | | public void PositionChanged(Vector3 pos) { OnPositionChange?.Invoke(pos); } |
| | 97 | |
|
| | 98 | | public void RotationChanged(Vector3 rot) |
| | 99 | | { |
| 1 | 100 | | currentEntity?.SetRotation(rot); |
| 1 | 101 | | OnRotationChange?.Invoke(rot); |
| 1 | 102 | | } |
| | 103 | |
|
| 2 | 104 | | public void ScaleChanged(Vector3 scale) { OnScaleChange?.Invoke(scale); } |
| | 105 | |
|
| 2 | 106 | | public void NameChanged(BIWEntity entity, string name) { OnNameChange?.Invoke(entity, name); } |
| | 107 | |
|
| 2 | 108 | | public void ToggleDetailsInfo() { entityInformationView.ToggleDetailsInfo(); } |
| | 109 | |
|
| 2 | 110 | | public void ToggleBasicInfo() { entityInformationView.ToggleBasicInfo(); } |
| | 111 | |
|
| 0 | 112 | | public void StartChangingName() { isChangingName = true; } |
| | 113 | |
|
| 0 | 114 | | public void EndChangingName() { isChangingName = false; } |
| | 115 | |
|
| | 116 | | public void SetEntity(BIWEntity entity, IParcelScene currentScene) |
| | 117 | | { |
| 1 | 118 | | currentEntity = entity; |
| 1 | 119 | | EntityDeselected(); |
| 1 | 120 | | entityInformationView.SetCurrentEntity(entity); |
| | 121 | |
|
| 1 | 122 | | if (entityInformationView.currentEntity != null) |
| | 123 | | { |
| 0 | 124 | | entity.OnStatusUpdate -= UpdateEntityName; |
| 0 | 125 | | entityInformationView.currentEntity.OnStatusUpdate += UpdateEntityName; |
| | 126 | | } |
| | 127 | |
|
| 1 | 128 | | parcelScene = currentScene; |
| | 129 | |
|
| 1 | 130 | | if (entity.HasSmartItemComponent()) |
| | 131 | | { |
| 0 | 132 | | entityInformationView.SetSmartItemListViewActive(false); |
| | 133 | | //TODO: Remove this comment when we implement smart items in builder in world |
| | 134 | | //if (entity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent baseComponen |
| | 135 | | // entityInformationView.smartItemList.SetSmartItemParameters(entity.GetSmartItemParameters(), ((SmartItem |
| 0 | 136 | | } |
| | 137 | | else |
| | 138 | | { |
| 1 | 139 | | entityInformationView.SetSmartItemListViewActive(false); |
| | 140 | | } |
| | 141 | |
|
| 1 | 142 | | entityInformationView.SetEntityThumbnailEnable(false); |
| 1 | 143 | | CatalogItem entitySceneObject = entity.GetCatalogItemAssociated(); |
| 1 | 144 | | GetThumbnail(entitySceneObject); |
| 1 | 145 | | UpdateLimitsInformation(entitySceneObject); |
| 1 | 146 | | UpdateEntityName(entityInformationView.currentEntity); |
| 1 | 147 | | UpdateInfo(entityInformationView.currentEntity); |
| 1 | 148 | | } |
| | 149 | |
|
| | 150 | | internal void GetThumbnail(CatalogItem catalogItem) |
| | 151 | | { |
| 2 | 152 | | if (catalogItem == null) |
| 1 | 153 | | return; |
| | 154 | |
|
| 1 | 155 | | var url = catalogItem.thumbnailURL; |
| | 156 | |
|
| 1 | 157 | | if (string.IsNullOrEmpty(url)) |
| 0 | 158 | | return; |
| | 159 | |
|
| 1 | 160 | | var newLoadedThumbnailPromise = new AssetPromise_Texture(url); |
| 1 | 161 | | newLoadedThumbnailPromise.OnSuccessEvent += SetThumbnail; |
| 3 | 162 | | newLoadedThumbnailPromise.OnFailEvent += (x, error) => { Debug.Log($"Error downloading: {url}, Exception: {error |
| 1 | 163 | | AssetPromiseKeeper_Texture.i.Keep(newLoadedThumbnailPromise); |
| 1 | 164 | | AssetPromiseKeeper_Texture.i.Forget(loadedThumbnailPromise); |
| 1 | 165 | | loadedThumbnailPromise = newLoadedThumbnailPromise; |
| 1 | 166 | | } |
| | 167 | |
|
| | 168 | | internal void SetThumbnail(Asset_Texture texture) |
| | 169 | | { |
| 1 | 170 | | entityInformationView.SetEntityThumbnailEnable(true); |
| 1 | 171 | | entityInformationView.SetEntityThumbnailTexture(texture.texture); |
| 1 | 172 | | } |
| | 173 | |
|
| | 174 | | internal void UpdateEntityName(BIWEntity entity) |
| | 175 | | { |
| 2 | 176 | | if (entity == null) |
| 1 | 177 | | return; |
| | 178 | |
|
| 1 | 179 | | string currentName = entity.GetDescriptiveName(); |
| | 180 | |
|
| 1 | 181 | | if (!isChangingName) |
| 1 | 182 | | entityInformationView.SetNameIFText(currentName); |
| 1 | 183 | | } |
| | 184 | |
|
| | 185 | | internal void UpdateLimitsInformation(CatalogItem catalogItem) |
| | 186 | | { |
| 3 | 187 | | if (catalogItem == null) |
| | 188 | | { |
| 2 | 189 | | entityInformationView.SeEntityLimitsText("", "", ""); |
| 2 | 190 | | return; |
| | 191 | | } |
| | 192 | |
|
| 1 | 193 | | string trisText = string.Format(TRIS_TEXT_FORMAT, catalogItem.metrics.triangles); |
| 1 | 194 | | string materialText = string.Format(MATERIALS_TEXT_FORMAT, catalogItem.metrics.materials); |
| 1 | 195 | | string textureText = string.Format(TEXTURES_TEXT_FORMAT, catalogItem.metrics.textures); |
| | 196 | |
|
| 1 | 197 | | entityInformationView.SeEntityLimitsText(trisText, materialText, textureText); |
| 1 | 198 | | } |
| | 199 | |
|
| 2 | 200 | | public void Enable() { entityInformationView.SetActive(true); } |
| | 201 | |
|
| | 202 | | public void Disable() |
| | 203 | | { |
| 1 | 204 | | entityInformationView.SetActive(false); |
| 1 | 205 | | EntityDeselected(); |
| 1 | 206 | | entityInformationView.SetCurrentEntity(null); |
| 1 | 207 | | OnDisable?.Invoke(); |
| 1 | 208 | | } |
| | 209 | |
|
| | 210 | | internal void EntityDeselected() |
| | 211 | | { |
| 2 | 212 | | if (entityInformationView.currentEntity == null) |
| 2 | 213 | | return; |
| | 214 | |
|
| 0 | 215 | | var scene = entityInformationView.currentEntity.rootEntity.scene; |
| 0 | 216 | | if (scene.componentsManagerLegacy.TryGetBaseComponent(entityInformationView.currentEntity.rootEntity, CLASS_ID_C |
| | 217 | | { |
| 0 | 218 | | SmartItemComponent smartItemComponent = (SmartItemComponent) component; |
| 0 | 219 | | OnSmartItemComponentUpdate?.Invoke(entityInformationView.currentEntity); |
| | 220 | | } |
| 0 | 221 | | } |
| | 222 | |
|
| | 223 | | public void UpdateInfo(BIWEntity entity) |
| | 224 | | { |
| 2 | 225 | | if (entity != null && entity.rootEntity.gameObject != null) |
| | 226 | | { |
| 1 | 227 | | Vector3 positionConverted = WorldStateUtils.ConvertUnityToScenePosition(entity.rootEntity.gameObject.transfo |
| 1 | 228 | | Vector3 currentRotation = entity.rootEntity.gameObject.transform.rotation.eulerAngles; |
| 1 | 229 | | Vector3 currentScale = entity.rootEntity.gameObject.transform.lossyScale; |
| | 230 | |
|
| 1 | 231 | | currentRotation = entity.GetEulerRotation(); |
| | 232 | |
|
| 1 | 233 | | entityInformationView.SetPositionAttribute(positionConverted); |
| 1 | 234 | | entityInformationView.SetRotationAttribute(currentRotation); |
| 1 | 235 | | entityInformationView.SetScaleAttribute(currentScale); |
| | 236 | | } |
| 2 | 237 | | } |
| | 238 | |
|
| 4 | 239 | | public void UpdateEntitiesSelection(int numberOfSelectedEntities) { entityInformationView.UpdateEntitiesSelection(nu |
| | 240 | |
|
| 4 | 241 | | public void SetTransparencyMode(bool isOn) { entityInformationView.SetTransparencyMode(isOn ? TRANSPARENCY_MODE_ALPH |
| | 242 | | } |