Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
514 changes: 295 additions & 219 deletions Plugins/SimpleFileBrowser/Prefabs/SimpleFileBrowserItem.prefab

Large diffs are not rendered by default.

412 changes: 240 additions & 172 deletions Plugins/SimpleFileBrowser/Prefabs/SimpleFileBrowserQuickLink.prefab

Large diffs are not rendered by default.

20,000 changes: 11,440 additions & 8,560 deletions Plugins/SimpleFileBrowser/Resources/SimpleFileBrowserCanvas.prefab

Large diffs are not rendered by default.

49 changes: 28 additions & 21 deletions Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//#define WIN_DIR_CHECK_WITHOUT_TIMEOUT // When uncommented, Directory.Exists won't be wrapped inside a Task/Thread on Windows but we won't be able to set a timeout for unreachable directories/drives
//#define WIN_DIR_CHECK_WITHOUT_TIMEOUT // When uncommented, Directory.Exists won't be wrapped inside a Task/Thread on Windows but we won't be able to set a timeout for unreachable directories/drives

using UnityEngine;
using UnityEngine.EventSystems;
Expand All @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using TMPro;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
using UnityEngine.InputSystem;
#endif
Expand Down Expand Up @@ -437,7 +438,7 @@ private static FileBrowser Instance
private readonly List<FileBrowserQuickLink> allQuickLinks = new List<FileBrowserQuickLink>( 8 );

[SerializeField]
private Text titleText;
private TMPro.TMP_Text titleText;

[SerializeField]
private Button backButton;
Expand All @@ -452,7 +453,7 @@ private static FileBrowser Instance
private Button moreOptionsButton;

[SerializeField]
private InputField pathInputField;
private TMPro.TMP_InputField pathInputField;

[SerializeField]
private RectTransform pathInputFieldSlotTop;
Expand All @@ -461,7 +462,7 @@ private static FileBrowser Instance
private RectTransform pathInputFieldSlotBottom;

[SerializeField]
private InputField searchInputField;
private TMPro.TMP_InputField searchInputField;

[SerializeField]
private RectTransform quickLinksContainer;
Expand All @@ -479,28 +480,28 @@ private static FileBrowser Instance
private RecycledListView listView;

[SerializeField]
private InputField filenameInputField;
private TMPro.TMP_InputField filenameInputField;

[SerializeField]
private Text filenameInputFieldOverlayText;
private TMPro.TMP_Text filenameInputFieldOverlayText;

[SerializeField]
private Image filenameImage;

[SerializeField]
private Dropdown filtersDropdown;
private TMPro.TMP_Dropdown filtersDropdown;

[SerializeField]
private RectTransform filtersDropdownContainer;

[SerializeField]
private Text filterItemTemplate;
private TMPro.TMP_Text filterItemTemplate;

[SerializeField]
private Toggle showHiddenFilesToggle;

[SerializeField]
private Text submitButtonText;
private TMPro.TMP_Text submitButtonText;

[SerializeField]
private Button[] allButtons;
Expand Down Expand Up @@ -739,7 +740,7 @@ private set

filtersDropdown.RefreshShownValue();

Text placeholder = filenameInputField.placeholder as Text;
TMPro.TMP_Text placeholder = filenameInputField.placeholder as TMPro.TMP_Text;
if( placeholder )
placeholder.gameObject.SetActive( m_pickerMode != PickMode.Folders );
}
Expand Down Expand Up @@ -2725,23 +2726,29 @@ private bool VerifyFilename( string filename )
return !isWhitespace;
}

// Credit: http://answers.unity3d.com/questions/898770/how-to-get-the-width-of-ui-text-with-horizontal-ov.html
private int CalculateLengthOfDropdownText( string str )
// Unity.UI.Text Credit: http://answers.unity3d.com/questions/898770/how-to-get-the-width-of-ui-text-with-horizontal-ov.html
// TMPro.Text Credit: https://forum.unity.com/threads/calculate-width-of-a-text-before-without-assigning-it-to-a-tmp-object.758867/#post-5057900
private int CalculateLengthOfDropdownText(string str)
{
Font font = filterItemTemplate.font;
font.RequestCharactersInTexture( str, filterItemTemplate.fontSize, filterItemTemplate.fontStyle );
float totalLength = 0;

int totalLength = 0;
for( int i = 0; i < str.Length; i++ )
TMPro.TMP_FontAsset myFont = filterItemTemplate.font;

float pointSizeScale = filterItemTemplate.fontSize / (myFont.faceInfo.pointSize * myFont.faceInfo.scale);
float emScale = filterItemTemplate.fontSize * 0.01f;

float styleSpacingAdjustment = (filterItemTemplate.fontStyle & TMPro.FontStyles.Bold) == TMPro.FontStyles.Bold ? myFont.boldSpacing : 0;
float normalSpacingAdjustment = myFont.normalSpacingOffset;

for (int i = 0; i < str.Length; i++)
{
CharacterInfo characterInfo;
if( !font.GetCharacterInfo( str[i], out characterInfo, filterItemTemplate.fontSize ) )
if (filterItemTemplate.font.characterLookupTable.TryGetValue(str[i], out var character))
totalLength += character.glyph.metrics.horizontalAdvance * pointSizeScale + (styleSpacingAdjustment + normalSpacingAdjustment) * emScale;
else
totalLength += 5;

totalLength += characterInfo.advance;
}

return totalLength;
return (int)totalLength + 10;
}

private string GetInitialPath( string initialPath )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
Expand All @@ -11,7 +11,7 @@ public class FileBrowserAccessRestrictedPanel : MonoBehaviour
{
#pragma warning disable 0649
[SerializeField]
private Text messageLabel;
private TMPro.TMP_Text messageLabel;

[SerializeField]
private Button okButton;
Expand Down
4 changes: 2 additions & 2 deletions Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;

namespace SimpleFileBrowser
Expand Down Expand Up @@ -27,7 +27,7 @@ public class FileBrowserContextMenu : MonoBehaviour
private GameObject selectAllButtonSeparator;

[SerializeField]
private Text[] allButtonTexts;
private TMPro.TMP_Text[] allButtonTexts;
[SerializeField]
private Image[] allButtonSeparators;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
Expand All @@ -15,7 +15,7 @@ public enum OperationType { Delete = 0, Overwrite = 1 };

#pragma warning disable 0649
[SerializeField]
private Text[] titleLabels;
private TMPro.TMP_Text[] titleLabels;

[SerializeField]
private GameObject[] targetItems;
Expand All @@ -24,13 +24,13 @@ public enum OperationType { Delete = 0, Overwrite = 1 };
private Image[] targetItemIcons;

[SerializeField]
private Text[] targetItemNames;
private TMPro.TMP_Text[] targetItemNames;

[SerializeField]
private GameObject targetItemsRest;

[SerializeField]
private Text targetItemsRestLabel;
private TMPro.TMP_Text targetItemsRestLabel;

[SerializeField]
private RectTransform yesButtonTransform;
Expand Down
4 changes: 2 additions & 2 deletions Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

Expand Down Expand Up @@ -29,7 +29,7 @@ public class FileBrowserItem : ListItem, IPointerClickHandler, IPointerDownHandl
private Image multiSelectionToggle;

[SerializeField]
private Text nameText;
private TMPro.TMP_Text nameText;
#pragma warning restore 0649

#pragma warning disable 0414
Expand Down
6 changes: 3 additions & 3 deletions Plugins/SimpleFileBrowser/Scripts/FileBrowserRenamedItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
Expand All @@ -19,8 +19,8 @@ public class FileBrowserRenamedItem : MonoBehaviour
private Image icon;

[SerializeField]
private InputField nameInputField;
public InputField InputField { get { return nameInputField; } }
private TMPro.TMP_InputField nameInputField;
public TMPro.TMP_InputField InputField { get { return nameInputField; } }
#pragma warning restore 0649

private OnRenameCompleted onRenameCompleted;
Expand Down
20 changes: 10 additions & 10 deletions Plugins/SimpleFileBrowser/Scripts/UISkin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
Expand Down Expand Up @@ -36,8 +36,8 @@ protected virtual void OnValidate()
#pragma warning disable 0649
[Header( "General" )]
[SerializeField]
private Font m_font;
public Font Font
private TMPro.TMP_FontAsset m_font;
public TMPro.TMP_FontAsset Font
{
get { return m_font; }
set { if( m_font != value ) { m_font = value; m_version++; } }
Expand Down Expand Up @@ -535,34 +535,34 @@ public Sprite PopupPanelsBackground
}
#pragma warning restore 0649

public void ApplyTo( Text text, Color textColor )
public void ApplyTo( TMPro.TMP_Text text, Color textColor )
{
text.color = textColor;
text.font = m_font;
text.fontSize = m_fontSize;
}

public void ApplyTo( InputField inputField )
public void ApplyTo( TMPro.TMP_InputField inputField )
{
inputField.image.color = m_inputFieldNormalBackgroundColor;
inputField.image.sprite = m_inputFieldBackground;
inputField.selectionColor = m_inputFieldSelectedTextColor;
inputField.caretColor = m_inputFieldCaretColor;

ApplyTo( inputField.textComponent, m_inputFieldTextColor );
if( inputField.placeholder as Text )
ApplyTo( (Text) inputField.placeholder, m_inputFieldPlaceholderTextColor );
if( inputField.placeholder as TMPro.TMP_Text )
ApplyTo( (TMPro.TMP_Text) inputField.placeholder, m_inputFieldPlaceholderTextColor );
}

public void ApplyTo( Button button )
{
button.image.color = m_buttonColor;
button.image.sprite = m_buttonBackground;

ApplyTo( button.GetComponentInChildren<Text>(), m_buttonTextColor );
ApplyTo( button.GetComponentInChildren<TMPro.TMP_Text>(), m_buttonTextColor );
}

public void ApplyTo( Dropdown dropdown )
public void ApplyTo( TMPro.TMP_Dropdown dropdown )
{
dropdown.image.color = m_dropdownColor;
dropdown.image.sprite = m_dropdownBackground;
Expand Down Expand Up @@ -590,7 +590,7 @@ public void ApplyTo( Toggle toggle )
toggle.graphic.color = m_toggleCheckmarkColor;
( (Image) toggle.graphic ).sprite = m_toggleCheckmark;

ApplyTo( toggle.GetComponentInChildren<Text>(), m_toggleTextColor );
ApplyTo( toggle.GetComponentInChildren<TMPro.TMP_Text>(), m_toggleTextColor );
}

public void ApplyTo( Scrollbar scrollbar )
Expand Down
17 changes: 14 additions & 3 deletions Plugins/SimpleFileBrowser/SimpleFileBrowser.Runtime.asmdef
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"name": "SimpleFileBrowser.Runtime"
}
{
"name": "SimpleFileBrowser.Runtime",
"references": [
"Unity.TextMeshPro"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"autoReferenced": true,
"overrideReferences": false,
"precompiledReferences": [],
"defineConstraints": [],
"optionalUnityReferences": []
}
40 changes: 15 additions & 25 deletions Plugins/SimpleFileBrowser/Skins/DarkSkin.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 66bc3ce4885990c40a88f80fe0ad0101, type: 3}
m_Name: DarkSkin
m_EditorClassIdentifier:
m_font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_font: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSize: 14
m_windowColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_filesListColor: {r: 0.15686275, g: 0.15686275, b: 0.15686275, a: 1}
Expand All @@ -20,36 +21,28 @@ MonoBehaviour:
m_titleTextColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_windowResizeGizmoColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_headerButtonsColor: {r: 1, g: 1, b: 1, a: 1}
m_windowResizeGizmo: {fileID: 21300000, guid: 285f1e681b119ce48ae469448241360b,
type: 3}
m_windowResizeGizmo: {fileID: 21300000, guid: 285f1e681b119ce48ae469448241360b, type: 3}
m_headerBackButton: {fileID: 21300000, guid: 130f660889a70c947bff4c8ba8a2c73e, type: 3}
m_headerForwardButton: {fileID: 21300000, guid: 130f660889a70c947bff4c8ba8a2c73e,
type: 3}
m_headerForwardButton: {fileID: 21300000, guid: 130f660889a70c947bff4c8ba8a2c73e, type: 3}
m_headerUpButton: {fileID: 21300000, guid: 130f660889a70c947bff4c8ba8a2c73e, type: 3}
m_headerContextMenuButton: {fileID: 21300000, guid: 3eb0ab0fddc930a498bef8ce7e149ea0,
type: 3}
m_inputFieldNormalBackgroundColor: {r: 0.18039216, g: 0.18039216, b: 0.18039216,
a: 1}
m_inputFieldInvalidBackgroundColor: {r: 0.4392157, g: 0.12156863, b: 0.12156863,
a: 1}
m_headerContextMenuButton: {fileID: 21300000, guid: 3eb0ab0fddc930a498bef8ce7e149ea0, type: 3}
m_inputFieldNormalBackgroundColor: {r: 0.18039216, g: 0.18039216, b: 0.18039216, a: 1}
m_inputFieldInvalidBackgroundColor: {r: 0.4392157, g: 0.12156863, b: 0.12156863, a: 1}
m_inputFieldTextColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_inputFieldPlaceholderTextColor: {r: 1, g: 1, b: 1, a: 0.6509804}
m_inputFieldSelectedTextColor: {r: 0.13725491, g: 0.46666667, b: 0.69411767, a: 0.5019608}
m_inputFieldCaretColor: {r: 1, g: 1, b: 1, a: 1}
m_inputFieldBackground: {fileID: 21300000, guid: f668f62689b67d242ad33ff665594344,
type: 3}
m_inputFieldBackground: {fileID: 21300000, guid: f668f62689b67d242ad33ff665594344, type: 3}
m_buttonColor: {r: 0.18039216, g: 0.18039216, b: 0.18039216, a: 1}
m_buttonTextColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_buttonBackground: {fileID: 21300000, guid: 2c46fa192de46b04e8281f225bee0230, type: 3}
m_dropdownColor: {r: 0.18039216, g: 0.18039216, b: 0.18039216, a: 1}
m_dropdownTextColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_dropdownArrowColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_dropdownCheckmarkColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_dropdownBackground: {fileID: 21300000, guid: 2c46fa192de46b04e8281f225bee0230,
type: 3}
m_dropdownBackground: {fileID: 21300000, guid: 2c46fa192de46b04e8281f225bee0230, type: 3}
m_dropdownArrow: {fileID: 21300000, guid: f73f38102c749484bbd884d4d8d87440, type: 3}
m_dropdownCheckmark: {fileID: 21300000, guid: 4924b77159e651e4aaa9a22286725d94,
type: 3}
m_dropdownCheckmark: {fileID: 21300000, guid: 4924b77159e651e4aaa9a22286725d94, type: 3}
m_toggleColor: {r: 0.18039216, g: 0.18039216, b: 0.18039216, a: 1}
m_toggleTextColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_toggleCheckmarkColor: {r: 1, g: 1, b: 1, a: 0.87058824}
Expand Down Expand Up @@ -137,14 +130,11 @@ MonoBehaviour:
icon: {fileID: 21300000, guid: 3b2a773e413d3e84f8c7c757734af584, type: 3}
- extension: .exe
icon: {fileID: 21300000, guid: c1e1f7ef76f59f54bbde5162f2709794, type: 3}
m_fileMultiSelectionToggleOffIcon: {fileID: 21300000, guid: d6beaeac8de2af749a48581db778df3e,
type: 3}
m_fileMultiSelectionToggleOnIcon: {fileID: 21300000, guid: 30a2566f94f937b4998542121050e68b,
type: 3}
m_fileMultiSelectionToggleOffIcon: {fileID: 21300000, guid: d6beaeac8de2af749a48581db778df3e, type: 3}
m_fileMultiSelectionToggleOnIcon: {fileID: 21300000, guid: 30a2566f94f937b4998542121050e68b, type: 3}
m_contextMenuBackgroundColor: {r: 0.11372549, g: 0.11372549, b: 0.11372549, a: 1}
m_contextMenuTextColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_contextMenuSeparatorColor: {r: 0.6392157, g: 0.6392157, b: 0.6392157, a: 1}
m_popupPanelsBackgroundColor: {r: 0.18039216, g: 0.18039216, b: 0.18039216, a: 1}
m_popupPanelsTextColor: {r: 1, g: 1, b: 1, a: 0.87058824}
m_popupPanelsBackground: {fileID: 21300000, guid: b9c5fedc997f125448c4d8be2fc43bcd,
type: 3}
m_popupPanelsBackground: {fileID: 21300000, guid: b9c5fedc997f125448c4d8be2fc43bcd, type: 3}
Loading