< Summary

Class:DCL.Helpers.UtilsDummyJsonUtilityFromArray[T]
Assembly:Utils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/Utils.cs
Covered lines:2
Uncovered lines:0
Coverable lines:2
Total lines:698
Line coverage:100% (2 of 2)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetFromJsonArray(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/Utils.cs

#LineLine coverage
 1#if UNITY_WEBGL && !UNITY_EDITOR
 2#define WEB_PLATFORM
 3#endif
 4
 5using System;
 6using System.Collections;
 7using System.Collections.Generic;
 8using System.Linq;
 9using System.Reflection;
 10using DCL.Configuration;
 11using Google.Protobuf.Collections;
 12using Newtonsoft.Json;
 13using TMPro;
 14using UnityEngine;
 15using UnityEngine.Assertions;
 16using UnityEngine.EventSystems;
 17using UnityEngine.Networking;
 18using UnityEngine.UI;
 19using Object = UnityEngine.Object;
 20using UnityEngine.Rendering.Universal;
 21
 22namespace DCL.Helpers
 23{
 24    public static class Utils
 25    {
 26        public static Dictionary<string, Material> staticMaterials;
 27
 28        public static Material EnsureResourcesMaterial(string path)
 29        {
 30            if (staticMaterials == null)
 31            {
 32                staticMaterials = new Dictionary<string, Material>();
 33            }
 34
 35            if (!staticMaterials.ContainsKey(path))
 36            {
 37                Material material = Resources.Load(path) as Material;
 38
 39                if (material != null)
 40                {
 41                    staticMaterials.Add(path, material);
 42                }
 43
 44                return material;
 45            }
 46
 47            return staticMaterials[path];
 48        }
 49
 50        public static void CleanMaterials(Renderer r)
 51        {
 52            if (r != null)
 53            {
 54                foreach (Material m in r.materials)
 55                {
 56                    if (m != null)
 57                    {
 58                        Material.Destroy(m);
 59                    }
 60                }
 61            }
 62        }
 63
 64        public static ScriptableRendererFeature ToggleRenderFeature<T>(this UniversalRenderPipelineAsset asset, bool ena
 65        {
 66            var type = asset.GetType();
 67            var propertyInfo = type.GetField("m_RendererDataList", BindingFlags.Instance | BindingFlags.NonPublic);
 68
 69            if (propertyInfo == null)
 70            {
 71                return null;
 72            }
 73
 74            var scriptableRenderData = (ScriptableRendererData[])propertyInfo.GetValue(asset);
 75
 76            if (scriptableRenderData != null && scriptableRenderData.Length > 0)
 77            {
 78                foreach (var renderData in scriptableRenderData)
 79                {
 80                    foreach (var rendererFeature in renderData.rendererFeatures)
 81                    {
 82                        if (rendererFeature is T)
 83                        {
 84                            rendererFeature.SetActive(enable);
 85
 86                            return rendererFeature;
 87                        }
 88                    }
 89                }
 90            }
 91
 92            return null;
 93        }
 94
 95        public static Vector2[] FloatArrayToV2List(RepeatedField<float> uvs)
 96        {
 97            Vector2[] uvsResult = new Vector2[uvs.Count / 2];
 98            int uvsResultIndex = 0;
 99
 100            for (int i = 0; i < uvs.Count;)
 101            {
 102                Vector2 tmpUv = Vector2.zero;
 103                tmpUv.x = uvs[i++];
 104                tmpUv.y = uvs[i++];
 105
 106                uvsResult[uvsResultIndex++] = tmpUv;
 107            }
 108
 109            return uvsResult;
 110        }
 111
 112        public static Vector2[] FloatArrayToV2List(IList<float> uvs)
 113        {
 114            Vector2[] uvsResult = new Vector2[uvs.Count / 2];
 115            int uvsResultIndex = 0;
 116
 117            for (int i = 0; i < uvs.Count;)
 118            {
 119                uvsResult[uvsResultIndex++] = new Vector2(uvs[i++],uvs[i++]);
 120            }
 121
 122            return uvsResult;
 123        }
 124
 125        public static Vector2Int StringToVector2Int(string coords)
 126        {
 127            string[] coordSplit = coords.Split(',');
 128            if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int 
 129            {
 130                return new Vector2Int(x, y);
 131            }
 132
 133            return Vector2Int.zero;
 134        }
 135
 136        private const int MAX_TRANSFORM_VALUE = 10000;
 137        public static void CapGlobalValuesToMax(this Transform transform)
 138        {
 139            bool positionOutsideBoundaries = transform.position.sqrMagnitude > MAX_TRANSFORM_VALUE * MAX_TRANSFORM_VALUE
 140            bool scaleOutsideBoundaries = transform.lossyScale.sqrMagnitude > MAX_TRANSFORM_VALUE * MAX_TRANSFORM_VALUE;
 141
 142            if (positionOutsideBoundaries || scaleOutsideBoundaries)
 143            {
 144                Vector3 newPosition = transform.position;
 145                if (positionOutsideBoundaries)
 146                {
 147                    if (Mathf.Abs(newPosition.x) > MAX_TRANSFORM_VALUE)
 148                        newPosition.x = MAX_TRANSFORM_VALUE * Mathf.Sign(newPosition.x);
 149
 150                    if (Mathf.Abs(newPosition.y) > MAX_TRANSFORM_VALUE)
 151                        newPosition.y = MAX_TRANSFORM_VALUE * Mathf.Sign(newPosition.y);
 152
 153                    if (Mathf.Abs(newPosition.z) > MAX_TRANSFORM_VALUE)
 154                        newPosition.z = MAX_TRANSFORM_VALUE * Mathf.Sign(newPosition.z);
 155                }
 156
 157                Vector3 newScale = transform.lossyScale;
 158                if (scaleOutsideBoundaries)
 159                {
 160                    if (Mathf.Abs(newScale.x) > MAX_TRANSFORM_VALUE)
 161                        newScale.x = MAX_TRANSFORM_VALUE * Mathf.Sign(newScale.x);
 162
 163                    if (Mathf.Abs(newScale.y) > MAX_TRANSFORM_VALUE)
 164                        newScale.y = MAX_TRANSFORM_VALUE * Mathf.Sign(newScale.y);
 165
 166                    if (Mathf.Abs(newScale.z) > MAX_TRANSFORM_VALUE)
 167                        newScale.z = MAX_TRANSFORM_VALUE * Mathf.Sign(newScale.z);
 168                }
 169
 170                SetTransformGlobalValues(transform, newPosition, transform.rotation, newScale, scaleOutsideBoundaries);
 171            }
 172        }
 173
 174        public static void SetTransformGlobalValues(Transform transform, Vector3 newPos, Quaternion newRot, Vector3 newS
 175        {
 176            transform.position = newPos;
 177            transform.rotation = newRot;
 178
 179            if (setScale)
 180            {
 181                transform.localScale = Vector3.one;
 182                var m = transform.worldToLocalMatrix;
 183
 184                m.SetColumn(0, new Vector4(m.GetColumn(0).magnitude, 0f));
 185                m.SetColumn(1, new Vector4(0f, m.GetColumn(1).magnitude));
 186                m.SetColumn(2, new Vector4(0f, 0f, m.GetColumn(2).magnitude));
 187                m.SetColumn(3, new Vector4(0f, 0f, 0f, 1f));
 188
 189                transform.localScale = m.MultiplyPoint(newScale);
 190            }
 191        }
 192
 193        public static void ResetLocalTRS(this Transform t)
 194        {
 195            t.localPosition = Vector3.zero;
 196            t.localRotation = Quaternion.identity;
 197            t.localScale = Vector3.one;
 198        }
 199
 200        public static void SetToMaxStretch(this RectTransform t)
 201        {
 202            t.anchorMin = Vector2.zero;
 203            t.offsetMin = Vector2.zero;
 204            t.anchorMax = Vector2.one;
 205            t.offsetMax = Vector2.one;
 206            t.sizeDelta = Vector2.zero;
 207            t.anchoredPosition = Vector2.zero;
 208        }
 209
 210        public static void SetToCentered(this RectTransform t)
 211        {
 212            t.anchorMin = Vector2.one * 0.5f;
 213            t.offsetMin = Vector2.one * 0.5f;
 214            t.anchorMax = Vector2.one * 0.5f;
 215            t.offsetMax = Vector2.one * 0.5f;
 216            t.sizeDelta = Vector2.one * 100;
 217        }
 218
 219        public static void SetToBottomLeft(this RectTransform t)
 220        {
 221            t.anchorMin = Vector2.zero;
 222            t.offsetMin = Vector2.zero;
 223            t.anchorMax = Vector2.zero;
 224            t.offsetMax = Vector2.zero;
 225            t.sizeDelta = Vector2.one * 100;
 226        }
 227
 228        public static void ForceUpdateLayout(this RectTransform rt, bool delayed = true)
 229        {
 230            if (!rt.gameObject.activeInHierarchy)
 231                return;
 232
 233            if (delayed)
 234                CoroutineStarter.Start(ForceUpdateLayoutRoutine(rt));
 235            else
 236            {
 237                InverseTransformChildTraversal<RectTransform>(
 238                    (x) => { ForceRebuildLayoutImmediate(x); },
 239                    rt);
 240            }
 241        }
 242
 243        /// <summary>
 244        /// Reimplementation of the LayoutRebuilder.ForceRebuildLayoutImmediate() function (Unity UI API) for make it mo
 245        /// </summary>
 246        /// <param name="rectTransformRoot">Root from which to rebuild.</param>
 247        public static void ForceRebuildLayoutImmediate(RectTransform rectTransformRoot)
 248        {
 249            if (rectTransformRoot == null)
 250                return;
 251
 252            // NOTE(Santi): It seems to be very much cheaper to execute the next instructions manually than execute dire
 253            //              'LayoutRebuilder.ForceRebuildLayoutImmediate()', that theorically already contains these ins
 254            var layoutElements = rectTransformRoot.GetComponentsInChildren(typeof(ILayoutElement), true).ToList();
 255            layoutElements.RemoveAll(e => (e is Behaviour && !((Behaviour) e).isActiveAndEnabled) || e is TextMeshProUGU
 256            foreach (var layoutElem in layoutElements)
 257            {
 258                (layoutElem as ILayoutElement).CalculateLayoutInputHorizontal();
 259                (layoutElem as ILayoutElement).CalculateLayoutInputVertical();
 260            }
 261
 262            var layoutControllers = rectTransformRoot.GetComponentsInChildren(typeof(ILayoutController), true).ToList();
 263            layoutControllers.RemoveAll(e => e is Behaviour && !((Behaviour) e).isActiveAndEnabled);
 264            foreach (var layoutCtrl in layoutControllers)
 265            {
 266                (layoutCtrl as ILayoutController).SetLayoutHorizontal();
 267                (layoutCtrl as ILayoutController).SetLayoutVertical();
 268            }
 269        }
 270
 271        private static IEnumerator ForceUpdateLayoutRoutine(RectTransform rt)
 272        {
 273            yield return null;
 274
 275            InverseTransformChildTraversal<RectTransform>(
 276                (x) => { ForceRebuildLayoutImmediate(x); },
 277                rt);
 278        }
 279
 280        public static void InverseTransformChildTraversal<TComponent>(Action<TComponent> action, Transform startTransfor
 281            where TComponent : Component
 282        {
 283            if (startTransform == null)
 284                return;
 285
 286            foreach (Transform t in startTransform)
 287            {
 288                InverseTransformChildTraversal(action, t);
 289            }
 290
 291            var component = startTransform.GetComponent<TComponent>();
 292
 293            if (component != null)
 294            {
 295                action.Invoke(component);
 296            }
 297        }
 298
 299        public static void ForwardTransformChildTraversal<TComponent>(Func<TComponent, bool> action, Transform startTran
 300            where TComponent : Component
 301        {
 302            Assert.IsTrue(startTransform != null, "startTransform must not be null");
 303
 304            var component = startTransform.GetComponent<TComponent>();
 305
 306            if (component != null)
 307            {
 308                if (!action.Invoke(component))
 309                    return;
 310            }
 311
 312            foreach (Transform t in startTransform)
 313            {
 314                ForwardTransformChildTraversal(action, t);
 315            }
 316        }
 317
 318        public static T GetOrCreateComponent<T>(this GameObject gameObject) where T : Component
 319        {
 320            T component = gameObject.GetComponent<T>();
 321
 322            if (!component)
 323            {
 324                return gameObject.AddComponent<T>();
 325            }
 326
 327            return component;
 328        }
 329
 330        public static IWebRequestAsyncOperation FetchTexture(string textureURL, bool isReadable, Action<Texture2D> OnSuc
 331        {
 332            //NOTE(Brian): This closure is called when the download is a success.
 333            void SuccessInternal(IWebRequestAsyncOperation request) { OnSuccess?.Invoke(DownloadHandlerTexture.GetConten
 334
 335            var asyncOp = Environment.i.platform.webRequest.GetTexture(
 336                url: textureURL,
 337                OnSuccess: SuccessInternal,
 338                OnFail: OnFail,
 339                isReadable: isReadable);
 340
 341            return asyncOp;
 342        }
 343
 344        public static bool SafeFromJsonOverwrite(string json, object objectToOverwrite)
 345        {
 346            try
 347            {
 348                JsonUtility.FromJsonOverwrite(json, objectToOverwrite);
 349            }
 350            catch (ArgumentException e)
 351            {
 352                Debug.LogError("ArgumentException Fail!... Json = " + json + " " + e.ToString());
 353                return false;
 354            }
 355
 356            return true;
 357        }
 358
 359        public static T FromJsonWithNulls<T>(string json) { return JsonConvert.DeserializeObject<T>(json); }
 360
 361        public static T SafeFromJson<T>(string json)
 362        {
 363            ProfilingEvents.OnMessageDecodeStart?.Invoke("Misc");
 364
 365            T returningValue = default(T);
 366
 367            if (!string.IsNullOrEmpty(json))
 368            {
 369                try
 370                {
 371                    returningValue = JsonUtility.FromJson<T>(json);
 372                }
 373                catch (ArgumentException e)
 374                {
 375                    Debug.LogError("ArgumentException Fail!... Json = " + json + " " + e.ToString());
 376                }
 377            }
 378
 379            ProfilingEvents.OnMessageDecodeEnds?.Invoke("Misc");
 380
 381            return returningValue;
 382        }
 383
 384        public static GameObject AttachPlaceholderRendererGameObject(Transform targetTransform)
 385        {
 386            var placeholderRenderer = GameObject.CreatePrimitive(PrimitiveType.Cube).GetComponent<MeshRenderer>();
 387
 388            placeholderRenderer.material = Resources.Load<Material>("Materials/AssetLoading");
 389            placeholderRenderer.transform.SetParent(targetTransform);
 390            placeholderRenderer.transform.localPosition = Vector3.zero;
 391            placeholderRenderer.name = "PlaceholderRenderer";
 392
 393            return placeholderRenderer.gameObject;
 394        }
 395
 396        public static void SafeDestroy(Object obj)
 397        {
 398            if (obj is Transform)
 399                return;
 400
 401#if UNITY_EDITOR
 402            if (Application.isPlaying)
 403                Object.Destroy(obj);
 404            else
 405                Object.DestroyImmediate(obj, false);
 406#else
 407                UnityEngine.Object.Destroy(obj);
 408#endif
 409        }
 410
 411        /**
 412         * Transforms a grid position into a world-relative 3d position
 413         */
 414        public static Vector3 GridToWorldPosition(float xGridPosition, float yGridPosition)
 415        {
 416            return new Vector3(
 417                x: xGridPosition * ParcelSettings.PARCEL_SIZE,
 418                y: 0f,
 419                z: yGridPosition * ParcelSettings.PARCEL_SIZE
 420            );
 421        }
 422
 423        /**
 424         * Transforms a world position into a grid position
 425         */
 426        public static Vector2Int WorldToGridPosition(Vector3 worldPosition)
 427        {
 428            return new Vector2Int(
 429                (int) Mathf.Floor(worldPosition.x / ParcelSettings.PARCEL_SIZE),
 430                (int) Mathf.Floor(worldPosition.z / ParcelSettings.PARCEL_SIZE)
 431            );
 432        }
 433
 434        public static Vector2 WorldToGridPositionUnclamped(Vector3 worldPosition)
 435        {
 436            return new Vector2(
 437                worldPosition.x / ParcelSettings.PARCEL_SIZE,
 438                worldPosition.z / ParcelSettings.PARCEL_SIZE
 439            );
 440        }
 441
 442        public static bool AproxComparison(this Color color1, Color color2, float tolerance = 0.01f) // tolerance of rou
 443        {
 444            if (Mathf.Abs(color1.r - color2.r) < tolerance
 445                && Mathf.Abs(color1.g - color2.g) < tolerance
 446                && Mathf.Abs(color1.b - color2.b) < tolerance)
 447            {
 448                return true;
 449            }
 450
 451            return false;
 452        }
 453
 454        public static T ParseJsonArray<T>(string jsonArray) where T : IEnumerable => DummyJsonUtilityFromArray<T>.GetFro
 455
 456        [Serializable]
 457        private class DummyJsonUtilityFromArray<T> where T : IEnumerable //UnityEngine.JsonUtility is really fast but ca
 458        {
 459            [SerializeField]
 460            private T value;
 461
 462            public static T GetFromJsonArray(string jsonArray)
 463            {
 5464                string newJson = $"{{ \"value\": {jsonArray}}}";
 5465                return JsonUtility.FromJson<DummyJsonUtilityFromArray<T>>(newJson).value;
 466            }
 467        }
 468
 469        private static int lockedInFrame = -1;
 470        public static bool LockedThisFrame() => lockedInFrame == Time.frameCount;
 471
 472        private static bool isCursorLocked;
 473        //NOTE(Brian): Made as an independent flag because the CI doesn't work well with the Cursor.lockState check.
 474        public static bool IsCursorLocked
 475        {
 476            get => isCursorLocked;
 477            private set
 478            {
 479                if (isCursorLocked == value) return;
 480                isCursorLocked = value;
 481                OnCursorLockChanged?.Invoke(isCursorLocked);
 482            }
 483        }
 484
 485        public static event Action<bool> OnCursorLockChanged;
 486
 487        public static void LockCursor()
 488        {
 489#if WEB_PLATFORM
 490            //TODO(Brian): Encapsulate all this mechanism to a new MouseLockController and branch
 491            //             behaviour using strategy pattern instead of this.
 492            if (IsCursorLocked)
 493            {
 494                return;
 495            }
 496#endif
 497            Cursor.visible = false;
 498            IsCursorLocked = true;
 499            Cursor.lockState = CursorLockMode.Locked;
 500            lockedInFrame = Time.frameCount;
 501
 502            EventSystem.current?.SetSelectedGameObject(null);
 503        }
 504
 505        public static void UnlockCursor()
 506        {
 507#if WEB_PLATFORM
 508            //TODO(Brian): Encapsulate all this mechanism to a new MouseLockController and branch
 509            //             behaviour using strategy pattern instead of this.
 510            if (!IsCursorLocked)
 511            {
 512                return;
 513            }
 514#endif
 515            Cursor.visible = true;
 516            IsCursorLocked = false;
 517            Cursor.lockState = CursorLockMode.None;
 518
 519            EventSystem.current?.SetSelectedGameObject(null);
 520        }
 521
 522        #region BROWSER_ONLY
 523
 524        //TODO(Brian): Encapsulate all this mechanism to a new MouseLockController and branch
 525        //             behaviour using strategy pattern instead of this.
 526        // NOTE: This should come from browser's pointerlockchange callback
 527        public static void BrowserSetCursorState(bool locked)
 528        {
 529            Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
 530
 531            IsCursorLocked = locked;
 532            Cursor.visible = !locked;
 533        }
 534
 535        #endregion
 536
 537        public static void DestroyAllChild(this Transform transform)
 538        {
 539            foreach (Transform child in transform)
 540            {
 541                Object.Destroy(child.gameObject);
 542            }
 543        }
 544
 545        public static List<Vector2Int> GetBottomLeftZoneArray(Vector2Int bottomLeftAnchor, Vector2Int size)
 546        {
 547            List<Vector2Int> coords = new List<Vector2Int>();
 548
 549            for (int x = bottomLeftAnchor.x; x < bottomLeftAnchor.x + size.x; x++)
 550            {
 551                for (int y = bottomLeftAnchor.y; y < bottomLeftAnchor.y + size.y; y++)
 552                {
 553                    coords.Add(new Vector2Int(x, y));
 554                }
 555            }
 556
 557            return coords;
 558        }
 559
 560        public static List<Vector2Int> GetCenteredZoneArray(Vector2Int center, Vector2Int size)
 561        {
 562            List<Vector2Int> coords = new List<Vector2Int>();
 563
 564            for (int x = center.x - size.x; x < center.x + size.x; x++)
 565            {
 566                for (int y = center.y - size.y; y < center.y + size.y; y++)
 567                {
 568                    coords.Add(new Vector2Int(x, y));
 569                }
 570            }
 571
 572            return coords;
 573        }
 574
 575        public static void DrawRectGizmo(Rect rect, Color color, float duration)
 576        {
 577            Vector3 tl2 = new Vector3(rect.xMin, rect.yMax, 0);
 578            Vector3 bl2 = new Vector3(rect.xMin, rect.yMin, 0);
 579            Vector3 tr2 = new Vector3(rect.xMax, rect.yMax, 0);
 580            Vector3 br2 = new Vector3(rect.xMax, rect.yMin, 0);
 581
 582            Debug.DrawLine(tl2, bl2, color, duration);
 583            Debug.DrawLine(tl2, tr2, color, duration);
 584            Debug.DrawLine(bl2, br2, color, duration);
 585            Debug.DrawLine(tr2, br2, color, duration);
 586        }
 587
 588        public static string ToUpperFirst(this string value)
 589        {
 590            if (!string.IsNullOrEmpty(value))
 591            {
 592                var capital = char.ToUpper(value[0]);
 593                value = capital + value.Substring(1);
 594            }
 595
 596            return value;
 597        }
 598
 599        public static Vector3 Sanitize(Vector3 value)
 600        {
 601            float x = float.IsInfinity(value.x) ? 0 : value.x;
 602            float y = float.IsInfinity(value.y) ? 0 : value.y;
 603            float z = float.IsInfinity(value.z) ? 0 : value.z;
 604
 605            return new Vector3(x, y, z);
 606        }
 607
 608        public static bool CompareFloats( float a, float b, float precision = 0.1f ) { return Mathf.Abs(a - b) < precisi
 609
 610        public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> tuple, out T1 key, out T2 value)
 611        {
 612            key = tuple.Key;
 613            value = tuple.Value;
 614        }
 615
 616        /// <summary>
 617        /// Set a layer to the given transform and its child
 618        /// </summary>
 619        /// <param name="transform"></param>
 620        public static void SetLayerRecursively(Transform transform, int layer)
 621        {
 622            transform.gameObject.layer = layer;
 623            foreach (Transform child in transform)
 624            {
 625                SetLayerRecursively(child, layer);
 626            }
 627        }
 628
 629        /// <summary>
 630        /// Converts a linear float (between 0 and 1) into an exponential curve fitting for audio volume.
 631        /// </summary>
 632        /// <param name="volume">Linear volume float</param>
 633        /// <returns>Exponential volume curve float</returns>
 634        public static float ToVolumeCurve(float volume) { return volume * (2f - volume); }
 635
 636        /// <summary>
 637        /// Takes a linear volume value between 0 and 1, converts to exponential curve and maps to a value fitting for a
 638        /// </summary>
 639        /// <param name="volume">Linear volume (0 to 1)</param>
 640        /// <returns>Value for audio mixer group volume</returns>
 641        public static float ToAudioMixerGroupVolume(float volume) { return (ToVolumeCurve(volume) * 80f) - 80f; }
 642
 643        public static IEnumerator Wait(float delay, Action onFinishCallback)
 644        {
 645            yield return new WaitForSeconds(delay);
 646            onFinishCallback.Invoke();
 647        }
 648
 649        public static string GetHierarchyPath(this Transform transform)
 650        {
 651            if (transform.parent == null)
 652                return transform.name;
 653            return $"{transform.parent.GetHierarchyPath()}/{transform.name}";
 654        }
 655
 656        public static bool TryFindChildRecursively(this Transform transform, string name, out Transform foundChild)
 657        {
 658            foundChild = transform.Find(name);
 659            if (foundChild != null)
 660                return true;
 661
 662            foreach (Transform child in transform)
 663            {
 664                if (TryFindChildRecursively(child, name, out foundChild))
 665                    return true;
 666            }
 667            return false;
 668        }
 669
 670        public static bool IsPointerOverUIElement(Vector3 mousePosition)
 671        {
 672            if (EventSystem.current == null)
 673                return false;
 674
 675            var eventData = new PointerEventData(EventSystem.current);
 676            eventData.position = mousePosition;
 677            var results = new List<RaycastResult>();
 678            EventSystem.current.RaycastAll(eventData, results);
 679            return results.Count > 1;
 680        }
 681
 682        public static bool IsPointerOverUIElement() { return IsPointerOverUIElement(Input.mousePosition); }
 683
 684        public static string UnixTimeStampToLocalTime(ulong unixTimeStampMilliseconds)
 685        {
 686            DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
 687            dtDateTime = dtDateTime.AddMilliseconds(unixTimeStampMilliseconds).ToLocalTime();
 688            return $"{dtDateTime.Hour}:{dtDateTime.Minute.ToString("D2")}";
 689        }
 690
 691        public static DateTime UnixToDateTimeWithTime(ulong unixTimeStampMilliseconds)
 692        {
 693            DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
 694            dtDateTime = dtDateTime.AddMilliseconds(unixTimeStampMilliseconds).ToLocalTime();
 695            return dtDateTime;
 696        }
 697    }
 698}

Methods/Properties

GetFromJsonArray(System.String)