// ------[ INITIALIZATION ]------ protected virtual void OnEnable() { // Grab Serialized Properties serializedObject.Update(); modIdProperty = serializedObject.FindProperty("modId"); initializedProfileId = modIdProperty.intValue; editableModProfileProperty = serializedObject.FindProperty("editableModProfile"); isModListLoading = false; profileViewParts = new IModProfileViewPart[] { new LoadingProfileViewPart() }; // Profile Initialization if (modIdProperty.intValue == ScriptableModProfile.UNINITIALIZED_MOD_ID) { this.profile = null; if (!UserAuthenticationData.instance.Equals(UserAuthenticationData.NONE)) { this.isModListLoading = true; this.modOptions = new string[] { "Loading..." }; Action <WebRequestError> onError = (e) => { WebRequestError.LogAsWarning(e); isModListLoading = false; }; ModManager.GetAuthenticatedUserProfile((userProfile) => { this.user = userProfile; // - Find User Mods - Action <List <ModProfile> > onGetUserMods = (profiles) => { modInitializationOptionIndex = 0; modList = profiles.ToArray(); modOptions = new string[modList.Length]; for (int i = 0; i < modList.Length; ++i) { ModProfile mod = modList[i]; modOptions[i] = mod.name; } isModListLoading = false; }; ModManager.GetAuthenticatedUserMods(onGetUserMods, onError); }, onError); } else { this.modOptions = new string[0]; } modInitializationOptionIndex = 0; } else { // Initialize View profile = null; if (modIdProperty.intValue == 0) { profile = null; profileViewParts = CreateProfileViewParts(); foreach (IModProfileViewPart viewPart in profileViewParts) { viewPart.OnEnable(editableModProfileProperty, null, this.user); } ; } else { System.Action <ModProfile> onGetProfile = (p) => { profile = p; profileViewParts = CreateProfileViewParts(); foreach (IModProfileViewPart viewPart in profileViewParts) { viewPart.OnEnable(editableModProfileProperty, p, this.user); } ; profileGetErrorMessage = string.Empty; }; System.Action <WebRequestError> onGetProfileError = (e) => { profile = null; profileViewParts = CreateProfileViewParts(); foreach (IModProfileViewPart viewPart in profileViewParts) { viewPart.OnEnable(editableModProfileProperty, null, this.user); } ; profileGetErrorMessage = ("Unable to fetch the mod profile data on the server.\n" + e.displayMessage); }; ModManager.GetModProfile(modIdProperty.intValue, onGetProfile, onGetProfileError); } } scrollPos = Vector2.zero; isProfileSyncing = false; // Events EditorApplication.update += OnUpdate; LoginWindow.userLoggedIn += OnUserLogin; }
/// <summary>Handles the completion of an image download.</summary> protected virtual void OnDownloadCompleted(UnityWebRequest webRequest, string imageURL) { // early out if destroyed if (this == null) { return; } Debug.Assert(webRequest != null); // - logging - #if DEBUG if (PluginSettings.data.logAllRequests && logDownloads) { if (webRequest.isNetworkError || webRequest.isHttpError) { WebRequestError.LogAsWarning(WebRequestError.GenerateFromWebRequest(webRequest)); } else { var headerString = new System.Text.StringBuilder(); var responseHeaders = webRequest.GetResponseHeaders(); if (responseHeaders != null && responseHeaders.Count > 0) { headerString.Append("\n"); foreach (var kvp in responseHeaders) { headerString.AppendLine("- [" + kvp.Key + "] " + kvp.Value); } } else { headerString.Append(" NONE"); } var responseTimeStamp = ServerTimeStamp.Now; string logString = ("IMAGE DOWNLOAD SUCCEEDED" + "\nURL: " + webRequest.url + "\nTime Stamp: " + responseTimeStamp + " (" + ServerTimeStamp.ToLocalDateTime(responseTimeStamp) + ")" + "\nResponse Headers: " + headerString.ToString() + "\nResponse Code: " + webRequest.responseCode + "\nResponse Error: " + webRequest.error + "\n"); Debug.Log(logString); } } #endif // handle callbacks Callbacks callbacks; bool isURLMapped = this.m_callbackMap.TryGetValue(imageURL, out callbacks); if (callbacks == null) { Debug.LogWarning("[mod.io] ImageRequestManager completed a download but the callbacks" + " entry for the download was null." + "\nImageURL = " + imageURL + "\nWebRequest.URL = " + webRequest.url + "\nm_callbackMap.TryGetValue() = " + isURLMapped.ToString() ); return; } if (webRequest.isHttpError || webRequest.isNetworkError) { if (callbacks.failed.Count > 0) { WebRequestError error = WebRequestError.GenerateFromWebRequest(webRequest); foreach (var errorCallback in callbacks.failed) { errorCallback(error); } } } else { Texture2D texture = ((DownloadHandlerTexture)webRequest.downloadHandler).texture; if (this.isActiveAndEnabled || !this.clearCacheOnDisable) { this.cache[imageURL] = texture; } foreach (var successCallback in callbacks.succeeded) { successCallback(texture); } } // remove from "in progress" this.m_callbackMap.Remove(imageURL); }