public void InitializeLODController()
        {
            if (lodController == null)
            {
                return;
            }

            UserProfile userProfile = null;

            if (!string.IsNullOrEmpty(model?.id))
            {
                userProfile = UserProfileController.GetProfileByUserId(model.id);
            }

            if (userProfile != null)
            {
                bodySnapshotTexturePromise = new AssetPromise_Texture(userProfile.bodySnapshotURL);
                bodySnapshotTexturePromise.OnSuccessEvent += asset => lodController.SetImpostorTexture(asset.texture);
                bodySnapshotTexturePromise.OnFailEvent    += asset => lodController.RandomizeAndApplyGenericImpostor();
                AssetPromiseKeeper_Texture.i.Keep(bodySnapshotTexturePromise);
            }
            else
            {
                lodController.RandomizeAndApplyGenericImpostor();
            }

            Environment.i.platform.avatarsLODController.RegisterAvatar(lodController);
        }
        public void Populate(Vector2Int coordinates, MinimapMetadata.MinimapSceneInfo sceneInfo)
        {
            if (!gameObject.activeSelf)
            {
                AudioScriptableObjects.dialogOpen.Play(true);
            }

            bool sceneInfoExists = sceneInfo != null;

            gameObject.SetActive(true);
            scenePreviewImage.gameObject.SetActive(false);
            location = coordinates;

            PositionToast(coordinates);

            sceneLocationText.text = $"{coordinates.x}, {coordinates.y}";

            sceneOwnerText.transform.parent.gameObject.SetActive(sceneInfoExists && !string.IsNullOrEmpty(sceneInfo.owner));
            sceneTitleText.text = "Untitled Scene";

            bool useDefaultThumbnail =
                !sceneInfoExists || (sceneInfoExists && string.IsNullOrEmpty(sceneInfo.previewImageUrl));

            if (useDefaultThumbnail)
            {
                DisplayThumbnail(scenePreviewFailImage.texture);
                currentImageUrl = "";
            }

            if (sceneInfoExists)
            {
                sceneTitleText.text = sceneInfo.name;
                sceneOwnerText.text = $"Created by: {sceneInfo.owner}";

                if (currentImageUrl == sceneInfo.previewImageUrl)
                {
                    DisplayThumbnail(texturePromise.asset.texture);
                    return;
                }

                if (texturePromise != null)
                {
                    AssetPromiseKeeper_Texture.i.Forget(texturePromise);
                    texturePromise = null;
                }


                if (!string.IsNullOrEmpty(sceneInfo.previewImageUrl))
                {
                    texturePromise = new AssetPromise_Texture(sceneInfo.previewImageUrl, storeTexAsNonReadable: false);
                    texturePromise.OnSuccessEvent += (textureAsset) => { DisplayThumbnail(textureAsset.texture); };
                    texturePromise.OnFailEvent    += (textureAsset) => { DisplayThumbnail(scenePreviewFailImage.texture); };
                    AssetPromiseKeeper_Texture.i.Keep(texturePromise);
                }

                currentImageUrl = sceneInfoExists ? sceneInfo.previewImageUrl : "";
            }
        }
 private void OnDestroy()
 {
     minimapMetadata.OnSceneInfoUpdated -= OnMapMetadataInfoUpdated;
     if (texturePromise != null)
     {
         AssetPromiseKeeper_Texture.i.Forget(texturePromise);
         texturePromise = null;
     }
 }
Beispiel #4
0
        public override void Dispose()
        {
            if (texturePromise != null)
            {
                AssetPromiseKeeper_Texture.i.Forget(texturePromise);
                texturePromise = null;
            }

            base.Dispose();
        }
Beispiel #5
0
        private static IEnumerator Create(string contentType, string url, Asset_Gif.MaxSize maxTextureSize,
                                          Action <ITexture, AssetPromise_Texture> OnSuccess, Action OnFail = null)
        {
            if (contentType != "image/gif")
            {
                AssetPromise_Texture texturePromise = new AssetPromise_Texture(url, storeTexAsNonReadable: false);
                texturePromise.OnSuccessEvent += texture => { OnSuccess?.Invoke(texture, texturePromise); };
                texturePromise.OnFailEvent    += (x) => OnFail?.Invoke();

                AssetPromiseKeeper_Texture.i.Keep(texturePromise);

                yield return(texturePromise);

                yield break;
            }

            var gif = new Asset_Gif(url, maxTextureSize, OnSuccess);

            yield return(gif.Load());
        }
        public static IEnumerator Fetch(string contentType, string url, Action <IPromiseLike_TextureAsset> OnSuccess, Action OnFail = null)
        {
            if (contentType == "image/gif")
            {
                AssetPromise_Gif gifPromise = new AssetPromise_Gif(url);
                gifPromise.OnSuccessEvent += texture => { OnSuccess?.Invoke(new PromiseLike_Gif(gifPromise)); };
                gifPromise.OnFailEvent    += (x) => OnFail?.Invoke();

                AssetPromiseKeeper_Gif.i.Keep(gifPromise);

                yield return(gifPromise);
            }
            else
            {
                AssetPromise_Texture texturePromise = new AssetPromise_Texture(url, storeTexAsNonReadable: false);
                texturePromise.OnSuccessEvent += texture => { OnSuccess?.Invoke(new PromiseLike_Texture(texturePromise)); };
                texturePromise.OnFailEvent    += (x) => OnFail?.Invoke();

                AssetPromiseKeeper_Texture.i.Keep(texturePromise);

                yield return(texturePromise);
            }
        }
Beispiel #7
0
        public override IEnumerator ApplyChanges(BaseModel newModel)
        {
            yield return(new WaitUntil(() => CommonScriptableObjects.rendererState.Get()));

            //If the scene creates and destroy the component before our renderer has been turned on bad things happen!
            //TODO: Analyze if we can catch this upstream and stop the IEnumerator
            if (isDisposed)
            {
                yield break;
            }

            Model model = (Model)newModel;

            unitySamplingMode = model.samplingMode;

            switch (model.wrap)
            {
            case BabylonWrapMode.CLAMP:
                unityWrap = TextureWrapMode.Clamp;
                break;

            case BabylonWrapMode.WRAP:
                unityWrap = TextureWrapMode.Repeat;
                break;

            case BabylonWrapMode.MIRROR:
                unityWrap = TextureWrapMode.Mirror;
                break;
            }

            if (texture == null && !string.IsNullOrEmpty(model.src))
            {
                bool isBase64 = model.src.Contains("image/png;base64");

                if (isBase64)
                {
                    string base64Data = model.src.Substring(model.src.IndexOf(',') + 1);

                    // The used texture variable can't be null for the ImageConversion.LoadImage to work
                    if (texture == null)
                    {
                        texture = new Texture2D(1, 1);
                    }

                    if (!ImageConversion.LoadImage(texture, Convert.FromBase64String(base64Data)))
                    {
                        Debug.LogError($"DCLTexture with id {id} couldn't parse its base64 image data.");
                    }

                    if (texture != null)
                    {
                        texture.wrapMode   = unityWrap;
                        texture.filterMode = unitySamplingMode;
                        texture.Compress(false);
                        texture.Apply(unitySamplingMode != FilterMode.Point, true);
                    }
                }
                else
                {
                    string contentsUrl   = string.Empty;
                    bool   isExternalURL = model.src.Contains("http://") || model.src.Contains("https://");

                    if (isExternalURL)
                    {
                        contentsUrl = model.src;
                    }
                    else
                    {
                        scene.contentProvider.TryGetContentsUrl(model.src, out contentsUrl);
                    }

                    if (!string.IsNullOrEmpty(contentsUrl))
                    {
                        if (texturePromise != null)
                        {
                            AssetPromiseKeeper_Texture.i.Forget(texturePromise);
                        }

                        texturePromise = new AssetPromise_Texture(contentsUrl, unityWrap, unitySamplingMode, storeDefaultTextureInAdvance: true);
                        texturePromise.OnSuccessEvent += (x) => texture = x.texture;
                        texturePromise.OnFailEvent    += (x) => { texture = null; };

                        AssetPromiseKeeper_Texture.i.Keep(texturePromise);
                        yield return(texturePromise);
                    }
                }
            }
        }