-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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
78 changes: 78 additions & 0 deletions
78
src/TalkClient.Unity3D/Assets/UnityPackages/UiManager/UiInputBox.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,78 @@ | ||
using System; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class UiInputBox : UiDialog | ||
{ | ||
public delegate void InputResultDelegate(string input); | ||
|
||
public enum ButtonType | ||
{ | ||
Ok, | ||
OkCancel, | ||
} | ||
|
||
public Text MessageText; | ||
public InputField ValueInput; | ||
public Button[] Buttons; | ||
|
||
public static UiDialogHandle Show( | ||
string msg, string value = null, ButtonType buttonType = ButtonType.Ok, | ||
InputResultDelegate callback = null, string customOkName = null) | ||
{ | ||
UiDialogHandle handle; | ||
{ | ||
var builtin = UiManager.Instance.FindFromDialogRoot("InputBox"); | ||
if (builtin != null) | ||
{ | ||
handle = UiManager.Instance.ShowModalTemplate(builtin.gameObject); | ||
} | ||
else | ||
{ | ||
var msgBoxPrefab = Resources.Load("InputBox") as GameObject; | ||
handle = UiManager.Instance.ShowModalPrefab(msgBoxPrefab); | ||
} | ||
} | ||
|
||
if (callback != null) | ||
handle.Hidden += (dlg, returnValue) => callback((string)returnValue); | ||
|
||
var msgBox = (UiInputBox)handle.Dialog; | ||
msgBox.MessageText.text = msg; | ||
msgBox.ValueInput.text = value ?? ""; | ||
|
||
var b0 = msgBox.Buttons[0]; | ||
var b0Text = b0.transform.Find("Text").GetComponent<Text>(); | ||
var b1 = msgBox.Buttons[1]; | ||
var b1Text = b1.transform.Find("Text").GetComponent<Text>(); | ||
|
||
b1.gameObject.SetActive(buttonType != ButtonType.Ok); | ||
|
||
switch (buttonType) | ||
{ | ||
case ButtonType.Ok: | ||
b0Text.text = customOkName ?? "Ok"; | ||
b0.onClick.AddListener(() => msgBox.OnButtonClick(true)); | ||
break; | ||
|
||
case ButtonType.OkCancel: | ||
b0Text.text = customOkName ?? "Ok"; | ||
b0.onClick.AddListener(() => msgBox.OnButtonClick(true)); | ||
b1Text.text = "Cancel"; | ||
b1.onClick.AddListener(() => msgBox.OnButtonClick(false)); | ||
break; | ||
} | ||
|
||
return handle; | ||
} | ||
|
||
private void OnButtonClick(bool ok) | ||
{ | ||
Hide(ok ? ValueInput.text : null); | ||
} | ||
|
||
public void OnInputSubmit() | ||
{ | ||
OnButtonClick(true); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/TalkClient.Unity3D/Assets/UnityPackages/UiManager/UiInputBox.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