< Summary

Class:BIWUtils
Assembly:BuilderInWorldUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Utils/BIWUtils.cs
Covered lines:78
Uncovered lines:392
Coverable lines:470
Total lines:941
Line coverage:16.5% (78 of 470)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DuplicateEntity(...)0%1101000%
IsParcelSceneSquare(...)0%8.068090.48%
BIWUtils()0%110100%
GetBIWCulling(...)0%2100%
Vector2INTToString(...)0%2100%
GetLandsToPublishProject(...)0%72800%
GetRowsAndColumsFromLand(...)0%20400%
CreateILandFromManifest(...)0%12300%
CreateILandFromParcelScene(...)0%6200%
AddSceneMappings(...)0%56700%
RemoveAssetsFromCurrentScene()0%6200%
ShowGenericNotification(...)0%6200%
ConvertToMilisecondsTimestamp(...)0%2100%
GetSceneMetricsLimits(...)0%2100%
CreateManifestFromProjectDataAndScene(...)0%2100%
CreateManifestFromProject(...)0%2100%
CreateEmtpyBuilderScene(...)0%30500%
CreateEmptyDefaultBuilderManifest(...)0%2100%
GetLandOwnershipType(...)0%2100%
GetLandOwnershipType(...)0%6200%
SnapFilterEulerAngles(...)0%2100%
ClosestNumber(...)0%12300%
GetSceneSize(...)0%2100%
HasSquareSize(...)0%90900%
GetSceneSize(...)0%42600%
CalculateUnityMiddlePoint(...)0%14.0114096.67%
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%2100%
IsPointerOverUIElement()0%2100%
ConvertEntityToJSON(...)0%90900%
ConvertJSONToEntityData(...)0%2100%
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    {
 029        if (!scene.entities.ContainsKey(entity.entityId))
 030            return null;
 31
 032        var sceneController = Environment.i.world.sceneController;
 033        IDCLEntity newEntity =
 34            scene.CreateEntity(
 35                sceneController.entityIdHelper.EntityFromLegacyEntityString(System.Guid.NewGuid().ToString()));
 36
 037        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
 049        if (entity.parent != null)
 050            scene.SetEntityParent(newEntity.entityId, entity.parent.entityId);
 51
 052        DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position);
 053        DCLTransform.model.rotation = entity.gameObject.transform.rotation;
 054        DCLTransform.model.scale = entity.gameObject.transform.lossyScale;
 55
 056        var components = scene.componentsManagerLegacy.GetComponentsDictionary(entity);
 57
 058        if (components != null)
 59        {
 060            foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> component in components)
 61            {
 062                scene.componentsManagerLegacy.EntityComponentCreateOrUpdate(newEntity.entityId, component.Key, component
 63            }
 64        }
 65
 066        using (var iterator = scene.componentsManagerLegacy.GetSharedComponents(entity))
 67        {
 068            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            }
 074        }
 75
 076        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    {
 0113        currentCulling += BIWSettings.FX_LAYER;
 0114        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    {
 0178        ILand land = new ILand();
 179
 180        // We don't use scene ids in the client anymore
 181        // land.sceneNumber = manifest.project.scene_id;
 182
 0183        land.baseUrl = BIWUrlUtils.GetUrlSceneObjectContent();
 184
 0185        land.mappingsResponse = new MappingsResponse();
 186
 187        // We don't use scene ids in the client anymore
 188        // land.mappingsResponse.parcel_id = land.sceneNumber;
 189        // land.mappingsResponse.root_cid = land.sceneNumber;
 190
 0191        land.mappingsResponse.contents = new List<ContentServerUtils.MappingPair>();
 192
 0193        land.sceneJsonData = new SceneJsonData();
 0194        land.sceneJsonData.main = "bin/game.js";
 0195        land.sceneJsonData.scene = new SceneParcels();
 0196        land.sceneJsonData.scene.@base = initialCoord.x + "," + initialCoord.y;
 197
 0198        int amountOfParcels = manifest.project.rows * manifest.project.cols;
 0199        land.sceneJsonData.scene.parcels = new string[amountOfParcels];
 200
 0201        int baseX = initialCoord.x;
 0202        int baseY = initialCoord.y;
 203
 0204        int currentPositionInRow = 0;
 0205        for (int i = 0; i < amountOfParcels; i++ )
 206        {
 0207            land.sceneJsonData.scene.parcels[i] = baseX + "," + baseY;
 0208            currentPositionInRow++;
 0209            baseX++;
 0210            if (currentPositionInRow >= manifest.project.rows)
 211            {
 0212                baseX = initialCoord.x;
 0213                baseY++;
 0214                currentPositionInRow = 0;
 215            }
 216        }
 217
 0218        return land;
 219    }
 220
 221    public static ILand CreateILandFromParcelScene(IParcelScene scene)
 222    {
 0223        ILand land = new ILand();
 0224        land.sceneNumber = scene.sceneData.sceneNumber;
 0225        land.baseUrl = scene.sceneData.baseUrl;
 0226        land.baseUrlBundles = scene.sceneData.baseUrlBundles;
 227
 0228        land.mappingsResponse = new MappingsResponse();
 229
 230        // We don't use scene ids in the client anymore
 231        // land.mappingsResponse.parcel_id = land.id;
 232        // land.mappingsResponse.root_cid = land.id;
 233
 0234        land.mappingsResponse.contents = scene.sceneData.contents;
 235
 0236        land.sceneJsonData = new SceneJsonData();
 0237        land.sceneJsonData.main = "bin/game.js";
 0238        land.sceneJsonData.scene = new SceneParcels();
 0239        land.sceneJsonData.scene.@base = scene.sceneData.basePosition.ToString();
 0240        land.sceneJsonData.scene.parcels = new string[scene.sceneData.parcels.Length];
 241
 0242        int count = 0;
 0243        foreach (Vector2Int parcel in scene.sceneData.parcels)
 244        {
 0245            land.sceneJsonData.scene.parcels[count] = parcel.x + "," + parcel.y;
 0246            count++;
 247        }
 248
 0249        return land;
 250    }
 251
 252    public static void AddSceneMappings(Dictionary<string, string> contents, string baseUrl, LoadParcelScenesMessage.Uni
 253    {
 0254        if (data == null)
 0255            data = new LoadParcelScenesMessage.UnityParcelScene();
 256
 0257        data.baseUrl = baseUrl;
 0258        if (data.contents == null)
 0259            data.contents = new List<ContentServerUtils.MappingPair>();
 260
 0261        foreach (KeyValuePair<string, string> content in contents)
 262        {
 0263            ContentServerUtils.MappingPair mappingPair = new ContentServerUtils.MappingPair();
 0264            mappingPair.file = content.Key;
 0265            mappingPair.hash = content.Value;
 0266            bool found = false;
 0267            foreach (ContentServerUtils.MappingPair mappingPairToCheck in data.contents)
 268            {
 0269                if (mappingPairToCheck.file == mappingPair.file)
 270                {
 0271                    found = true;
 0272                    break;
 273                }
 274            }
 275
 0276            if (!found)
 0277                data.contents.Add(mappingPair);
 278        }
 0279    }
 280
 281    public static void RemoveAssetsFromCurrentScene()
 282    {
 283        //We remove the old assets to they don't collide with the new ones
 0284        foreach (var catalogItem in DataStore.i.builderInWorld.currentSceneCatalogItemDict.GetValues())
 285        {
 0286            AssetCatalogBridge.i.RemoveSceneObjectToSceneCatalog(catalogItem.id);
 287        }
 0288        DataStore.i.builderInWorld.currentSceneCatalogItemDict.Clear();
 0289    }
 290
 291    public static void ShowGenericNotification(string message, DCL.NotificationModel.Type type = DCL.NotificationModel.T
 292    {
 0293        if (NotificationsController.i == null)
 0294            return;
 0295        NotificationsController.i.ShowNotification(new DCL.NotificationModel.Model
 296        {
 297            message = message,
 298            type = DCL.NotificationModel.Type.GENERIC,
 299            timer = timer,
 300            destroyOnFinish = true
 301        });
 0302    }
 303
 304    public static long ConvertToMilisecondsTimestamp(DateTime value)
 305    {
 0306        TimeSpan elapsedTime = value - Epoch;
 0307        return (long) elapsedTime.TotalMilliseconds;
 308    }
 309
 310    public static SceneMetricsModel GetSceneMetricsLimits(int parcelAmount)
 311    {
 0312        SceneMetricsModel  cachedModel = new SceneMetricsModel();
 313
 0314        float log = Mathf.Log(parcelAmount + 1, 2);
 0315        float lineal = parcelAmount;
 316
 0317        cachedModel.triangles = (int) (lineal * SceneMetricsCounter.LimitsConfig.triangles);
 0318        cachedModel.bodies = (int) (lineal * SceneMetricsCounter.LimitsConfig.bodies);
 0319        cachedModel.entities = (int) (lineal * SceneMetricsCounter.LimitsConfig.entities);
 0320        cachedModel.materials = (int) (log * SceneMetricsCounter.LimitsConfig.materials);
 0321        cachedModel.textures = (int) (log * SceneMetricsCounter.LimitsConfig.textures);
 0322        cachedModel.meshes = (int) (log * SceneMetricsCounter.LimitsConfig.meshes);
 0323        cachedModel.sceneHeight = (int) (log * SceneMetricsCounter.LimitsConfig.height);
 324
 0325        return cachedModel;
 326    }
 327
 328    public static Manifest CreateManifestFromProjectDataAndScene(ProjectData data, WebBuilderScene scene)
 329    {
 0330        Manifest manifest = new Manifest();
 0331        manifest.version = BIWSettings.MANIFEST_VERSION;
 0332        manifest.project = data;
 0333        manifest.scene = scene;
 334
 0335        manifest.project.scene_number = manifest.scene.sceneNumber;
 0336        return manifest;
 337    }
 338
 339    public static Manifest CreateManifestFromProject(ProjectData projectData)
 340    {
 0341        Manifest manifest = new Manifest();
 0342        manifest.version = BIWSettings.MANIFEST_VERSION;
 0343        manifest.project = projectData;
 0344        manifest.scene = CreateEmtpyBuilderScene(projectData.rows, projectData.cols);
 345
 0346        manifest.project.scene_number = manifest.scene.sceneNumber;
 0347        return manifest;
 348    }
 349
 350    //We create the scene the same way as the current builder do, so we ensure the compatibility between both builders
 351    private static WebBuilderScene CreateEmtpyBuilderScene(int rows, int cols)
 352    {
 0353        Dictionary<string, BuilderEntity> entities = new Dictionary<string, BuilderEntity>();
 0354        Dictionary<string, BuilderComponent> components = new Dictionary<string, BuilderComponent>();
 0355        Dictionary<string, SceneObject> assets = new Dictionary<string, SceneObject>();
 356
 357        // We get the asset
 0358        var floorAsset = CreateFloorSceneObject();
 0359        assets.Add(floorAsset.id,floorAsset);
 360
 361        // We create the ground
 0362        BuilderGround ground = new BuilderGround();
 0363        ground.assetId = floorAsset.id;
 0364        ground.componentId = Guid.NewGuid().ToString();
 365
 0366        for (int x = 0; x < rows; x++)
 367        {
 0368            for (int y = 0; y < cols; y++)
 369            {
 370                // We create the entity for the ground
 0371                BuilderEntity entity = new BuilderEntity();
 0372                entity.id = Guid.NewGuid().ToString();
 0373                entity.disableGizmos = true;
 0374                entity.name = "entity"+x+y;
 375
 376                // We need a transform for the entity so we create it
 0377                BuilderComponent transformComponent = new BuilderComponent();
 0378                transformComponent.id = Guid.NewGuid().ToString();
 0379                transformComponent.type = "Transform";
 380
 381                // We create the transform data
 0382                TransformComponent entityTransformComponentModel = new TransformComponent();
 0383                entityTransformComponentModel.position = new Vector3(8+(16*x), 0, 8+(16*y));
 0384                entityTransformComponentModel.rotation = new ProtocolV2.QuaternionRepresentation(Quaternion.identity);
 0385                entityTransformComponentModel.scale = Vector3.one;
 386
 0387                transformComponent.data = entityTransformComponentModel;
 0388                entity.components.Add(transformComponent.id);
 0389                if(!components.ContainsKey(transformComponent.id))
 0390                    components.Add(transformComponent.id,transformComponent);
 391
 392                // We create the GLTFShape component
 0393                BuilderComponent gltfShapeComponent = new BuilderComponent();
 0394                gltfShapeComponent.id = ground.componentId;
 0395                gltfShapeComponent.type = "GLTFShape";
 396
 0397                LoadableShape.Model model = new GLTFShape.Model();
 0398                model.assetId = floorAsset.id;
 0399                gltfShapeComponent.data = model;
 400
 0401                entity.components.Add(ground.componentId);
 0402                if(!components.ContainsKey(gltfShapeComponent.id))
 0403                    components.Add(gltfShapeComponent.id,gltfShapeComponent);
 404
 405                // Finally, we add the entity to the list
 0406                entities.Add(entity.id,entity);
 407            }
 408        }
 409
 0410        WebBuilderScene scene = new WebBuilderScene
 411        {
 412            sceneNumber = Guid.NewGuid().GetHashCode(),
 413            entities = entities,
 414            components =  components,
 415            assets = assets,
 416            limits = GetSceneMetricsLimits(rows*cols),
 417            metrics = new SceneMetricsModel(),
 418            ground = ground
 419        };
 420
 0421        return scene;
 422    }
 423
 424    public static Manifest CreateEmptyDefaultBuilderManifest(Vector2Int size, string landCoordinates)
 425    {
 0426        Manifest manifest = new Manifest();
 0427        manifest.version = BIWSettings.MANIFEST_VERSION;
 428
 429        //We create a new project data for the scene
 0430        ProjectData projectData = new ProjectData();
 0431        projectData.id = Guid.NewGuid().ToString();
 0432        projectData.eth_address = UserProfile.GetOwnUserProfile().ethAddress;
 0433        projectData.title = "Builder " + landCoordinates;
 0434        projectData.description = "Scene created from the explorer builder";
 0435        projectData.creation_coords = landCoordinates;
 0436        projectData.rows = size.x;
 0437        projectData.cols = size.y;
 0438        projectData.updated_at = DateTime.Now;
 0439        projectData.created_at = DateTime.Now;
 0440        projectData.thumbnail = "thumbnail.png";
 441
 442        //We create an empty scene
 0443        manifest.scene = CreateEmtpyBuilderScene(size.x, size.y);
 444
 0445        projectData.scene_number = manifest.scene.sceneNumber;
 0446        manifest.project = projectData;
 0447        return manifest;
 448    }
 449
 450    public static LandRole GetLandOwnershipType(List<LandWithAccess> lands, IParcelScene scene)
 451    {
 0452        LandWithAccess filteredLand = lands.FirstOrDefault(land => scene.sceneData.basePosition == land.baseCoords);
 0453        return GetLandOwnershipType(filteredLand);
 454    }
 455
 456    public static LandRole GetLandOwnershipType(LandWithAccess land)
 457    {
 0458        if (land != null)
 0459            return land.role;
 0460        return LandRole.OWNER;
 461    }
 462
 463    public static Vector3 SnapFilterEulerAngles(Vector3 vectorToFilter, float degrees)
 464    {
 0465        vectorToFilter.x = ClosestNumber(vectorToFilter.x, degrees);
 0466        vectorToFilter.y = ClosestNumber(vectorToFilter.y, degrees);
 0467        vectorToFilter.z = ClosestNumber(vectorToFilter.z, degrees);
 468
 0469        return vectorToFilter;
 470    }
 471
 472    static float ClosestNumber(float n, float m)
 473    {
 474        // find the quotient
 0475        int q = Mathf.RoundToInt(n / m);
 476
 477        // 1st possible closest number
 0478        float n1 = m * q;
 479
 480        // 2nd possible closest number
 0481        float n2 = (n * m) > 0 ? (m * (q + 1)) : (m * (q - 1));
 482
 483        // if true, then n1 is the required closest number
 0484        if (Math.Abs(n - n1) < Math.Abs(n - n2))
 0485            return n1;
 486
 487        // else n2 is the required closest number
 0488        return n2;
 489    }
 490
 0491    public static Vector2Int GetSceneSize(IParcelScene parcelScene) { return GetSceneSize(parcelScene.sceneData.parcels)
 492
 493    public static bool HasSquareSize(LandWithAccess land)
 494    {
 0495        Vector2Int size = GetSceneSize(land.parcels);
 496
 0497        for (int x = land.baseCoords.x; x < size.x; x++)
 498        {
 0499            bool found = false;
 0500            foreach (Vector2Int parcel in land.parcels)
 501            {
 0502                if (parcel.x == x)
 503                {
 0504                    found = true;
 0505                    break;
 506                }
 507            }
 0508            if (!found)
 0509                return false;
 510        }
 511
 0512        for (int y = land.baseCoords.y; y < size.x; y++)
 513        {
 0514            bool found = false;
 0515            foreach (Vector2Int parcel in land.parcels)
 516            {
 0517                if (parcel.y == y)
 518                {
 0519                    found = true;
 0520                    break;
 521                }
 522            }
 0523            if (!found)
 0524                return false;
 525        }
 526
 0527        return true;
 528    }
 529
 530    public static Vector2Int GetSceneSize(Vector2Int[] parcels)
 531    {
 0532        int minX = Int32.MaxValue;
 0533        int maxX = Int32.MinValue;
 0534        int minY = Int32.MaxValue;
 0535        int maxY = Int32.MinValue;
 536
 0537        foreach (var parcel in parcels)
 538        {
 0539            if (parcel.x > maxX)
 0540                maxX = parcel.x;
 0541            if (parcel.x < minX)
 0542                minX = parcel.x;
 543
 0544            if (parcel.y > maxY)
 0545                maxY = parcel.y;
 0546            if (parcel.y < minY)
 0547                minY = parcel.y;
 548        }
 549
 0550        int sizeX = maxX - minX + 1;
 0551        int sizeY = maxY - minY + 1;
 0552        return new Vector2Int(sizeX, sizeY);
 553    }
 554
 555    public static Vector3 CalculateUnityMiddlePoint(IParcelScene parcelScene)
 556    {
 557        Vector3 position;
 558
 68559        float totalX = 0f;
 68560        float totalY = 0f;
 68561        float totalZ = 0f;
 562
 68563        int minX = int.MaxValue;
 68564        int minY = int.MaxValue;
 68565        int maxX = int.MinValue;
 68566        int maxY = int.MinValue;
 567
 68568        if (parcelScene?.sceneData == null || parcelScene?.sceneData.parcels == null)
 0569            return Vector3.zero;
 570
 272571        foreach (Vector2Int vector in parcelScene?.sceneData.parcels)
 572        {
 68573            totalX += vector.x;
 68574            totalZ += vector.y;
 68575            if (vector.x < minX)
 68576                minX = vector.x;
 68577            if (vector.y < minY)
 68578                minY = vector.y;
 68579            if (vector.x > maxX)
 68580                maxX = vector.x;
 68581            if (vector.y > maxY)
 68582                maxY = vector.y;
 583        }
 584
 68585        float centerX = totalX / parcelScene.sceneData.parcels.Length + 0.5f;
 68586        float centerZ = totalZ / parcelScene.sceneData.parcels.Length + 0.5f;
 587
 68588        position.x = centerX;
 68589        position.y = totalY;
 68590        position.z = centerZ;
 591
 68592        Vector3 scenePosition = Utils.GridToWorldPosition(centerX, centerZ);
 68593        position = PositionUtils.WorldToUnityPosition(scenePosition);
 594
 68595        return position;
 596    }
 597
 598    public static SceneObject CreateFloorSceneObject()
 599    {
 0600        SceneObject floorSceneObject = new SceneObject();
 0601        floorSceneObject.id = BIWSettings.FLOOR_ID;
 602
 0603        floorSceneObject.model = BIWSettings.FLOOR_MODEL;
 0604        floorSceneObject.name = BIWSettings.FLOOR_NAME;
 0605        floorSceneObject.asset_pack_id = BIWSettings.FLOOR_ASSET_PACK_ID;
 0606        floorSceneObject.thumbnail = BIWSettings.FLOOR_ASSET_THUMBNAIL;
 0607        floorSceneObject.category = BIWSettings.FLOOR_CATEGORY;
 608
 0609        floorSceneObject.tags = new List<string>();
 0610        floorSceneObject.tags.Add("genesis");
 0611        floorSceneObject.tags.Add("city");
 0612        floorSceneObject.tags.Add("town");
 0613        floorSceneObject.tags.Add("ground");
 614
 0615        floorSceneObject.contents = new Dictionary<string, string>();
 616
 0617        floorSceneObject.contents.Add(BIWSettings.FLOOR_GLTF_KEY, BIWSettings.FLOOR_GLTF_VALUE);
 0618        floorSceneObject.contents.Add(BIWSettings.FLOOR_TEXTURE_KEY, BIWSettings.FLOOR_TEXTURE_VALUE);
 0619        floorSceneObject.contents.Add(BIWSettings.FLOOR_THUMBNAIL_KEY, BIWSettings.FLOOR_THUMBNAIL_VALUE);
 620
 0621        floorSceneObject.metrics = new SceneObject.ObjectMetrics();
 622
 0623        return floorSceneObject;
 624    }
 625
 626    public static CatalogItem CreateFloorCatalogItem()
 627    {
 0628        CatalogItem floorSceneObject = new CatalogItem();
 0629        floorSceneObject.id = BIWSettings.FLOOR_ID;
 630
 0631        floorSceneObject.model = BIWSettings.FLOOR_MODEL;
 0632        floorSceneObject.name = BIWSettings.FLOOR_NAME;
 0633        floorSceneObject.assetPackName = BIWSettings.FLOOR_ASSET_PACK_NAME;
 0634        floorSceneObject.thumbnailURL = BIWSettings.FLOOR_ASSET_THUMBNAIL;
 635
 0636        floorSceneObject.tags = new List<string>();
 0637        floorSceneObject.tags.Add("genesis");
 0638        floorSceneObject.tags.Add("city");
 0639        floorSceneObject.tags.Add("town");
 0640        floorSceneObject.tags.Add("ground");
 641
 0642        floorSceneObject.contents = new Dictionary<string, string>();
 643
 0644        floorSceneObject.contents.Add(BIWSettings.FLOOR_GLTF_KEY, BIWSettings.FLOOR_GLTF_VALUE);
 0645        floorSceneObject.contents.Add(BIWSettings.FLOOR_TEXTURE_KEY, BIWSettings.FLOOR_TEXTURE_VALUE);
 0646        floorSceneObject.contents.Add(BIWSettings.FLOOR_THUMBNAIL_KEY, BIWSettings.FLOOR_THUMBNAIL_VALUE);
 647
 0648        floorSceneObject.metrics = new SceneObject.ObjectMetrics();
 649
 0650        return floorSceneObject;
 651    }
 652
 653    public static Dictionary<string, string> ConvertMappingsToDictionary(ContentServerUtils.MappingPair[] contents)
 654    {
 0655        Dictionary<string, string> mappingDict = new Dictionary<string, string>();
 656
 0657        foreach (ContentServerUtils.MappingPair mappingPair in contents)
 658        {
 0659            mappingDict.Add(mappingPair.file, mappingPair.hash);
 660        }
 661
 0662        return mappingDict;
 663    }
 664
 665    public static void DrawScreenRect(Rect rect, Color color)
 666    {
 0667        GUI.color = color;
 0668        GUI.DrawTexture(rect, Texture2D.whiteTexture);
 0669    }
 670
 671    public static void DrawScreenRectBorder(Rect rect, float thickness, Color color)
 672    {
 673        //Top
 0674        DrawScreenRect(new Rect(rect.xMin, rect.yMin, rect.width, thickness), color);
 675        // Left
 0676        DrawScreenRect(new Rect(rect.xMin, rect.yMin, thickness, rect.height), color);
 677        // Right
 0678        DrawScreenRect(new Rect(rect.xMax - thickness, rect.yMin, thickness, rect.height), color);
 679        // Bottom
 0680        DrawScreenRect(new Rect(rect.xMin, rect.yMax - thickness, rect.width, thickness), color);
 0681    }
 682
 683    public static Rect GetScreenRect(Vector3 screenPosition1, Vector3 screenPosition2)
 684    {
 685        // Move origin from bottom left to top left
 0686        screenPosition1.y = Screen.height - screenPosition1.y;
 0687        screenPosition2.y = Screen.height - screenPosition2.y;
 688        // Calculate corners
 0689        var topLeft = Vector3.Min(screenPosition1, screenPosition2);
 0690        var bottomRight = Vector3.Max(screenPosition1, screenPosition2);
 691        // Create Rect
 0692        return Rect.MinMaxRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
 693    }
 694
 695    public static Bounds GetViewportBounds(Camera camera, Vector3 screenPosition1, Vector3 screenPosition2)
 696    {
 2697        var v1 = camera.ScreenToViewportPoint(screenPosition1);
 2698        var v2 = camera.ScreenToViewportPoint(screenPosition2);
 2699        var min = Vector3.Min(v1, v2);
 2700        var max = Vector3.Max(v1, v2);
 2701        min.z = camera.nearClipPlane;
 2702        max.z = camera.farClipPlane;
 703
 2704        var bounds = new Bounds();
 705
 2706        bounds.SetMinMax(min, max);
 2707        return bounds;
 708    }
 709
 0710    public static bool IsWithinSelectionBounds(Transform transform, Vector3 lastClickMousePosition, Vector3 mousePositio
 711
 712    public static bool IsWithinSelectionBounds(Vector3 point, Vector3 lastClickMousePosition, Vector3 mousePosition)
 713    {
 2714        Camera camera = Camera.main;
 2715        var viewPortBounds = GetViewportBounds(camera, lastClickMousePosition, mousePosition);
 2716        return viewPortBounds.Contains(camera.WorldToViewportPoint(point));
 717    }
 718
 719    public static bool IsBoundInsideCamera(Bounds bound)
 720    {
 0721        Vector3[] points = { bound.max, bound.center, bound.min };
 0722        return IsPointInsideCamera(points);
 723    }
 724
 725    public static bool IsPointInsideCamera(Vector3[] points)
 726    {
 0727        foreach (Vector3 point in points)
 728        {
 0729            if (IsPointInsideCamera(point))
 0730                return true;
 731        }
 0732        return false;
 733    }
 734
 735    public static bool IsPointInsideCamera(Vector3 point)
 736    {
 0737        Vector3 topRight = new Vector3(Screen.width, Screen.height, 0);
 0738        var viewPortBounds = GetViewportBounds(Camera.main, Vector3.zero, topRight);
 0739        return viewPortBounds.Contains(Camera.main.WorldToViewportPoint(point));
 740    }
 741
 742    public static void CopyGameObjectStatus(GameObject gameObjectToCopy, GameObject gameObjectToReceive, bool copyParent
 743    {
 2744        if (copyParent)
 0745            gameObjectToReceive.transform.SetParent(gameObjectToCopy.transform.parent);
 746
 2747        gameObjectToReceive.transform.position = gameObjectToCopy.transform.position;
 748
 2749        if (localRotation)
 0750            gameObjectToReceive.transform.localRotation = gameObjectToCopy.transform.localRotation;
 751        else
 2752            gameObjectToReceive.transform.rotation = gameObjectToCopy.transform.rotation;
 753
 2754        gameObjectToReceive.transform.localScale = gameObjectToCopy.transform.lossyScale;
 2755    }
 756
 757    public static bool IsPointerOverMaskElement(LayerMask mask)
 758    {
 759        RaycastHit hitInfo;
 1760        UnityEngine.Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
 1761        return Physics.Raycast(mouseRay, out hitInfo, 5555, mask);
 762    }
 763
 764    public static bool IsPointerOverUIElement(Vector3 mousePosition)
 765    {
 0766        var eventData = new PointerEventData(EventSystem.current);
 0767        eventData.position = mousePosition;
 0768        var results = new List<RaycastResult>();
 0769        EventSystem.current.RaycastAll(eventData, results);
 0770        return results.Count > 2;
 771    }
 772
 0773    public static bool IsPointerOverUIElement() { return IsPointerOverUIElement(Input.mousePosition); }
 774
 775    public static string ConvertEntityToJSON(IDCLEntity entity)
 776    {
 0777        EntityData builderInWorldEntityData = new EntityData();
 0778        builderInWorldEntityData.entityId = entity.entityId;
 779
 0780        var components = entity.scene.componentsManagerLegacy.GetComponentsDictionary(entity);
 781
 0782        if (components != null)
 783        {
 0784            foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in components)
 785            {
 0786                if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
 787                {
 0788                    EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent();
 789
 0790                    entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transf
 0791                    entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles;
 0792                    entityComponentModel.scale = entity.gameObject.transform.localScale;
 793
 0794                    builderInWorldEntityData.transformComponent = entityComponentModel;
 795                }
 796                else
 797                {
 0798                    ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
 0799                    entityComponentModel.componentId = (int)keyValuePair.Key;
 0800                    entityComponentModel.data = keyValuePair.Value.GetModel();
 801
 0802                    builderInWorldEntityData.components.Add(entityComponentModel);
 803                }
 804            }
 805        }
 806
 0807        var sharedComponents = entity.scene.componentsManagerLegacy.GetSharedComponentsDictionary(entity);
 808
 0809        if (sharedComponents != null)
 810        {
 0811            foreach (KeyValuePair<Type, ISharedComponent> keyValuePair in sharedComponents)
 812            {
 0813                if (keyValuePair.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
 814                {
 0815                    EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent();
 0816                    NFTShape.Model model = (NFTShape.Model)keyValuePair.Value.GetModel();
 817
 0818                    nFTComponent.id = keyValuePair.Value.id;
 0819                    nFTComponent.color = new ColorRepresentation(model.color);
 0820                    nFTComponent.assetId = model.assetId;
 0821                    nFTComponent.src = model.src;
 0822                    nFTComponent.style = model.style;
 823
 0824                    builderInWorldEntityData.nftComponent = nFTComponent;
 825                }
 826                else
 827                {
 0828                    ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
 0829                    entityComponentModel.componentId = keyValuePair.Value.GetClassId();
 0830                    entityComponentModel.data = keyValuePair.Value.GetModel();
 0831                    entityComponentModel.classId = keyValuePair.Value.id;
 832
 0833                    builderInWorldEntityData.sharedComponents.Add(entityComponentModel);
 834                }
 835            }
 836        }
 837
 838
 0839        return JsonConvert.SerializeObject(builderInWorldEntityData);
 840    }
 841
 0842    public static EntityData ConvertJSONToEntityData(string json) { return JsonConvert.DeserializeObject<EntityData>(jso
 843
 844    public static List<BIWEntity> RemoveGroundEntities(List<BIWEntity> entityList)
 845    {
 0846        List<BIWEntity> newList = new List<BIWEntity>();
 847
 0848        foreach (BIWEntity entity in entityList)
 849        {
 0850            if (entity.isFloor)
 851                continue;
 852
 0853            newList.Add(entity);
 854        }
 855
 0856        return newList;
 857    }
 858
 859    public static List<BIWEntity> FilterEntitiesBySmartItemComponentAndActions(List<BIWEntity> entityList)
 860    {
 0861        List<BIWEntity> newList = new List<BIWEntity>();
 862
 0863        foreach (BIWEntity entity in entityList)
 864        {
 0865            if (!entity.HasSmartItemComponent() || !entity.HasSmartItemActions())
 866                continue;
 867
 0868            newList.Add(entity);
 869        }
 870
 0871        return newList;
 872    }
 873
 874    public static void CopyRectTransform(RectTransform original, RectTransform rectTransformToCopy)
 875    {
 0876        original.anchoredPosition = rectTransformToCopy.anchoredPosition;
 0877        original.anchorMax = rectTransformToCopy.anchorMax;
 0878        original.anchorMin = rectTransformToCopy.anchorMin;
 0879        original.offsetMax = rectTransformToCopy.offsetMax;
 0880        original.offsetMin = rectTransformToCopy.offsetMin;
 0881        original.sizeDelta = rectTransformToCopy.sizeDelta;
 0882        original.pivot = rectTransformToCopy.pivot;
 0883    }
 884
 885    public static IWebRequestAsyncOperation MakeGetCall(string url, Promise<string> callPromise, Dictionary<string, stri
 886    {
 4887        headers["Cache-Control"] = "no-cache";
 4888        var asyncOperation = Environment.i.platform.webRequest.Get(
 889            url: url,
 890            OnSuccess: (webRequestResult) =>
 891            {
 4892                byte[] byteArray = webRequestResult.GetResultData();
 4893                string result = System.Text.Encoding.UTF8.GetString(byteArray);
 4894                callPromise?.Resolve(result);
 4895            },
 896            OnFail: (webRequestResult) =>
 897            {
 898                try
 899                {
 0900                    byte[] byteArray = webRequestResult.GetResultData();
 0901                    string result = System.Text.Encoding.UTF8.GetString(byteArray);
 0902                    APIResponse response = JsonConvert.DeserializeObject<APIResponse>(result);
 0903                    callPromise?.Resolve(result);
 0904                }
 0905                catch (Exception e)
 906                {
 0907                    Debug.Log(webRequestResult.webRequest.error);
 0908                    callPromise.Reject(webRequestResult.webRequest.error);
 0909                }
 0910            },
 911            headers: headers);
 912
 4913        return asyncOperation;
 914    }
 915
 916    public static IWebRequestAsyncOperation MakeGetTextureCall(string url, Promise<Texture2D> callPromise)
 917    {
 0918        var asyncOperation = Environment.i.platform.webRequest.GetTexture(
 919            url: url,
 920            OnSuccess: (webRequestResult) =>
 921            {
 0922                callPromise.Resolve(DownloadHandlerTexture.GetContent(webRequestResult.webRequest));
 0923            },
 924            OnFail: (webRequestResult) =>
 925            {
 0926                callPromise.Reject(webRequestResult.webRequest.error);
 0927            });
 928
 0929        return asyncOperation;
 930    }
 931
 932    public static void ConfigureEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType, UnityAction<BaseEven
 933    {
 811934        EventTrigger.Entry entry = new EventTrigger.Entry();
 811935        entry.eventID = eventType;
 811936        entry.callback.AddListener(call);
 811937        eventTrigger.triggers.Add(entry);
 811938    }
 939
 2118940    public static void RemoveEventTrigger(EventTrigger eventTrigger, EventTriggerType eventType) { eventTrigger.triggers
 941}

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)