// ------[ INITIALIZATION ]------ public void OnEnable(SerializedProperty serializedEditableModProfile, ModProfile baseProfile, UserProfile user) { this.editableProfileProperty = serializedEditableModProfile; this.profile = baseProfile; this.isUndoEnabled = (baseProfile != null); isTagsExpanded = false; isKVPsExpanded = false; // - Game Profile - ModManager.GetGameProfile((g) => { this.gameProfile = g; isRepaintRequired = true; }, null); // - Configure Properties - logoProperty = editableProfileProperty.FindPropertyRelative("logoLocator"); // - Load Textures - if (logoProperty.FindPropertyRelative("isDirty").boolValue == true) { logoLocation = logoProperty.FindPropertyRelative("value.url").stringValue; logoTexture = CacheClient.ReadImageFile(logoLocation); if (logoTexture != null) { lastLogoWriteTime = (new FileInfo(logoLocation)).LastWriteTime; } } else if (profile != null) { logoLocation = profile.logoLocator.GetSizeURL(LOGO_PREVIEW_SIZE); logoTexture = ApplicationImages.LoadingPlaceholder; ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE, (t) => { logoTexture = t; isRepaintRequired = true; }, WebRequestError.LogAsWarning); } else { logoLocation = string.Empty; logoTexture = null; } }
protected virtual void LayoutLogoField() { bool doBrowse = false; // - Browse Field - EditorGUILayout.BeginHorizontal(); doBrowse |= EditorGUILayoutExtensions.BrowseButton(logoLocation, new GUIContent("Logo")); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); // - Draw Texture - if (logoTexture != null) { Rect logoRect = EditorGUILayout.GetControlRect(false, LOGO_PREVIEW_HEIGHT, null); EditorGUI.DrawPreviewTexture(new Rect((logoRect.width - LOGO_PREVIEW_WIDTH) * 0.5f, logoRect.y, LOGO_PREVIEW_WIDTH, logoRect.height), logoTexture, null, ScaleMode.ScaleAndCrop); doBrowse |= GUI.Button(logoRect, "", GUI.skin.label); } if (doBrowse) { EditorApplication.delayCall += () => { string path = EditorUtility.OpenFilePanelWithFilters("Select Mod Logo", "", IMAGE_FILE_FILTER); Texture2D newLogoTexture = CacheClient.ReadImageFile(path); if (newLogoTexture) { logoProperty.FindPropertyRelative("value.url").stringValue = path; logoProperty.FindPropertyRelative("value.fileName").stringValue = Path.GetFileName(path); logoProperty.FindPropertyRelative("isDirty").boolValue = true; logoProperty.serializedObject.ApplyModifiedProperties(); logoTexture = newLogoTexture; logoLocation = path; lastLogoWriteTime = (new FileInfo(logoLocation)).LastWriteTime; } }; } if (isUndoRequested) { logoProperty.FindPropertyRelative("value.url").stringValue = profile.logoLocator.GetURL(); logoProperty.FindPropertyRelative("value.fileName").stringValue = profile.logoLocator.GetFileName(); logoProperty.FindPropertyRelative("isDirty").boolValue = false; logoLocation = profile.logoLocator.GetSizeURL(LOGO_PREVIEW_SIZE); logoTexture = ApplicationImages.LoadingPlaceholder; ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE, (t) => { logoTexture = t; isRepaintRequired = true; }, WebRequestError.LogAsWarning); } }