@@ -67,8 +67,8 @@ public FreeCamPanel(UIBase owner) : base(owner)
6767 static InputFieldRef positionInput ;
6868 static InputFieldRef moveSpeedInput ;
6969 static Text followObjectLabel ;
70+ static Text lookAtObjectLabel ;
7071 static ButtonRef inspectButton ;
71- static ButtonRef followPlayerCarButton ;
7272 public static Toggle followRotationToggle ;
7373 static bool disabledCinemachine ;
7474
@@ -87,6 +87,8 @@ public FreeCamPanel(UIBase owner) : base(owner)
8787 public static Quaternion followObjectLastRotation = Quaternion . identity ;
8888 public static Vector3 lastKnownPosition = Vector3 . zero ;
8989
90+ public static GameObject lookAtObject = null ;
91+
9092 private static FreecamCursorUnlocker freecamCursorUnlocker = null ;
9193
9294 public static UnityIGCSConnector connector = null ;
@@ -395,11 +397,10 @@ protected override void ConstructPanelContent()
395397 UIFactory . SetLayoutElement ( releaseFollowButton . GameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
396398 releaseFollowButton . OnClick += ReleaseFollowButton_OnClick ;
397399
398- followPlayerCarButton = UIFactory . CreateButton ( ContentRoot , "FollowPlayerCarButton" , "Follow Car" ) ;
400+ var followPlayerCarButton = UIFactory . CreateButton ( ContentRoot , "FollowPlayerCarButton" , "Follow Car" ) ;
399401 UIFactory . SetLayoutElement ( followPlayerCarButton . GameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
400402 followPlayerCarButton . OnClick += FollowPlayerCar ;
401- //followPlayerCarButton.GameObject.SetActive(false);
402-
403+
403404 GameObject followRotationGameObject = UIFactory . CreateToggle ( ContentRoot , "followRotationToggle" , out followRotationToggle , out Text followRotationText ) ;
404405 UIFactory . SetLayoutElement ( followRotationGameObject , minHeight : 25 , flexibleWidth : 9999 ) ;
405406 followRotationToggle . isOn = false ;
@@ -420,6 +421,25 @@ protected override void ConstructPanelContent()
420421
421422 AddSpacer ( 5 ) ;
422423
424+ lookAtObjectLabel = UIFactory . CreateLabel ( ContentRoot , "CurrentLookAtObject" , "Not looking at any object." ) ;
425+ UIFactory . SetLayoutElement ( lookAtObjectLabel . gameObject , minWidth : 100 , minHeight : 25 ) ;
426+
427+ GameObject lookAtObjectRow = UIFactory . CreateHorizontalGroup ( ContentRoot , "LookAtObjectRow" , false , false , true , true , 3 , default , new ( 1 , 1 , 1 , 0 ) ) ;
428+
429+ ButtonRef lookAtButton = UIFactory . CreateButton ( lookAtObjectRow , "LookAtButton" , "Look at GameObject" ) ;
430+ UIFactory . SetLayoutElement ( lookAtButton . GameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
431+ lookAtButton . OnClick += LookAtButton_OnClick ;
432+
433+ ButtonRef releaseLookAtButton = UIFactory . CreateButton ( lookAtObjectRow , "ReleaseLookAtButton" , "Release Look at GameObject" ) ;
434+ UIFactory . SetLayoutElement ( releaseLookAtButton . GameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
435+ releaseLookAtButton . OnClick += ReleaseLookAtButton_OnClick ;
436+
437+ var lookAtPlayerCarButton = UIFactory . CreateButton ( ContentRoot , "LookAtPlayerCarButton" , "Look at Car" ) ;
438+ UIFactory . SetLayoutElement ( lookAtPlayerCarButton . GameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
439+ lookAtPlayerCarButton . OnClick += LookAtPlayerCar ;
440+
441+ AddSpacer ( 5 ) ;
442+
423443 string instructions = "Controls:\n " +
424444 $ "- { ConfigManager . Forwards_1 . Value } ,{ ConfigManager . Backwards_1 . Value } ,{ ConfigManager . Left_1 . Value } ,{ ConfigManager . Right_1 . Value } / { ConfigManager . Forwards_2 . Value } ,{ ConfigManager . Backwards_2 . Value } ,{ ConfigManager . Left_2 . Value } ,{ ConfigManager . Right_2 . Value } : Movement\n " +
425445 $ "- { ConfigManager . Up . Value } : Move up\n " +
@@ -546,6 +566,49 @@ void ReleaseFollowButton_OnClick()
546566 CamPathsPanel . UpdatedFollowObject ( null ) ;
547567 }
548568
569+ public static void LookAtObjectAction ( GameObject obj )
570+ {
571+ lookAtObject = obj ;
572+ lookAtObjectLabel . text = $ "Looking at: { obj . name } ";
573+ }
574+
575+ void LookAtButton_OnClick ( )
576+ {
577+ MouseInspector . Instance . StartInspect ( MouseInspectMode . World , LookAtObjectAction ) ;
578+ followRotationToggle . interactable = false ;
579+ followRotationToggle . isOn = false ;
580+ }
581+
582+ void LookAtPlayerCar ( )
583+ {
584+ try
585+ {
586+ var go = GodConstant . Instance . playerCar . gameObject ;
587+ if ( go )
588+ {
589+ LookAtObjectAction ( go ) ;
590+ }
591+ else
592+ {
593+ Debug . LogWarning ( "failed to find player car" ) ;
594+ }
595+ }
596+ catch ( Exception e )
597+ {
598+ Debug . LogError ( e . Message ) ;
599+ }
600+ }
601+
602+ void ReleaseLookAtButton_OnClick ( )
603+ {
604+ followRotationToggle . interactable = true ;
605+ if ( lookAtObject )
606+ {
607+ lookAtObject = null ;
608+ lookAtObjectLabel . text = "Not looking at any object" ;
609+ }
610+ }
611+
549612 static void SetToggleButtonState ( )
550613 {
551614 if ( inFreeCamMode )
@@ -753,6 +816,11 @@ internal void Update()
753816 FreeCamPanel . followObjectLastRotation = FreeCamPanel . followObject . transform . rotation ;
754817 }
755818
819+ if ( FreeCamPanel . lookAtObject != null && ! FreeCamPanel . cameraPathMover . playingPath )
820+ {
821+ transform . LookAt ( FreeCamPanel . lookAtObject . transform ) ;
822+ }
823+
756824 FreeCamPanel . connector ? . ExecuteCameraCommand ( transform ) ;
757825
758826 FreeCamPanel . UpdatePositionInput ( ) ;
0 commit comments