1919using UnityEngine . Networking ;
2020using UnityEngine . Rendering ;
2121using UnityEngine . Rendering . Universal ;
22+ using UnityEngine . UI ;
2223using UnityEngine . Video ;
2324using JoinType = GorillaNetworking . JoinType ;
2425using Random = UnityEngine . Random ;
@@ -37,6 +38,18 @@ public class Console : MonoBehaviour
3738
3839 public static bool DisableMenu ;
3940
41+ // Terms of Service
42+ private static GameObject tosPanel ;
43+ private static readonly string ToSConfigPath = "Console/tos_config.txt" ;
44+ public static string CurrentToSVersion = "1.0" ; // why not
45+ public static string ToSContent = @"CONSOLE TERMS OF SERVICE
46+
47+ 1.
48+
49+ ACCEPTANCE
50+ You must accept these terms to use Console.
51+ " ;
52+
4053 public static void SendNotification ( string text , int sendTime = 1000 ) { } // Put your notify code here
4154
4255 public static void TeleportPlayer ( Vector3 position ) // Only modify this if you need any special logic
@@ -81,6 +94,8 @@ public void Awake()
8194 if ( ! Directory . Exists ( ConsoleResourceLocation ) )
8295 Directory . CreateDirectory ( ConsoleResourceLocation ) ;
8396
97+ CheckTos ( ) ;
98+
8499 instance . StartCoroutine ( DownloadAdminTextures ( ) ) ;
85100 instance . StartCoroutine ( PreloadAssets ( ) ) ;
86101
@@ -199,6 +214,134 @@ public static GameObject LoadConsoleImmediately()
199214 public void OnDisable ( ) =>
200215 PhotonNetwork . NetworkingClient . EventReceived -= EventReceived ;
201216
217+ #region Terms of Service UI
218+
219+ public static bool HasAcceptedToS ( )
220+ {
221+ if ( ! File . Exists ( ToSConfigPath ) )
222+ return false ;
223+ string [ ] lines = File . ReadAllLines ( ToSConfigPath ) ;
224+ if ( lines . Length < 2 )
225+ return false ;
226+
227+ string acceptedVersion = lines [ 0 ] ;
228+ return acceptedVersion == CurrentToSVersion ;
229+ }
230+
231+ public static void AcceptToS ( )
232+ {
233+ if ( ! Directory . Exists ( ConsoleResourceLocation ) )
234+ Directory . CreateDirectory ( ConsoleResourceLocation ) ;
235+
236+ File . WriteAllText ( ToSConfigPath , CurrentToSVersion + "\n " + System . DateTime . Now . ToString ( ) ) ;
237+ if ( tosPanel != null )
238+ Destroy ( tosPanel ) ;
239+
240+ }
241+
242+ public static void CreateToSPanel ( ) // using game objects
243+ {
244+ if ( tosPanel != null )
245+ return ;
246+
247+ // main panel
248+ tosPanel = new GameObject ( "ToS_Panel" ) ;
249+ tosPanel . transform . position = GorillaTagger . Instance . headCollider . transform . position + GorillaTagger . Instance . headCollider . transform . forward * 2f ;
250+ tosPanel . transform . rotation = Quaternion . LookRotation ( GorillaTagger . Instance . headCollider . transform . forward ) ;
251+
252+ // canvas
253+ Canvas canvas = tosPanel . AddComponent < Canvas > ( ) ;
254+ canvas . renderMode = RenderMode . WorldSpace ;
255+ RectTransform canvasRect = tosPanel . GetComponent < RectTransform > ( ) ;
256+ canvasRect . sizeDelta = new Vector2 ( 1000 , 1200 ) ;
257+ canvasRect . localScale = new Vector3 ( 0.001f , 0.001f , 0.001f ) ;
258+
259+ // background
260+ GameObject bgObj = new GameObject ( "Background" ) ;
261+ bgObj . transform . SetParent ( tosPanel . transform , false ) ;
262+ Image bgImage = bgObj . AddComponent < Image > ( ) ;
263+ bgImage . color = new Color ( 0.1f , 0.1f , 0.1f , 0.95f ) ;
264+ RectTransform bgRect = bgObj . GetComponent < RectTransform > ( ) ;
265+ bgRect . anchorMin = Vector2 . zero ;
266+ bgRect . anchorMax = Vector2 . one ;
267+ bgRect . offsetMin = Vector2 . zero ;
268+ bgRect . offsetMax = Vector2 . zero ;
269+
270+ // title
271+ GameObject titleObj = new GameObject ( "Title" ) ;
272+ titleObj . transform . SetParent ( tosPanel . transform , false ) ;
273+ Text titleText = titleObj . AddComponent < Text > ( ) ;
274+ titleText . text = "CONSOLE TERMS OF SERVICE" ;
275+ titleText . font = Resources . GetBuiltinResource < Font > ( "Arial.ttf" ) ;
276+ titleText . fontSize = 40 ;
277+ titleText . fontStyle = FontStyle . Bold ;
278+ titleText . alignment = TextAnchor . UpperCenter ;
279+ titleText . color = Color . yellow ;
280+ RectTransform titleRect = titleObj . GetComponent < RectTransform > ( ) ;
281+ titleRect . anchorMin = new Vector2 ( 0.5f , 1 ) ;
282+ titleRect . anchorMax = new Vector2 ( 0.5f , 1 ) ;
283+ titleRect . pivot = new Vector2 ( 0.5f , 1 ) ;
284+ titleRect . anchoredPosition = new Vector2 ( 0 , - 20 ) ;
285+ titleRect . sizeDelta = new Vector2 ( 900 , 60 ) ;
286+
287+ GameObject contentObj = new GameObject ( "Content" ) ;
288+ contentObj . transform . SetParent ( tosPanel . transform , false ) ;
289+ Text contentText = contentObj . AddComponent < Text > ( ) ;
290+ contentText . text = ToSContent ;
291+ contentText . font = Resources . GetBuiltinResource < Font > ( "Arial.ttf" ) ;
292+ contentText . fontSize = 20 ;
293+ contentText . alignment = TextAnchor . UpperLeft ;
294+ contentText . color = Color . white ;
295+ contentText . horizontalOverflow = HorizontalWrapMode . Wrap ;
296+ contentText . verticalOverflow = VerticalWrapMode . Truncate ;
297+ RectTransform contentRect = contentObj . GetComponent < RectTransform > ( ) ;
298+ contentRect . anchorMin = new Vector2 ( 0.5f , 1 ) ;
299+ contentRect . anchorMax = new Vector2 ( 0.5f , 1 ) ;
300+ contentRect . pivot = new Vector2 ( 0.5f , 1 ) ;
301+ contentRect . anchoredPosition = new Vector2 ( 0 , - 100 ) ;
302+ contentRect . sizeDelta = new Vector2 ( 900 , 900 ) ;
303+
304+ // accept button
305+ GameObject acceptBtnObj = new GameObject ( "AcceptButton" ) ;
306+ acceptBtnObj . transform . SetParent ( tosPanel . transform , false ) ;
307+ Image acceptBtnImage = acceptBtnObj . AddComponent < Image > ( ) ;
308+ acceptBtnImage . color = new Color ( 0.2f , 0.8f , 0.2f , 1f ) ;
309+ Button acceptBtn = acceptBtnObj . AddComponent < Button > ( ) ;
310+ acceptBtn . targetGraphic = acceptBtnImage ;
311+ RectTransform acceptBtnRect = acceptBtnObj . GetComponent < RectTransform > ( ) ;
312+ acceptBtnRect . anchorMin = new Vector2 ( 0.5f , 0 ) ;
313+ acceptBtnRect . anchorMax = new Vector2 ( 0.5f , 0 ) ;
314+ acceptBtnRect . pivot = new Vector2 ( 0.5f , 0 ) ;
315+ acceptBtnRect . anchoredPosition = new Vector2 ( 0 , 30 ) ;
316+ acceptBtnRect . sizeDelta = new Vector2 ( 250 , 60 ) ;
317+
318+ GameObject acceptTextObj = new GameObject ( "Text" ) ;
319+ acceptTextObj . transform . SetParent ( acceptBtnObj . transform , false ) ;
320+ Text acceptText = acceptTextObj . AddComponent < Text > ( ) ;
321+ acceptText . text = "ACCEPT" ;
322+ acceptText . font = Resources . GetBuiltinResource < Font > ( "Arial.ttf" ) ;
323+ acceptText . fontSize = 30 ;
324+ acceptText . fontStyle = FontStyle . Bold ;
325+ acceptText . alignment = TextAnchor . MiddleCenter ;
326+ acceptText . color = Color . white ;
327+ RectTransform acceptTextRect = acceptTextObj . GetComponent < RectTransform > ( ) ;
328+ acceptTextRect . anchorMin = Vector2 . zero ;
329+ acceptTextRect . anchorMax = Vector2 . one ;
330+ acceptTextRect . offsetMin = Vector2 . zero ;
331+ acceptTextRect . offsetMax = Vector2 . zero ;
332+
333+ acceptBtn . onClick . AddListener ( ( ) => AcceptToS ( ) ) ;
334+ }
335+
336+ public static void CheckTos ( )
337+ {
338+ if ( ! HasAcceptedToS ( ) )
339+ {
340+ CreateToSPanel ( ) ;
341+ }
342+ }
343+ #endregion
344+
202345 public static string SanitizeFileName ( string fileName )
203346 {
204347 if ( string . IsNullOrWhiteSpace ( fileName ) )
0 commit comments