Esempio n. 1
0
        // ------[ INITIALIZATION ]------
        public void OnEnable(SerializedProperty serializedEditableModProfile, ModProfile baseProfile, UserProfile user)
        {
            this.profile           = baseProfile;
            this.youtubeURLsProp   = serializedEditableModProfile.FindPropertyRelative("youtubeURLs");
            this.sketchfabURLsProp = serializedEditableModProfile.FindPropertyRelative("sketchfabURLs");
            this.galleryImagesProp = serializedEditableModProfile.FindPropertyRelative("galleryImageLocators");

            this.isYouTubeExpanded   = false;
            this.isSketchFabExpanded = false;
            this.isImagesExpanded    = false;

            // Initialize textureCache
            this.textureCache = new Dictionary <string, Texture2D>(galleryImagesProp.FindPropertyRelative("value").arraySize);
            for (int i = 0;
                 i < galleryImagesProp.FindPropertyRelative("value").arraySize;
                 ++i)
            {
                string imageFileName = GetGalleryImageFileName(i);
                string imageURL      = GetGalleryImageSource(i);

                if (!String.IsNullOrEmpty(imageFileName) &&
                    !String.IsNullOrEmpty(imageURL))
                {
                    this.textureCache[imageFileName] = ApplicationImages.LoadingPlaceholder;

                    Texture2D texture = CacheClient.ReadImageFile(imageURL);

                    if (texture != null)
                    {
                        this.textureCache[imageFileName] = texture;
                    }
                    else
                    {
                        ModManager.GetModGalleryImage(baseProfile,
                                                      imageFileName,
                                                      IMAGE_PREVIEW_SIZE,
                                                      (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; },
                                                      WebRequestError.LogAsWarning);
                    }
                }
            }
        }
Esempio n. 2
0
        private Texture2D GetGalleryImageTexture(string imageFileName,
                                                 string imageSource)
        {
            if (String.IsNullOrEmpty(imageFileName))
            {
                return(null);
            }

            Texture2D texture;

            // - Get -
            if (this.textureCache.TryGetValue(imageFileName, out texture))
            {
                return(texture);
            }
            // - Load -
            else if ((texture = CacheClient.ReadImageFile(imageSource)) != null)
            {
                this.textureCache.Add(imageFileName, texture);
                return(texture);
            }
            // - LoadOrDownload -
            else if (profile != null)
            {
                this.textureCache.Add(imageFileName, ApplicationImages.LoadingPlaceholder);

                ModManager.GetModGalleryImage(profile,
                                              imageFileName,
                                              IMAGE_PREVIEW_SIZE,
                                              (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; },
                                              null);
                return(this.textureCache[imageFileName]);
            }

            return(null);
        }