Topic: Smart Gallery Remote Texture

Hello, I purchased your Smart Gallery from the Unity Asset Store and it looks great. I am however having trouble loading remote assets. I can see how this is done in Unity by inserting files into the Inspector but I am going to load them via C Sharp from an ftp server file that downloads files within the app itself. Is there a script that would handle this in your asset? Looks like the way to do it would be to build a Gallery with the ftp files that I am loading to Persistent Data Path. Just trying to avoid writing another application if you had already put something in there to do it.

Re: Smart Gallery Remote Texture

Hello.

Unfortunately, I have never worked with FTP inside Unity.
I have looked at some examples for C#, but they don't work.

It is very easy to add third party source support in Smart Gallery.
You just need to implement your own content type, and select it in the gallery.
Example (doesn't work, but if you are already successfully downloading files via FTP, you can fix it):

using System.Collections;
using System.IO;
using System.Net;
using InfinityCode.SmartGallery.Modules;
using UnityEngine;

namespace InfinityCode.SmartGallery.ContentTypes
{
    public class FtpTextureContent: RawImageContent
    {
        public string url;
        public string login;
        public string password;
        
        public override bool allowZoom => true;
        public override string name => "Ftp Texture";

        protected override void LoadContentData(Content content)
        {
            contentRawImage.enabled = false;
            messageSystem.SetLoadingState?.Invoke(true);
            content.viewer.StartCoroutine(LoadCoroutine());
        }

        private IEnumerator LoadCoroutine()
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            request.Credentials = new NetworkCredential(login, password);
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            
            byte[] bytes = new byte[responseStream.Length];
            reader.BaseStream.Read(bytes, 0, bytes.Length);
            
            Texture2D texture = new Texture2D(2, 2);
            texture.LoadImage(bytes);
            
            if (texture == null)
            {
                messageSystem.SetLoadingState?.Invoke(false);
                Debug.LogError("Texture is null.");
                yield break;
            }
            
            contentRawImage.texture = texture;
            contentRectTransform.sizeDelta = new Vector2(texture.width, texture.height);
            
            content.InitContentSize();
            content.AdjustSize();
            messageSystem.SetLoadingState?.Invoke(false);
        }

        protected override bool ValidateProperties()
        {
            return true;
        }
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.