private static string GetHardwareHash()
 {
     return(InternalEditorUtility.GetAuthToken().Substring(40, 40));
 }
예제 #2
0
 private static string GetToken()
 {
     return(InternalEditorUtility.GetAuthToken());
 }
예제 #3
0
 public string GetAuthToken()
 {
     return(InternalEditorUtility.GetAuthToken());
 }
 private static string GetLicenseHash()
 {
     return(InternalEditorUtility.GetAuthToken().Substring(0, 40));
 }
예제 #5
0
        public void Login(string user, string pass, Action <HttpWebResponse, string> onCompleted = null)
        {
            string         endPoint = EndPoint + "/login";
            string         post     = string.Format("user={0}&pass={1}&unityversion={2}&toolversion={3}&license_hash={4}&hardware_hash={5}", user, pass, Application.unityVersion, AssetStoreToolsVersion, InternalEditorUtility.GetAuthToken().Substring(0, 40), InternalEditorUtility.GetAuthToken().Substring(40, 40));
            HttpWebRequest request  = CreateRequest(endPoint);

            byte[] data = Encoding.ASCII.GetBytes(post);

            if (SessionConnecting != null)
            {
                SessionConnecting();
            }

            request.Accept        = "application/json";
            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            HandleRequest(request, endPoint.GetHashCode(), OnLoginCompleted(onCompleted));
        }
예제 #6
0
 public static string GetActiveSessionID()
 {
     return((!string.IsNullOrEmpty(AssetStoreClient.ActiveSessionID)) ? (AssetStoreClient.ActiveSessionID + InternalEditorUtility.GetAuthToken()) : string.Empty);
 }
예제 #7
0
            internal static IEnumerable <SearchItem> SearchItems(SearchContext context, SearchProvider provider)
            {
                var webRequest = UnityWebRequest.Get(url + context.searchQuery);

                webRequest.SetRequestHeader("X-Unity-Session", InternalEditorUtility.GetAuthToken());
                webRequest.SendWebRequest(); // Don't yield return this, as it is not a coroutine and will block the UI

                while (!webRequest.isDone)
                {
                    if (webRequest.isHttpError || webRequest.isNetworkError)
                    {
                        yield break;
                    }
                    yield return(null);
                }

                if (string.IsNullOrEmpty(webRequest.downloadHandler.text))
                {
                    yield break;
                }


                var reqJson = Utils.JsonDeserialize(webRequest.downloadHandler.text) as Dictionary <string, object>;

                if (reqJson == null || !reqJson.ContainsKey("status") || reqJson["status"].ToString() != "ok" || !reqJson.ContainsKey("groups"))
                {
                    yield break;
                }

                if (!(reqJson["groups"] is List <object> groups))
                {
                    yield break;
                }

                foreach (var g in groups)
                {
                    var group = g as Dictionary <string, object>;
                    if (group == null || !group.ContainsKey("matches"))
                    {
                        yield return(null);

                        continue;
                    }

                    var matches = group["matches"] as List <object>;
                    if (matches == null)
                    {
                        yield return(null);

                        continue;
                    }

                    foreach (var m in matches.Take(50))
                    {
                        var match = m as Dictionary <string, object>;
                        if (match == null)
                        {
                            yield return(null);

                            continue;
                        }
                        match["groupType"] = group["name"];

                        if (!match.ContainsKey("name") || !match.ContainsKey("id") || !match.ContainsKey("package_id"))
                        {
                            yield return(null);

                            continue;
                        }
                        var id   = match["id"].ToString();
                        var data = new AssetStoreData {
                            packageId = Convert.ToInt32(match["package_id"]), id = Convert.ToInt32(match["id"])
                        };
                        var item = provider.CreateItem(id, match["name"].ToString(), $"Asset Store ({match["groupType"]})", null, data);

                        if (match.ContainsKey("static_preview_url") && !s_CurrentSearchAssetData.ContainsKey(id))
                        {
                            s_CurrentSearchAssetData.Add(id, new AssetPreviewData()
                            {
                                staticPreviewUrl = match["static_preview_url"].ToString()
                            });
                        }

                        yield return(item);
                    }
                }
            }
예제 #8
0
            internal static SearchProvider CreateProvider()
            {
                return(new SearchProvider(type, displayName)
                {
                    filterId = "store:",
                    fetchItems = (context, items, provider) =>
                    {
                        if (s_CurrentSearchRequestOp != null)
                        {
                            s_CurrentSearchRequestOp.completed -= SearchCompleted;
                        }

                        s_SearchId = context.searchId;
                        s_Provider = provider;
                        s_AddAsyncItems = context.sendAsyncItems;
                        s_CurrentSearchRequest = UnityWebRequest.Get(url + context.searchQuery);
                        s_CurrentSearchRequest.SetRequestHeader("X-Unity-Session", InternalEditorUtility.GetAuthToken());
                        s_CurrentSearchRequestOp = s_CurrentSearchRequest.SendWebRequest();
                        s_CurrentSearchRequestOp.completed += SearchCompleted;
                    },

                    fetchThumbnail = (item, context) =>
                    {
                        if (item.thumbnail)
                        {
                            return item.thumbnail;
                        }

                        if (s_CurrentSearchAssetData.ContainsKey(item.id))
                        {
                            var searchPreview = s_CurrentSearchAssetData[item.id];
                            if (searchPreview.preview)
                            {
                                item.thumbnail = s_CurrentSearchAssetData[item.id].preview;
                            }

                            if (item.thumbnail)
                            {
                                return item.thumbnail;
                            }

                            if (searchPreview.request == null)
                            {
                                searchPreview.request = UnityWebRequestTexture.GetTexture(searchPreview.staticPreviewUrl);
                                searchPreview.requestOp = searchPreview.request.SendWebRequest();
                                searchPreview.requestOp.completed += TextureFetched;
                            }
                        }

                        item.thumbnail = InternalEditorUtility.FindIconForFile(item.label);
                        return item.thumbnail ?? Icons.store;
                    },

                    onDisable = () =>
                    {
                        foreach (var sp in s_CurrentSearchAssetData.Values)
                        {
                            if (sp.preview)
                            {
                                UnityEngine.Object.DestroyImmediate(sp.preview);
                            }
                            sp.request = null;
                            sp.requestOp = null;
                        }
                        s_CurrentSearchAssetData.Clear();
                    }
                });
            }
 public string GetAuthToken() =>
 InternalEditorUtility.GetAuthToken();