diff --git a/Assets/GoogleARCore/Examples/ObjectManipulation/Scripts/ManipulationSystem.cs b/Assets/GoogleARCore/Examples/ObjectManipulation/Scripts/ManipulationSystem.cs index ce3cd7f7..7929c08b 100644 --- a/Assets/GoogleARCore/Examples/ObjectManipulation/Scripts/ManipulationSystem.cs +++ b/Assets/GoogleARCore/Examples/ObjectManipulation/Scripts/ManipulationSystem.cs @@ -34,6 +34,16 @@ public class ManipulationSystem : MonoBehaviour { private static ManipulationSystem s_Instance = null; + private DragGestureRecognizer m_DragGestureRecognizer = new DragGestureRecognizer(); + + private PinchGestureRecognizer m_PinchGestureRecognizer = new PinchGestureRecognizer(); + + private TwoFingerDragGestureRecognizer m_TwoFingerDragGestureRecognizer = new TwoFingerDragGestureRecognizer(); + + private TapGestureRecognizer m_TapGestureRecognizer = new TapGestureRecognizer(); + + private TwistGestureRecognizer m_TwistGestureRecognizer = new TwistGestureRecognizer(); + /// /// Gets the ManipulationSystem instance. /// @@ -43,7 +53,15 @@ public static ManipulationSystem Instance { if (s_Instance == null) { - Debug.LogError("No instance of ManipulationSystem exists in the scene."); + var manipulationSystems = FindObjectsOfType(); + if (manipulationSystems.Length > 0) + { + s_Instance = manipulationSystems[0]; + } + else + { + Debug.LogError("No instance of ManipulationSystem exists in the scene."); + } } return s_Instance; @@ -53,27 +71,57 @@ public static ManipulationSystem Instance /// /// Gets the Drag gesture recognizer. /// - public DragGestureRecognizer DragGestureRecognizer { get; private set; } + public DragGestureRecognizer DragGestureRecognizer + { + get + { + return m_DragGestureRecognizer; + } + } /// /// Gets the Pinch gesture recognizer. /// - public PinchGestureRecognizer PinchGestureRecognizer { get; private set; } + public PinchGestureRecognizer PinchGestureRecognizer + { + get + { + return m_PinchGestureRecognizer; + } + } /// /// Gets the two finger drag gesture recognizer. /// - public TwoFingerDragGestureRecognizer TwoFingerDragGestureRecognizer { get; private set; } + public TwoFingerDragGestureRecognizer TwoFingerDragGestureRecognizer + { + get + { + return m_TwoFingerDragGestureRecognizer; + } + } /// /// Gets the Tap gesture recognizer. /// - public TapGestureRecognizer TapGestureRecognizer { get; private set; } + public TapGestureRecognizer TapGestureRecognizer + { + get + { + return m_TapGestureRecognizer; + } + } /// /// Gets the Twist gesture recognizer. /// - public TwistGestureRecognizer TwistGestureRecognizer { get; private set; } + public TwistGestureRecognizer TwistGestureRecognizer + { + get + { + return m_TwistGestureRecognizer; + } + } /// /// Gets the current selected object. @@ -85,12 +133,16 @@ public static ManipulationSystem Instance /// public void Awake() { - _InitializeSingleton(); - DragGestureRecognizer = new DragGestureRecognizer(); - PinchGestureRecognizer = new PinchGestureRecognizer(); - TwoFingerDragGestureRecognizer = new TwoFingerDragGestureRecognizer(); - TapGestureRecognizer = new TapGestureRecognizer(); - TwistGestureRecognizer = new TwistGestureRecognizer(); + if (Instance != this) + { + Debug.LogWarning("Multiple instances of ManipulationSystem detected in the scene." + + " Only one instance can exist at a time. The duplicate instances" + + " will be destroyed."); + DestroyImmediate(gameObject); + return; + } + + DontDestroyOnLoad(gameObject); } /// @@ -116,7 +168,7 @@ internal void Deselect() /// /// Select an object. /// - /// The object to select. + /// The object to select. internal void Select(GameObject target) { if (SelectedObject == target) @@ -127,22 +179,5 @@ internal void Select(GameObject target) Deselect(); SelectedObject = target; } - - private void _InitializeSingleton() - { - if (s_Instance == null) - { - s_Instance = this; - DontDestroyOnLoad(gameObject); - } - else if (Instance != this) - { - Debug.LogWarning("Multiple instances of ManipulationSystem detected in the scene." + - " Only one instance can exist at a time. The duplicate instances" + - " will be destroyed."); - DestroyImmediate(gameObject); - return; - } - } } }