193 lines
5.7 KiB
C#
193 lines
5.7 KiB
C#
using System;
|
||
using System.Collections;
|
||
using UIWidgets;
|
||
using UnityEngine;
|
||
|
||
namespace UIWidgetsSamples
|
||
{
|
||
public class UITestSamples : MonoBehaviour
|
||
{
|
||
[SerializeField]
|
||
private Sprite questionIcon;
|
||
|
||
[SerializeField]
|
||
private Sprite attentionIcon;
|
||
|
||
public void ShowNotifySticky()
|
||
{
|
||
Notify.Template("NotifyTemplateSimple").Show("Sticky Notification. Click on the × above to close.", 0f);
|
||
}
|
||
|
||
public void ShowNotifyStack()
|
||
{
|
||
Notify.Template("NotifyTemplateSimple").Show("Stack Notification 1.", 3f, null, null, null, null, NotifySequence.First);
|
||
Notify.Template("NotifyTemplateSimple").Show("Stack Notification 2.", 3f, null, null, null, null, NotifySequence.First);
|
||
Notify.Template("NotifyTemplateSimple").Show("Stack Notification 3.", 3f, null, null, null, null, NotifySequence.First);
|
||
}
|
||
|
||
public void ShowNotifyQueue()
|
||
{
|
||
Notify.Template("NotifyTemplateSimple").Show("Queue Notification 1.", 3f, null, null, null, null, NotifySequence.Last);
|
||
Notify.Template("NotifyTemplateSimple").Show("Queue Notification 2.", 3f, null, null, null, null, NotifySequence.Last);
|
||
Notify.Template("NotifyTemplateSimple").Show("Queue Notification 3.", 3f, null, null, null, null, NotifySequence.Last);
|
||
}
|
||
|
||
public void ShowNotifySequenceClear()
|
||
{
|
||
Notify.Template("NotifyTemplateSimple").Show("Stack Notification 1.", 3f, null, null, null, null, NotifySequence.First);
|
||
Notify.Template("NotifyTemplateSimple").Show("Stack Notification 2.", 3f, null, null, null, null, NotifySequence.First);
|
||
Notify.Template("NotifyTemplateSimple").Show("Stack Notification 3.", 3f, null, null, null, null, NotifySequence.First, 0.3f, true);
|
||
}
|
||
|
||
public void ShowNotifyAutohide()
|
||
{
|
||
Notify.Template("NotifyTemplateAutoHide").Show("Achievement unlocked. Hide after 3 seconds.", 3f);
|
||
}
|
||
|
||
private bool CallShowNotifyAutohide()
|
||
{
|
||
ShowNotifyAutohide();
|
||
return true;
|
||
}
|
||
|
||
public void ShowNotifyAutohideRotate()
|
||
{
|
||
Notify notify = Notify.Template("NotifyTemplateAutoHide");
|
||
string message = "Achievement unlocked. Hide after 4 seconds.";
|
||
float? customHideDelay = 4f;
|
||
Func<Notify, IEnumerator> hideAnimation = Notify.AnimationRotate;
|
||
notify.Show(message, customHideDelay, null, null, hideAnimation);
|
||
}
|
||
|
||
public void ShowNotifyBlack()
|
||
{
|
||
Notify notify = Notify.Template("NotifyTemplateBlack");
|
||
string message = "Another Notification. Hide after 5 seconds or click on the × above to close.";
|
||
float? customHideDelay = 5f;
|
||
Func<Notify, IEnumerator> hideAnimation = Notify.AnimationCollapse;
|
||
notify.Show(message, customHideDelay, null, null, hideAnimation, false);
|
||
}
|
||
|
||
private bool ShowNotifyYes()
|
||
{
|
||
Notify.Template("NotifyTemplateAutoHide").Show("Action on 'Yes' button click.", 3f);
|
||
return true;
|
||
}
|
||
|
||
private bool ShowNotifyNo()
|
||
{
|
||
Notify.Template("NotifyTemplateAutoHide").Show("Action on 'No' button click.", 3f);
|
||
return true;
|
||
}
|
||
|
||
public void ShowDialogSimple()
|
||
{
|
||
Dialog.Template("DialogTemplateSample").Show("Simple Dialog", "Simple dialog with only close button.", new DialogActions {
|
||
{
|
||
"Close",
|
||
Dialog.Close
|
||
} }, "Close");
|
||
}
|
||
|
||
private bool CallShowDialogSimple()
|
||
{
|
||
ShowDialogSimple();
|
||
return true;
|
||
}
|
||
|
||
public void ShowDialogYesNoCancel()
|
||
{
|
||
Dialog dialog = Dialog.Template("DialogTemplateSample");
|
||
string title = "Dialog Yes No Cancel";
|
||
string message = "Question?";
|
||
DialogActions buttons = new DialogActions
|
||
{
|
||
{ "Yes", ShowNotifyYes },
|
||
{ "No", ShowNotifyNo },
|
||
{
|
||
"Cancel",
|
||
Dialog.Close
|
||
}
|
||
};
|
||
string focusButton = "Yes";
|
||
Sprite icon = questionIcon;
|
||
dialog.Show(title, message, buttons, focusButton, null, icon);
|
||
}
|
||
|
||
public void ShowDialogExtended()
|
||
{
|
||
Dialog.Template("DialogTemplateSample").Show("Another Dialog", "Same template with another position and long text.\nChange\nheight\nto\nfit\ntext.", new DialogActions
|
||
{
|
||
{ "Show notification", CallShowNotifyAutohide },
|
||
{ "Open simple dialog", CallShowDialogSimple },
|
||
{
|
||
"Close",
|
||
Dialog.Close
|
||
}
|
||
}, "Show notification", new Vector3(40f, -40f, 0f));
|
||
}
|
||
|
||
public void ShowDialogModal()
|
||
{
|
||
Dialog dialog = Dialog.Template("DialogTemplateSample");
|
||
string title = "Modal Dialog";
|
||
string message = "Simple Modal Dialog.";
|
||
DialogActions buttons = new DialogActions {
|
||
{
|
||
"Close",
|
||
Dialog.Close
|
||
} };
|
||
string focusButton = "Close";
|
||
Color? modalColor = new Color(0f, 0f, 0f, 0.8f);
|
||
dialog.Show(title, message, buttons, focusButton, null, null, true, null, modalColor);
|
||
}
|
||
|
||
public void ShowDialogSignIn()
|
||
{
|
||
Dialog dialog = Dialog.Template("DialogSignInTemplateSample");
|
||
DialogInputHelper helper = dialog.GetComponent<DialogInputHelper>();
|
||
helper.Refresh();
|
||
string title = "Sign into your Account";
|
||
DialogActions buttons = new DialogActions
|
||
{
|
||
{
|
||
"Sign in",
|
||
() => SignInNotify(helper)
|
||
},
|
||
{
|
||
"Cancel",
|
||
Dialog.Close
|
||
}
|
||
};
|
||
Color? modalColor = new Color(0f, 0f, 0f, 0.8f);
|
||
dialog.Show(title, null, buttons, "Sign in", null, null, true, null, modalColor);
|
||
}
|
||
|
||
private bool SignInNotify(DialogInputHelper helper)
|
||
{
|
||
if (!helper.Validate())
|
||
{
|
||
return false;
|
||
}
|
||
string message = "Sign in.\nUsername: " + helper.Username.text + "\nPassword: <hidden>";
|
||
Notify.Template("NotifyTemplateAutoHide").Show(message, 3f);
|
||
return true;
|
||
}
|
||
|
||
public void ShowDialogTreeView()
|
||
{
|
||
Dialog dialog = Dialog.Template("DialogTreeView");
|
||
DialogTreeViewInputHelper component = dialog.GetComponent<DialogTreeViewInputHelper>();
|
||
string title = "Sign into your Account";
|
||
DialogActions buttons = new DialogActions {
|
||
{
|
||
"Close",
|
||
Dialog.Close
|
||
} };
|
||
Color? modalColor = new Color(0f, 0f, 0f, 0.8f);
|
||
dialog.Show(title, null, buttons, "Sign in", null, null, true, null, modalColor);
|
||
component.Refresh();
|
||
}
|
||
}
|
||
}
|