@@ -8,6 +8,8 @@ namespace CandyCoded.ARFoundationComponents
88{
99
1010 [ RequireComponent ( typeof ( ARSessionOrigin ) ) ]
11+ [ RequireComponent ( typeof ( ARRaycastManager ) ) ]
12+ [ RequireComponent ( typeof ( ARPlaneManager ) ) ]
1113 [ HelpURL (
1214 "https://github.com/CandyCoded/ARFoundation-Components/blob/master/Documentation/ARShowPlacementMarkerOnPlane.md" ) ]
1315 public class ARShowPlacementMarkerOnPlane : MonoBehaviour
@@ -39,12 +41,47 @@ public GameObject placementMarker
3941
4042 private GameObject _placementMarkerGameObject ;
4143
42- public Camera mainCamera { get ; private set ; }
44+ private ARRaycastManager _raycastManager ;
45+
46+ private ARPlaneManager _planeManager ;
47+
48+ private Camera _mainCamera ;
4349
4450 private void Awake ( )
4551 {
4652
47- mainCamera = gameObject . GetComponent < ARSessionOrigin > ( ) . camera ;
53+ _raycastManager = gameObject . GetComponent < ARRaycastManager > ( ) ;
54+ _planeManager = gameObject . GetComponent < ARPlaneManager > ( ) ;
55+
56+ _mainCamera = gameObject . GetComponent < ARSessionOrigin > ( ) . camera ;
57+
58+ }
59+
60+ private void Start ( )
61+ {
62+
63+ if ( ARSession . state == ARSessionState . None ||
64+ ARSession . state == ARSessionState . Unsupported )
65+ {
66+
67+ enabled = false ;
68+
69+ }
70+
71+ }
72+
73+ private void Update ( )
74+ {
75+
76+ if ( ! _planeManager . enabled )
77+ {
78+ return ;
79+ }
80+
81+ var planeVisible = ARFoundationExtensions . IsLookingAtPlane ( _raycastManager , _planeManager ,
82+ out var lookingAtPose , out var lookingAtPlane ) ;
83+
84+ ShowPlacementMarkerOnPlane ( planeVisible , lookingAtPose , lookingAtPlane ) ;
4885
4986 }
5087
@@ -67,7 +104,7 @@ public void ShowPlacementMarkerOnPlane(bool planeVisible, Pose pose, ARPlane pla
67104 return ;
68105 }
69106
70- var cameraPosition = mainCamera . transform . position ;
107+ var cameraPosition = _mainCamera . transform . position ;
71108
72109 _placementMarkerGameObject . transform . LookAt ( new Vector3 (
73110 cameraPosition . x ,
0 commit comments