22using System . Collections . Generic ;
33using System . IO ;
44using System . Reflection ;
5+ using System . Text ;
56using TMPro ;
67using UnityEngine ;
78using UnityEngine . SceneManagement ;
@@ -25,28 +26,31 @@ public NPCCache(string npc, TextAsset asset)
2526
2627 static GameObject OverlayCanvas = null ;
2728 static GameObject _textPanel ;
29+ static TextMeshProUGUI textComp ;
2830 static CanvasUtil . RectData topRight = new CanvasUtil . RectData ( new Vector2 ( 0 , 0 ) , new Vector2 ( 0 , 0 ) ,
2931 new Vector2 ( 0.89f , 0.80f ) , new Vector2 ( 0.99f , .96f ) , new Vector2 ( 0 , 0 ) ) ;
3032
3133 PlayerMachine PlayerMachine = null ;
3234 BossController bossController = null ;
33- bool _enabled = false ;
35+
3436
3537 // Cached objects
3638 List < NPCCache > dialogueCache = new List < NPCCache > ( 10 ) ;
3739 GameObjectCache < VoidOut > collPlaneCache = new GameObjectCache < VoidOut > ( ) ;
3840 GameObjectCache < TalkVolume > tvRadiusCache = new GameObjectCache < TalkVolume > ( ) ;
3941 Dictionary < string , Texture2D > modTextures = new Dictionary < string , Texture2D > ( 2 ) ;
42+ StringBuilder textBuilder = new StringBuilder ( 500 ) ;
4043
4144 // Warp cam related
4245 Camera warpCam = null ;
46+ Vector3 warpSimPos = Vector3 . zero ;
4347 float yaw = 0f ;
4448 float pitch = 0f ;
4549
4650 // Noclip mode
4751 LayerMask origMask ;
4852 float origGrav ;
49- public static bool NoClipActive = false ;
53+ public static bool NoClipActive { get ; private set ; } = false ;
5054
5155 // UI constants
5256 static readonly string [ ] costumeNames = { "Noid" , "Green" , "Sanic" , "Cappy" } ;
@@ -58,11 +62,13 @@ public NPCCache(string npc, TextAsset asset)
5862 int currentNpcIdx = 0 ;
5963 int currentLvlIdx = 0 ;
6064 float deltaTime = 0f ;
65+
66+ bool _enabled = false ;
6167 bool _visible = false ;
68+
6269 bool deathPlaneStatus = true ;
6370 bool collisionRenderFlag = false ;
6471 bool talkVolumeRenderFlag = false ;
65- Vector3 warpSimPos = new Vector3 ( 0f , 0f , 0f ) ;
6672
6773 public void Awake ( )
6874 {
@@ -78,6 +84,7 @@ public void Awake()
7884 _textPanel = CanvasUtil . CreateTMProPanel ( _background , string . Empty , 20 ,
7985 TextAnchor . UpperLeft ,
8086 new CanvasUtil . RectData ( new Vector2 ( - 5 , - 5 ) , new Vector2 ( 0 , 0 ) , new Vector2 ( 0 , 0 ) , new Vector2 ( 1 , 1 ) ) ) ;
87+ textComp = _textPanel . GetComponent < TextMeshProUGUI > ( ) ;
8188 }
8289
8390 foreach ( string fn in Assembly . GetExecutingAssembly ( ) . GetManifestResourceNames ( ) )
@@ -247,18 +254,20 @@ private void SetupNoClip(bool toggle)
247254
248255 }
249256
257+ string OnOffStr ( bool val ) => val ? "ON" : "OFF" ;
258+
250259 public void Update ( )
251260 {
252261 if ( Input . GetKeyDown ( KeyCode . F11 ) )
253262 {
254263 _visible = ! _visible ;
264+ var cg = OverlayCanvas . GetComponent < CanvasGroup > ( ) ;
255265 StartCoroutine ( _visible
256- ? CanvasUtil . FadeInCanvasGroup ( OverlayCanvas . GetComponent < CanvasGroup > ( ) )
257- : CanvasUtil . FadeOutCanvasGroup ( OverlayCanvas . GetComponent < CanvasGroup > ( ) ) ) ;
266+ ? CanvasUtil . FadeInCanvasGroup ( cg )
267+ : CanvasUtil . FadeOutCanvasGroup ( cg ) ) ;
258268 }
259269
260- var t = _textPanel . GetComponent < TextMeshProUGUI > ( ) ;
261- t . text = "" ;
270+ textComp . text = "" ;
262271
263272 if ( ! _enabled || ! _visible || PlayerMachine == null )
264273 {
@@ -319,14 +328,8 @@ public void Update()
319328
320329 if ( Input . GetKeyDown ( KeyCode . F6 ) || Input . GetKeyDown ( KeyCode . Keypad6 ) )
321330 {
322- if ( QualitySettings . vSyncCount == 2 )
323- {
324- QualitySettings . vSyncCount = 0 ;
325- }
326- else
327- {
328- QualitySettings . vSyncCount ++ ;
329- }
331+ ++ QualitySettings . vSyncCount ;
332+ QualitySettings . vSyncCount %= 3 ;
330333 }
331334
332335 bool inVoid = SceneManager . GetActiveScene ( ) . name == "void" ;
@@ -335,7 +338,7 @@ public void Update()
335338 var pizza = FindObjectOfType < PizzaBox > ( ) ;
336339 if ( pizza == null )
337340 {
338- Logger . LogDebug ( "No PizzaBox!" ) ;
341+ Logger . LogError ( "No PizzaBox!" ) ;
339342 }
340343 else
341344 {
@@ -344,15 +347,15 @@ public void Update()
344347 GameObject . Find ( "Global Manager" ) . GetComponent < Manager > ( ) . LoadScene ( level , pizza . ExitId , pizza . gameObject ) ;
345348 }
346349 }
347- else if ( Input . GetKeyDown ( KeyCode . L ) )
350+ else if ( inVoid && Input . GetKeyDown ( KeyCode . L ) )
348351 {
349352 do
350353 {
351354 currentLvlIdx = ( currentLvlIdx + 1 ) % levelNames . Length ;
352355 } while ( levelNames [ currentLvlIdx ] == SceneManager . GetActiveScene ( ) . name ) ;
353356 }
354357
355- if ( Input . GetKeyDown ( KeyCode . K ) )
358+ if ( ! inVoid && Input . GetKeyDown ( KeyCode . K ) )
356359 {
357360 var key = FindObjectsOfType < Key > ( ) ;
358361 foreach ( var k in key )
@@ -451,7 +454,7 @@ public void Update()
451454 }
452455 }
453456
454- if ( Input . GetKeyDown ( KeyCode . F8 ) )
457+ if ( Input . GetKeyDown ( KeyCode . F8 ) || Input . GetKeyDown ( KeyCode . Keypad8 ) )
455458 {
456459 foreach ( var e in FindObjectsOfType < HiddenPlatform > ( ) )
457460 {
@@ -462,43 +465,50 @@ public void Update()
462465 deltaTime += ( Time . unscaledDeltaTime - deltaTime ) * 0.1f ;
463466 bool ? b = PlayerMachine . CoyoteFrameEnabled ;
464467
465- t . text += "FPS: " + 1f / deltaTime + "\n " ;
466- t . text += "<F1>: Coyote Frames: " + ( b . HasValue ? ( b . Value ? "ON" : "OFF" ) : "Default" ) + "\n " ;
467- t . text += "<F2><[]>: Set Costume: " + costumeNames [ currentCostIdx ] + "\n " ;
468- if ( dialogueCache . Count > 0 ) t . text += "<F3><,.>: Dialogue: " + dialogueCache [ currentNpcIdx ] . NpcName + "\n " ;
469- t . text += "<F4>: Time Scale: x" + Time . timeScale . ToString ( "F2" ) + "\n " ;
470- t . text += "<F5>: Text Storage/Warp\n " ;
471- t . text += "<F6>: VSync Count :" + QualitySettings . vSyncCount + "\n " ;
472- t . text += "<F7><L>: Level Load: " + ( ! inVoid ? "void" : levelNames [ currentLvlIdx ] ) + "\n " ;
473- t . text += "<F8>: Reset Camera Events\n " ;
474- t . text += "<K>: Get All Keys\n " ;
475- t . text += "<V>: Render Death Planes: " + ( collisionRenderFlag ? "ON" : "OFF" ) + "\n " ;
476- t . text += "<M>: Active Death Planes: " + ( deathPlaneStatus ? "ON" : "OFF" ) + "\n " ;
477- t . text += "<G>: Show NPC Talk Zone: " + ( talkVolumeRenderFlag ? "ON" : "OFF" ) + "\n " ;
478- t . text += "<R><noparse><B></noparse>: Warp Cam Move/Toggle \n " ;
479- t . text += "<N>: Set Obj Transparent\n " ;
480- t . text += "<T>: NoClip: " + ( NoClipActive ? "ON" : "OFF" ) + "\n " ;
481- t . text += "<F11> Toggle UI\n \n " ;
482- t . text += "Move Dir:" + PlayerMachine . moveDirection . ToString ( ) + "\n " ;
483- t . text += "Pos:" + PlayerMachine . transform . position + "\n " ;
484- t . text += "SpawnPos:" + PlayerMachine . LastGroundLoc . ToString ( ) + "\n " ;
485- t . text += "Look Dir:" + PlayerMachine . lookDirection . ToString ( ) + "\n " ;
486- t . text += "Player State:" + PlayerMachine . currentState . ToString ( ) + "\n " ;
468+ textBuilder . Length = 0 ;
469+ textBuilder . AppendFormat ( "FPS: {0:F3}\n " , 1f / deltaTime ) ;
470+ textBuilder . AppendFormat ( "<F1>: Coyote Frames: {0}\n " , b . HasValue ? OnOffStr ( b . Value ) : "Default" ) ;
471+ textBuilder . Append ( "<F2><[]>: Set Costume: " ) . AppendLine ( costumeNames [ currentCostIdx ] ) ;
472+ textBuilder . AppendFormat ( "<F3><,.>: Dialogue: " ) . AppendLine ( dialogueCache [ currentNpcIdx ] . NpcName ) ;
473+ textBuilder . Append ( "<F4>: Time Scale: x" ) . AppendLine ( Time . timeScale . ToString ( "F2" ) ) ;
474+ textBuilder . Append ( "<F5>: Text Storage/Warp\n " ) ;
475+ textBuilder . AppendFormat ( "<F6>: VSync Count :{0}\n " , QualitySettings . vSyncCount ) ;
476+ textBuilder . AppendFormat ( "<F7><L>: Level Load: {0}\n " , ! inVoid ? "void" : levelNames [ currentLvlIdx ] ) ;
477+ textBuilder . Append ( "<F8>: Reset Camera Events\n " ) ;
478+ textBuilder . Append ( "<K>: Get All Keys\n " ) ;
479+ textBuilder . Append ( "<V>: Render Death Planes: " ) . AppendLine ( OnOffStr ( collisionRenderFlag ) ) ;
480+ textBuilder . Append ( "<M>: Active Death Planes: " ) . AppendLine ( OnOffStr ( deathPlaneStatus ) ) ;
481+ textBuilder . Append ( "<G>: Show NPC Talk Zone: " ) . AppendLine ( OnOffStr ( talkVolumeRenderFlag ) ) ;
482+ textBuilder . Append ( "<R><noparse><B></noparse>: Warp Cam Move/Toggle\n " ) ;
483+ textBuilder . Append ( "<N>: Set Obj Transparent\n " ) ;
484+ textBuilder . Append ( "<T>: NoClip: " ) . AppendLine ( OnOffStr ( NoClipActive ) ) ;
485+ textBuilder . Append ( "<F11> Toggle UI\n " ) . AppendLine ( ) ;
486+
487+ textBuilder . Append ( "Move Dir:" ) . AppendLine ( PlayerMachine . moveDirection . ToString ( ) ) ;
488+ textBuilder . Append ( "Pos:" ) . AppendLine ( PlayerMachine . transform . position . ToString ( ) ) ;
489+ textBuilder . Append ( "SpawnPos:" ) . AppendLine ( PlayerMachine . LastGroundLoc . ToString ( ) ) ;
490+ textBuilder . Append ( "Look Dir:" ) . AppendLine ( PlayerMachine . lookDirection . ToString ( ) ) ;
491+ textBuilder . Append ( "Player State:" ) . AppendLine ( PlayerMachine . currentState . ToString ( ) ) ;
487492
488493 if ( bossController )
489494 {
490- t . text += "\n Boss Health: " + bossController . Health + "\n " ;
491- t . text += "Boss State: " + bossStates [ ( int ) BossController . State ] + "\n " ;
495+ textBuilder . AppendLine ( ) ;
496+ textBuilder . Append ( "Boss Health: " ) . AppendLine ( bossController . Health . ToString ( ) ) ;
497+ textBuilder . Append ( "Boss State: " ) . AppendLine ( bossStates [ ( int ) BossController . State ] ) ;
492498 }
493499 if ( warpCam . enabled )
494500 {
495- t . text += "\n LGP:" + PlayerMachine . controller . LastGroundPos . ToString ( ) + "\n " ;
496- t . text += "LGO:" + PlayerMachine . controller . LastGroundOffset . ToString ( ) + "\n " ;
497- t . text += "LGR:" + PlayerMachine . controller . LastGroundRot . ToString ( ) + "\n " ;
498- t . text += "CG:" + PlayerMachine . controller . currentGround . transform . position . ToString ( ) + "\n " ;
499- t . text += "CR:" + PlayerMachine . controller . currentGround . transform . rotation . ToString ( ) + "\n " ;
500- t . text += "Warp Pos:" + warpSimPos . ToString ( ) + "\n " ;
501+ textBuilder . AppendLine ( ) ;
502+ textBuilder . Append ( "LGP:" ) . AppendLine ( PlayerMachine . controller . LastGroundPos . ToString ( ) ) ;
503+ textBuilder . Append ( "LGO:" ) . AppendLine ( PlayerMachine . controller . LastGroundOffset . ToString ( ) ) ;
504+ textBuilder . Append ( "LGR:" ) . AppendLine ( PlayerMachine . controller . LastGroundRot . ToString ( ) ) ;
505+ textBuilder . Append ( "CG:" ) . AppendLine ( PlayerMachine . controller . currentGround . transform . position . ToString ( ) ) ;
506+ textBuilder . Append ( "CR:" ) . AppendLine ( PlayerMachine . controller . currentGround . transform . rotation . ToString ( ) ) ;
507+ textBuilder . Append ( "Warp Pos:" ) . AppendLine ( warpSimPos . ToString ( ) ) ;
508+
501509 }
510+
511+ textComp . SetText ( textBuilder ) ;
502512 }
503513 }
504514}
0 commit comments