8 using System.Collections.Generic;
11 #if UNITY_WSA && UNITY_2017_2_OR_NEWER 23 private int maxCharsPerLine = 45;
26 private TextMesh titleText;
29 private TextMesh messageText;
32 private GameObject[] twoButtonSet;
40 public int MaxCharsPerLine
44 return maxCharsPerLine;
49 maxCharsPerLine = value;
58 if (messageText != null)
60 messageText.text = WordWrap(messageText.text, MaxCharsPerLine);
71 #if UNITY_WSA && UNITY_2017_2_OR_NEWER 73 if (HolographicSettings.IsDisplayOpaque)
88 List<DialogButtonType> buttonTypes =
new List<DialogButtonType>();
97 if ((buttonType & result.Buttons) == buttonType)
99 buttonTypes.Add(buttonType);
103 twoButtonSet =
new GameObject[2];
106 List<DialogButton> buttonsOnDialog = GetAllDialogButtons();
109 SetButtonsActiveStates(buttonsOnDialog, buttonTypes.Count);
112 if (buttonTypes.Count > 0)
115 int step = buttonTypes.Count == 2 ? 1 : 0;
116 for (
int i = 0; i < buttonTypes.Count; ++i)
118 twoButtonSet[i] = buttonsOnDialog[i + step].gameObject;
119 buttonsOnDialog[i + step].SetTitle(buttonTypes[i].ToString());
120 buttonsOnDialog[i + step].ButtonTypeEnum = buttonTypes[i];
125 private void SetButtonsActiveStates(List<DialogButton> buttons,
int count)
128 for (
int i = 0; i < buttons.Count; ++i)
130 var flag1 = (count == 1) && (i == 0);
131 var flag2 = (count == 2) && (i > 0);
132 buttons[i].ParentDialog =
this;
133 buttons[i].gameObject.SetActive(flag1 || flag2);
137 private List<DialogButton> GetAllDialogButtons()
139 List<DialogButton> buttonsOnDialog =
new List<DialogButton>();
140 for (
int i = 0; i < transform.childCount; i++)
142 Transform child = transform.GetChild(i);
143 if (child.name ==
"ButtonParent")
145 for (
int childIndex = 0; childIndex < child.transform.childCount; ++childIndex)
147 Transform t = child.transform.GetChild(childIndex);
153 buttonsOnDialog.Add(button);
159 return buttonsOnDialog;
167 foreach (Transform child
in transform)
169 if (child != null && child.name ==
"TitleText")
171 titleText = child.GetComponent<TextMesh>();
173 else if (child != null && child.name ==
"TitleMessage")
175 messageText = child.GetComponent<TextMesh>();
179 if (titleText != null)
181 titleText.text = Result.Title;
184 if (messageText != null)
186 messageText.text = WordWrap(Result.Message, MaxCharsPerLine);
196 public static string WordWrap(
string text,
int maxCharsPerLine)
200 StringBuilder stringBuilder =
new StringBuilder();
202 if (maxCharsPerLine < 1)
207 for (pos = 0; pos < text.Length; pos = next)
209 int endOfLine = text.IndexOf(Environment.NewLine, pos, StringComparison.Ordinal);
213 next = endOfLine = text.Length;
217 next = endOfLine + Environment.NewLine.Length;
224 int len = endOfLine - pos;
226 if (len > maxCharsPerLine)
227 len = BreakLine(text, pos, maxCharsPerLine);
229 stringBuilder.Append(text, pos, len);
230 stringBuilder.Append(Environment.NewLine);
234 while (pos < endOfLine && Char.IsWhiteSpace(text[pos]))
239 }
while (endOfLine > pos);
243 stringBuilder.Append(
System.Environment.NewLine);
247 return stringBuilder.ToString();
257 public static int BreakLine(
string text,
int pos,
int max)
261 while (i >= 0 && !Char.IsWhiteSpace(text[pos + i]))
271 while (i >= 0 && Char.IsWhiteSpace(text[pos + i]))