-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added context menu that can be opened in 2 ways: a) right clicking …
…a file on standalone platforms or b) clicking the More Options button located at the top-right corner. Context menu has the following buttons: - Select All (only when multi selection is enabled and More Options button is clicked) - Deselect All (only when more than 1 items are selected and More Options button is clicked) - New Folder (closed #25) - Delete (only when 1 or more items are selected) - Rename (only when 1 item is selected)
- Loading branch information
Showing
15 changed files
with
7,601 additions
and
2,491 deletions.
There are no files selected for viewing
9,244 changes: 6,816 additions & 2,428 deletions
9,244
Plugins/SimpleFileBrowser/Resources/SimpleFileBrowserCanvas.prefab
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace SimpleFileBrowser | ||
{ | ||
public class FileBrowserContextMenu : MonoBehaviour | ||
{ | ||
#pragma warning disable 0649 | ||
[SerializeField] | ||
private FileBrowser fileBrowser; | ||
|
||
[SerializeField] | ||
private RectTransform rectTransform; | ||
|
||
[SerializeField] | ||
private Button selectAllButton; | ||
[SerializeField] | ||
private Button deselectAllButton; | ||
[SerializeField] | ||
private Button deleteButton; | ||
[SerializeField] | ||
private Button renameButton; | ||
|
||
[SerializeField] | ||
private GameObject selectAllButtonSeparator; | ||
|
||
[SerializeField] | ||
private float minDistanceToEdges = 10f; | ||
#pragma warning restore 0649 | ||
|
||
internal void Show( bool selectAllButtonVisible, bool deselectAllButtonVisible, bool deleteButtonVisible, bool renameButtonVisible, Vector2 position, bool isMoreOptionsMenu ) | ||
{ | ||
selectAllButton.gameObject.SetActive( selectAllButtonVisible ); | ||
deselectAllButton.gameObject.SetActive( deselectAllButtonVisible ); | ||
deleteButton.gameObject.SetActive( deleteButtonVisible ); | ||
renameButton.gameObject.SetActive( renameButtonVisible ); | ||
selectAllButtonSeparator.SetActive( !deselectAllButtonVisible ); | ||
|
||
rectTransform.anchoredPosition = position; | ||
gameObject.SetActive( true ); | ||
|
||
if( isMoreOptionsMenu ) | ||
rectTransform.pivot = Vector2.one; | ||
else | ||
{ | ||
// Find the optimal pivot value | ||
LayoutRebuilder.ForceRebuildLayoutImmediate( rectTransform ); | ||
|
||
Vector2 size = rectTransform.sizeDelta; | ||
Vector2 canvasSize = fileBrowser.rectTransform.sizeDelta; | ||
|
||
// Take canvas' Pivot into consideration | ||
Vector2 positionOffset = canvasSize; | ||
positionOffset.Scale( fileBrowser.rectTransform.pivot ); | ||
position += positionOffset; | ||
|
||
// Try bottom-right corner first | ||
Vector2 cornerPos = position + new Vector2( size.x + minDistanceToEdges, -size.y - minDistanceToEdges ); | ||
if( cornerPos.x <= canvasSize.x && cornerPos.y >= 0f ) | ||
rectTransform.pivot = new Vector2( 0f, 1f ); | ||
else | ||
{ | ||
// Try bottom-left corner | ||
cornerPos = position - new Vector2( size.x + minDistanceToEdges, size.y + minDistanceToEdges ); | ||
if( cornerPos.x >= 0f && cornerPos.y >= 0f ) | ||
rectTransform.pivot = Vector2.one; | ||
else | ||
{ | ||
// Try top-right corner | ||
cornerPos = position + new Vector2( size.x + minDistanceToEdges, size.y + minDistanceToEdges ); | ||
if( cornerPos.x <= canvasSize.x && cornerPos.y <= canvasSize.y ) | ||
rectTransform.pivot = Vector2.zero; | ||
else | ||
{ | ||
// Use top-left corner | ||
rectTransform.pivot = new Vector2( 1f, 0f ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void Hide() | ||
{ | ||
gameObject.SetActive( false ); | ||
} | ||
|
||
public void OnSelectAllButtonClicked() | ||
{ | ||
Hide(); | ||
fileBrowser.SelectAllFiles(); | ||
} | ||
|
||
public void OnDeselectAllButtonClicked() | ||
{ | ||
Hide(); | ||
fileBrowser.DeselectAllFiles(); | ||
} | ||
|
||
public void OnCreateFolderButtonClicked() | ||
{ | ||
Hide(); | ||
fileBrowser.CreateNewFolder(); | ||
} | ||
|
||
public void OnDeleteButtonClicked() | ||
{ | ||
Hide(); | ||
fileBrowser.DeleteSelectedFiles(); | ||
} | ||
|
||
public void OnRenameButtonClicked() | ||
{ | ||
Hide(); | ||
fileBrowser.RenameSelectedFile(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
Plugins/SimpleFileBrowser/Scripts/FileBrowserDeleteConfirmationPanel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace SimpleFileBrowser | ||
{ | ||
public class FileBrowserDeleteConfirmationPanel : MonoBehaviour | ||
{ | ||
public delegate void OnDeletionConfirmed(); | ||
|
||
#pragma warning disable 0649 | ||
[SerializeField] | ||
private GameObject[] deletedItems; | ||
|
||
[SerializeField] | ||
private Image[] deletedItemIcons; | ||
|
||
[SerializeField] | ||
private Text[] deletedItemNames; | ||
|
||
[SerializeField] | ||
private GameObject deletedItemsRest; | ||
|
||
[SerializeField] | ||
private Text deletedItemsRestLabel; | ||
|
||
[SerializeField] | ||
private RectTransform yesButtonTransform; | ||
|
||
[SerializeField] | ||
private RectTransform noButtonTransform; | ||
|
||
[SerializeField] | ||
private float narrowScreenWidth = 380f; | ||
#pragma warning restore 0649 | ||
|
||
private OnDeletionConfirmed onDeletionConfirmed; | ||
|
||
internal void Show( Sprite[] icons, string[] filenames, OnDeletionConfirmed onDeletionConfirmed ) | ||
{ | ||
this.onDeletionConfirmed = onDeletionConfirmed; | ||
|
||
for( int i = 0; i < deletedItems.Length; i++ ) | ||
deletedItems[i].SetActive( i < icons.Length ); | ||
|
||
for( int i = 0; i < deletedItems.Length && i < icons.Length; i++ ) | ||
{ | ||
deletedItemIcons[i].sprite = icons[i]; | ||
deletedItemNames[i].text = filenames[i]; | ||
} | ||
|
||
if( icons.Length > deletedItems.Length ) | ||
{ | ||
deletedItemsRestLabel.text = string.Concat( "...and ", ( icons.Length - deletedItems.Length ).ToString(), " other" ); | ||
deletedItemsRest.SetActive( true ); | ||
} | ||
else | ||
deletedItemsRest.SetActive( false ); | ||
|
||
gameObject.SetActive( true ); | ||
} | ||
|
||
// Handles responsive user interface | ||
internal void OnCanvasDimensionsChanged( Vector2 size ) | ||
{ | ||
if( size.x >= narrowScreenWidth ) | ||
{ | ||
yesButtonTransform.anchorMin = new Vector2( 0.5f, 0f ); | ||
yesButtonTransform.anchorMax = new Vector2( 0.75f, 1f ); | ||
noButtonTransform.anchorMin = new Vector2( 0.75f, 0f ); | ||
} | ||
else | ||
{ | ||
yesButtonTransform.anchorMin = Vector2.zero; | ||
yesButtonTransform.anchorMax = new Vector2( 0.5f, 1f ); | ||
noButtonTransform.anchorMin = new Vector2( 0.5f, 0f ); | ||
} | ||
} | ||
|
||
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0 | ||
private void LateUpdate() | ||
{ | ||
// Handle keyboard shortcuts | ||
if( Input.GetKeyDown( KeyCode.Return ) || Input.GetKeyDown( KeyCode.KeypadEnter ) ) | ||
YesButtonClicked(); | ||
|
||
if( Input.GetKeyDown( KeyCode.Escape ) ) | ||
NoButtonClicked(); | ||
} | ||
#endif | ||
|
||
public void YesButtonClicked() | ||
{ | ||
gameObject.SetActive( false ); | ||
|
||
if( onDeletionConfirmed != null ) | ||
onDeletionConfirmed(); | ||
} | ||
|
||
public void NoButtonClicked() | ||
{ | ||
gameObject.SetActive( false ); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Plugins/SimpleFileBrowser/Scripts/FileBrowserDeleteConfirmationPanel.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Plugins/SimpleFileBrowser/Scripts/FileBrowserRenamedItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
using UnityEngine.UI; | ||
|
||
namespace SimpleFileBrowser | ||
{ | ||
public class FileBrowserRenamedItem : MonoBehaviour | ||
{ | ||
public delegate void OnRenameCompleted( string filename ); | ||
|
||
#pragma warning disable 0649 | ||
[SerializeField] | ||
private Image background; | ||
|
||
[SerializeField] | ||
private Image icon; | ||
|
||
[SerializeField] | ||
private InputField nameInputField; | ||
#pragma warning restore 0649 | ||
|
||
private OnRenameCompleted onRenameCompleted; | ||
|
||
public void Show( string initialFilename, Color backgroundColor, Sprite icon, OnRenameCompleted onRenameCompleted ) | ||
{ | ||
background.color = backgroundColor; | ||
this.icon.sprite = icon; | ||
this.onRenameCompleted = onRenameCompleted; | ||
|
||
transform.SetAsLastSibling(); | ||
gameObject.SetActive( true ); | ||
|
||
nameInputField.text = initialFilename; | ||
nameInputField.ActivateInputField(); | ||
} | ||
|
||
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0 | ||
private void LateUpdate() | ||
{ | ||
// Don't allow scrolling with mouse wheel while renaming a file or creating a folder | ||
if( Input.mouseScrollDelta.y != 0f ) | ||
nameInputField.DeactivateInputField(); | ||
} | ||
#endif | ||
|
||
public void OnInputFieldEndEdit( string filename ) | ||
{ | ||
gameObject.SetActive( false ); | ||
|
||
// If we don't deselect the InputField manually, FileBrowser's keyboard shortcuts | ||
// no longer work until user clicks on a UI element and thus, deselects the InputField | ||
if( !EventSystem.current.alreadySelecting && EventSystem.current.currentSelectedGameObject == nameInputField.gameObject ) | ||
EventSystem.current.SetSelectedGameObject( null ); | ||
|
||
if( onRenameCompleted != null ) | ||
onRenameCompleted( filename ); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Plugins/SimpleFileBrowser/Scripts/FileBrowserRenamedItem.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace SimpleFileBrowser | ||
{ | ||
// Credit: http://answers.unity.com/answers/1157876/view.html | ||
[RequireComponent( typeof( CanvasRenderer ) )] | ||
public class NonDrawingGraphic : Graphic | ||
{ | ||
public override void SetMaterialDirty() { return; } | ||
public override void SetVerticesDirty() { return; } | ||
|
||
protected override void OnPopulateMesh( VertexHelper vh ) | ||
{ | ||
vh.Clear(); | ||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.