Files
peng-zhihui 06ec2e469e Released.
2022-03-13 06:31:07 +08:00

109 lines
2.4 KiB
C#

namespace UIWidgets.Examples
{
using System;
using UIWidgets;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
/// <summary>
/// Test FolderDialog.
/// </summary>
public class TestFolderDialog : MonoBehaviour, IUpgradeable
{
/// <summary>
/// FolderDialog template.
/// </summary>
[SerializeField]
protected FolderDialog PickerTemplate;
/// <summary>
/// Text component to display selected value.
/// </summary>
[SerializeField]
[HideInInspector]
[Obsolete("Replaced with InfoAdapter.")]
protected Text Info;
/// <summary>
/// Text component to display selected value.
/// </summary>
[SerializeField]
protected TextAdapter InfoAdapter;
/// <summary>
/// Current value.
/// </summary>
[NonSerialized]
[FormerlySerializedAs("currentValue")]
protected 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
}
}