/// <summary> /// Controls subpart of the window layout /// </summary> private void ControlsGUI(FolderInspector fI) { GUILayout.Space(4); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); bool validName = styleName.Length > 2 && styleName.Length < 15 && styleName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1; GUI.enabled = validName; string saveTitle = editStyle != null ? "Save" : "Create"; if (GUILayout.Button(saveTitle, GUILayout.Width(80.0f))) { SaveStyle(fI); } GUI.enabled = true; if (GUILayout.Button("Discard", GUILayout.Width(80.0f))) { fI.CloseSubWindow(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (!creationSuccess) { EditorGUILayout.HelpBox("The same style already exists !", MessageType.Error); } if (!validName) { EditorGUILayout.HelpBox("Style name is not a valid name !", MessageType.Error); } }
private void SaveStyle(FolderInspector fI) { Vector2Int highResOffset = GetClampedBigIconOffset(); Vector2Int lowResOffset = GetClampedSmallIconOffset(); Texture2D finalHigh; if (PreferencesUI.settings.useNewUI) { Vector2Int offset = GetClampedBigIconOffset(); UpdateTextureColor(folderOriginalIcon48, folderIcon48, (32 + offset.x - 3) * 2, (14 - offset.y + 1) * 2, 96, 80, 16, 24, 2.0F); finalHigh = BakeFinalTexture(folderTexture64, folderIcon48, (32 + highResOffset.x) * 2, (14 - highResOffset.y) * 2); } else { finalHigh = BakeFinalTexture(folderTexture64, folderIcon24, 32 + highResOffset.x, 14 - highResOffset.y); } Texture2D finalLow = BakeFinalTexture(folderTexture16, folderIcon10, 6 + lowResOffset.x, -lowResOffset.y); if (editStyle != null) { EditStyle(finalHigh, true, "64"); EditStyle(finalLow, false, "16"); // Delete previous json info if existing if (lastJsonPath != null) { AssetDatabase.DeleteAsset(lastJsonPath); } WriteGradientInfo(); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); fI.CloseSubWindow(); } else { bool success = SaveStyle(finalHigh, "64"); success = success && SaveStyle(finalLow, "16"); WriteGradientInfo(); if (success) { AssetDatabase.Refresh(); fI.CloseSubWindow(); } else { creationSuccess = false; } } }
/// <summary> /// Define window layout /// </summary> /// <param name="fI"></param> public void OnInspectorGUI(FolderInspector fI) { InitTextures(); //// Header EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginHorizontal(); string headerTitle = (editStyle != null ? "Edit" : "New") + " style: "; Rect labelRect = GUILayoutUtility.GetRect(new GUIContent(headerTitle), "label"); GUI.Label(labelRect, headerTitle, EditorStyles.boldLabel); // Name field string newStyleName = EditorGUILayout.TextField(styleName); if (!styleName.Equals(newStyleName)) { styleName = newStyleName; nameEdited = true; } EditorGUILayout.EndHorizontal(); ColorGUI(); // Icons IconGUI(); GUILayout.Space(2); //// Preview // Real time change pixels UpdateTextureColor(folderOriginalTexture64, folderTexture64, 64, 3, 3 + 3, 56, 50, 4, 10, 1.0F); UpdateTextureColor(folderOriginalTexture16, folderTexture16, 16, 2, 3, 15, 13, 0, 1, 0.25F); Vector2Int offset = GetClampedBigIconOffset(); UpdateTextureColor(folderOriginalIcon24, folderIcon24, 64, 32 + offset.x + 3, 14 - offset.y + 6, 56, 50, 4, 10, 1.0F); offset = GetClampedSmallIconOffset(); UpdateTextureColor(folderOriginalIcon10, folderIcon10, 16, 6 + offset.x + 2, -offset.y + 3, 15, 13, 0, 1, 0.25F); PreviewGUI(); EditorGUILayout.EndVertical(); //// Button pannel ControlsGUI(fI); }
/// <summary> /// Define window layout /// </summary> /// <param name="fI"></param> public void OnInspectorGUI(FolderInspector fI) { InitTextures(); //// Header GUILayout.BeginHorizontal(FolderInspector.titleBarStyle); string headerTitle = (editStyle != null ? " Edit" : " New") + " style: "; GUIContent folderGuiContent = GUIHelper.ContentFromAssets(headerTitle, ResourceUtil.TexturesPath + "/folder_icon_16.png"); GUILayout.Label(folderGuiContent); GUILayout.FlexibleSpace(); // Name field GUILayout.BeginHorizontal(); GUILayout.Label("Name:", FolderInspector.titleBarLabelStyle); string newStyleName = EditorGUILayout.TextField(styleName, FolderInspector.titleBarTextFieldStyle, GUILayout.ExpandWidth(false), GUILayout.Width(150.0f)); if (!styleName.Equals(newStyleName)) { styleName = newStyleName; nameEdited = true; } GUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); ColorGUI(); // Icons IconGUI(); GUILayout.Space(2); //// Preview // Real time change pixels if (PreferencesUI.settings.useNewUI) { UpdateTextureColor(folderOriginalTexture64, folderTexture64, -7, 2, 96, 80, 16, 24, 2.0F); UpdateTextureColor(folderOriginalTexture16, folderTexture16, 1, 3, 15, 13, 2, 3, 0.25F); Vector2Int offset = GetClampedBigIconOffset(); UpdateTextureColor(folderOriginalIcon24, folderIcon24, 32 + offset.x - 3, 14 - offset.y + 1, 48, 40, 8, 16, 1.0F); offset = GetClampedSmallIconOffset(); UpdateTextureColor(folderOriginalIcon10, folderIcon10, 6 + offset.x + 1, -offset.y + 3, 15, 13, 2, 3, 0.25F); } else { UpdateTextureColor(folderOriginalTexture64, folderTexture64, 3, 7, 56, 50, 3, 10, 1.0F); UpdateTextureColor(folderOriginalTexture16, folderTexture16, 2, 3, 15, 13, 0, 1, 0.25F); Vector2Int offset = GetClampedBigIconOffset(); UpdateTextureColor(folderOriginalIcon24, folderIcon24, 32 + offset.x + 3, 14 - offset.y + 6, 56, 50, 4, 10, 1.0F); offset = GetClampedSmallIconOffset(); UpdateTextureColor(folderOriginalIcon10, folderIcon10, 6 + offset.x + 2, -offset.y + 3, 15, 13, 0, 1, 0.25F); } GUILayout.BeginVertical(); PreviewGUI(); //// Button pannel ControlsGUI(fI); GUILayout.EndVertical(); }
/// <summary> /// Controls subpart of the window layout /// </summary> private void ControlsGUI(FolderInspector fI) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Back", GUILayout.Width(80.0F))) { fI.CloseSubWindow(); } bool validName = styleName.Length > 2 && styleName.Length < 15 && styleName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1; GUI.enabled = validName; if (GUILayout.Button(editStyle != null ? "Save" : "Create", GUILayout.Width(80.0F))) { Vector2Int highResOffset = GetClampedBigIconOffset(); Vector2Int lowResOffset = GetClampedSmallIconOffset(); if (editStyle != null) { EditStyle(BakeFinalTexture(folderTexture64, folderIcon24, 32 + highResOffset.x, 14 - highResOffset.y), true, "64"); EditStyle(BakeFinalTexture(folderTexture16, folderIcon10, 6 + lowResOffset.x, -lowResOffset.y), false, "16"); // Delete previous json info if existing if (lastJsonPath != null) { AssetDatabase.DeleteAsset(lastJsonPath); } WriteGradientInfo(); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); fI.CloseSubWindow(); } else { bool success = SaveStyle(BakeFinalTexture(folderTexture64, folderIcon24, 32 + highResOffset.x, 14 - highResOffset.y), "64"); success = success && SaveStyle(BakeFinalTexture(folderTexture16, folderIcon10, 6 + lowResOffset.x, -lowResOffset.y), "16"); WriteGradientInfo(); if (success) { AssetDatabase.Refresh(); fI.CloseSubWindow(); } else { creationSuccess = false; } } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); if (!creationSuccess) { EditorGUILayout.HelpBox("The same style already exists !", MessageType.Error); } if (!validName) { EditorGUILayout.HelpBox("Style name is not a valid name !", MessageType.Error); } }