| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Models; |
| | 4 | | using System; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.EventSystems; |
| | 9 | | using Newtonsoft.Json; |
| | 10 | | using Newtonsoft.Json.Linq; |
| | 11 | | using DCL.Configuration; |
| | 12 | | using static ProtocolV2; |
| | 13 | | using Environment = DCL.Environment; |
| | 14 | | using System.IO; |
| | 15 | | using System.Linq; |
| | 16 | | using System.Runtime.Serialization.Formatters.Binary; |
| | 17 | | using DCL.Builder; |
| | 18 | | using DCL.Builder.Manifest; |
| | 19 | | using DCL.Controllers; |
| | 20 | | using DCL.Helpers; |
| | 21 | | using UnityEditor; |
| | 22 | | using UnityEngine.Networking; |
| | 23 | | using UnityEngine.Events; |
| | 24 | |
|
| | 25 | | public static partial class BIWUtils |
| | 26 | | { |
| 1 | 27 | | private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| | 28 | |
|
| | 29 | | public static LoadParcelScenesMessage.UnityParcelScene AddSceneMappings(Dictionary<string, string> contents, string |
| | 30 | | { |
| 15 | 31 | | if (data == null) |
| 0 | 32 | | data = new LoadParcelScenesMessage.UnityParcelScene(); |
| | 33 | |
|
| 15 | 34 | | data.baseUrl = baseUrl; |
| 15 | 35 | | if (data.contents == null) |
| 10 | 36 | | data.contents = new List<ContentServerUtils.MappingPair>(); |
| | 37 | |
|
| 88 | 38 | | foreach (KeyValuePair<string, string> content in contents) |
| | 39 | | { |
| 29 | 40 | | ContentServerUtils.MappingPair mappingPair = new ContentServerUtils.MappingPair(); |
| 29 | 41 | | mappingPair.file = content.Key; |
| 29 | 42 | | mappingPair.hash = content.Value; |
| 29 | 43 | | bool found = false; |
| 161 | 44 | | foreach (ContentServerUtils.MappingPair mappingPairToCheck in data.contents) |
| | 45 | | { |
| 55 | 46 | | if (mappingPairToCheck.file == mappingPair.file) |
| | 47 | | { |
| 7 | 48 | | found = true; |
| 7 | 49 | | break; |
| | 50 | | } |
| | 51 | | } |
| | 52 | |
|
| 29 | 53 | | if (!found) |
| 22 | 54 | | data.contents.Add(mappingPair); |
| | 55 | | } |
| 15 | 56 | | return data; |
| | 57 | | } |
| | 58 | |
|
| | 59 | | public static void RemoveAssetsFromCurrentScene() |
| | 60 | | { |
| | 61 | | //We remove the old assets to they don't collide with the new ones |
| 0 | 62 | | foreach (var catalogItem in DataStore.i.builderInWorld.currentSceneCatalogItemDict.GetValues()) |
| | 63 | | { |
| 0 | 64 | | AssetCatalogBridge.i.RemoveSceneObjectToSceneCatalog(catalogItem.id); |
| | 65 | | } |
| 0 | 66 | | DataStore.i.builderInWorld.currentSceneCatalogItemDict.Clear(); |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public static void ShowGenericNotification(string message, DCL.NotificationModel.Type type = DCL.NotificationModel.T |
| | 70 | | { |
| 2 | 71 | | if (NotificationsController.i == null) |
| 1 | 72 | | return; |
| 1 | 73 | | NotificationsController.i.ShowNotification(new DCL.NotificationModel.Model |
| | 74 | | { |
| | 75 | | message = message, |
| | 76 | | type = DCL.NotificationModel.Type.GENERIC, |
| | 77 | | timer = timer, |
| | 78 | | destroyOnFinish = true |
| | 79 | | }); |
| 1 | 80 | | } |
| | 81 | |
|
| | 82 | | public static long ConvertToMilisecondsTimestamp(DateTime value) |
| | 83 | | { |
| 7 | 84 | | TimeSpan elapsedTime = value - Epoch; |
| 7 | 85 | | return (long) elapsedTime.TotalMilliseconds; |
| | 86 | | } |
| | 87 | |
|
| | 88 | | public static SceneMetricsModel GetSceneMetricsLimits(int parcelAmount) |
| | 89 | | { |
| 0 | 90 | | SceneMetricsModel cachedModel = new SceneMetricsModel(); |
| | 91 | |
|
| 0 | 92 | | float log = Mathf.Log(parcelAmount + 1, 2); |
| 0 | 93 | | float lineal = parcelAmount; |
| | 94 | |
|
| 0 | 95 | | cachedModel.triangles = (int) (lineal * SceneMetricsCounter.LimitsConfig.triangles); |
| 0 | 96 | | cachedModel.bodies = (int) (lineal * SceneMetricsCounter.LimitsConfig.bodies); |
| 0 | 97 | | cachedModel.entities = (int) (lineal * SceneMetricsCounter.LimitsConfig.entities); |
| 0 | 98 | | cachedModel.materials = (int) (log * SceneMetricsCounter.LimitsConfig.materials); |
| 0 | 99 | | cachedModel.textures = (int) (log * SceneMetricsCounter.LimitsConfig.textures); |
| 0 | 100 | | cachedModel.meshes = (int) (log * SceneMetricsCounter.LimitsConfig.meshes); |
| 0 | 101 | | cachedModel.sceneHeight = (int) (log * SceneMetricsCounter.LimitsConfig.height); |
| | 102 | |
|
| 0 | 103 | | return cachedModel; |
| | 104 | | } |
| | 105 | |
|
| | 106 | | public static Manifest CreateManifestFromProject(ProjectData projectData) |
| | 107 | | { |
| 0 | 108 | | Manifest manifest = new Manifest(); |
| 0 | 109 | | manifest.version = 10; |
| 0 | 110 | | manifest.project = projectData; |
| 0 | 111 | | manifest.scene = CreateEmtpyBuilderScene(projectData.rows * projectData.cols); |
| | 112 | |
|
| 0 | 113 | | manifest.project.scene_id = manifest.scene.id; |
| 0 | 114 | | return manifest; |
| | 115 | | } |
| | 116 | |
|
| | 117 | | //We create the scene the same way as the current builder do, so we ensure the compatibility between both builders |
| | 118 | | private static WebBuilderScene CreateEmtpyBuilderScene(int parcelsAmount) |
| | 119 | | { |
| 0 | 120 | | BuilderGround ground = new BuilderGround(); |
| 0 | 121 | | ground.assetId = BIWSettings.FLOOR_ID; |
| 0 | 122 | | ground.componentId = Guid.NewGuid().ToString(); |
| | 123 | |
|
| 0 | 124 | | WebBuilderScene scene = new WebBuilderScene |
| | 125 | | { |
| | 126 | | id = Guid.NewGuid().ToString(), |
| | 127 | | limits = GetSceneMetricsLimits(parcelsAmount), |
| | 128 | | metrics = new SceneMetricsModel(), |
| | 129 | | ground = ground |
| | 130 | | }; |
| | 131 | |
|
| 0 | 132 | | return scene; |
| | 133 | | } |
| | 134 | |
|
| | 135 | | public static Manifest CreateEmptyDefaultBuilderManifest(string landCoordinates) |
| | 136 | | { |
| 0 | 137 | | Manifest manifest = new Manifest(); |
| 0 | 138 | | return manifest; |
| | 139 | | } |
| | 140 | |
|
| | 141 | | public static LandRole GetLandOwnershipType(List<LandWithAccess> lands, IParcelScene scene) |
| | 142 | | { |
| 5 | 143 | | LandWithAccess filteredLand = lands.FirstOrDefault(land => scene.sceneData.basePosition == land.baseCoords); |
| 5 | 144 | | return GetLandOwnershipType(filteredLand); |
| | 145 | | } |
| | 146 | |
|
| | 147 | | public static LandRole GetLandOwnershipType(LandWithAccess land) |
| | 148 | | { |
| 0 | 149 | | if (land != null) |
| 0 | 150 | | return land.role; |
| 0 | 151 | | return LandRole.OWNER; |
| | 152 | | } |
| | 153 | |
|
| | 154 | | public static Vector3 SnapFilterEulerAngles(Vector3 vectorToFilter, float degrees) |
| | 155 | | { |
| 0 | 156 | | vectorToFilter.x = ClosestNumber(vectorToFilter.x, degrees); |
| 0 | 157 | | vectorToFilter.y = ClosestNumber(vectorToFilter.y, degrees); |
| 0 | 158 | | vectorToFilter.z = ClosestNumber(vectorToFilter.z, degrees); |
| | 159 | |
|
| 0 | 160 | | return vectorToFilter; |
| | 161 | | } |
| | 162 | |
|
| | 163 | | static float ClosestNumber(float n, float m) |
| | 164 | | { |
| | 165 | | // find the quotient |
| 0 | 166 | | int q = Mathf.RoundToInt(n / m); |
| | 167 | |
|
| | 168 | | // 1st possible closest number |
| 0 | 169 | | float n1 = m * q; |
| | 170 | |
|
| | 171 | | // 2nd possible closest number |
| 0 | 172 | | float n2 = (n * m) > 0 ? (m * (q + 1)) : (m * (q - 1)); |
| | 173 | |
|
| | 174 | | // if true, then n1 is the required closest number |
| 0 | 175 | | if (Math.Abs(n - n1) < Math.Abs(n - n2)) |
| 0 | 176 | | return n1; |
| | 177 | |
|
| | 178 | | // else n2 is the required closest number |
| 0 | 179 | | return n2; |
| | 180 | | } |
| | 181 | |
|
| 11 | 182 | | public static Vector2Int GetSceneSize(IParcelScene parcelScene) { return GetSceneSize(parcelScene.sceneData.parcels) |
| | 183 | |
|
| | 184 | | public static Vector2Int GetSceneSize(Vector2Int[] parcels) |
| | 185 | | { |
| 11 | 186 | | int minX = Int32.MaxValue; |
| 11 | 187 | | int maxX = Int32.MinValue; |
| 11 | 188 | | int minY = Int32.MaxValue; |
| 11 | 189 | | int maxY = Int32.MinValue; |
| | 190 | |
|
| 60 | 191 | | foreach (var parcel in parcels) |
| | 192 | | { |
| 19 | 193 | | if (parcel.x > maxX) |
| 13 | 194 | | maxX = parcel.x; |
| 19 | 195 | | if (parcel.x < minX) |
| 13 | 196 | | minX = parcel.x; |
| | 197 | |
|
| 19 | 198 | | if (parcel.y > maxY) |
| 13 | 199 | | maxY = parcel.y; |
| 19 | 200 | | if (parcel.y < minY) |
| 13 | 201 | | minY = parcel.y; |
| | 202 | | } |
| | 203 | |
|
| 11 | 204 | | int sizeX = maxX - minX + 1; |
| 11 | 205 | | int sizeY = maxY - minY + 1; |
| 11 | 206 | | return new Vector2Int(sizeX, sizeY); |
| | 207 | | } |
| | 208 | |
|
| | 209 | | public static Vector3 CalculateUnityMiddlePoint(IParcelScene parcelScene) |
| | 210 | | { |
| | 211 | | Vector3 position; |
| | 212 | |
|
| 78 | 213 | | float totalX = 0f; |
| 78 | 214 | | float totalY = 0f; |
| 78 | 215 | | float totalZ = 0f; |
| | 216 | |
|
| 78 | 217 | | int minX = int.MaxValue; |
| 78 | 218 | | int minY = int.MaxValue; |
| 78 | 219 | | int maxX = int.MinValue; |
| 78 | 220 | | int maxY = int.MinValue; |
| | 221 | |
|
| 78 | 222 | | if (parcelScene.sceneData == null || parcelScene.sceneData.parcels == null) |
| 2 | 223 | | return Vector3.zero; |
| | 224 | |
|
| 304 | 225 | | foreach (Vector2Int vector in parcelScene.sceneData.parcels) |
| | 226 | | { |
| 76 | 227 | | totalX += vector.x; |
| 76 | 228 | | totalZ += vector.y; |
| 76 | 229 | | if (vector.x < minX) |
| 76 | 230 | | minX = vector.x; |
| 76 | 231 | | if (vector.y < minY) |
| 76 | 232 | | minY = vector.y; |
| 76 | 233 | | if (vector.x > maxX) |
| 76 | 234 | | maxX = vector.x; |
| 76 | 235 | | if (vector.y > maxY) |
| 76 | 236 | | maxY = vector.y; |
| | 237 | | } |
| | 238 | |
|
| 76 | 239 | | float centerX = totalX / parcelScene.sceneData.parcels.Length; |
| 76 | 240 | | float centerZ = totalZ / parcelScene.sceneData.parcels.Length; |
| | 241 | |
|
| 76 | 242 | | position.x = centerX; |
| 76 | 243 | | position.y = totalY; |
| 76 | 244 | | position.z = centerZ; |
| | 245 | |
|
| 76 | 246 | | position = WorldStateUtils.ConvertScenePositionToUnityPosition(parcelScene); |
| | 247 | |
|
| 76 | 248 | | position.x += ParcelSettings.PARCEL_SIZE / 2; |
| 76 | 249 | | position.z += ParcelSettings.PARCEL_SIZE / 2; |
| | 250 | |
|
| 76 | 251 | | return position; |
| | 252 | | } |
| | 253 | |
|
| | 254 | | public static CatalogItem CreateFloorSceneObject() |
| | 255 | | { |
| 0 | 256 | | CatalogItem floorSceneObject = new CatalogItem(); |
| 0 | 257 | | floorSceneObject.id = BIWSettings.FLOOR_ID; |
| | 258 | |
|
| 0 | 259 | | floorSceneObject.model = BIWSettings.FLOOR_MODEL; |
| 0 | 260 | | floorSceneObject.name = BIWSettings.FLOOR_NAME; |
| 0 | 261 | | floorSceneObject.assetPackName = BIWSettings.FLOOR_ASSET_PACK_NAME; |
| | 262 | |
|
| 0 | 263 | | floorSceneObject.contents = new Dictionary<string, string>(); |
| | 264 | |
|
| 0 | 265 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_GLTF_KEY, BIWSettings.FLOOR_GLTF_VALUE); |
| 0 | 266 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_TEXTURE_KEY, BIWSettings.FLOOR_TEXTURE_VALUE); |
| | 267 | |
|
| 0 | 268 | | floorSceneObject.metrics = new SceneObject.ObjectMetrics(); |
| | 269 | |
|
| 0 | 270 | | return floorSceneObject; |
| | 271 | | } |
| | 272 | |
|
| | 273 | | public static Dictionary<string, string> ConvertMappingsToDictionary(ContentServerUtils.MappingPair[] contents) |
| | 274 | | { |
| 0 | 275 | | Dictionary<string, string> mappingDict = new Dictionary<string, string>(); |
| | 276 | |
|
| 0 | 277 | | foreach (ContentServerUtils.MappingPair mappingPair in contents) |
| | 278 | | { |
| 0 | 279 | | mappingDict.Add(mappingPair.file, mappingPair.hash); |
| | 280 | | } |
| | 281 | |
|
| 0 | 282 | | return mappingDict; |
| | 283 | | } |
| | 284 | |
|
| | 285 | | public static void DrawScreenRect(Rect rect, Color color) |
| | 286 | | { |
| 0 | 287 | | GUI.color = color; |
| 0 | 288 | | GUI.DrawTexture(rect, Texture2D.whiteTexture); |
| 0 | 289 | | } |
| | 290 | |
|
| | 291 | | public static void DrawScreenRectBorder(Rect rect, float thickness, Color color) |
| | 292 | | { |
| | 293 | | //Top |
| 0 | 294 | | DrawScreenRect(new Rect(rect.xMin, rect.yMin, rect.width, thickness), color); |
| | 295 | | // Left |
| 0 | 296 | | DrawScreenRect(new Rect(rect.xMin, rect.yMin, thickness, rect.height), color); |
| | 297 | | // Right |
| 0 | 298 | | DrawScreenRect(new Rect(rect.xMax - thickness, rect.yMin, thickness, rect.height), color); |
| | 299 | | // Bottom |
| 0 | 300 | | DrawScreenRect(new Rect(rect.xMin, rect.yMax - thickness, rect.width, thickness), color); |
| 0 | 301 | | } |
| | 302 | |
|
| | 303 | | public static Rect GetScreenRect(Vector3 screenPosition1, Vector3 screenPosition2) |
| | 304 | | { |
| | 305 | | // Move origin from bottom left to top left |
| 0 | 306 | | screenPosition1.y = Screen.height - screenPosition1.y; |
| 0 | 307 | | screenPosition2.y = Screen.height - screenPosition2.y; |
| | 308 | | // Calculate corners |
| 0 | 309 | | var topLeft = Vector3.Min(screenPosition1, screenPosition2); |
| 0 | 310 | | var bottomRight = Vector3.Max(screenPosition1, screenPosition2); |
| | 311 | | // Create Rect |
| 0 | 312 | | return Rect.MinMaxRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); |
| | 313 | | } |
| | 314 | |
|
| | 315 | | public static Bounds GetViewportBounds(Camera camera, Vector3 screenPosition1, Vector3 screenPosition2) |
| | 316 | | { |
| 2 | 317 | | var v1 = camera.ScreenToViewportPoint(screenPosition1); |
| 2 | 318 | | var v2 = camera.ScreenToViewportPoint(screenPosition2); |
| 2 | 319 | | var min = Vector3.Min(v1, v2); |
| 2 | 320 | | var max = Vector3.Max(v1, v2); |
| 2 | 321 | | min.z = camera.nearClipPlane; |
| 2 | 322 | | max.z = camera.farClipPlane; |
| | 323 | |
|
| 2 | 324 | | var bounds = new Bounds(); |
| | 325 | |
|
| 2 | 326 | | bounds.SetMinMax(min, max); |
| 2 | 327 | | return bounds; |
| | 328 | | } |
| | 329 | |
|
| 0 | 330 | | public static bool IsWithinSelectionBounds(Transform transform, Vector3 lastClickMousePosition, Vector3 mousePositio |
| | 331 | |
|
| | 332 | | public static bool IsWithinSelectionBounds(Vector3 point, Vector3 lastClickMousePosition, Vector3 mousePosition) |
| | 333 | | { |
| 2 | 334 | | Camera camera = Camera.main; |
| 2 | 335 | | var viewPortBounds = GetViewportBounds(camera, lastClickMousePosition, mousePosition); |
| 2 | 336 | | return viewPortBounds.Contains(camera.WorldToViewportPoint(point)); |
| | 337 | | } |
| | 338 | |
|
| | 339 | | public static bool IsBoundInsideCamera(Bounds bound) |
| | 340 | | { |
| 0 | 341 | | Vector3[] points = { bound.max, bound.center, bound.min }; |
| 0 | 342 | | return IsPointInsideCamera(points); |
| | 343 | | } |
| | 344 | |
|
| | 345 | | public static bool IsPointInsideCamera(Vector3[] points) |
| | 346 | | { |
| 0 | 347 | | foreach (Vector3 point in points) |
| | 348 | | { |
| 0 | 349 | | if (IsPointInsideCamera(point)) |
| 0 | 350 | | return true; |
| | 351 | | } |
| 0 | 352 | | return false; |
| | 353 | | } |
| | 354 | |
|
| | 355 | | public static bool IsPointInsideCamera(Vector3 point) |
| | 356 | | { |
| 0 | 357 | | Vector3 topRight = new Vector3(Screen.width, Screen.height, 0); |
| 0 | 358 | | var viewPortBounds = GetViewportBounds(Camera.main, Vector3.zero, topRight); |
| 0 | 359 | | return viewPortBounds.Contains(Camera.main.WorldToViewportPoint(point)); |
| | 360 | | } |
| | 361 | |
|
| | 362 | | public static void CopyGameObjectStatus(GameObject gameObjectToCopy, GameObject gameObjectToReceive, bool copyParent |
| | 363 | | { |
| 5 | 364 | | if (copyParent) |
| 0 | 365 | | gameObjectToReceive.transform.SetParent(gameObjectToCopy.transform.parent); |
| | 366 | |
|
| 5 | 367 | | gameObjectToReceive.transform.position = gameObjectToCopy.transform.position; |
| | 368 | |
|
| 5 | 369 | | if (localRotation) |
| 0 | 370 | | gameObjectToReceive.transform.localRotation = gameObjectToCopy.transform.localRotation; |
| | 371 | | else |
| 5 | 372 | | gameObjectToReceive.transform.rotation = gameObjectToCopy.transform.rotation; |
| | 373 | |
|
| 5 | 374 | | gameObjectToReceive.transform.localScale = gameObjectToCopy.transform.lossyScale; |
| 5 | 375 | | } |
| | 376 | |
|
| | 377 | | public static bool IsPointerOverMaskElement(LayerMask mask) |
| | 378 | | { |
| | 379 | | RaycastHit hitInfo; |
| 2 | 380 | | UnityEngine.Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); |
| 2 | 381 | | return Physics.Raycast(mouseRay, out hitInfo, 5555, mask); |
| | 382 | | } |
| | 383 | |
|
| | 384 | | public static bool IsPointerOverUIElement(Vector3 mousePosition) |
| | 385 | | { |
| 1 | 386 | | var eventData = new PointerEventData(EventSystem.current); |
| 1 | 387 | | eventData.position = mousePosition; |
| 1 | 388 | | var results = new List<RaycastResult>(); |
| 1 | 389 | | EventSystem.current.RaycastAll(eventData, results); |
| 1 | 390 | | return results.Count > 2; |
| | 391 | | } |
| | 392 | |
|
| 1 | 393 | | public static bool IsPointerOverUIElement() { return IsPointerOverUIElement(Input.mousePosition); } |
| | 394 | |
|
| | 395 | | public static string ConvertEntityToJSON(IDCLEntity entity) |
| | 396 | | { |
| 4 | 397 | | EntityData builderInWorldEntityData = new EntityData(); |
| 4 | 398 | | builderInWorldEntityData.entityId = entity.entityId; |
| | 399 | |
|
| | 400 | |
|
| 10 | 401 | | foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in entity.components) |
| | 402 | | { |
| 1 | 403 | | if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM) |
| | 404 | | { |
| 1 | 405 | | EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent(); |
| | 406 | |
|
| 1 | 407 | | entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform. |
| 1 | 408 | | entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles; |
| 1 | 409 | | entityComponentModel.scale = entity.gameObject.transform.localScale; |
| | 410 | |
|
| 1 | 411 | | builderInWorldEntityData.transformComponent = entityComponentModel; |
| 1 | 412 | | } |
| | 413 | | else |
| | 414 | | { |
| 0 | 415 | | ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent(); |
| 0 | 416 | | entityComponentModel.componentId = (int) keyValuePair.Key; |
| 0 | 417 | | entityComponentModel.data = keyValuePair.Value.GetModel(); |
| | 418 | |
|
| 0 | 419 | | builderInWorldEntityData.components.Add(entityComponentModel); |
| | 420 | | } |
| | 421 | | } |
| | 422 | |
|
| 8 | 423 | | foreach (KeyValuePair<Type, ISharedComponent> keyValuePair in entity.sharedComponents) |
| | 424 | | { |
| 0 | 425 | | if (keyValuePair.Value.GetClassId() == (int) CLASS_ID.NFT_SHAPE) |
| | 426 | | { |
| 0 | 427 | | EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent(); |
| 0 | 428 | | NFTShape.Model model = (NFTShape.Model) keyValuePair.Value.GetModel(); |
| | 429 | |
|
| 0 | 430 | | nFTComponent.id = keyValuePair.Value.id; |
| 0 | 431 | | nFTComponent.color = new ColorRepresentation(model.color); |
| 0 | 432 | | nFTComponent.assetId = model.assetId; |
| 0 | 433 | | nFTComponent.src = model.src; |
| 0 | 434 | | nFTComponent.style = model.style; |
| | 435 | |
|
| 0 | 436 | | builderInWorldEntityData.nftComponent = nFTComponent; |
| 0 | 437 | | } |
| | 438 | | else |
| | 439 | | { |
| 0 | 440 | | ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent(); |
| 0 | 441 | | entityComponentModel.componentId = keyValuePair.Value.GetClassId(); |
| 0 | 442 | | entityComponentModel.data = keyValuePair.Value.GetModel(); |
| 0 | 443 | | entityComponentModel.classId = keyValuePair.Value.id; |
| | 444 | |
|
| 0 | 445 | | builderInWorldEntityData.sharedComponents.Add(entityComponentModel); |
| | 446 | | } |
| | 447 | | } |
| | 448 | |
|
| | 449 | |
|
| 4 | 450 | | return JsonConvert.SerializeObject(builderInWorldEntityData); |
| | 451 | | } |
| | 452 | |
|
| 3 | 453 | | public static EntityData ConvertJSONToEntityData(string json) { return JsonConvert.DeserializeObject<EntityData>(jso |
| | 454 | |
|
| | 455 | | public static List<BIWEntity> RemoveGroundEntities(List<BIWEntity> entityList) |
| | 456 | | { |
| 0 | 457 | | List<BIWEntity> newList = new List<BIWEntity>(); |
| | 458 | |
|
| 0 | 459 | | foreach (BIWEntity entity in entityList) |
| | 460 | | { |
| 0 | 461 | | if (entity.isFloor) |
| | 462 | | continue; |
| | 463 | |
|
| 0 | 464 | | newList.Add(entity); |
| | 465 | | } |
| | 466 | |
|
| 0 | 467 | | return newList; |
| | 468 | | } |
| | 469 | |
|
| | 470 | | public static List<BIWEntity> FilterEntitiesBySmartItemComponentAndActions(List<BIWEntity> entityList) |
| | 471 | | { |
| 0 | 472 | | List<BIWEntity> newList = new List<BIWEntity>(); |
| | 473 | |
|
| 0 | 474 | | foreach (BIWEntity entity in entityList) |
| | 475 | | { |
| 0 | 476 | | if (!entity.HasSmartItemComponent() || !entity.HasSmartItemActions()) |
| | 477 | | continue; |
| | 478 | |
|
| 0 | 479 | | newList.Add(entity); |
| | 480 | | } |
| | 481 | |
|
| 0 | 482 | | return newList; |
| | 483 | | } |
| | 484 | |
|
| | 485 | | public static void CopyRectTransform(RectTransform original, RectTransform rectTransformToCopy) |
| | 486 | | { |
| 0 | 487 | | original.anchoredPosition = rectTransformToCopy.anchoredPosition; |
| 0 | 488 | | original.anchorMax = rectTransformToCopy.anchorMax; |
| 0 | 489 | | original.anchorMin = rectTransformToCopy.anchorMin; |
| 0 | 490 | | original.offsetMax = rectTransformToCopy.offsetMax; |
| 0 | 491 | | original.offsetMin = rectTransformToCopy.offsetMin; |
| 0 | 492 | | original.sizeDelta = rectTransformToCopy.sizeDelta; |
| 0 | 493 | | original.pivot = rectTransformToCopy.pivot; |
| 0 | 494 | | } |
| | 495 | |
|
| | 496 | | public static IWebRequestAsyncOperation MakeGetCall(string url, Promise<string> callPromise, Dictionary<string, stri |
| | 497 | | { |
| 4 | 498 | | var asyncOperation = Environment.i.platform.webRequest.Get( |
| | 499 | | url: url, |
| | 500 | | OnSuccess: (webRequestResult) => |
| | 501 | | { |
| 4 | 502 | | byte[] byteArray = webRequestResult.GetResultData(); |
| 4 | 503 | | string result = System.Text.Encoding.UTF8.GetString(byteArray); |
| 4 | 504 | | callPromise?.Resolve(result); |
| 4 | 505 | | }, |
| | 506 | | OnFail: (webRequestResult) => |
| | 507 | | { |
| 0 | 508 | | Debug.Log(webRequestResult.webRequest.error); |
| 0 | 509 | | callPromise.Reject(webRequestResult.webRequest.error); |
| 0 | 510 | | }, |
| | 511 | | headers: headers); |
| | 512 | |
|
| 4 | 513 | | return asyncOperation; |
| | 514 | | } |
| | 515 | |
|
| | 516 | | public static void ConfigureEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType, UnityAction<BaseEven |
| | 517 | | { |
| 2084 | 518 | | EventTrigger.Entry entry = new EventTrigger.Entry(); |
| 2084 | 519 | | entry.eventID = eventType; |
| 2084 | 520 | | entry.callback.AddListener(call); |
| 2084 | 521 | | eventTrigger.triggers.Add(entry); |
| 2084 | 522 | | } |
| | 523 | |
|
| 5124 | 524 | | public static void RemoveEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType) { eventTrigger.triggers |
| | 525 | | } |