| | 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 | | { |
| | 27 | | public static IDCLEntity DuplicateEntity(IParcelScene scene, IDCLEntity entity) |
| | 28 | | { |
| 3 | 29 | | if (!scene.entities.ContainsKey(entity.entityId)) |
| 0 | 30 | | return null; |
| | 31 | |
|
| 3 | 32 | | var sceneController = Environment.i.world.sceneController; |
| 3 | 33 | | IDCLEntity newEntity = |
| | 34 | | scene.CreateEntity( |
| | 35 | | sceneController.entityIdHelper.EntityFromLegacyEntityString(System.Guid.NewGuid().ToString())); |
| | 36 | |
|
| 3 | 37 | | if (entity.children.Count > 0) |
| | 38 | | { |
| 0 | 39 | | using (var iterator = entity.children.GetEnumerator()) |
| | 40 | | { |
| 0 | 41 | | while (iterator.MoveNext()) |
| | 42 | | { |
| 0 | 43 | | IDCLEntity childDuplicate = DuplicateEntity(scene, iterator.Current.Value); |
| 0 | 44 | | childDuplicate.SetParent(newEntity); |
| | 45 | | } |
| 0 | 46 | | } |
| | 47 | | } |
| | 48 | |
|
| 3 | 49 | | if (entity.parent != null) |
| 0 | 50 | | scene.SetEntityParent(newEntity.entityId, entity.parent.entityId); |
| | 51 | |
|
| 3 | 52 | | DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position); |
| 3 | 53 | | DCLTransform.model.rotation = entity.gameObject.transform.rotation; |
| 3 | 54 | | DCLTransform.model.scale = entity.gameObject.transform.lossyScale; |
| | 55 | |
|
| 3 | 56 | | var components = scene.componentsManagerLegacy.GetComponentsDictionary(entity); |
| | 57 | |
|
| 3 | 58 | | if (components != null) |
| | 59 | | { |
| 4 | 60 | | foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> component in components) |
| | 61 | | { |
| 1 | 62 | | scene.componentsManagerLegacy.EntityComponentCreateOrUpdate(newEntity.entityId, component.Key, component |
| | 63 | | } |
| | 64 | | } |
| | 65 | |
|
| 3 | 66 | | using (var iterator = scene.componentsManagerLegacy.GetSharedComponents(entity)) |
| | 67 | | { |
| 3 | 68 | | while (iterator.MoveNext()) |
| | 69 | | { |
| 0 | 70 | | ISharedComponent sharedComponent = scene.componentsManagerLegacy.SceneSharedComponentCreate(System.Guid. |
| 0 | 71 | | sharedComponent.UpdateFromModel(iterator.Current.GetModel()); |
| 0 | 72 | | scene.componentsManagerLegacy.SceneSharedComponentAttach(newEntity.entityId, sharedComponent.id); |
| | 73 | | } |
| 3 | 74 | | } |
| | 75 | |
|
| 3 | 76 | | return newEntity; |
| | 77 | | } |
| | 78 | |
|
| | 79 | | public static bool IsParcelSceneSquare(Vector2Int[] parcelsPoints) |
| | 80 | | { |
| 3 | 81 | | int minX = int.MaxValue; |
| 3 | 82 | | int minY = int.MaxValue; |
| 3 | 83 | | int maxX = int.MinValue; |
| 3 | 84 | | int maxY = int.MinValue; |
| | 85 | |
|
| 12 | 86 | | foreach (Vector2Int vector in parcelsPoints) |
| | 87 | | { |
| 3 | 88 | | if (vector.x < minX) |
| 3 | 89 | | minX = vector.x; |
| 3 | 90 | | if (vector.y < minY) |
| 3 | 91 | | minY = vector.y; |
| 3 | 92 | | if (vector.x > maxX) |
| 3 | 93 | | maxX = vector.x; |
| 3 | 94 | | if (vector.y > maxY) |
| 3 | 95 | | maxY = vector.y; |
| | 96 | | } |
| | 97 | |
|
| 3 | 98 | | if (maxX - minX != maxY - minY) |
| 0 | 99 | | return false; |
| | 100 | |
|
| 3 | 101 | | int lateralLengh = Math.Abs((maxX - minX) + 1); |
| | 102 | |
|
| 3 | 103 | | if (parcelsPoints.Length != lateralLengh * lateralLengh) |
| 0 | 104 | | return false; |
| | 105 | |
|
| 3 | 106 | | return true; |
| | 107 | | } |
| | 108 | |
|
| 1 | 109 | | private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| | 110 | |
|
| | 111 | | public static LayerMask GetBIWCulling(LayerMask currentCulling) |
| | 112 | | { |
| 5 | 113 | | currentCulling += BIWSettings.FX_LAYER; |
| 5 | 114 | | return currentCulling; |
| | 115 | | } |
| | 116 | |
|
| 0 | 117 | | public static string Vector2INTToString(Vector2Int vector) { return vector.x + "," + vector.y; } |
| | 118 | |
|
| | 119 | | public static List<Vector2Int> GetLandsToPublishProject(LandWithAccess[] lands, IBuilderScene scene) |
| | 120 | | { |
| 0 | 121 | | List<Vector2Int> availableLandsToPublish = new List<Vector2Int>(); |
| 0 | 122 | | List<Vector2Int> totalParcels = new List<Vector2Int>(); |
| 0 | 123 | | foreach (LandWithAccess land in lands) |
| | 124 | | { |
| 0 | 125 | | totalParcels.AddRange(land.parcels.ToList()); |
| | 126 | | } |
| | 127 | |
|
| 0 | 128 | | Vector2Int sceneSize = GetSceneSize(scene.scene.sceneData.parcels); |
| 0 | 129 | | foreach (Vector2Int parcel in totalParcels) |
| | 130 | | { |
| 0 | 131 | | List<Vector2Int> necessaryParcelsToOwn = new List<Vector2Int>(); |
| 0 | 132 | | for (int x = 0; x < sceneSize.x; x++) |
| | 133 | | { |
| 0 | 134 | | for (int y = 0; y < sceneSize.y; y++) |
| | 135 | | { |
| 0 | 136 | | necessaryParcelsToOwn.Add(new Vector2Int(parcel.x + x, parcel.y + y)); |
| | 137 | | } |
| | 138 | | } |
| | 139 | |
|
| 0 | 140 | | int amountOfParcelFounds = 0; |
| 0 | 141 | | foreach (Vector2Int parcelToCheck in totalParcels) |
| | 142 | | { |
| 0 | 143 | | if (necessaryParcelsToOwn.Contains(parcelToCheck)) |
| 0 | 144 | | amountOfParcelFounds++; |
| | 145 | | } |
| | 146 | |
|
| 0 | 147 | | if (amountOfParcelFounds == necessaryParcelsToOwn.Count) |
| 0 | 148 | | availableLandsToPublish.Add(parcel); |
| | 149 | | } |
| 0 | 150 | | return availableLandsToPublish; |
| | 151 | | } |
| | 152 | |
|
| | 153 | | public static Vector2Int GetRowsAndColumsFromLand(LandWithAccess landWithAccess) |
| | 154 | | { |
| 0 | 155 | | Vector2Int result = new Vector2Int(); |
| 0 | 156 | | int baseX = landWithAccess.baseCoords.x; |
| 0 | 157 | | int baseY = landWithAccess.baseCoords.y; |
| | 158 | |
|
| 0 | 159 | | int amountX = 0; |
| 0 | 160 | | int amountY = 0; |
| | 161 | |
|
| 0 | 162 | | foreach (Vector2Int parcel in landWithAccess.parcels) |
| | 163 | | { |
| 0 | 164 | | if (parcel.x == baseX) |
| 0 | 165 | | amountX++; |
| | 166 | |
|
| 0 | 167 | | if (parcel.y == baseY) |
| 0 | 168 | | amountY++; |
| | 169 | | } |
| | 170 | |
|
| 0 | 171 | | result.x = amountX; |
| 0 | 172 | | result.y = amountY; |
| 0 | 173 | | return result; |
| | 174 | | } |
| | 175 | |
|
| | 176 | | public static ILand CreateILandFromManifest(IManifest manifest, Vector2Int initialCoord) |
| | 177 | | { |
| 5 | 178 | | ILand land = new ILand(); |
| 5 | 179 | | land.sceneId = manifest.project.scene_id; |
| 5 | 180 | | land.baseUrl = BIWUrlUtils.GetUrlSceneObjectContent(); |
| | 181 | |
|
| 5 | 182 | | land.mappingsResponse = new MappingsResponse(); |
| 5 | 183 | | land.mappingsResponse.parcel_id = land.sceneId; |
| 5 | 184 | | land.mappingsResponse.root_cid = land.sceneId; |
| 5 | 185 | | land.mappingsResponse.contents = new List<ContentServerUtils.MappingPair>(); |
| | 186 | |
|
| 5 | 187 | | land.sceneJsonData = new SceneJsonData(); |
| 5 | 188 | | land.sceneJsonData.main = "bin/game.js"; |
| 5 | 189 | | land.sceneJsonData.scene = new SceneParcels(); |
| 5 | 190 | | land.sceneJsonData.scene.@base = initialCoord.x + "," + initialCoord.y; |
| | 191 | |
|
| 5 | 192 | | int amountOfParcels = manifest.project.rows * manifest.project.cols; |
| 5 | 193 | | land.sceneJsonData.scene.parcels = new string[amountOfParcels]; |
| | 194 | |
|
| 5 | 195 | | int baseX = initialCoord.x; |
| 5 | 196 | | int baseY = initialCoord.y; |
| | 197 | |
|
| 5 | 198 | | int currentPositionInRow = 0; |
| 10 | 199 | | for (int i = 0; i < amountOfParcels; i++ ) |
| | 200 | | { |
| 0 | 201 | | land.sceneJsonData.scene.parcels[i] = baseX + "," + baseY; |
| 0 | 202 | | currentPositionInRow++; |
| 0 | 203 | | baseX++; |
| 0 | 204 | | if (currentPositionInRow >= manifest.project.rows) |
| | 205 | | { |
| 0 | 206 | | baseX = initialCoord.x; |
| 0 | 207 | | baseY++; |
| 0 | 208 | | currentPositionInRow = 0; |
| | 209 | | } |
| | 210 | | } |
| | 211 | |
|
| 5 | 212 | | return land; |
| | 213 | | } |
| | 214 | |
|
| | 215 | | public static ILand CreateILandFromParcelScene(IParcelScene scene) |
| | 216 | | { |
| 0 | 217 | | ILand land = new ILand(); |
| 0 | 218 | | land.sceneId = scene.sceneData.id; |
| 0 | 219 | | land.baseUrl = scene.sceneData.baseUrl; |
| 0 | 220 | | land.baseUrlBundles = scene.sceneData.baseUrlBundles; |
| | 221 | |
|
| 0 | 222 | | land.mappingsResponse = new MappingsResponse(); |
| 0 | 223 | | land.mappingsResponse.parcel_id = land.sceneId; |
| 0 | 224 | | land.mappingsResponse.root_cid = land.sceneId; |
| 0 | 225 | | land.mappingsResponse.contents = scene.sceneData.contents; |
| | 226 | |
|
| 0 | 227 | | land.sceneJsonData = new SceneJsonData(); |
| 0 | 228 | | land.sceneJsonData.main = "bin/game.js"; |
| 0 | 229 | | land.sceneJsonData.scene = new SceneParcels(); |
| 0 | 230 | | land.sceneJsonData.scene.@base = scene.sceneData.basePosition.ToString(); |
| 0 | 231 | | land.sceneJsonData.scene.parcels = new string[scene.sceneData.parcels.Length]; |
| | 232 | |
|
| 0 | 233 | | int count = 0; |
| 0 | 234 | | foreach (Vector2Int parcel in scene.sceneData.parcels) |
| | 235 | | { |
| 0 | 236 | | land.sceneJsonData.scene.parcels[count] = parcel.x + "," + parcel.y; |
| 0 | 237 | | count++; |
| | 238 | | } |
| | 239 | |
|
| 0 | 240 | | return land; |
| | 241 | | } |
| | 242 | |
|
| | 243 | | public static void AddSceneMappings(Dictionary<string, string> contents, string baseUrl, LoadParcelScenesMessage.Uni |
| | 244 | | { |
| 16 | 245 | | if (data == null) |
| 0 | 246 | | data = new LoadParcelScenesMessage.UnityParcelScene(); |
| | 247 | |
|
| 16 | 248 | | data.baseUrl = baseUrl; |
| 16 | 249 | | if (data.contents == null) |
| 11 | 250 | | data.contents = new List<ContentServerUtils.MappingPair>(); |
| | 251 | |
|
| 90 | 252 | | foreach (KeyValuePair<string, string> content in contents) |
| | 253 | | { |
| 29 | 254 | | ContentServerUtils.MappingPair mappingPair = new ContentServerUtils.MappingPair(); |
| 29 | 255 | | mappingPair.file = content.Key; |
| 29 | 256 | | mappingPair.hash = content.Value; |
| 29 | 257 | | bool found = false; |
| 161 | 258 | | foreach (ContentServerUtils.MappingPair mappingPairToCheck in data.contents) |
| | 259 | | { |
| 55 | 260 | | if (mappingPairToCheck.file == mappingPair.file) |
| | 261 | | { |
| 7 | 262 | | found = true; |
| 7 | 263 | | break; |
| | 264 | | } |
| | 265 | | } |
| | 266 | |
|
| 29 | 267 | | if (!found) |
| 22 | 268 | | data.contents.Add(mappingPair); |
| | 269 | | } |
| 16 | 270 | | } |
| | 271 | |
|
| | 272 | | public static void RemoveAssetsFromCurrentScene() |
| | 273 | | { |
| | 274 | | //We remove the old assets to they don't collide with the new ones |
| 2 | 275 | | foreach (var catalogItem in DataStore.i.builderInWorld.currentSceneCatalogItemDict.GetValues()) |
| | 276 | | { |
| 0 | 277 | | AssetCatalogBridge.i.RemoveSceneObjectToSceneCatalog(catalogItem.id); |
| | 278 | | } |
| 1 | 279 | | DataStore.i.builderInWorld.currentSceneCatalogItemDict.Clear(); |
| 1 | 280 | | } |
| | 281 | |
|
| | 282 | | public static void ShowGenericNotification(string message, DCL.NotificationModel.Type type = DCL.NotificationModel.T |
| | 283 | | { |
| 2 | 284 | | if (NotificationsController.i == null) |
| 1 | 285 | | return; |
| 1 | 286 | | NotificationsController.i.ShowNotification(new DCL.NotificationModel.Model |
| | 287 | | { |
| | 288 | | message = message, |
| | 289 | | type = DCL.NotificationModel.Type.GENERIC, |
| | 290 | | timer = timer, |
| | 291 | | destroyOnFinish = true |
| | 292 | | }); |
| 1 | 293 | | } |
| | 294 | |
|
| | 295 | | public static long ConvertToMilisecondsTimestamp(DateTime value) |
| | 296 | | { |
| 7 | 297 | | TimeSpan elapsedTime = value - Epoch; |
| 7 | 298 | | return (long) elapsedTime.TotalMilliseconds; |
| | 299 | | } |
| | 300 | |
|
| | 301 | | public static SceneMetricsModel GetSceneMetricsLimits(int parcelAmount) |
| | 302 | | { |
| 0 | 303 | | SceneMetricsModel cachedModel = new SceneMetricsModel(); |
| | 304 | |
|
| 0 | 305 | | float log = Mathf.Log(parcelAmount + 1, 2); |
| 0 | 306 | | float lineal = parcelAmount; |
| | 307 | |
|
| 0 | 308 | | cachedModel.triangles = (int) (lineal * SceneMetricsCounter.LimitsConfig.triangles); |
| 0 | 309 | | cachedModel.bodies = (int) (lineal * SceneMetricsCounter.LimitsConfig.bodies); |
| 0 | 310 | | cachedModel.entities = (int) (lineal * SceneMetricsCounter.LimitsConfig.entities); |
| 0 | 311 | | cachedModel.materials = (int) (log * SceneMetricsCounter.LimitsConfig.materials); |
| 0 | 312 | | cachedModel.textures = (int) (log * SceneMetricsCounter.LimitsConfig.textures); |
| 0 | 313 | | cachedModel.meshes = (int) (log * SceneMetricsCounter.LimitsConfig.meshes); |
| 0 | 314 | | cachedModel.sceneHeight = (int) (log * SceneMetricsCounter.LimitsConfig.height); |
| | 315 | |
|
| 0 | 316 | | return cachedModel; |
| | 317 | | } |
| | 318 | |
|
| | 319 | | public static Manifest CreateManifestFromProjectDataAndScene(ProjectData data, WebBuilderScene scene) |
| | 320 | | { |
| 0 | 321 | | Manifest manifest = new Manifest(); |
| 0 | 322 | | manifest.version = BIWSettings.MANIFEST_VERSION; |
| 0 | 323 | | manifest.project = data; |
| 0 | 324 | | manifest.scene = scene; |
| | 325 | |
|
| 0 | 326 | | manifest.project.scene_id = manifest.scene.id; |
| 0 | 327 | | return manifest; |
| | 328 | | } |
| | 329 | |
|
| | 330 | | public static Manifest CreateManifestFromProject(ProjectData projectData) |
| | 331 | | { |
| 0 | 332 | | Manifest manifest = new Manifest(); |
| 0 | 333 | | manifest.version = BIWSettings.MANIFEST_VERSION; |
| 0 | 334 | | manifest.project = projectData; |
| 0 | 335 | | manifest.scene = CreateEmtpyBuilderScene(projectData.rows, projectData.cols); |
| | 336 | |
|
| 0 | 337 | | manifest.project.scene_id = manifest.scene.id; |
| 0 | 338 | | return manifest; |
| | 339 | | } |
| | 340 | |
|
| | 341 | | //We create the scene the same way as the current builder do, so we ensure the compatibility between both builders |
| | 342 | | private static WebBuilderScene CreateEmtpyBuilderScene(int rows, int cols) |
| | 343 | | { |
| 0 | 344 | | Dictionary<string, BuilderEntity> entities = new Dictionary<string, BuilderEntity>(); |
| 0 | 345 | | Dictionary<string, BuilderComponent> components = new Dictionary<string, BuilderComponent>(); |
| 0 | 346 | | Dictionary<string, SceneObject> assets = new Dictionary<string, SceneObject>(); |
| | 347 | |
|
| | 348 | | // We get the asset |
| 0 | 349 | | var floorAsset = CreateFloorSceneObject(); |
| 0 | 350 | | assets.Add(floorAsset.id,floorAsset); |
| | 351 | |
|
| | 352 | | // We create the ground |
| 0 | 353 | | BuilderGround ground = new BuilderGround(); |
| 0 | 354 | | ground.assetId = floorAsset.id; |
| 0 | 355 | | ground.componentId = Guid.NewGuid().ToString(); |
| | 356 | |
|
| 0 | 357 | | for (int x = 0; x < rows; x++) |
| | 358 | | { |
| 0 | 359 | | for (int y = 0; y < cols; y++) |
| | 360 | | { |
| | 361 | | // We create the entity for the ground |
| 0 | 362 | | BuilderEntity entity = new BuilderEntity(); |
| 0 | 363 | | entity.id = Guid.NewGuid().ToString(); |
| 0 | 364 | | entity.disableGizmos = true; |
| 0 | 365 | | entity.name = "entity"+x+y; |
| | 366 | |
|
| | 367 | | // We need a transform for the entity so we create it |
| 0 | 368 | | BuilderComponent transformComponent = new BuilderComponent(); |
| 0 | 369 | | transformComponent.id = Guid.NewGuid().ToString(); |
| 0 | 370 | | transformComponent.type = "Transform"; |
| | 371 | |
|
| | 372 | | // We create the transform data |
| 0 | 373 | | TransformComponent entityTransformComponentModel = new TransformComponent(); |
| 0 | 374 | | entityTransformComponentModel.position = new Vector3(8+(16*x), 0, 8+(16*y)); |
| 0 | 375 | | entityTransformComponentModel.rotation = new ProtocolV2.QuaternionRepresentation(Quaternion.identity); |
| 0 | 376 | | entityTransformComponentModel.scale = Vector3.one; |
| | 377 | |
|
| 0 | 378 | | transformComponent.data = entityTransformComponentModel; |
| 0 | 379 | | entity.components.Add(transformComponent.id); |
| 0 | 380 | | if(!components.ContainsKey(transformComponent.id)) |
| 0 | 381 | | components.Add(transformComponent.id,transformComponent); |
| | 382 | |
|
| | 383 | | // We create the GLTFShape component |
| 0 | 384 | | BuilderComponent gltfShapeComponent = new BuilderComponent(); |
| 0 | 385 | | gltfShapeComponent.id = ground.componentId; |
| 0 | 386 | | gltfShapeComponent.type = "GLTFShape"; |
| | 387 | |
|
| 0 | 388 | | LoadableShape.Model model = new GLTFShape.Model(); |
| 0 | 389 | | model.assetId = floorAsset.id; |
| 0 | 390 | | gltfShapeComponent.data = model; |
| | 391 | |
|
| 0 | 392 | | entity.components.Add(ground.componentId); |
| 0 | 393 | | if(!components.ContainsKey(gltfShapeComponent.id)) |
| 0 | 394 | | components.Add(gltfShapeComponent.id,gltfShapeComponent); |
| | 395 | |
|
| | 396 | | // Finally, we add the entity to the list |
| 0 | 397 | | entities.Add(entity.id,entity); |
| | 398 | | } |
| | 399 | | } |
| | 400 | |
|
| 0 | 401 | | WebBuilderScene scene = new WebBuilderScene |
| | 402 | | { |
| | 403 | | id = Guid.NewGuid().ToString(), |
| | 404 | | entities = entities, |
| | 405 | | components = components, |
| | 406 | | assets = assets, |
| | 407 | | limits = GetSceneMetricsLimits(rows*cols), |
| | 408 | | metrics = new SceneMetricsModel(), |
| | 409 | | ground = ground |
| | 410 | | }; |
| | 411 | |
|
| 0 | 412 | | return scene; |
| | 413 | | } |
| | 414 | |
|
| | 415 | | public static Manifest CreateEmptyDefaultBuilderManifest(Vector2Int size, string landCoordinates) |
| | 416 | | { |
| 0 | 417 | | Manifest manifest = new Manifest(); |
| 0 | 418 | | manifest.version = BIWSettings.MANIFEST_VERSION; |
| | 419 | |
|
| | 420 | | //We create a new project data for the scene |
| 0 | 421 | | ProjectData projectData = new ProjectData(); |
| 0 | 422 | | projectData.id = Guid.NewGuid().ToString(); |
| 0 | 423 | | projectData.eth_address = UserProfile.GetOwnUserProfile().ethAddress; |
| 0 | 424 | | projectData.title = "Builder " + landCoordinates; |
| 0 | 425 | | projectData.description = "Scene created from the explorer builder"; |
| 0 | 426 | | projectData.creation_coords = landCoordinates; |
| 0 | 427 | | projectData.rows = size.x; |
| 0 | 428 | | projectData.cols = size.y; |
| 0 | 429 | | projectData.updated_at = DateTime.Now; |
| 0 | 430 | | projectData.created_at = DateTime.Now; |
| 0 | 431 | | projectData.thumbnail = "thumbnail.png"; |
| | 432 | |
|
| | 433 | | //We create an empty scene |
| 0 | 434 | | manifest.scene = CreateEmtpyBuilderScene(size.x, size.y); |
| | 435 | |
|
| 0 | 436 | | projectData.scene_id = manifest.scene.id; |
| 0 | 437 | | manifest.project = projectData; |
| 0 | 438 | | return manifest; |
| | 439 | | } |
| | 440 | |
|
| | 441 | | public static LandRole GetLandOwnershipType(List<LandWithAccess> lands, IParcelScene scene) |
| | 442 | | { |
| 5 | 443 | | LandWithAccess filteredLand = lands.FirstOrDefault(land => scene.sceneData.basePosition == land.baseCoords); |
| 5 | 444 | | return GetLandOwnershipType(filteredLand); |
| | 445 | | } |
| | 446 | |
|
| | 447 | | public static LandRole GetLandOwnershipType(LandWithAccess land) |
| | 448 | | { |
| 0 | 449 | | if (land != null) |
| 0 | 450 | | return land.role; |
| 0 | 451 | | return LandRole.OWNER; |
| | 452 | | } |
| | 453 | |
|
| | 454 | | public static Vector3 SnapFilterEulerAngles(Vector3 vectorToFilter, float degrees) |
| | 455 | | { |
| 0 | 456 | | vectorToFilter.x = ClosestNumber(vectorToFilter.x, degrees); |
| 0 | 457 | | vectorToFilter.y = ClosestNumber(vectorToFilter.y, degrees); |
| 0 | 458 | | vectorToFilter.z = ClosestNumber(vectorToFilter.z, degrees); |
| | 459 | |
|
| 0 | 460 | | return vectorToFilter; |
| | 461 | | } |
| | 462 | |
|
| | 463 | | static float ClosestNumber(float n, float m) |
| | 464 | | { |
| | 465 | | // find the quotient |
| 0 | 466 | | int q = Mathf.RoundToInt(n / m); |
| | 467 | |
|
| | 468 | | // 1st possible closest number |
| 0 | 469 | | float n1 = m * q; |
| | 470 | |
|
| | 471 | | // 2nd possible closest number |
| 0 | 472 | | float n2 = (n * m) > 0 ? (m * (q + 1)) : (m * (q - 1)); |
| | 473 | |
|
| | 474 | | // if true, then n1 is the required closest number |
| 0 | 475 | | if (Math.Abs(n - n1) < Math.Abs(n - n2)) |
| 0 | 476 | | return n1; |
| | 477 | |
|
| | 478 | | // else n2 is the required closest number |
| 0 | 479 | | return n2; |
| | 480 | | } |
| | 481 | |
|
| 12 | 482 | | public static Vector2Int GetSceneSize(IParcelScene parcelScene) { return GetSceneSize(parcelScene.sceneData.parcels) |
| | 483 | |
|
| | 484 | | public static bool HasSquareSize(LandWithAccess land) |
| | 485 | | { |
| 0 | 486 | | Vector2Int size = GetSceneSize(land.parcels); |
| | 487 | |
|
| 0 | 488 | | for (int x = land.baseCoords.x; x < size.x; x++) |
| | 489 | | { |
| 0 | 490 | | bool found = false; |
| 0 | 491 | | foreach (Vector2Int parcel in land.parcels) |
| | 492 | | { |
| 0 | 493 | | if (parcel.x == x) |
| | 494 | | { |
| 0 | 495 | | found = true; |
| 0 | 496 | | break; |
| | 497 | | } |
| | 498 | | } |
| 0 | 499 | | if (!found) |
| 0 | 500 | | return false; |
| | 501 | | } |
| | 502 | |
|
| 0 | 503 | | for (int y = land.baseCoords.y; y < size.x; y++) |
| | 504 | | { |
| 0 | 505 | | bool found = false; |
| 0 | 506 | | foreach (Vector2Int parcel in land.parcels) |
| | 507 | | { |
| 0 | 508 | | if (parcel.y == y) |
| | 509 | | { |
| 0 | 510 | | found = true; |
| 0 | 511 | | break; |
| | 512 | | } |
| | 513 | | } |
| 0 | 514 | | if (!found) |
| 0 | 515 | | return false; |
| | 516 | | } |
| | 517 | |
|
| 0 | 518 | | return true; |
| | 519 | | } |
| | 520 | |
|
| | 521 | | public static Vector2Int GetSceneSize(Vector2Int[] parcels) |
| | 522 | | { |
| 12 | 523 | | int minX = Int32.MaxValue; |
| 12 | 524 | | int maxX = Int32.MinValue; |
| 12 | 525 | | int minY = Int32.MaxValue; |
| 12 | 526 | | int maxY = Int32.MinValue; |
| | 527 | |
|
| 64 | 528 | | foreach (var parcel in parcels) |
| | 529 | | { |
| 20 | 530 | | if (parcel.x > maxX) |
| 14 | 531 | | maxX = parcel.x; |
| 20 | 532 | | if (parcel.x < minX) |
| 14 | 533 | | minX = parcel.x; |
| | 534 | |
|
| 20 | 535 | | if (parcel.y > maxY) |
| 14 | 536 | | maxY = parcel.y; |
| 20 | 537 | | if (parcel.y < minY) |
| 14 | 538 | | minY = parcel.y; |
| | 539 | | } |
| | 540 | |
|
| 12 | 541 | | int sizeX = maxX - minX + 1; |
| 12 | 542 | | int sizeY = maxY - minY + 1; |
| 12 | 543 | | return new Vector2Int(sizeX, sizeY); |
| | 544 | | } |
| | 545 | |
|
| | 546 | | public static Vector3 CalculateUnityMiddlePoint(IParcelScene parcelScene) |
| | 547 | | { |
| | 548 | | Vector3 position; |
| | 549 | |
|
| 80 | 550 | | float totalX = 0f; |
| 80 | 551 | | float totalY = 0f; |
| 80 | 552 | | float totalZ = 0f; |
| | 553 | |
|
| 80 | 554 | | int minX = int.MaxValue; |
| 80 | 555 | | int minY = int.MaxValue; |
| 80 | 556 | | int maxX = int.MinValue; |
| 80 | 557 | | int maxY = int.MinValue; |
| | 558 | |
|
| 80 | 559 | | if (parcelScene?.sceneData == null || parcelScene?.sceneData.parcels == null) |
| 6 | 560 | | return Vector3.zero; |
| | 561 | |
|
| 296 | 562 | | foreach (Vector2Int vector in parcelScene?.sceneData.parcels) |
| | 563 | | { |
| 74 | 564 | | totalX += vector.x; |
| 74 | 565 | | totalZ += vector.y; |
| 74 | 566 | | if (vector.x < minX) |
| 74 | 567 | | minX = vector.x; |
| 74 | 568 | | if (vector.y < minY) |
| 74 | 569 | | minY = vector.y; |
| 74 | 570 | | if (vector.x > maxX) |
| 74 | 571 | | maxX = vector.x; |
| 74 | 572 | | if (vector.y > maxY) |
| 74 | 573 | | maxY = vector.y; |
| | 574 | | } |
| | 575 | |
|
| 74 | 576 | | float centerX = totalX / parcelScene.sceneData.parcels.Length + 0.5f; |
| 74 | 577 | | float centerZ = totalZ / parcelScene.sceneData.parcels.Length + 0.5f; |
| | 578 | |
|
| 74 | 579 | | position.x = centerX; |
| 74 | 580 | | position.y = totalY; |
| 74 | 581 | | position.z = centerZ; |
| | 582 | |
|
| 74 | 583 | | Vector3 scenePosition = Utils.GridToWorldPosition(centerX, centerZ); |
| 74 | 584 | | position = PositionUtils.WorldToUnityPosition(scenePosition); |
| | 585 | |
|
| 74 | 586 | | return position; |
| | 587 | | } |
| | 588 | |
|
| | 589 | | public static SceneObject CreateFloorSceneObject() |
| | 590 | | { |
| 0 | 591 | | SceneObject floorSceneObject = new SceneObject(); |
| 0 | 592 | | floorSceneObject.id = BIWSettings.FLOOR_ID; |
| | 593 | |
|
| 0 | 594 | | floorSceneObject.model = BIWSettings.FLOOR_MODEL; |
| 0 | 595 | | floorSceneObject.name = BIWSettings.FLOOR_NAME; |
| 0 | 596 | | floorSceneObject.asset_pack_id = BIWSettings.FLOOR_ASSET_PACK_ID; |
| 0 | 597 | | floorSceneObject.thumbnail = BIWSettings.FLOOR_ASSET_THUMBNAIL; |
| 0 | 598 | | floorSceneObject.category = BIWSettings.FLOOR_CATEGORY; |
| | 599 | |
|
| 0 | 600 | | floorSceneObject.tags = new List<string>(); |
| 0 | 601 | | floorSceneObject.tags.Add("genesis"); |
| 0 | 602 | | floorSceneObject.tags.Add("city"); |
| 0 | 603 | | floorSceneObject.tags.Add("town"); |
| 0 | 604 | | floorSceneObject.tags.Add("ground"); |
| | 605 | |
|
| 0 | 606 | | floorSceneObject.contents = new Dictionary<string, string>(); |
| | 607 | |
|
| 0 | 608 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_GLTF_KEY, BIWSettings.FLOOR_GLTF_VALUE); |
| 0 | 609 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_TEXTURE_KEY, BIWSettings.FLOOR_TEXTURE_VALUE); |
| 0 | 610 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_THUMBNAIL_KEY, BIWSettings.FLOOR_THUMBNAIL_VALUE); |
| | 611 | |
|
| 0 | 612 | | floorSceneObject.metrics = new SceneObject.ObjectMetrics(); |
| | 613 | |
|
| 0 | 614 | | return floorSceneObject; |
| | 615 | | } |
| | 616 | |
|
| | 617 | | public static CatalogItem CreateFloorCatalogItem() |
| | 618 | | { |
| 0 | 619 | | CatalogItem floorSceneObject = new CatalogItem(); |
| 0 | 620 | | floorSceneObject.id = BIWSettings.FLOOR_ID; |
| | 621 | |
|
| 0 | 622 | | floorSceneObject.model = BIWSettings.FLOOR_MODEL; |
| 0 | 623 | | floorSceneObject.name = BIWSettings.FLOOR_NAME; |
| 0 | 624 | | floorSceneObject.assetPackName = BIWSettings.FLOOR_ASSET_PACK_NAME; |
| 0 | 625 | | floorSceneObject.thumbnailURL = BIWSettings.FLOOR_ASSET_THUMBNAIL; |
| | 626 | |
|
| 0 | 627 | | floorSceneObject.tags = new List<string>(); |
| 0 | 628 | | floorSceneObject.tags.Add("genesis"); |
| 0 | 629 | | floorSceneObject.tags.Add("city"); |
| 0 | 630 | | floorSceneObject.tags.Add("town"); |
| 0 | 631 | | floorSceneObject.tags.Add("ground"); |
| | 632 | |
|
| 0 | 633 | | floorSceneObject.contents = new Dictionary<string, string>(); |
| | 634 | |
|
| 0 | 635 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_GLTF_KEY, BIWSettings.FLOOR_GLTF_VALUE); |
| 0 | 636 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_TEXTURE_KEY, BIWSettings.FLOOR_TEXTURE_VALUE); |
| 0 | 637 | | floorSceneObject.contents.Add(BIWSettings.FLOOR_THUMBNAIL_KEY, BIWSettings.FLOOR_THUMBNAIL_VALUE); |
| | 638 | |
|
| 0 | 639 | | floorSceneObject.metrics = new SceneObject.ObjectMetrics(); |
| | 640 | |
|
| 0 | 641 | | return floorSceneObject; |
| | 642 | | } |
| | 643 | |
|
| | 644 | | public static Dictionary<string, string> ConvertMappingsToDictionary(ContentServerUtils.MappingPair[] contents) |
| | 645 | | { |
| 0 | 646 | | Dictionary<string, string> mappingDict = new Dictionary<string, string>(); |
| | 647 | |
|
| 0 | 648 | | foreach (ContentServerUtils.MappingPair mappingPair in contents) |
| | 649 | | { |
| 0 | 650 | | mappingDict.Add(mappingPair.file, mappingPair.hash); |
| | 651 | | } |
| | 652 | |
|
| 0 | 653 | | return mappingDict; |
| | 654 | | } |
| | 655 | |
|
| | 656 | | public static void DrawScreenRect(Rect rect, Color color) |
| | 657 | | { |
| 0 | 658 | | GUI.color = color; |
| 0 | 659 | | GUI.DrawTexture(rect, Texture2D.whiteTexture); |
| 0 | 660 | | } |
| | 661 | |
|
| | 662 | | public static void DrawScreenRectBorder(Rect rect, float thickness, Color color) |
| | 663 | | { |
| | 664 | | //Top |
| 0 | 665 | | DrawScreenRect(new Rect(rect.xMin, rect.yMin, rect.width, thickness), color); |
| | 666 | | // Left |
| 0 | 667 | | DrawScreenRect(new Rect(rect.xMin, rect.yMin, thickness, rect.height), color); |
| | 668 | | // Right |
| 0 | 669 | | DrawScreenRect(new Rect(rect.xMax - thickness, rect.yMin, thickness, rect.height), color); |
| | 670 | | // Bottom |
| 0 | 671 | | DrawScreenRect(new Rect(rect.xMin, rect.yMax - thickness, rect.width, thickness), color); |
| 0 | 672 | | } |
| | 673 | |
|
| | 674 | | public static Rect GetScreenRect(Vector3 screenPosition1, Vector3 screenPosition2) |
| | 675 | | { |
| | 676 | | // Move origin from bottom left to top left |
| 0 | 677 | | screenPosition1.y = Screen.height - screenPosition1.y; |
| 0 | 678 | | screenPosition2.y = Screen.height - screenPosition2.y; |
| | 679 | | // Calculate corners |
| 0 | 680 | | var topLeft = Vector3.Min(screenPosition1, screenPosition2); |
| 0 | 681 | | var bottomRight = Vector3.Max(screenPosition1, screenPosition2); |
| | 682 | | // Create Rect |
| 0 | 683 | | return Rect.MinMaxRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); |
| | 684 | | } |
| | 685 | |
|
| | 686 | | public static Bounds GetViewportBounds(Camera camera, Vector3 screenPosition1, Vector3 screenPosition2) |
| | 687 | | { |
| 2 | 688 | | var v1 = camera.ScreenToViewportPoint(screenPosition1); |
| 2 | 689 | | var v2 = camera.ScreenToViewportPoint(screenPosition2); |
| 2 | 690 | | var min = Vector3.Min(v1, v2); |
| 2 | 691 | | var max = Vector3.Max(v1, v2); |
| 2 | 692 | | min.z = camera.nearClipPlane; |
| 2 | 693 | | max.z = camera.farClipPlane; |
| | 694 | |
|
| 2 | 695 | | var bounds = new Bounds(); |
| | 696 | |
|
| 2 | 697 | | bounds.SetMinMax(min, max); |
| 2 | 698 | | return bounds; |
| | 699 | | } |
| | 700 | |
|
| 0 | 701 | | public static bool IsWithinSelectionBounds(Transform transform, Vector3 lastClickMousePosition, Vector3 mousePositio |
| | 702 | |
|
| | 703 | | public static bool IsWithinSelectionBounds(Vector3 point, Vector3 lastClickMousePosition, Vector3 mousePosition) |
| | 704 | | { |
| 2 | 705 | | Camera camera = Camera.main; |
| 2 | 706 | | var viewPortBounds = GetViewportBounds(camera, lastClickMousePosition, mousePosition); |
| 2 | 707 | | return viewPortBounds.Contains(camera.WorldToViewportPoint(point)); |
| | 708 | | } |
| | 709 | |
|
| | 710 | | public static bool IsBoundInsideCamera(Bounds bound) |
| | 711 | | { |
| 0 | 712 | | Vector3[] points = { bound.max, bound.center, bound.min }; |
| 0 | 713 | | return IsPointInsideCamera(points); |
| | 714 | | } |
| | 715 | |
|
| | 716 | | public static bool IsPointInsideCamera(Vector3[] points) |
| | 717 | | { |
| 0 | 718 | | foreach (Vector3 point in points) |
| | 719 | | { |
| 0 | 720 | | if (IsPointInsideCamera(point)) |
| 0 | 721 | | return true; |
| | 722 | | } |
| 0 | 723 | | return false; |
| | 724 | | } |
| | 725 | |
|
| | 726 | | public static bool IsPointInsideCamera(Vector3 point) |
| | 727 | | { |
| 0 | 728 | | Vector3 topRight = new Vector3(Screen.width, Screen.height, 0); |
| 0 | 729 | | var viewPortBounds = GetViewportBounds(Camera.main, Vector3.zero, topRight); |
| 0 | 730 | | return viewPortBounds.Contains(Camera.main.WorldToViewportPoint(point)); |
| | 731 | | } |
| | 732 | |
|
| | 733 | | public static void CopyGameObjectStatus(GameObject gameObjectToCopy, GameObject gameObjectToReceive, bool copyParent |
| | 734 | | { |
| 5 | 735 | | if (copyParent) |
| 0 | 736 | | gameObjectToReceive.transform.SetParent(gameObjectToCopy.transform.parent); |
| | 737 | |
|
| 5 | 738 | | gameObjectToReceive.transform.position = gameObjectToCopy.transform.position; |
| | 739 | |
|
| 5 | 740 | | if (localRotation) |
| 0 | 741 | | gameObjectToReceive.transform.localRotation = gameObjectToCopy.transform.localRotation; |
| | 742 | | else |
| 5 | 743 | | gameObjectToReceive.transform.rotation = gameObjectToCopy.transform.rotation; |
| | 744 | |
|
| 5 | 745 | | gameObjectToReceive.transform.localScale = gameObjectToCopy.transform.lossyScale; |
| 5 | 746 | | } |
| | 747 | |
|
| | 748 | | public static bool IsPointerOverMaskElement(LayerMask mask) |
| | 749 | | { |
| | 750 | | RaycastHit hitInfo; |
| 2 | 751 | | UnityEngine.Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); |
| 2 | 752 | | return Physics.Raycast(mouseRay, out hitInfo, 5555, mask); |
| | 753 | | } |
| | 754 | |
|
| | 755 | | public static bool IsPointerOverUIElement(Vector3 mousePosition) |
| | 756 | | { |
| 1 | 757 | | var eventData = new PointerEventData(EventSystem.current); |
| 1 | 758 | | eventData.position = mousePosition; |
| 1 | 759 | | var results = new List<RaycastResult>(); |
| 1 | 760 | | EventSystem.current.RaycastAll(eventData, results); |
| 1 | 761 | | return results.Count > 2; |
| | 762 | | } |
| | 763 | |
|
| 1 | 764 | | public static bool IsPointerOverUIElement() { return IsPointerOverUIElement(Input.mousePosition); } |
| | 765 | |
|
| | 766 | | public static string ConvertEntityToJSON(IDCLEntity entity) |
| | 767 | | { |
| 4 | 768 | | EntityData builderInWorldEntityData = new EntityData(); |
| 4 | 769 | | builderInWorldEntityData.entityId = entity.entityId; |
| | 770 | |
|
| 4 | 771 | | var components = entity.scene.componentsManagerLegacy.GetComponentsDictionary(entity); |
| | 772 | |
|
| 4 | 773 | | if (components != null) |
| | 774 | | { |
| 4 | 775 | | foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in components) |
| | 776 | | { |
| 1 | 777 | | if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM) |
| | 778 | | { |
| 1 | 779 | | EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent(); |
| | 780 | |
|
| 1 | 781 | | entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transf |
| 1 | 782 | | entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles; |
| 1 | 783 | | entityComponentModel.scale = entity.gameObject.transform.localScale; |
| | 784 | |
|
| 1 | 785 | | builderInWorldEntityData.transformComponent = entityComponentModel; |
| 1 | 786 | | } |
| | 787 | | else |
| | 788 | | { |
| 0 | 789 | | ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent(); |
| 0 | 790 | | entityComponentModel.componentId = (int)keyValuePair.Key; |
| 0 | 791 | | entityComponentModel.data = keyValuePair.Value.GetModel(); |
| | 792 | |
|
| 0 | 793 | | builderInWorldEntityData.components.Add(entityComponentModel); |
| | 794 | | } |
| | 795 | | } |
| | 796 | | } |
| | 797 | |
|
| 4 | 798 | | var sharedComponents = entity.scene.componentsManagerLegacy.GetSharedComponentsDictionary(entity); |
| | 799 | |
|
| 4 | 800 | | if (sharedComponents != null) |
| | 801 | | { |
| 0 | 802 | | foreach (KeyValuePair<Type, ISharedComponent> keyValuePair in sharedComponents) |
| | 803 | | { |
| 0 | 804 | | if (keyValuePair.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE) |
| | 805 | | { |
| 0 | 806 | | EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent(); |
| 0 | 807 | | NFTShape.Model model = (NFTShape.Model)keyValuePair.Value.GetModel(); |
| | 808 | |
|
| 0 | 809 | | nFTComponent.id = keyValuePair.Value.id; |
| 0 | 810 | | nFTComponent.color = new ColorRepresentation(model.color); |
| 0 | 811 | | nFTComponent.assetId = model.assetId; |
| 0 | 812 | | nFTComponent.src = model.src; |
| 0 | 813 | | nFTComponent.style = model.style; |
| | 814 | |
|
| 0 | 815 | | builderInWorldEntityData.nftComponent = nFTComponent; |
| 0 | 816 | | } |
| | 817 | | else |
| | 818 | | { |
| 0 | 819 | | ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent(); |
| 0 | 820 | | entityComponentModel.componentId = keyValuePair.Value.GetClassId(); |
| 0 | 821 | | entityComponentModel.data = keyValuePair.Value.GetModel(); |
| 0 | 822 | | entityComponentModel.classId = keyValuePair.Value.id; |
| | 823 | |
|
| 0 | 824 | | builderInWorldEntityData.sharedComponents.Add(entityComponentModel); |
| | 825 | | } |
| | 826 | | } |
| | 827 | | } |
| | 828 | |
|
| | 829 | |
|
| 4 | 830 | | return JsonConvert.SerializeObject(builderInWorldEntityData); |
| | 831 | | } |
| | 832 | |
|
| 3 | 833 | | public static EntityData ConvertJSONToEntityData(string json) { return JsonConvert.DeserializeObject<EntityData>(jso |
| | 834 | |
|
| | 835 | | public static List<BIWEntity> RemoveGroundEntities(List<BIWEntity> entityList) |
| | 836 | | { |
| 0 | 837 | | List<BIWEntity> newList = new List<BIWEntity>(); |
| | 838 | |
|
| 0 | 839 | | foreach (BIWEntity entity in entityList) |
| | 840 | | { |
| 0 | 841 | | if (entity.isFloor) |
| | 842 | | continue; |
| | 843 | |
|
| 0 | 844 | | newList.Add(entity); |
| | 845 | | } |
| | 846 | |
|
| 0 | 847 | | return newList; |
| | 848 | | } |
| | 849 | |
|
| | 850 | | public static List<BIWEntity> FilterEntitiesBySmartItemComponentAndActions(List<BIWEntity> entityList) |
| | 851 | | { |
| 0 | 852 | | List<BIWEntity> newList = new List<BIWEntity>(); |
| | 853 | |
|
| 0 | 854 | | foreach (BIWEntity entity in entityList) |
| | 855 | | { |
| 0 | 856 | | if (!entity.HasSmartItemComponent() || !entity.HasSmartItemActions()) |
| | 857 | | continue; |
| | 858 | |
|
| 0 | 859 | | newList.Add(entity); |
| | 860 | | } |
| | 861 | |
|
| 0 | 862 | | return newList; |
| | 863 | | } |
| | 864 | |
|
| | 865 | | public static void CopyRectTransform(RectTransform original, RectTransform rectTransformToCopy) |
| | 866 | | { |
| 0 | 867 | | original.anchoredPosition = rectTransformToCopy.anchoredPosition; |
| 0 | 868 | | original.anchorMax = rectTransformToCopy.anchorMax; |
| 0 | 869 | | original.anchorMin = rectTransformToCopy.anchorMin; |
| 0 | 870 | | original.offsetMax = rectTransformToCopy.offsetMax; |
| 0 | 871 | | original.offsetMin = rectTransformToCopy.offsetMin; |
| 0 | 872 | | original.sizeDelta = rectTransformToCopy.sizeDelta; |
| 0 | 873 | | original.pivot = rectTransformToCopy.pivot; |
| 0 | 874 | | } |
| | 875 | |
|
| | 876 | | public static IWebRequestAsyncOperation MakeGetCall(string url, Promise<string> callPromise, Dictionary<string, stri |
| | 877 | | { |
| 4 | 878 | | headers["Cache-Control"] = "no-cache"; |
| 4 | 879 | | var asyncOperation = Environment.i.platform.webRequest.Get( |
| | 880 | | url: url, |
| | 881 | | OnSuccess: (webRequestResult) => |
| | 882 | | { |
| 4 | 883 | | byte[] byteArray = webRequestResult.GetResultData(); |
| 4 | 884 | | string result = System.Text.Encoding.UTF8.GetString(byteArray); |
| 4 | 885 | | callPromise?.Resolve(result); |
| 4 | 886 | | }, |
| | 887 | | OnFail: (webRequestResult) => |
| | 888 | | { |
| | 889 | | try |
| | 890 | | { |
| 0 | 891 | | byte[] byteArray = webRequestResult.GetResultData(); |
| 0 | 892 | | string result = System.Text.Encoding.UTF8.GetString(byteArray); |
| 0 | 893 | | APIResponse response = JsonConvert.DeserializeObject<APIResponse>(result); |
| 0 | 894 | | callPromise?.Resolve(result); |
| 0 | 895 | | } |
| 0 | 896 | | catch (Exception e) |
| | 897 | | { |
| 0 | 898 | | Debug.Log(webRequestResult.webRequest.error); |
| 0 | 899 | | callPromise.Reject(webRequestResult.webRequest.error); |
| 0 | 900 | | } |
| 0 | 901 | | }, |
| | 902 | | headers: headers); |
| | 903 | |
|
| 4 | 904 | | return asyncOperation; |
| | 905 | | } |
| | 906 | |
|
| | 907 | | public static IWebRequestAsyncOperation MakeGetTextureCall(string url, Promise<Texture2D> callPromise) |
| | 908 | | { |
| 0 | 909 | | var asyncOperation = Environment.i.platform.webRequest.GetTexture( |
| | 910 | | url: url, |
| | 911 | | OnSuccess: (webRequestResult) => |
| | 912 | | { |
| 0 | 913 | | callPromise.Resolve(DownloadHandlerTexture.GetContent(webRequestResult.webRequest)); |
| 0 | 914 | | }, |
| | 915 | | OnFail: (webRequestResult) => |
| | 916 | | { |
| 0 | 917 | | callPromise.Reject(webRequestResult.webRequest.error); |
| 0 | 918 | | }); |
| | 919 | |
|
| 0 | 920 | | return asyncOperation; |
| | 921 | | } |
| | 922 | |
|
| | 923 | | public static void ConfigureEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType, UnityAction<BaseEven |
| | 924 | | { |
| 2084 | 925 | | EventTrigger.Entry entry = new EventTrigger.Entry(); |
| 2084 | 926 | | entry.eventID = eventType; |
| 2084 | 927 | | entry.callback.AddListener(call); |
| 2084 | 928 | | eventTrigger.triggers.Add(entry); |
| 2084 | 929 | | } |
| | 930 | |
|
| 5124 | 931 | | public static void RemoveEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType) { eventTrigger.triggers |
| | 932 | | } |