Ejemplo n.º 1
0
    public IEnumerator Loading(string key)
    {
        posts = new root_posts();

        //t_path = Application.persistentDataPath + "/images/thumbnails/";
        s_path    = Application.persistentDataPath + "/images/standart/";
        PostsPath = Application.persistentDataPath + "/posts.json";

        root_posts _posts = DataSave.GetpostsData();

        if (_posts != null)
        {
            //string[] tpath = Directory.GetFiles(t_path);
            string[] spath = Directory.GetFiles(s_path);

            DownloadManager.instance.CreateLoadingBar();

            for (int i = 0; i < _posts._p.Count; i++)
            {
                //byte[] t_imgBytes = File.ReadAllBytes(t_path + "t_" + i + ".png"); // File.ReadAllBytes(tpath[i]);
                byte[] s_imgBytes = File.ReadAllBytes(s_path + "s_" + i + ".png");

                // Texture2D t_tex = new Texture2D(2, 2);
                Texture2D s_tex = new Texture2D(2, 2);

                // t_tex.LoadImage(t_imgBytes);
                s_tex.LoadImage(s_imgBytes);

                PostInfo info = new PostInfo
                {
                    StandartTexture = s_tex, //((DownloadHandlerTexture)s_request.downloadHandler).texture,
                    //ThumbnailTexture = t_tex, //((DownloadHandlerTexture)t_request.downloadHandler).texture,
                    comments     = _posts._p[i].comments,
                    thumbnail    = _posts._p[i].thumbnail,
                    description  = _posts._p[i].description,
                    id           = _posts._p[i].id,
                    likes        = _posts._p[i].likes,
                    post_url     = _posts._p[i].post_url,
                    standard     = _posts._p[i].standard,
                    usernameFrom = _posts._p[i].usernameFrom,
                    postLink     = _posts._p[i].postLink
                };

                posts._p.Add(info);
                DownloadManager.ProgressHandler?.Invoke(i, _posts._p.Count);
                yield return(null);
            }
            DownloadManager.instance.DeleteLoadingBar();
        }
        else
        {
            posts.AccountKey = DownloadManager.notFoundError;
            yield break;
        }
    }
Ejemplo n.º 2
0
    public static void SavePostsInfo(root_posts data)
    {
        for (int i = 0; i < data._p.Count; i++)
        {
            SaveImage(data._p[i].StandartTexture, "s_" + i, Application.persistentDataPath + "/images/standart/");
        }

        string str = JsonUtility.ToJson(data, true);

        File.WriteAllText(Application.persistentDataPath + "/posts.json", str);
    }
Ejemplo n.º 3
0
    public static root_posts GetpostsData()
    {
        root_posts root     = new root_posts();
        string     filepath = Application.persistentDataPath + "/posts.json";

        if (File.Exists(filepath))
        {
            string dataAsJson = File.ReadAllText(filepath);
            root = JsonUtility.FromJson <root_posts>(dataAsJson);
            return(root);
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 4
0
    IEnumerator LoadFromCache()
    {
        root_posts posts = DataSave.GetpostsData();

        if (posts != null)
        {
            Iloading load = new Download_FromCache();
            //yield return StartCoroutine(load.Loading(null));
            yield return(StartCoroutine(PreloadingManager.instance.LoadingProcess("self", load)));

            //root_posts _loadedData = load.GetPosts();
            //yield return StartCoroutine(AtlasController.instance.Init(_loadedData));

            GameControllerScr.loadGame = true;
            SceneManager.LoadScene("Game");
        }
    }
Ejemplo n.º 5
0
    public IEnumerator Loading(string key)
    {
        posts = new root_posts();

        UnityWebRequest IdRequest = UnityWebRequest.Get("https://www.instagram.com/" + key + "/?__a=1");

        yield return(IdRequest.SendWebRequest());

        Debug.Log("trying get account: " + key);
        Debug.Log(IdRequest.downloadHandler.data.Length);

#if UNITY_EDITOR || UNITY_ANDROID
        if (IdRequest.downloadHandler.data.Length != 20713)
        {
#elif UNITY_IOS
        if (IdRequest.downloadHandler.data.Length != 20832)
        {
#endif
            Debug.Log("Started account deserialization");
            var _accId = JsonConvert.DeserializeObject <Assets.Accounts.RootObject>(IdRequest.downloadHandler.text);
            Debug.Log(key);
            UnityWebRequest request = UnityWebRequest.Get("https://www.instagram.com/graphql/query/?query_id=17888483320059182&id=" + _accId.graphql.user.id + "&first=36");
            yield return(request.SendWebRequest());

            var dyn = JsonConvert.DeserializeObject <Assets.Accounts.LoadImages.RootObject>(request.downloadHandler.text);

            if (dyn.data.user.edge_owner_to_timeline_media.edges.Count >= 36)
            {
                posts.AccountKey = _accId.graphql.user.username;
                History.SaveToHistory(posts.AccountKey, 0, 0);
            }
            else
            {
                posts.AccountKey = DownloadManager.less20Error;
            }
        }
        else
        {
            Debug.Log("Account not found");
            posts.AccountKey = DownloadManager.notFoundError;
        }
    }
Ejemplo n.º 6
0
    public IEnumerator Init(root_posts data)
    {
        //posts.Clear();

        //ClearMaterials();

        Debug.Log("Inited");

        Texture2D[] images = new Texture2D[data._p.Count];
        for (int i = 0; i < data._p.Count; i++)
        {
            images[i] = data._p[i].StandartTexture;
        }
        //posts = data._p;

        yield return(StartCoroutine(Pack(Atlases[0], 1024, images)));

        yield return(StartCoroutine(Pack(Atlases[1], 4096, images)));

        yield return(StartCoroutine(CreateMaterials(Atlases[0])));

        yield return(StartCoroutine(CreateMaterials(Atlases[1])));
        // UnloadTextures();
    }
Ejemplo n.º 7
0
    public IEnumerator Downloading(string key, Iloading _loading)
    {
        Resources.UnloadUnusedAssets();
        _tempPosts = new root_posts();

        Iloading loading = _loading;

        //checking witch account to load
        yield return(StartCoroutine(loading.Loading(key)));

        //handlers
        if (loading.isContainErrors())
        {
            ErrorHandler?.Invoke(LocalizationManager.instance.GetLocalizedValue(loading.GetPosts().AccountKey));
        }
        else
        {
            _tempPosts = loading.GetPosts();
            ConvertTexturesToSprites();
            yield return(new WaitForEndOfFrame());

            SuccessfullHandler?.Invoke("Account successful loaded");
        }
    }
    public IEnumerator Loading(string key)
    {
        posts = new root_posts();

        UnityWebRequest IdRequest = UnityWebRequest.Get("https://www.instagram.com/explore/tags/" + key + "/?__a=1");

        yield return(IdRequest.SendWebRequest());

        //get account id

        if (IdRequest.downloadHandler.data.Length != 20713 || IdRequest.downloadHandler.data.Length != 20832)
        {
            History.SaveToHistory(key, 1, 0);


            var _accId = JsonConvert.DeserializeObject <Assets.Accounts.Hashtag.RootObject>(IdRequest.downloadHandler.text);

            Debug.Log(_accId.graphql.hashtag.edge_hashtag_to_media.edges.Count);

            if (_accId.graphql.hashtag.edge_hashtag_to_media.edges.Count < 36)
            {
                posts.AccountKey = DownloadManager.less20Error;
                yield break;
            }
            int i = 1;

            DownloadManager.instance.CreateLoadingBar();

            posts.AccountKey = key;

            foreach (var data in _accId.graphql.hashtag.edge_hashtag_to_media.edges)
            {
                var post_info = new PostInfo();

                post_info.id        = i;
                post_info.thumbnail = data.node.thumbnail_src;
                post_info.standard  = data.node.display_url;

                if (data.node.edge_media_to_caption.edges.Count > 0)
                {
                    post_info.description = data.node.edge_media_to_caption.edges[0].node.text;
                }
                post_info.likes    = data.node.edge_media_preview_like.count;
                post_info.comments = data.node.edge_media_to_comment.count;
                Debug.Log(data.node.owner.id);
                //Get username
                UnityWebRequest NameRequest = UnityWebRequest.Get("https://i.instagram.com/api/v1/users/" + data.node.owner.id + "/info/");
                yield return(NameRequest.SendWebRequest());

                Debug.Log(NameRequest.downloadHandler.text);

                var _accName = JsonConvert.DeserializeObject <Assets.Accounts.Hashtag.GetAccountName.RootObject>(NameRequest.downloadHandler.text);

                if (_accName.user != null)
                {
                    post_info.usernameFrom = _accName.user.username;
                }
                else
                {
                    post_info.usernameFrom = "#" + key;
                }

                post_info.postLink = data.node.shortcode;

                UnityWebRequest s_request = new UnityWebRequest();
                s_request = UnityWebRequestTexture.GetTexture(post_info.standard, false);
                yield return(s_request.SendWebRequest());

                if (s_request.isNetworkError || s_request.isHttpError)
                {
                    Debug.Log("Error");
                }

                yield return(s_request.isDone);

                post_info.StandartTexture = ((DownloadHandlerTexture)s_request.downloadHandler).texture;

                posts._p.Add(post_info);

                // DataSave.SaveImage(post_info.ThumbnailTexture, "t_" + post_info.id, Application.persistentDataPath + "/t_images");
                //  DataSave.SaveImage(post_info.StandartTexture, "s_" + post_info.id, Application.persistentDataPath + "/s_images");

                DownloadManager.ProgressHandler?.Invoke(i, 36);

                i++;
                if (i > 36)
                {
                    yield break;
                }
            }
            DownloadManager.instance.DeleteLoadingBar();
            yield return(null);
        }
        else
        {
            posts.AccountKey = DownloadManager.notFoundError;
            yield break;
        }
    }
Ejemplo n.º 9
0
 public void StopLoading()
 {
     StopAllCoroutines();
     _tempPosts = new root_posts();
     Debug.Log("Stop loading");
 }
Ejemplo n.º 10
0
    public IEnumerator Loading(string key)
    {
        _tempPosts = new root_posts();

        UnityWebRequest request = UnityWebRequest.Get("https://api.instagram.com/v1/users/self/media/recent/?access_token=" + key);

        yield return(request.SendWebRequest());

        Debug.Log("first ");

        var dyn = JsonConvert.DeserializeObject <RootObject>(request.downloadHandler.text);
        int i   = 1;

        Debug.Log("after deserialize");
        _tempPosts.AccountKey = dyn.data[0].user.username;

        DownloadManager.instance.CreateLoadingBar();

        Debug.Log("Creating posts");

        foreach (var data in dyn.data)
        {
            var post_info = new PostInfo();

            post_info.id        = i;
            post_info.thumbnail = data.images.thumbnail.url;
            post_info.standard  = data.images.standard_resolution.url;

            if (data.caption != null)
            {
                post_info.description = data.caption.text;
            }
            post_info.likes    = data.likes.count;
            post_info.comments = data.comments.count;
            post_info.postLink = data.link.Substring(data.link.LastIndexOf("/p/") + 3);

            if (data.caption != null)
            {
                post_info.usernameFrom = data.caption.from.username;
            }

            UnityWebRequest s_request = new UnityWebRequest();
            s_request = UnityWebRequestTexture.GetTexture(post_info.standard, false);
            yield return(s_request.SendWebRequest());

            if (s_request.isNetworkError || s_request.isHttpError)
            {
                Debug.Log("Error");
            }

            yield return(s_request.isDone);

            post_info.StandartTexture = ((DownloadHandlerTexture)s_request.downloadHandler).texture;

            //thumbnails
            //UnityWebRequest t_request = new UnityWebRequest();
            //t_request = UnityWebRequestTexture.GetTexture(post_info.thumbnail, false);
            //yield return t_request.SendWebRequest();

            //if (t_request.isNetworkError || t_request.isHttpError)
            //    Debug.Log("Error");

            //yield return t_request.isDone;

            //post_info.ThumbnailTexture = ((DownloadHandlerTexture)t_request.downloadHandler).texture;

            _tempPosts._p.Add(post_info);

            // DataSave.SaveImage(post_info.ThumbnailTexture, "t_" + post_info.id, Application.persistentDataPath + "/t_images");
            //  DataSave.SaveImage(post_info.StandartTexture, "s_" + post_info.id, Application.persistentDataPath + "/s_images");

            i++;

            //progress
            DownloadManager.ProgressHandler?.Invoke(i, dyn.data.Count);
        }

        Debug.Log("after creating posts ");
        //DownloadManager.instance.DeleteLoadingBar();
        yield return(null);
    }