@@ -73,7 +73,7 @@ public FreeCamPanel(UIBase owner) : base(owner)
7373 public static Toggle blockGamesInputOnFreecamToggle ;
7474 static InputFieldRef positionInput ;
7575 static InputFieldRef moveSpeedInput ;
76- static Text followObjectLabel ;
76+ static Text followLookAtObjectLabel ;
7777 static ButtonRef inspectButton ;
7878 public static Toggle followRotationToggle ;
7979 static bool disabledCinemachine ;
@@ -89,6 +89,7 @@ public FreeCamPanel(UIBase owner) : base(owner)
8989 static float farClipPlaneValue ;
9090
9191 public static GameObject followObject = null ;
92+ public static GameObject lookAtObject = null ;
9293 public static Vector3 followObjectLastPosition = Vector3 . zero ;
9394 public static Quaternion followObjectLastRotation = Quaternion . identity ;
9495
@@ -472,21 +473,17 @@ protected override void ConstructPanelContent()
472473
473474 AddSpacer ( 5 ) ;
474475
475- followObjectLabel = UIFactory . CreateLabel ( ContentRoot , "CurrentFollowObject " , "Not following any object." ) ;
476- UIFactory . SetLayoutElement ( followObjectLabel . gameObject , minWidth : 100 , minHeight : 25 ) ;
476+ followLookAtObjectLabel = UIFactory . CreateLabel ( ContentRoot , "CurrentFollowLookAtObject " , "Not following/looking at any object." ) ;
477+ UIFactory . SetLayoutElement ( followLookAtObjectLabel . gameObject , minWidth : 150 , minHeight : 25 ) ;
477478
478479 GameObject followObjectRow = UIFactory . CreateHorizontalGroup ( ContentRoot , $ "FollowObjectRow", false , false , true , true , 3 , default , new ( 1 , 1 , 1 , 0 ) ) ;
479480
480481 ButtonRef followButton = UIFactory . CreateButton ( followObjectRow , "FollowButton" , "Follow GameObject" ) ;
481482 UIFactory . SetLayoutElement ( followButton . GameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
482483 followButton . OnClick += FollowButton_OnClick ;
483484
484- ButtonRef releaseFollowButton = UIFactory . CreateButton ( followObjectRow , "ReleaseFollowButton" , "Release Follow GameObject" ) ;
485- UIFactory . SetLayoutElement ( releaseFollowButton . GameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
486- releaseFollowButton . OnClick += ReleaseFollowButton_OnClick ;
487-
488- GameObject followRotationGameObject = UIFactory . CreateToggle ( ContentRoot , "followRotationToggle" , out followRotationToggle , out Text followRotationText ) ;
489- UIFactory . SetLayoutElement ( followRotationGameObject , minHeight : 25 , flexibleWidth : 9999 ) ;
485+ GameObject followRotationGameObject = UIFactory . CreateToggle ( followObjectRow , "followRotationToggle" , out followRotationToggle , out Text followRotationText ) ;
486+ UIFactory . SetLayoutElement ( followRotationGameObject , minWidth : 150 , minHeight : 25 , flexibleWidth : 9999 ) ;
490487 followRotationToggle . isOn = false ;
491488 followRotationText . text = "Follow Object Rotation" ;
492489 followRotationToggle . onValueChanged . AddListener ( ( value ) => {
@@ -503,6 +500,16 @@ protected override void ConstructPanelContent()
503500 }
504501 } ) ;
505502
503+ GameObject lookAtObjectRow = UIFactory . CreateHorizontalGroup ( ContentRoot , $ "LookAtObjectRow", false , false , true , true , 3 , default , new ( 1 , 1 , 1 , 0 ) ) ;
504+
505+ ButtonRef lookAtButton = UIFactory . CreateButton ( lookAtObjectRow , "LookAtButton" , "Look At GameObject" ) ;
506+ UIFactory . SetLayoutElement ( lookAtButton . GameObject , minWidth : 140 , minHeight : 25 , flexibleWidth : 9999 ) ;
507+ lookAtButton . OnClick += LookAtButton_OnClick ;
508+
509+ ButtonRef releaseFollowLookAtButton = UIFactory . CreateButton ( lookAtObjectRow , "ReleaseFollowLookAtButton" , "Release Follow/Look At" ) ;
510+ UIFactory . SetLayoutElement ( releaseFollowLookAtButton . GameObject , minWidth : 160 , minHeight : 25 , flexibleWidth : 9999 ) ;
511+ releaseFollowLookAtButton . OnClick += ReleaseFollowLookAtButton_OnClick ;
512+
506513 AddSpacer ( 5 ) ;
507514
508515 string instructions = "Controls:\n " +
@@ -573,6 +580,8 @@ public static void StartStopButton_OnClick()
573580 }
574581
575582 public static void FollowObjectAction ( GameObject obj ) {
583+ ReleaseFollowLookAtButton_OnClick ( ) ;
584+
576585 CamPaths CamPathsPanel = UIManager . GetPanel < CamPaths > ( UIManager . Panels . CamPaths ) ;
577586
578587 if ( followObject != null ) {
@@ -582,7 +591,7 @@ public static void FollowObjectAction(GameObject obj){
582591 followObject = obj ;
583592 followObjectLastPosition = followObject . transform . position ;
584593 followObjectLastRotation = followObject . transform . rotation ;
585- followObjectLabel . text = $ "Following: { obj . name } ";
594+ followLookAtObjectLabel . text = $ "Following: { obj . name } ";
586595
587596 CamPathsPanel . UpdatedFollowObject ( obj ) ;
588597
@@ -596,19 +605,30 @@ void FollowButton_OnClick()
596605 MouseInspector . Instance . StartInspect ( MouseInspectMode . World , FollowObjectAction ) ;
597606 }
598607
599- void ReleaseFollowButton_OnClick ( )
608+ public static void LookAtObjectAction ( GameObject obj ) {
609+ ReleaseFollowLookAtButton_OnClick ( ) ;
610+ lookAtObject = obj ;
611+ followLookAtObjectLabel . text = $ "Looking at: { obj . name } ";
612+ }
613+
614+ void LookAtButton_OnClick ( )
600615 {
601- if ( followObject ) {
602- followObject = null ;
603- followObjectLastPosition = Vector3 . zero ;
604- followObjectLastRotation = Quaternion . identity ;
605- followObjectLabel . text = "Not following any object" ;
606- }
607- CamPaths CamPathsPanel = UIManager . GetPanel < CamPaths > ( UIManager . Panels . CamPaths ) ;
616+ MouseInspector . Instance . StartInspect ( MouseInspectMode . World , LookAtObjectAction ) ;
617+ }
608618
609- CamPathsPanel . TranslatePointsToGlobal ( followRotationToggle . isOn ) ;
619+ static void ReleaseFollowLookAtButton_OnClick ( )
620+ {
621+ if ( followObject != null ) {
622+ CamPaths CamPathsPanel = UIManager . GetPanel < CamPaths > ( UIManager . Panels . CamPaths ) ;
623+ CamPathsPanel . TranslatePointsToGlobal ( followRotationToggle . isOn ) ;
624+ CamPathsPanel . UpdatedFollowObject ( null ) ;
625+ }
610626
611- CamPathsPanel . UpdatedFollowObject ( null ) ;
627+ lookAtObject = null ;
628+ followObject = null ;
629+ followObjectLastPosition = Vector3 . zero ;
630+ followObjectLastRotation = Quaternion . identity ;
631+ followLookAtObjectLabel . text = "Not following/looking at any object" ;
612632 }
613633
614634 static void SetToggleButtonState ( )
@@ -765,6 +785,9 @@ public static void SetCameraPosition(Vector3 newPosition, bool isAbsolute = fals
765785
766786 public static void SetCameraRotation ( Quaternion newRotation , bool isAbsolute = false ) {
767787 Camera freecam = GetFreecam ( ) ;
788+ if ( lookAtObject ) {
789+ return ;
790+ }
768791 if ( isAbsolute ) {
769792 freecam . transform . rotation = newRotation ;
770793 }
@@ -832,6 +855,11 @@ internal void Update()
832855 FreeCamPanel . connector ? . ExecuteCameraCommand ( FreeCamPanel . GetFreecam ( ) ) ;
833856
834857 FreeCamPanel . UpdatePositionInput ( ) ;
858+
859+ if ( FreeCamPanel . lookAtObject != null )
860+ {
861+ movingTransform . LookAt ( FreeCamPanel . lookAtObject . transform ) ;
862+ }
835863 }
836864 }
837865
0 commit comments