mirror of
https://github.com/peng-zhihui/ElectronBot.git
synced 2026-10-21 14:51:57 +08:00
102 lines
2.2 KiB
C#
102 lines
2.2 KiB
C#
namespace UIWidgets.Examples
|
|
{
|
|
using UIWidgets;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// Test FileDialog.
|
|
/// </summary>
|
|
public class TestFileDialog : MonoBehaviour, IUpgradeable
|
|
{
|
|
/// <summary>
|
|
/// FileDialog template.
|
|
/// </summary>
|
|
[SerializeField]
|
|
protected FileDialog PickerTemplate;
|
|
|
|
/// <summary>
|
|
/// Text component to display selected value.
|
|
/// </summary>
|
|
[SerializeField]
|
|
[HideInInspector]
|
|
[System.Obsolete("Replaced with InfoAdapter.")]
|
|
protected Text Info;
|
|
|
|
/// <summary>
|
|
/// Text component to display selected value.
|
|
/// </summary>
|
|
[SerializeField]
|
|
protected TextAdapter InfoAdapter;
|
|
|
|
string currentValue = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Show picker and log selected value.
|
|
/// </summary>
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")]
|
|
public void Test()
|
|
{
|
|
// create picker from template
|
|
var picker = PickerTemplate.Clone();
|
|
|
|
// show picker
|
|
picker.Show(currentValue, ValueSelected, Canceled);
|
|
}
|
|
|
|
void ValueSelected(string value)
|
|
{
|
|
currentValue = value;
|
|
Debug.Log(string.Format("value: {0}", value));
|
|
}
|
|
|
|
void Canceled()
|
|
{
|
|
Debug.Log("canceled");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Show picker and display selected value.
|
|
/// </summary>
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")]
|
|
public void TestShow()
|
|
{
|
|
// create picker from template
|
|
var picker = PickerTemplate.Clone();
|
|
|
|
// show picker
|
|
picker.Show(currentValue, ShowValueSelected, ShowCanceled);
|
|
}
|
|
|
|
void ShowValueSelected(string value)
|
|
{
|
|
currentValue = value;
|
|
InfoAdapter.text = string.Format("Value: {0}", value);
|
|
}
|
|
|
|
void ShowCanceled()
|
|
{
|
|
InfoAdapter.text = "Canceled";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upgrade this instance.
|
|
/// </summary>
|
|
public virtual void Upgrade()
|
|
{
|
|
#pragma warning disable 0612, 0618
|
|
Utilities.GetOrAddComponent(Info, ref InfoAdapter);
|
|
#pragma warning restore 0612, 0618
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
/// <summary>
|
|
/// Validate this instance.
|
|
/// </summary>
|
|
protected virtual void OnValidate()
|
|
{
|
|
Compatibility.Upgrade(this);
|
|
}
|
|
#endif
|
|
}
|
|
} |