Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Fixing issue where the Object Manipulation example fails in Unity 2018.3 #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/// <summary>
/// Gets the ManipulationSystem instance.
/// </summary>
Expand All @@ -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<ManipulationSystem>();
if (manipulationSystems.Length > 0)
{
s_Instance = manipulationSystems[0];
}
else
{
Debug.LogError("No instance of ManipulationSystem exists in the scene.");
}
}

return s_Instance;
Expand All @@ -53,27 +71,57 @@ public static ManipulationSystem Instance
/// <summary>
/// Gets the Drag gesture recognizer.
/// </summary>
public DragGestureRecognizer DragGestureRecognizer { get; private set; }
public DragGestureRecognizer DragGestureRecognizer
{
get
{
return m_DragGestureRecognizer;
}
}

/// <summary>
/// Gets the Pinch gesture recognizer.
/// </summary>
public PinchGestureRecognizer PinchGestureRecognizer { get; private set; }
public PinchGestureRecognizer PinchGestureRecognizer
{
get
{
return m_PinchGestureRecognizer;
}
}

/// <summary>
/// Gets the two finger drag gesture recognizer.
/// </summary>
public TwoFingerDragGestureRecognizer TwoFingerDragGestureRecognizer { get; private set; }
public TwoFingerDragGestureRecognizer TwoFingerDragGestureRecognizer
{
get
{
return m_TwoFingerDragGestureRecognizer;
}
}

/// <summary>
/// Gets the Tap gesture recognizer.
/// </summary>
public TapGestureRecognizer TapGestureRecognizer { get; private set; }
public TapGestureRecognizer TapGestureRecognizer
{
get
{
return m_TapGestureRecognizer;
}
}

/// <summary>
/// Gets the Twist gesture recognizer.
/// </summary>
public TwistGestureRecognizer TwistGestureRecognizer { get; private set; }
public TwistGestureRecognizer TwistGestureRecognizer
{
get
{
return m_TwistGestureRecognizer;
}
}

/// <summary>
/// Gets the current selected object.
Expand All @@ -85,12 +133,16 @@ public static ManipulationSystem Instance
/// </summary>
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);
}

/// <summary>
Expand All @@ -116,7 +168,7 @@ internal void Deselect()
/// <summary>
/// Select an object.
/// </summary>
/// <param name="target">The object to select.</param>
/// <param name="target">The object to select.</param>
internal void Select(GameObject target)
{
if (SelectedObject == target)
Expand All @@ -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;
}
}
}
}