Пример #1
0
        public static void FetchList(Action <IEnumerable <ApiWorld> > successCallback, Action <string> errorCallback = null, SortHeading heading = SortHeading.Featured, SortOwnership owner = SortOwnership.Any, SortOrder order = SortOrder.Descending, int offset = 0, int count = 10, string search = "", string[] tags = null, string[] excludeTags = null, string[] userTags = null, string userId = "", ReleaseStatus releaseStatus = ReleaseStatus.Public, string includePlatforms = null, string excludePlatforms = null, bool disableCache = false, bool compatibleVersionsOnly = true)
        {
            string endpoint = "worlds";
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            switch (heading)
            {
            case SortHeading.Featured:
                dictionary.Add("sort", "order");
                dictionary.Add("featured", "true");
                break;

            case SortHeading.Trending:
                dictionary.Add("sort", "popularity");
                dictionary.Add("featured", "false");
                break;

            case SortHeading.Updated:
                dictionary.Add("sort", "updated");
                break;

            case SortHeading.Created:
                dictionary.Add("sort", "created");
                break;

            case SortHeading.Publication:
                dictionary.Add("sort", "publicationDate");
                break;

            case SortHeading.Shuffle:
                dictionary.Add("sort", "shuffle");
                break;

            case SortHeading.Active:
                endpoint = "worlds/active";
                break;

            case SortHeading.Recent:
                endpoint = "worlds/recent";
                break;

            case SortHeading.Playlist:
                endpoint = "worlds/favorites";
                dictionary.Add("userId", userId);
                break;

            case SortHeading.Favorite:
                endpoint = "worlds/favorites";
                break;

            case SortHeading.Labs:
                dictionary.Add("sort", "labsPublicationDate");
                break;

            case SortHeading.Heat:
                dictionary.Add("sort", "heat");
                dictionary.Add("featured", "false");
                break;
            }
            switch (owner)
            {
            case SortOwnership.Mine:
                dictionary.Add("user", "me");
                break;

            case SortOwnership.Friend:
                dictionary.Add("userId", userId);
                break;
            }
            dictionary.Add("n", count);
            switch (order)
            {
            case SortOrder.Ascending:
                dictionary.Add("order", "ascending");
                break;

            case SortOrder.Descending:
                dictionary.Add("order", "descending");
                break;
            }
            dictionary.Add("offset", offset);
            if (!string.IsNullOrEmpty(search))
            {
                dictionary.Add("search", search);
            }
            int num  = (tags != null) ? tags.Length : 0;
            int num2 = (userTags != null) ? userTags.Length : 0;

            if (num + num2 > 0)
            {
                string[] array = new string[num + num2];
                if (num > 0)
                {
                    tags.CopyTo(array, 0);
                }
                if (num2 > 0)
                {
                    userTags.CopyTo(array, num);
                }
                dictionary.Add("tag", string.Join(",", array));
            }
            if (excludeTags != null && excludeTags.Length > 0)
            {
                dictionary.Add("notag", string.Join(",", excludeTags));
            }
            dictionary.Add("releaseStatus", releaseStatus.ToString().ToLower());
            if (compatibleVersionsOnly)
            {
                dictionary.Add("maxUnityVersion", VERSION.UnityVersion);
                dictionary.Add("minUnityVersion", MIN_LOADABLE_VERSION.UnityVersion);
                dictionary.Add("maxAssetVersion", VERSION.ApiVersion);
                dictionary.Add("minAssetVersion", MIN_LOADABLE_VERSION.ApiVersion);
            }
            if (includePlatforms != null || excludePlatforms != null)
            {
                if (includePlatforms != null)
                {
                    dictionary.Add("platform", includePlatforms);
                }
                if (excludePlatforms != null)
                {
                    dictionary.Add("noplatform", excludePlatforms);
                }
            }
            ApiModelListContainer <ApiWorld> apiModelListContainer = new ApiModelListContainer <ApiWorld>();

            apiModelListContainer.OnSuccess = delegate(ApiContainer c)
            {
                if (successCallback != null)
                {
                    successCallback((c as ApiModelListContainer <ApiWorld>).ResponseModels);
                }
            };
            apiModelListContainer.OnError = delegate(ApiContainer c)
            {
                Debug.LogError((object)("Could not fetch worlds, with error - " + c.Error));
                if (errorCallback != null)
                {
                    errorCallback(c.Error);
                }
            };
            ApiModelListContainer <ApiWorld> responseContainer = apiModelListContainer;

            API.SendRequest(endpoint, HTTPMethods.Get, responseContainer, dictionary, authenticationRequired: true, disableCache, 180f);
        }
Пример #2
0
        public static void FetchList(Action <IEnumerable <ApiAvatar> > successCallback, Action <string> errorCallback, Owner owner, ReleaseStatus relStatus = ReleaseStatus.All, string search = null, int number = 10, int offset = 0, SortHeading heading = SortHeading.None, SortOrder order = SortOrder.Descending, string includePlatforms = null, string excludePlatforms = null, bool disableCache = false, bool areFavorites = false, string tags = null, bool compatibleVersionsOnly = true)
        {
            string endpoint = "avatars";
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if (owner == Owner.Licensed)
            {
                dictionary.Add("n", number);
                dictionary.Add("offset", offset);
                endpoint = "avatars/licensed";
            }
            else
            {
                if (areFavorites)
                {
                    endpoint = "avatars/favorites";
                }
                if (owner == Owner.Mine)
                {
                    dictionary.Add("user", "me");
                }
                if (owner == Owner.Public)
                {
                    dictionary.Add("featured", "true");
                }
                if (owner == Owner.Developer)
                {
                    dictionary.Add("tag", "admin_developer");
                }
                dictionary.Add("releaseStatus", relStatus.ToString().ToLower());
                if (search != null)
                {
                    dictionary.Add("search", search);
                }
                dictionary.Add("n", number);
                dictionary.Add("offset", offset);
                if (heading != 0)
                {
                    dictionary.Add("sort", heading.ToString().ToLower());
                }
                switch (order)
                {
                case SortOrder.Ascending:
                    dictionary.Add("order", "ascending");
                    break;

                case SortOrder.Descending:
                    dictionary.Add("order", "descending");
                    break;
                }
                if (compatibleVersionsOnly)
                {
                    dictionary.Add("maxUnityVersion", VERSION.UnityVersion);
                    dictionary.Add("minUnityVersion", MIN_LOADABLE_VERSION.UnityVersion);
                    dictionary.Add("maxAssetVersion", VERSION.ApiVersion);
                    dictionary.Add("minAssetVersion", MIN_LOADABLE_VERSION.ApiVersion);
                }
                if (includePlatforms != null || excludePlatforms != null)
                {
                    if (includePlatforms != null)
                    {
                        dictionary.Add("platform", includePlatforms);
                    }
                    if (excludePlatforms != null)
                    {
                        dictionary.Add("noplatform", excludePlatforms);
                    }
                }
                if (tags != null)
                {
                    dictionary.Add("tag", tags);
                }
            }
            ApiModelListContainer <ApiAvatar> apiModelListContainer = new ApiModelListContainer <ApiAvatar>();

            apiModelListContainer.OnSuccess = delegate(ApiContainer c)
            {
                if (successCallback != null)
                {
                    successCallback((c as ApiModelListContainer <ApiAvatar>).ResponseModels);
                }
            };
            apiModelListContainer.OnError = delegate(ApiContainer c)
            {
                Logger.Log("Could not fetch avatars with error - " + c.Error);
                if (errorCallback != null)
                {
                    errorCallback(c.Error);
                }
            };
            ApiModelListContainer <ApiAvatar> responseContainer = apiModelListContainer;

            API.SendRequest(endpoint, HTTPMethods.Get, responseContainer, dictionary, authenticationRequired: true, disableCache, 180f);
        }