namespace UIWidgets.Examples { using UIWidgets; using UnityEngine; using UnityEngine.UI; /// /// Test FileDialog. /// public class TestFileDialog : MonoBehaviour, IUpgradeable { /// /// FileDialog template. /// [SerializeField] protected FileDialog PickerTemplate; /// /// Text component to display selected value. /// [SerializeField] [HideInInspector] [System.Obsolete("Replaced with InfoAdapter.")] protected Text Info; /// /// Text component to display selected value. /// [SerializeField] protected TextAdapter InfoAdapter; string currentValue = string.Empty; /// /// Show picker and log selected value. /// [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"); } /// /// Show picker and display selected value. /// [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"; } /// /// Upgrade this instance. /// public virtual void Upgrade() { #pragma warning disable 0612, 0618 Utilities.GetOrAddComponent(Info, ref InfoAdapter); #pragma warning restore 0612, 0618 } #if UNITY_EDITOR /// /// Validate this instance. /// protected virtual void OnValidate() { Compatibility.Upgrade(this); } #endif } }