< Summary

Class:BIWUtils
Assembly:BuilderInWorldUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Utils/BIWUtils.cs
Covered lines:181
Uncovered lines:296
Coverable lines:477
Total lines:932
Line coverage:37.9% (181 of 477)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DuplicateEntity(...)0%14.5510064.29%
IsParcelSceneSquare(...)0%8.068090.48%
BIWUtils()0%110100%
GetBIWCulling(...)0%110100%
Vector2INTToString(...)0%2100%
GetLandsToPublishProject(...)0%72800%
GetRowsAndColumsFromLand(...)0%20400%
CreateILandFromManifest(...)0%3.233070.37%
CreateILandFromParcelScene(...)0%6200%
AddSceneMappings(...)0%7.017095.24%
RemoveAssetsFromCurrentScene()0%2.152066.67%
ShowGenericNotification(...)0%220100%
ConvertToMilisecondsTimestamp(...)0%110100%
GetSceneMetricsLimits(...)0%2100%
CreateManifestFromProjectDataAndScene(...)0%2100%
CreateManifestFromProject(...)0%2100%
CreateEmtpyBuilderScene(...)0%30500%
CreateEmptyDefaultBuilderManifest(...)0%2100%
GetLandOwnershipType(...)0%110100%
GetLandOwnershipType(...)0%6200%
SnapFilterEulerAngles(...)0%2100%
ClosestNumber(...)0%12300%
GetSceneSize(...)0%110100%
HasSquareSize(...)0%90900%
GetSceneSize(...)0%660100%
CalculateUnityMiddlePoint(...)0%14140100%
CreateFloorSceneObject()0%2100%
CreateFloorCatalogItem()0%2100%
ConvertMappingsToDictionary(...)0%6200%
DrawScreenRect(...)0%2100%
DrawScreenRectBorder(...)0%2100%
GetScreenRect(...)0%2100%
GetViewportBounds(...)0%110100%
IsWithinSelectionBounds(...)0%2100%
IsWithinSelectionBounds(...)0%110100%
IsBoundInsideCamera(...)0%2100%
IsPointInsideCamera(...)0%12300%
IsPointInsideCamera(...)0%2100%
CopyGameObjectStatus(...)0%3.143075%
IsPointerOverMaskElement(...)0%110100%
IsPointerOverUIElement(...)0%110100%
IsPointerOverUIElement()0%110100%
ConvertEntityToJSON(...)0%23.549043.59%
ConvertJSONToEntityData(...)0%110100%
RemoveGroundEntities(...)0%12300%
FilterEntitiesBySmartItemComponentAndActions(...)0%20400%
CopyRectTransform(...)0%2100%
MakeGetCall(...)0%110100%
MakeGetTextureCall(...)0%2100%
ConfigureEventTrigger(...)0%110100%
RemoveEventTrigger(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Utils/BIWUtils.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Models;
 4using System;
 5using System.Collections;
 6using System.Collections.Generic;
 7using UnityEngine;
 8using UnityEngine.EventSystems;
 9using Newtonsoft.Json;
 10using Newtonsoft.Json.Linq;
 11using DCL.Configuration;
 12using static ProtocolV2;
 13using Environment = DCL.Environment;
 14using System.IO;
 15using System.Linq;
 16using System.Runtime.Serialization.Formatters.Binary;
 17using DCL.Builder;
 18using DCL.Builder.Manifest;
 19using DCL.Controllers;
 20using DCL.Helpers;
 21using UnityEditor;
 22using UnityEngine.Networking;
 23using UnityEngine.Events;
 24
 25public static partial class BIWUtils
 26{
 27    public static IDCLEntity DuplicateEntity(IParcelScene scene, IDCLEntity entity)
 28    {
 329        if (!scene.entities.ContainsKey(entity.entityId))
 030            return null;
 31
 332        var sceneController = Environment.i.world.sceneController;
 333        IDCLEntity newEntity =
 34            scene.CreateEntity(
 35                sceneController.entityIdHelper.EntityFromLegacyEntityString(System.Guid.NewGuid().ToString()));
 36
 337        if (entity.children.Count > 0)
 38        {
 039            using (var iterator = entity.children.GetEnumerator())
 40            {
 041                while (iterator.MoveNext())
 42                {
 043                    IDCLEntity childDuplicate = DuplicateEntity(scene, iterator.Current.Value);
 044                    childDuplicate.SetParent(newEntity);
 45                }
 046            }
 47        }
 48
 349        if (entity.parent != null)
 050            scene.SetEntityParent(newEntity.entityId, entity.parent.entityId);
 51
 352        DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position);
 353        DCLTransform.model.rotation = entity.gameObject.transform.rotation;
 354        DCLTransform.model.scale = entity.gameObject.transform.lossyScale;
 55
 356        var components = scene.componentsManagerLegacy.GetComponentsDictionary(entity);
 57
 358        if (components != null)
 59        {
 460            foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> component in components)
 61            {
 162                scene.componentsManagerLegacy.EntityComponentCreateOrUpdate(newEntity.entityId, component.Key, component
 63            }
 64        }
 65
 366        using (var iterator = scene.componentsManagerLegacy.GetSharedComponents(entity))
 67        {
 368            while (iterator.MoveNext())
 69            {
 070                ISharedComponent sharedComponent = scene.componentsManagerLegacy.SceneSharedComponentCreate(System.Guid.
 071                sharedComponent.UpdateFromModel(iterator.Current.GetModel());
 072                scene.componentsManagerLegacy.SceneSharedComponentAttach(newEntity.entityId, sharedComponent.id);
 73            }
 374        }
 75
 376        return newEntity;
 77    }
 78
 79    public static bool IsParcelSceneSquare(Vector2Int[] parcelsPoints)
 80    {
 381        int minX = int.MaxValue;
 382        int minY = int.MaxValue;
 383        int maxX = int.MinValue;
 384        int maxY = int.MinValue;
 85
 1286        foreach (Vector2Int vector in parcelsPoints)
 87        {
 388            if (vector.x < minX)
 389                minX = vector.x;
 390            if (vector.y < minY)
 391                minY = vector.y;
 392            if (vector.x > maxX)
 393                maxX = vector.x;
 394            if (vector.y > maxY)
 395                maxY = vector.y;
 96        }
 97
 398        if (maxX - minX != maxY - minY)
 099            return false;
 100
 3101        int lateralLengh = Math.Abs((maxX - minX) + 1);
 102
 3103        if (parcelsPoints.Length != lateralLengh * lateralLengh)
 0104            return false;
 105
 3106        return true;
 107    }
 108
 1109    private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
 110
 111    public static LayerMask GetBIWCulling(LayerMask currentCulling)
 112    {
 5113        currentCulling += BIWSettings.FX_LAYER;
 5114        return currentCulling;
 115    }
 116
 0117    public static string Vector2INTToString(Vector2Int vector) { return vector.x + "," + vector.y; }
 118
 119    public static List<Vector2Int> GetLandsToPublishProject(LandWithAccess[] lands, IBuilderScene scene)
 120    {
 0121        List<Vector2Int> availableLandsToPublish = new List<Vector2Int>();
 0122        List<Vector2Int> totalParcels = new List<Vector2Int>();
 0123        foreach (LandWithAccess land in lands)
 124        {
 0125            totalParcels.AddRange(land.parcels.ToList());
 126        }
 127
 0128        Vector2Int sceneSize = GetSceneSize(scene.scene.sceneData.parcels);
 0129        foreach (Vector2Int parcel in totalParcels)
 130        {
 0131            List<Vector2Int> necessaryParcelsToOwn = new List<Vector2Int>();
 0132            for (int x = 0; x < sceneSize.x; x++)
 133            {
 0134                for (int y = 0; y < sceneSize.y; y++)
 135                {
 0136                    necessaryParcelsToOwn.Add(new Vector2Int(parcel.x + x, parcel.y + y));
 137                }
 138            }
 139
 0140            int amountOfParcelFounds = 0;
 0141            foreach (Vector2Int parcelToCheck in totalParcels)
 142            {
 0143                if (necessaryParcelsToOwn.Contains(parcelToCheck))
 0144                    amountOfParcelFounds++;
 145            }
 146
 0147            if (amountOfParcelFounds == necessaryParcelsToOwn.Count)
 0148                availableLandsToPublish.Add(parcel);
 149        }
 0150        return availableLandsToPublish;
 151    }
 152
 153    public static Vector2Int GetRowsAndColumsFromLand(LandWithAccess landWithAccess)
 154    {
 0155        Vector2Int result = new Vector2Int();
 0156        int baseX = landWithAccess.baseCoords.x;
 0157        int baseY = landWithAccess.baseCoords.y;
 158
 0159        int amountX = 0;
 0160        int amountY = 0;
 161
 0162        foreach (Vector2Int parcel in landWithAccess.parcels)
 163        {
 0164            if (parcel.x == baseX)
 0165                amountX++;
 166
 0167            if (parcel.y == baseY)
 0168                amountY++;
 169        }
 170
 0171        result.x = amountX;
 0172        result.y = amountY;
 0173        return result;
 174    }
 175
 176    public static ILand CreateILandFromManifest(IManifest manifest, Vector2Int initialCoord)
 177    {
 5178        ILand land = new ILand();
 5179        land.sceneId = manifest.project.scene_id;
 5180        land.baseUrl = BIWUrlUtils.GetUrlSceneObjectContent();
 181
 5182        land.mappingsResponse = new MappingsResponse();
 5183        land.mappingsResponse.parcel_id = land.sceneId;
 5184        land.mappingsResponse.root_cid = land.sceneId;
 5185        land.mappingsResponse.contents = new List<ContentServerUtils.MappingPair>();
 186
 5187        land.sceneJsonData = new SceneJsonData();
 5188        land.sceneJsonData.main = "bin/game.js";
 5189        land.sceneJsonData.scene = new SceneParcels();
 5190        land.sceneJsonData.scene.@base = initialCoord.x + "," + initialCoord.y;
 191
 5192        int amountOfParcels = manifest.project.rows * manifest.project.cols;
 5193        land.sceneJsonData.scene.parcels = new string[amountOfParcels];
 194
 5195        int baseX = initialCoord.x;
 5196        int baseY = initialCoord.y;
 197
 5198        int currentPositionInRow = 0;
 10199        for (int i = 0; i < amountOfParcels; i++ )
 200        {
 0201            land.sceneJsonData.scene.parcels[i] = baseX + "," + baseY;
 0202            currentPositionInRow++;
 0203            baseX++;
 0204            if (currentPositionInRow >= manifest.project.rows)
 205            {
 0206                baseX = initialCoord.x;
 0207                baseY++;
 0208                currentPositionInRow = 0;
 209            }
 210        }
 211
 5212        return land;
 213    }
 214
 215    public static ILand CreateILandFromParcelScene(IParcelScene scene)
 216    {
 0217        ILand land = new ILand();
 0218        land.sceneId = scene.sceneData.id;
 0219        land.baseUrl = scene.sceneData.baseUrl;
 0220        land.baseUrlBundles = scene.sceneData.baseUrlBundles;
 221
 0222        land.mappingsResponse = new MappingsResponse();
 0223        land.mappingsResponse.parcel_id = land.sceneId;
 0224        land.mappingsResponse.root_cid = land.sceneId;
 0225        land.mappingsResponse.contents = scene.sceneData.contents;
 226
 0227        land.sceneJsonData = new SceneJsonData();
 0228        land.sceneJsonData.main = "bin/game.js";
 0229        land.sceneJsonData.scene = new SceneParcels();
 0230        land.sceneJsonData.scene.@base = scene.sceneData.basePosition.ToString();
 0231        land.sceneJsonData.scene.parcels = new string[scene.sceneData.parcels.Length];
 232
 0233        int count = 0;
 0234        foreach (Vector2Int parcel in scene.sceneData.parcels)
 235        {
 0236            land.sceneJsonData.scene.parcels[count] = parcel.x + "," + parcel.y;
 0237            count++;
 238        }
 239
 0240        return land;
 241    }
 242
 243    public static void AddSceneMappings(Dictionary<string, string> contents, string baseUrl, LoadParcelScenesMessage.Uni
 244    {
 16245        if (data == null)
 0246            data = new LoadParcelScenesMessage.UnityParcelScene();
 247
 16248        data.baseUrl = baseUrl;
 16249        if (data.contents == null)
 11250            data.contents = new List<ContentServerUtils.MappingPair>();
 251
 90252        foreach (KeyValuePair<string, string> content in contents)
 253        {
 29254            ContentServerUtils.MappingPair mappingPair = new ContentServerUtils.MappingPair();
 29255            mappingPair.file = content.Key;
 29256            mappingPair.hash = content.Value;
 29257            bool found = false;
 161258            foreach (ContentServerUtils.MappingPair mappingPairToCheck in data.contents)
 259            {
 55260                if (mappingPairToCheck.file == mappingPair.file)
 261                {
 7262                    found = true;
 7263                    break;
 264                }
 265            }
 266
 29267            if (!found)
 22268                data.contents.Add(mappingPair);
 269        }
 16270    }
 271
 272    public static void RemoveAssetsFromCurrentScene()
 273    {
 274        //We remove the old assets to they don't collide with the new ones
 2275        foreach (var catalogItem in DataStore.i.builderInWorld.currentSceneCatalogItemDict.GetValues())
 276        {
 0277            AssetCatalogBridge.i.RemoveSceneObjectToSceneCatalog(catalogItem.id);
 278        }
 1279        DataStore.i.builderInWorld.currentSceneCatalogItemDict.Clear();
 1280    }
 281
 282    public static void ShowGenericNotification(string message, DCL.NotificationModel.Type type = DCL.NotificationModel.T
 283    {
 2284        if (NotificationsController.i == null)
 1285            return;
 1286        NotificationsController.i.ShowNotification(new DCL.NotificationModel.Model
 287        {
 288            message = message,
 289            type = DCL.NotificationModel.Type.GENERIC,
 290            timer = timer,
 291            destroyOnFinish = true
 292        });
 1293    }
 294
 295    public static long ConvertToMilisecondsTimestamp(DateTime value)
 296    {
 7297        TimeSpan elapsedTime = value - Epoch;
 7298        return (long) elapsedTime.TotalMilliseconds;
 299    }
 300
 301    public static SceneMetricsModel GetSceneMetricsLimits(int parcelAmount)
 302    {
 0303        SceneMetricsModel  cachedModel = new SceneMetricsModel();
 304
 0305        float log = Mathf.Log(parcelAmount + 1, 2);
 0306        float lineal = parcelAmount;
 307
 0308        cachedModel.triangles = (int) (lineal * SceneMetricsCounter.LimitsConfig.triangles);
 0309        cachedModel.bodies = (int) (lineal * SceneMetricsCounter.LimitsConfig.bodies);
 0310        cachedModel.entities = (int) (lineal * SceneMetricsCounter.LimitsConfig.entities);
 0311        cachedModel.materials = (int) (log * SceneMetricsCounter.LimitsConfig.materials);
 0312        cachedModel.textures = (int) (log * SceneMetricsCounter.LimitsConfig.textures);
 0313        cachedModel.meshes = (int) (log * SceneMetricsCounter.LimitsConfig.meshes);
 0314        cachedModel.sceneHeight = (int) (log * SceneMetricsCounter.LimitsConfig.height);
 315
 0316        return cachedModel;
 317    }
 318
 319    public static Manifest CreateManifestFromProjectDataAndScene(ProjectData data, WebBuilderScene scene)
 320    {
 0321        Manifest manifest = new Manifest();
 0322        manifest.version = BIWSettings.MANIFEST_VERSION;
 0323        manifest.project = data;
 0324        manifest.scene = scene;
 325
 0326        manifest.project.scene_id = manifest.scene.id;
 0327        return manifest;
 328    }
 329
 330    public static Manifest CreateManifestFromProject(ProjectData projectData)
 331    {
 0332        Manifest manifest = new Manifest();
 0333        manifest.version = BIWSettings.MANIFEST_VERSION;
 0334        manifest.project = projectData;
 0335        manifest.scene = CreateEmtpyBuilderScene(projectData.rows, projectData.cols);
 336
 0337        manifest.project.scene_id = manifest.scene.id;
 0338        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    {
 0344        Dictionary<string, BuilderEntity> entities = new Dictionary<string, BuilderEntity>();
 0345        Dictionary<string, BuilderComponent> components = new Dictionary<string, BuilderComponent>();
 0346        Dictionary<string, SceneObject> assets = new Dictionary<string, SceneObject>();
 347
 348        // We get the asset
 0349        var floorAsset = CreateFloorSceneObject();
 0350        assets.Add(floorAsset.id,floorAsset);
 351
 352        // We create the ground
 0353        BuilderGround ground = new BuilderGround();
 0354        ground.assetId = floorAsset.id;
 0355        ground.componentId = Guid.NewGuid().ToString();
 356
 0357        for (int x = 0; x < rows; x++)
 358        {
 0359            for (int y = 0; y < cols; y++)
 360            {
 361                // We create the entity for the ground
 0362                BuilderEntity entity = new BuilderEntity();
 0363                entity.id = Guid.NewGuid().ToString();
 0364                entity.disableGizmos = true;
 0365                entity.name = "entity"+x+y;
 366
 367                // We need a transform for the entity so we create it
 0368                BuilderComponent transformComponent = new BuilderComponent();
 0369                transformComponent.id = Guid.NewGuid().ToString();
 0370                transformComponent.type = "Transform";
 371
 372                // We create the transform data
 0373                TransformComponent entityTransformComponentModel = new TransformComponent();
 0374                entityTransformComponentModel.position = new Vector3(8+(16*x), 0, 8+(16*y));
 0375                entityTransformComponentModel.rotation = new ProtocolV2.QuaternionRepresentation(Quaternion.identity);
 0376                entityTransformComponentModel.scale = Vector3.one;
 377
 0378                transformComponent.data = entityTransformComponentModel;
 0379                entity.components.Add(transformComponent.id);
 0380                if(!components.ContainsKey(transformComponent.id))
 0381                    components.Add(transformComponent.id,transformComponent);
 382
 383                // We create the GLTFShape component
 0384                BuilderComponent gltfShapeComponent = new BuilderComponent();
 0385                gltfShapeComponent.id = ground.componentId;
 0386                gltfShapeComponent.type = "GLTFShape";
 387
 0388                LoadableShape.Model model = new GLTFShape.Model();
 0389                model.assetId = floorAsset.id;
 0390                gltfShapeComponent.data = model;
 391
 0392                entity.components.Add(ground.componentId);
 0393                if(!components.ContainsKey(gltfShapeComponent.id))
 0394                    components.Add(gltfShapeComponent.id,gltfShapeComponent);
 395
 396                // Finally, we add the entity to the list
 0397                entities.Add(entity.id,entity);
 398            }
 399        }
 400
 0401        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
 0412        return scene;
 413    }
 414
 415    public static Manifest CreateEmptyDefaultBuilderManifest(Vector2Int size, string landCoordinates)
 416    {
 0417        Manifest manifest = new Manifest();
 0418        manifest.version = BIWSettings.MANIFEST_VERSION;
 419
 420        //We create a new project data for the scene
 0421        ProjectData projectData = new ProjectData();
 0422        projectData.id = Guid.NewGuid().ToString();
 0423        projectData.eth_address = UserProfile.GetOwnUserProfile().ethAddress;
 0424        projectData.title = "Builder " + landCoordinates;
 0425        projectData.description = "Scene created from the explorer builder";
 0426        projectData.creation_coords = landCoordinates;
 0427        projectData.rows = size.x;
 0428        projectData.cols = size.y;
 0429        projectData.updated_at = DateTime.Now;
 0430        projectData.created_at = DateTime.Now;
 0431        projectData.thumbnail = "thumbnail.png";
 432
 433        //We create an empty scene
 0434        manifest.scene = CreateEmtpyBuilderScene(size.x, size.y);
 435
 0436        projectData.scene_id = manifest.scene.id;
 0437        manifest.project = projectData;
 0438        return manifest;
 439    }
 440
 441    public static LandRole GetLandOwnershipType(List<LandWithAccess> lands, IParcelScene scene)
 442    {
 5443        LandWithAccess filteredLand = lands.FirstOrDefault(land => scene.sceneData.basePosition == land.baseCoords);
 5444        return GetLandOwnershipType(filteredLand);
 445    }
 446
 447    public static LandRole GetLandOwnershipType(LandWithAccess land)
 448    {
 0449        if (land != null)
 0450            return land.role;
 0451        return LandRole.OWNER;
 452    }
 453
 454    public static Vector3 SnapFilterEulerAngles(Vector3 vectorToFilter, float degrees)
 455    {
 0456        vectorToFilter.x = ClosestNumber(vectorToFilter.x, degrees);
 0457        vectorToFilter.y = ClosestNumber(vectorToFilter.y, degrees);
 0458        vectorToFilter.z = ClosestNumber(vectorToFilter.z, degrees);
 459
 0460        return vectorToFilter;
 461    }
 462
 463    static float ClosestNumber(float n, float m)
 464    {
 465        // find the quotient
 0466        int q = Mathf.RoundToInt(n / m);
 467
 468        // 1st possible closest number
 0469        float n1 = m * q;
 470
 471        // 2nd possible closest number
 0472        float n2 = (n * m) > 0 ? (m * (q + 1)) : (m * (q - 1));
 473
 474        // if true, then n1 is the required closest number
 0475        if (Math.Abs(n - n1) < Math.Abs(n - n2))
 0476            return n1;
 477
 478        // else n2 is the required closest number
 0479        return n2;
 480    }
 481
 12482    public static Vector2Int GetSceneSize(IParcelScene parcelScene) { return GetSceneSize(parcelScene.sceneData.parcels)
 483
 484    public static bool HasSquareSize(LandWithAccess land)
 485    {
 0486        Vector2Int size = GetSceneSize(land.parcels);
 487
 0488        for (int x = land.baseCoords.x; x < size.x; x++)
 489        {
 0490            bool found = false;
 0491            foreach (Vector2Int parcel in land.parcels)
 492            {
 0493                if (parcel.x == x)
 494                {
 0495                    found = true;
 0496                    break;
 497                }
 498            }
 0499            if (!found)
 0500                return false;
 501        }
 502
 0503        for (int y = land.baseCoords.y; y < size.x; y++)
 504        {
 0505            bool found = false;
 0506            foreach (Vector2Int parcel in land.parcels)
 507            {
 0508                if (parcel.y == y)
 509                {
 0510                    found = true;
 0511                    break;
 512                }
 513            }
 0514            if (!found)
 0515                return false;
 516        }
 517
 0518        return true;
 519    }
 520
 521    public static Vector2Int GetSceneSize(Vector2Int[] parcels)
 522    {
 12523        int minX = Int32.MaxValue;
 12524        int maxX = Int32.MinValue;
 12525        int minY = Int32.MaxValue;
 12526        int maxY = Int32.MinValue;
 527
 64528        foreach (var parcel in parcels)
 529        {
 20530            if (parcel.x > maxX)
 14531                maxX = parcel.x;
 20532            if (parcel.x < minX)
 14533                minX = parcel.x;
 534
 20535            if (parcel.y > maxY)
 14536                maxY = parcel.y;
 20537            if (parcel.y < minY)
 14538                minY = parcel.y;
 539        }
 540
 12541        int sizeX = maxX - minX + 1;
 12542        int sizeY = maxY - minY + 1;
 12543        return new Vector2Int(sizeX, sizeY);
 544    }
 545
 546    public static Vector3 CalculateUnityMiddlePoint(IParcelScene parcelScene)
 547    {
 548        Vector3 position;
 549
 80550        float totalX = 0f;
 80551        float totalY = 0f;
 80552        float totalZ = 0f;
 553
 80554        int minX = int.MaxValue;
 80555        int minY = int.MaxValue;
 80556        int maxX = int.MinValue;
 80557        int maxY = int.MinValue;
 558
 80559        if (parcelScene?.sceneData == null || parcelScene?.sceneData.parcels == null)
 6560            return Vector3.zero;
 561
 296562        foreach (Vector2Int vector in parcelScene?.sceneData.parcels)
 563        {
 74564            totalX += vector.x;
 74565            totalZ += vector.y;
 74566            if (vector.x < minX)
 74567                minX = vector.x;
 74568            if (vector.y < minY)
 74569                minY = vector.y;
 74570            if (vector.x > maxX)
 74571                maxX = vector.x;
 74572            if (vector.y > maxY)
 74573                maxY = vector.y;
 574        }
 575
 74576        float centerX = totalX / parcelScene.sceneData.parcels.Length + 0.5f;
 74577        float centerZ = totalZ / parcelScene.sceneData.parcels.Length + 0.5f;
 578
 74579        position.x = centerX;
 74580        position.y = totalY;
 74581        position.z = centerZ;
 582
 74583        Vector3 scenePosition = Utils.GridToWorldPosition(centerX, centerZ);
 74584        position = PositionUtils.WorldToUnityPosition(scenePosition);
 585
 74586        return position;
 587    }
 588
 589    public static SceneObject CreateFloorSceneObject()
 590    {
 0591        SceneObject floorSceneObject = new SceneObject();
 0592        floorSceneObject.id = BIWSettings.FLOOR_ID;
 593
 0594        floorSceneObject.model = BIWSettings.FLOOR_MODEL;
 0595        floorSceneObject.name = BIWSettings.FLOOR_NAME;
 0596        floorSceneObject.asset_pack_id = BIWSettings.FLOOR_ASSET_PACK_ID;
 0597        floorSceneObject.thumbnail = BIWSettings.FLOOR_ASSET_THUMBNAIL;
 0598        floorSceneObject.category = BIWSettings.FLOOR_CATEGORY;
 599
 0600        floorSceneObject.tags = new List<string>();
 0601        floorSceneObject.tags.Add("genesis");
 0602        floorSceneObject.tags.Add("city");
 0603        floorSceneObject.tags.Add("town");
 0604        floorSceneObject.tags.Add("ground");
 605
 0606        floorSceneObject.contents = new Dictionary<string, string>();
 607
 0608        floorSceneObject.contents.Add(BIWSettings.FLOOR_GLTF_KEY, BIWSettings.FLOOR_GLTF_VALUE);
 0609        floorSceneObject.contents.Add(BIWSettings.FLOOR_TEXTURE_KEY, BIWSettings.FLOOR_TEXTURE_VALUE);
 0610        floorSceneObject.contents.Add(BIWSettings.FLOOR_THUMBNAIL_KEY, BIWSettings.FLOOR_THUMBNAIL_VALUE);
 611
 0612        floorSceneObject.metrics = new SceneObject.ObjectMetrics();
 613
 0614        return floorSceneObject;
 615    }
 616
 617    public static CatalogItem CreateFloorCatalogItem()
 618    {
 0619        CatalogItem floorSceneObject = new CatalogItem();
 0620        floorSceneObject.id = BIWSettings.FLOOR_ID;
 621
 0622        floorSceneObject.model = BIWSettings.FLOOR_MODEL;
 0623        floorSceneObject.name = BIWSettings.FLOOR_NAME;
 0624        floorSceneObject.assetPackName = BIWSettings.FLOOR_ASSET_PACK_NAME;
 0625        floorSceneObject.thumbnailURL = BIWSettings.FLOOR_ASSET_THUMBNAIL;
 626
 0627        floorSceneObject.tags = new List<string>();
 0628        floorSceneObject.tags.Add("genesis");
 0629        floorSceneObject.tags.Add("city");
 0630        floorSceneObject.tags.Add("town");
 0631        floorSceneObject.tags.Add("ground");
 632
 0633        floorSceneObject.contents = new Dictionary<string, string>();
 634
 0635        floorSceneObject.contents.Add(BIWSettings.FLOOR_GLTF_KEY, BIWSettings.FLOOR_GLTF_VALUE);
 0636        floorSceneObject.contents.Add(BIWSettings.FLOOR_TEXTURE_KEY, BIWSettings.FLOOR_TEXTURE_VALUE);
 0637        floorSceneObject.contents.Add(BIWSettings.FLOOR_THUMBNAIL_KEY, BIWSettings.FLOOR_THUMBNAIL_VALUE);
 638
 0639        floorSceneObject.metrics = new SceneObject.ObjectMetrics();
 640
 0641        return floorSceneObject;
 642    }
 643
 644    public static Dictionary<string, string> ConvertMappingsToDictionary(ContentServerUtils.MappingPair[] contents)
 645    {
 0646        Dictionary<string, string> mappingDict = new Dictionary<string, string>();
 647
 0648        foreach (ContentServerUtils.MappingPair mappingPair in contents)
 649        {
 0650            mappingDict.Add(mappingPair.file, mappingPair.hash);
 651        }
 652
 0653        return mappingDict;
 654    }
 655
 656    public static void DrawScreenRect(Rect rect, Color color)
 657    {
 0658        GUI.color = color;
 0659        GUI.DrawTexture(rect, Texture2D.whiteTexture);
 0660    }
 661
 662    public static void DrawScreenRectBorder(Rect rect, float thickness, Color color)
 663    {
 664        //Top
 0665        DrawScreenRect(new Rect(rect.xMin, rect.yMin, rect.width, thickness), color);
 666        // Left
 0667        DrawScreenRect(new Rect(rect.xMin, rect.yMin, thickness, rect.height), color);
 668        // Right
 0669        DrawScreenRect(new Rect(rect.xMax - thickness, rect.yMin, thickness, rect.height), color);
 670        // Bottom
 0671        DrawScreenRect(new Rect(rect.xMin, rect.yMax - thickness, rect.width, thickness), color);
 0672    }
 673
 674    public static Rect GetScreenRect(Vector3 screenPosition1, Vector3 screenPosition2)
 675    {
 676        // Move origin from bottom left to top left
 0677        screenPosition1.y = Screen.height - screenPosition1.y;
 0678        screenPosition2.y = Screen.height - screenPosition2.y;
 679        // Calculate corners
 0680        var topLeft = Vector3.Min(screenPosition1, screenPosition2);
 0681        var bottomRight = Vector3.Max(screenPosition1, screenPosition2);
 682        // Create Rect
 0683        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    {
 2688        var v1 = camera.ScreenToViewportPoint(screenPosition1);
 2689        var v2 = camera.ScreenToViewportPoint(screenPosition2);
 2690        var min = Vector3.Min(v1, v2);
 2691        var max = Vector3.Max(v1, v2);
 2692        min.z = camera.nearClipPlane;
 2693        max.z = camera.farClipPlane;
 694
 2695        var bounds = new Bounds();
 696
 2697        bounds.SetMinMax(min, max);
 2698        return bounds;
 699    }
 700
 0701    public static bool IsWithinSelectionBounds(Transform transform, Vector3 lastClickMousePosition, Vector3 mousePositio
 702
 703    public static bool IsWithinSelectionBounds(Vector3 point, Vector3 lastClickMousePosition, Vector3 mousePosition)
 704    {
 2705        Camera camera = Camera.main;
 2706        var viewPortBounds = GetViewportBounds(camera, lastClickMousePosition, mousePosition);
 2707        return viewPortBounds.Contains(camera.WorldToViewportPoint(point));
 708    }
 709
 710    public static bool IsBoundInsideCamera(Bounds bound)
 711    {
 0712        Vector3[] points = { bound.max, bound.center, bound.min };
 0713        return IsPointInsideCamera(points);
 714    }
 715
 716    public static bool IsPointInsideCamera(Vector3[] points)
 717    {
 0718        foreach (Vector3 point in points)
 719        {
 0720            if (IsPointInsideCamera(point))
 0721                return true;
 722        }
 0723        return false;
 724    }
 725
 726    public static bool IsPointInsideCamera(Vector3 point)
 727    {
 0728        Vector3 topRight = new Vector3(Screen.width, Screen.height, 0);
 0729        var viewPortBounds = GetViewportBounds(Camera.main, Vector3.zero, topRight);
 0730        return viewPortBounds.Contains(Camera.main.WorldToViewportPoint(point));
 731    }
 732
 733    public static void CopyGameObjectStatus(GameObject gameObjectToCopy, GameObject gameObjectToReceive, bool copyParent
 734    {
 5735        if (copyParent)
 0736            gameObjectToReceive.transform.SetParent(gameObjectToCopy.transform.parent);
 737
 5738        gameObjectToReceive.transform.position = gameObjectToCopy.transform.position;
 739
 5740        if (localRotation)
 0741            gameObjectToReceive.transform.localRotation = gameObjectToCopy.transform.localRotation;
 742        else
 5743            gameObjectToReceive.transform.rotation = gameObjectToCopy.transform.rotation;
 744
 5745        gameObjectToReceive.transform.localScale = gameObjectToCopy.transform.lossyScale;
 5746    }
 747
 748    public static bool IsPointerOverMaskElement(LayerMask mask)
 749    {
 750        RaycastHit hitInfo;
 2751        UnityEngine.Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
 2752        return Physics.Raycast(mouseRay, out hitInfo, 5555, mask);
 753    }
 754
 755    public static bool IsPointerOverUIElement(Vector3 mousePosition)
 756    {
 1757        var eventData = new PointerEventData(EventSystem.current);
 1758        eventData.position = mousePosition;
 1759        var results = new List<RaycastResult>();
 1760        EventSystem.current.RaycastAll(eventData, results);
 1761        return results.Count > 2;
 762    }
 763
 1764    public static bool IsPointerOverUIElement() { return IsPointerOverUIElement(Input.mousePosition); }
 765
 766    public static string ConvertEntityToJSON(IDCLEntity entity)
 767    {
 4768        EntityData builderInWorldEntityData = new EntityData();
 4769        builderInWorldEntityData.entityId = entity.entityId;
 770
 4771        var components = entity.scene.componentsManagerLegacy.GetComponentsDictionary(entity);
 772
 4773        if (components != null)
 774        {
 4775            foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in components)
 776            {
 1777                if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
 778                {
 1779                    EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent();
 780
 1781                    entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transf
 1782                    entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles;
 1783                    entityComponentModel.scale = entity.gameObject.transform.localScale;
 784
 1785                    builderInWorldEntityData.transformComponent = entityComponentModel;
 1786                }
 787                else
 788                {
 0789                    ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
 0790                    entityComponentModel.componentId = (int)keyValuePair.Key;
 0791                    entityComponentModel.data = keyValuePair.Value.GetModel();
 792
 0793                    builderInWorldEntityData.components.Add(entityComponentModel);
 794                }
 795            }
 796        }
 797
 4798        var sharedComponents = entity.scene.componentsManagerLegacy.GetSharedComponentsDictionary(entity);
 799
 4800        if (sharedComponents != null)
 801        {
 0802            foreach (KeyValuePair<Type, ISharedComponent> keyValuePair in sharedComponents)
 803            {
 0804                if (keyValuePair.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
 805                {
 0806                    EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent();
 0807                    NFTShape.Model model = (NFTShape.Model)keyValuePair.Value.GetModel();
 808
 0809                    nFTComponent.id = keyValuePair.Value.id;
 0810                    nFTComponent.color = new ColorRepresentation(model.color);
 0811                    nFTComponent.assetId = model.assetId;
 0812                    nFTComponent.src = model.src;
 0813                    nFTComponent.style = model.style;
 814
 0815                    builderInWorldEntityData.nftComponent = nFTComponent;
 0816                }
 817                else
 818                {
 0819                    ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
 0820                    entityComponentModel.componentId = keyValuePair.Value.GetClassId();
 0821                    entityComponentModel.data = keyValuePair.Value.GetModel();
 0822                    entityComponentModel.classId = keyValuePair.Value.id;
 823
 0824                    builderInWorldEntityData.sharedComponents.Add(entityComponentModel);
 825                }
 826            }
 827        }
 828
 829
 4830        return JsonConvert.SerializeObject(builderInWorldEntityData);
 831    }
 832
 3833    public static EntityData ConvertJSONToEntityData(string json) { return JsonConvert.DeserializeObject<EntityData>(jso
 834
 835    public static List<BIWEntity> RemoveGroundEntities(List<BIWEntity> entityList)
 836    {
 0837        List<BIWEntity> newList = new List<BIWEntity>();
 838
 0839        foreach (BIWEntity entity in entityList)
 840        {
 0841            if (entity.isFloor)
 842                continue;
 843
 0844            newList.Add(entity);
 845        }
 846
 0847        return newList;
 848    }
 849
 850    public static List<BIWEntity> FilterEntitiesBySmartItemComponentAndActions(List<BIWEntity> entityList)
 851    {
 0852        List<BIWEntity> newList = new List<BIWEntity>();
 853
 0854        foreach (BIWEntity entity in entityList)
 855        {
 0856            if (!entity.HasSmartItemComponent() || !entity.HasSmartItemActions())
 857                continue;
 858
 0859            newList.Add(entity);
 860        }
 861
 0862        return newList;
 863    }
 864
 865    public static void CopyRectTransform(RectTransform original, RectTransform rectTransformToCopy)
 866    {
 0867        original.anchoredPosition = rectTransformToCopy.anchoredPosition;
 0868        original.anchorMax = rectTransformToCopy.anchorMax;
 0869        original.anchorMin = rectTransformToCopy.anchorMin;
 0870        original.offsetMax = rectTransformToCopy.offsetMax;
 0871        original.offsetMin = rectTransformToCopy.offsetMin;
 0872        original.sizeDelta = rectTransformToCopy.sizeDelta;
 0873        original.pivot = rectTransformToCopy.pivot;
 0874    }
 875
 876    public static IWebRequestAsyncOperation MakeGetCall(string url, Promise<string> callPromise, Dictionary<string, stri
 877    {
 4878        headers["Cache-Control"] = "no-cache";
 4879        var asyncOperation = Environment.i.platform.webRequest.Get(
 880            url: url,
 881            OnSuccess: (webRequestResult) =>
 882            {
 4883                byte[] byteArray = webRequestResult.GetResultData();
 4884                string result = System.Text.Encoding.UTF8.GetString(byteArray);
 4885                callPromise?.Resolve(result);
 4886            },
 887            OnFail: (webRequestResult) =>
 888            {
 889                try
 890                {
 0891                    byte[] byteArray = webRequestResult.GetResultData();
 0892                    string result = System.Text.Encoding.UTF8.GetString(byteArray);
 0893                    APIResponse response = JsonConvert.DeserializeObject<APIResponse>(result);
 0894                    callPromise?.Resolve(result);
 0895                }
 0896                catch (Exception e)
 897                {
 0898                    Debug.Log(webRequestResult.webRequest.error);
 0899                    callPromise.Reject(webRequestResult.webRequest.error);
 0900                }
 0901            },
 902            headers: headers);
 903
 4904        return asyncOperation;
 905    }
 906
 907    public static IWebRequestAsyncOperation MakeGetTextureCall(string url, Promise<Texture2D> callPromise)
 908    {
 0909        var asyncOperation = Environment.i.platform.webRequest.GetTexture(
 910            url: url,
 911            OnSuccess: (webRequestResult) =>
 912            {
 0913                callPromise.Resolve(DownloadHandlerTexture.GetContent(webRequestResult.webRequest));
 0914            },
 915            OnFail: (webRequestResult) =>
 916            {
 0917                callPromise.Reject(webRequestResult.webRequest.error);
 0918            });
 919
 0920        return asyncOperation;
 921    }
 922
 923    public static void ConfigureEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType, UnityAction<BaseEven
 924    {
 2084925        EventTrigger.Entry entry = new EventTrigger.Entry();
 2084926        entry.eventID = eventType;
 2084927        entry.callback.AddListener(call);
 2084928        eventTrigger.triggers.Add(entry);
 2084929    }
 930
 5124931    public static void RemoveEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType) { eventTrigger.triggers
 932}

Methods/Properties

DuplicateEntity(DCL.Controllers.IParcelScene, DCL.Models.IDCLEntity)
IsParcelSceneSquare(UnityEngine.Vector2Int[])
BIWUtils()
GetBIWCulling(UnityEngine.LayerMask)
Vector2INTToString(UnityEngine.Vector2Int)
GetLandsToPublishProject(LandWithAccess[], DCL.Builder.IBuilderScene)
GetRowsAndColumsFromLand(LandWithAccess)
CreateILandFromManifest(DCL.Builder.Manifest.IManifest, UnityEngine.Vector2Int)
CreateILandFromParcelScene(DCL.Controllers.IParcelScene)
AddSceneMappings(System.Collections.Generic.Dictionary[String,String], System.String, DCL.Models.LoadParcelScenesMessage/UnityParcelScene)
RemoveAssetsFromCurrentScene()
ShowGenericNotification(System.String, DCL.NotificationModel.Type, System.Single)
ConvertToMilisecondsTimestamp(System.DateTime)
GetSceneMetricsLimits(System.Int32)
CreateManifestFromProjectDataAndScene(DCL.Builder.ProjectData, DCL.Builder.Manifest.WebBuilderScene)
CreateManifestFromProject(DCL.Builder.ProjectData)
CreateEmtpyBuilderScene(System.Int32, System.Int32)
CreateEmptyDefaultBuilderManifest(UnityEngine.Vector2Int, System.String)
GetLandOwnershipType(System.Collections.Generic.List[LandWithAccess], DCL.Controllers.IParcelScene)
GetLandOwnershipType(LandWithAccess)
SnapFilterEulerAngles(UnityEngine.Vector3, System.Single)
ClosestNumber(System.Single, System.Single)
GetSceneSize(DCL.Controllers.IParcelScene)
HasSquareSize(LandWithAccess)
GetSceneSize(UnityEngine.Vector2Int[])
CalculateUnityMiddlePoint(DCL.Controllers.IParcelScene)
CreateFloorSceneObject()
CreateFloorCatalogItem()
ConvertMappingsToDictionary(DCL.ContentServerUtils/MappingPair[])
DrawScreenRect(UnityEngine.Rect, UnityEngine.Color)
DrawScreenRectBorder(UnityEngine.Rect, System.Single, UnityEngine.Color)
GetScreenRect(UnityEngine.Vector3, UnityEngine.Vector3)
GetViewportBounds(UnityEngine.Camera, UnityEngine.Vector3, UnityEngine.Vector3)
IsWithinSelectionBounds(UnityEngine.Transform, UnityEngine.Vector3, UnityEngine.Vector3)
IsWithinSelectionBounds(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3)
IsBoundInsideCamera(UnityEngine.Bounds)
IsPointInsideCamera(UnityEngine.Vector3[])
IsPointInsideCamera(UnityEngine.Vector3)
CopyGameObjectStatus(UnityEngine.GameObject, UnityEngine.GameObject, System.Boolean, System.Boolean)
IsPointerOverMaskElement(UnityEngine.LayerMask)
IsPointerOverUIElement(UnityEngine.Vector3)
IsPointerOverUIElement()
ConvertEntityToJSON(DCL.Models.IDCLEntity)
ConvertJSONToEntityData(System.String)
RemoveGroundEntities(System.Collections.Generic.List[BIWEntity])
FilterEntitiesBySmartItemComponentAndActions(System.Collections.Generic.List[BIWEntity])
CopyRectTransform(UnityEngine.RectTransform, UnityEngine.RectTransform)
MakeGetCall(System.String, DCL.Helpers.Promise[String], System.Collections.Generic.Dictionary[String,String])
MakeGetTextureCall(System.String, DCL.Helpers.Promise[Texture2D])
ConfigureEventTrigger(UnityEngine.EventSystems.EventTrigger, UnityEngine.EventSystems.EventTriggerType, UnityEngine.Events.UnityAction[BaseEventData])
RemoveEventTrigger(UnityEngine.EventSystems.EventTrigger, UnityEngine.EventSystems.EventTriggerType)