From b0262ff2cf1a7c0da51a112970bc19c922bcef56 Mon Sep 17 00:00:00 2001 From: Matt Schoen Date: Thu, 27 Aug 2020 21:22:31 -0700 Subject: [PATCH] Apply fixes from MARS Companion project--mostly fixes for null refs --- .../MultipleRayInputModule.cs | 21 ++++++++----------- .../MultipleRayInputModule/RayInputModule.cs | 5 +++-- .../Modules/SnappingModule/SnappingModule.cs | 3 +++ Runtime/Tools/TransformTool/TransformTool.cs | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Runtime/Scripts/Input/MultipleRayInputModule/MultipleRayInputModule.cs b/Runtime/Scripts/Input/MultipleRayInputModule/MultipleRayInputModule.cs index dff8a1985..700349631 100644 --- a/Runtime/Scripts/Input/MultipleRayInputModule/MultipleRayInputModule.cs +++ b/Runtime/Scripts/Input/MultipleRayInputModule/MultipleRayInputModule.cs @@ -476,6 +476,15 @@ public override void Process() var usedEvent = SendUpdateEventToSelectedObject(); + // Position the event camera to cast physics rays + if (m_EventCamera != null) + { + var eventCameraTransform = m_EventCamera.transform; + var mainCameraTransform = m_MainCamera.transform; + eventCameraTransform.position = mainCameraTransform.position; + eventCameraTransform.rotation = mainCameraTransform.rotation; + } + // case 1004066 - touch / mouse events should be processed before navigation events in case // they change the current selected gameobject and the submit button is a touch / mouse button. @@ -495,12 +504,6 @@ public override void Process() bool ProcessTouchEvents() { - // Position the event camera to cast physics rays - var eventCameraTransform = m_EventCamera.transform; - var mainCameraTransform = m_MainCamera.transform; - eventCameraTransform.position = mainCameraTransform.position; - eventCameraTransform.rotation = mainCameraTransform.rotation; - for (var i = 0; i < input.touchCount; ++i) { var touch = input.GetTouch(i); @@ -720,12 +723,6 @@ protected void ProcessMouseEvent() /// protected void ProcessMouseEvent(int id) { - // Position the event camera to cast physics rays - var eventCameraTransform = m_EventCamera.transform; - var mainCameraTransform = m_MainCamera.transform; - eventCameraTransform.position = mainCameraTransform.position; - eventCameraTransform.rotation = mainCameraTransform.rotation; - var mouseData = GetMouseRayEventData(id); var leftButtonData = mouseData.GetButtonState(PointerEventData.InputButton.Left).eventData; diff --git a/Runtime/Scripts/Input/MultipleRayInputModule/RayInputModule.cs b/Runtime/Scripts/Input/MultipleRayInputModule/RayInputModule.cs index 01159d242..b510511e9 100644 --- a/Runtime/Scripts/Input/MultipleRayInputModule/RayInputModule.cs +++ b/Runtime/Scripts/Input/MultipleRayInputModule/RayInputModule.cs @@ -55,9 +55,10 @@ abstract class RayInputModule : BaseInputModule, IUsesViewerScale // Local method use only -- created here to reduce garbage collection RayEventData m_TempRayEvent; - protected override void Awake() + + protected override void OnEnable() { - base.Awake(); + base.OnEnable(); m_TempRayEvent = new RayEventData(eventSystem); } diff --git a/Runtime/Scripts/Modules/SnappingModule/SnappingModule.cs b/Runtime/Scripts/Modules/SnappingModule/SnappingModule.cs index 5365f6e44..b523c2013 100644 --- a/Runtime/Scripts/Modules/SnappingModule/SnappingModule.cs +++ b/Runtime/Scripts/Modules/SnappingModule/SnappingModule.cs @@ -420,6 +420,9 @@ public void OnDeserializePreferences(object obj) public void OnBehaviorUpdate() { + if (m_ModuleParent == null) + return; + if (snappingEnabled) { var camera = CameraUtils.GetMainCamera(); diff --git a/Runtime/Tools/TransformTool/TransformTool.cs b/Runtime/Tools/TransformTool/TransformTool.cs index 12de9ce85..0564990e5 100644 --- a/Runtime/Tools/TransformTool/TransformTool.cs +++ b/Runtime/Tools/TransformTool/TransformTool.cs @@ -445,7 +445,7 @@ void Start() public void OnSelectionChanged() { - if (!this.IsSharedUpdater(this)) + if (!this.IsSharedUpdater(this) || !m_CurrentManipulator) return; if (Selection.gameObjects.Length == 0)