Skip to content

Commit 96c64ac

Browse files
committed
Merge branch 'staging'
2 parents 32e4971 + 396f901 commit 96c64ac

File tree

13 files changed

+244
-67
lines changed

13 files changed

+244
-67
lines changed

Scripts/Core/EditorVR.MiniWorlds.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,17 @@ internal void UpdateMiniWorlds(ConsumeControlDelegate consumeControl)
324324
}
325325

326326
// Drop from TransformTool to take control of object
327-
if (directSelection != null)
327+
objectsGrabber.DropHeldObjects(miniWorldRayOrigin, out positionOffsets, out rotationOffsets);
328+
foreach (var kvp in m_Rays)
328329
{
329-
objectsGrabber.DropHeldObjects(miniWorldRayOrigin, out positionOffsets, out rotationOffsets);
330-
miniWorldRay.originalPositionOffsets = positionOffsets;
331-
miniWorldRay.originalRotationOffsets = rotationOffsets;
332-
miniWorldRay.wasHeld = true;
330+
var otherRay = kvp.Value;
331+
if (otherRay.originalRayOrigin == miniWorldRay.originalRayOrigin)
332+
{
333+
otherRay.originalPositionOffsets = positionOffsets;
334+
otherRay.originalRotationOffsets = rotationOffsets;
335+
otherRay.originalScales = originalScales;
336+
otherRay.wasHeld = true;
337+
}
333338
}
334339
}
335340
}

Scripts/Core/EditorVR.Rays.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public void ConnectInterface(object obj, Transform rayOrigin = null)
8080
}
8181
}
8282
}
83+
84+
var selectionModule = obj as SelectionModule;
85+
if (selectionModule)
86+
{
87+
selectionModule.selected += SetLastSelectionRayOrigin; // when a selection occurs in the selection tool, call show in the alternate menu, allowing it to show/hide itself.
88+
selectionModule.getGroupRoot = GetGroupRoot;
89+
selectionModule.overrideSelectObject = OverrideSelectObject;
90+
}
8391
}
8492

8593
public void DisconnectInterface(object obj)
@@ -102,11 +110,27 @@ internal static void UpdateRayForDevice(DeviceData deviceData, Transform rayOrig
102110
}
103111
}
104112

105-
internal void SetLastSelectionRayOrigin(Transform rayOrigin)
113+
void SetLastSelectionRayOrigin(Transform rayOrigin)
106114
{
107115
lastSelectionRayOrigin = rayOrigin;
108116
}
109117

118+
static GameObject GetGroupRoot(GameObject hoveredObject)
119+
{
120+
if (!hoveredObject)
121+
return null;
122+
123+
var groupRoot = PrefabUtility.FindPrefabRoot(hoveredObject);
124+
125+
return groupRoot;
126+
}
127+
128+
static bool OverrideSelectObject(GameObject hoveredObject)
129+
{
130+
// The player head can hovered, but not selected (only directly manipulated)
131+
return hoveredObject && hoveredObject.CompareTag(k_VRPlayerTag);
132+
}
133+
110134
internal void CreateAllProxies()
111135
{
112136
var deviceInputModule = evr.m_DeviceInputModule;

Scripts/Core/EditorVR.Tools.cs

+8-7
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ internal void SpawnDefaultTools(IProxy proxy)
8787
continue;
8888

8989
HashSet<InputDevice> devices;
90-
var toolData = SpawnTool(typeof(SelectionTool), out devices, inputDevice);
90+
91+
var toolData = SpawnTool(typeof(TransformTool), out devices, inputDevice);
92+
AddToolToDeviceData(toolData, devices);
93+
var transformTool = (TransformTool)toolData.tool;
94+
if (transformTool.IsSharedUpdater(transformTool))
95+
evr.m_DirectSelection.objectsGrabber = transformTool;
96+
97+
toolData = SpawnTool(typeof(SelectionTool), out devices, inputDevice);
9198
AddToolToDeviceData(toolData, devices);
9299
var selectionTool = (SelectionTool)toolData.tool;
93100
selectionTool.hovered += lockModule.OnHovered;
@@ -103,12 +110,6 @@ internal void SpawnDefaultTools(IProxy proxy)
103110
toolData = SpawnTool(typeof(MoveWorkspacesTool), out devices, inputDevice);
104111
AddToolToDeviceData(toolData, devices);
105112

106-
toolData = SpawnTool(typeof(TransformTool), out devices, inputDevice);
107-
AddToolToDeviceData(toolData, devices);
108-
var transformTool = (TransformTool)toolData.tool;
109-
if (transformTool.IsSharedUpdater(transformTool))
110-
evr.m_DirectSelection.objectsGrabber = transformTool;
111-
112113
toolData = SpawnTool(typeof(BlinkLocomotionTool), out devices, inputDevice);
113114
AddToolToDeviceData(toolData, devices);
114115

Scripts/Core/EditorVR.cs

+1-13
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ void Awake()
162162
var lockModule = AddModule<LockModule>();
163163
lockModule.updateAlternateMenu = (rayOrigin, o) => m_Menus.SetAlternateMenuVisibility(rayOrigin, o != null);
164164

165-
var selectionModule = AddModule<SelectionModule>();
166-
selectionModule.selected += m_Rays.SetLastSelectionRayOrigin; // when a selection occurs in the selection tool, call show in the alternate menu, allowing it to show/hide itself.
167-
selectionModule.getGroupRoot = GetGroupRoot;
165+
AddModule<SelectionModule>();
168166

169167
var spatialHashModule = AddModule<SpatialHashModule>();
170168
spatialHashModule.shouldExcludeObject = go => go.GetComponentInParent<EditorVR>();
@@ -445,16 +443,6 @@ void LateBindNestedModules(IEnumerable<Type> types)
445443
}
446444
}
447445

448-
static GameObject GetGroupRoot(GameObject hoveredObject)
449-
{
450-
if (!hoveredObject)
451-
return null;
452-
453-
var groupRoot = PrefabUtility.FindPrefabRoot(hoveredObject);
454-
455-
return groupRoot;
456-
}
457-
458446
static EditorVR s_Instance;
459447
static InputManager s_InputManager;
460448

Scripts/Modules/LockModule/LockModule.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ void Awake()
4747

4848
public bool IsLocked(GameObject go)
4949
{
50-
return go && (go.hideFlags & HideFlags.NotEditable) != 0;
50+
if (!go)
51+
return false;
52+
53+
// EditorVR objects (i.e. PlayerHead) may get HideAndDontSave, which includes NotEditable, but should not count as locked
54+
if (go.transform.IsChildOf(transform))
55+
return false;
56+
57+
return (go.hideFlags & HideFlags.NotEditable) != 0;
5158
}
5259

5360
bool ToggleLocked()

Scripts/Modules/SelectionModule.cs

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sealed class SelectionModule : MonoBehaviour, IUsesGameObjectLocking, ISelection
1212
readonly List<Object> m_SelectedObjects = new List<Object>(); // Keep the list to avoid allocations--we do not use it to maintain state
1313

1414
public Func<GameObject, GameObject> getGroupRoot { private get; set; }
15+
public Func<GameObject, bool> overrideSelectObject { private get; set; }
1516

1617
public event Action<Transform> selected;
1718

@@ -49,6 +50,9 @@ bool CanSelectObject(GameObject hoveredObject, bool useGrouping)
4950

5051
public void SelectObject(GameObject hoveredObject, Transform rayOrigin, bool multiSelect, bool useGrouping = false)
5152
{
53+
if (overrideSelectObject(hoveredObject))
54+
return;
55+
5256
var selection = GetSelectionCandidate(hoveredObject, useGrouping);
5357

5458
var groupRoot = getGroupRoot(hoveredObject);

Scripts/Modules/SnappingModule/SnappingModule.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -725,40 +725,40 @@ void SetupUI()
725725
handle.hoverEnded += (baseHandle, data) => { text.text = m_Preferences.disableAll ? "Snapping disabled" : "Snapping enabled"; };
726726

727727
var groundSnappingUI = m_SnappingModuleSettingsUI.groundSnappingEnabled;
728-
groundSnappingUI.isOn = groundSnappingEnabled;
728+
groundSnappingUI.isOn = m_Preferences.groundSnappingEnabled;
729729
groundSnappingUI.onValueChanged.AddListener(b =>
730730
{
731-
groundSnappingEnabled = groundSnappingUI.isOn;
731+
m_Preferences.groundSnappingEnabled = groundSnappingUI.isOn;
732732
Reset();
733733
});
734734

735735
var surfaceSnappingUI = m_SnappingModuleSettingsUI.surfaceSnappingEnabled;
736-
surfaceSnappingUI.isOn = surfaceSnappingEnabled;
736+
surfaceSnappingUI.isOn = m_Preferences.surfaceSnappingEnabled;
737737
surfaceSnappingUI.onValueChanged.AddListener(b =>
738738
{
739-
surfaceSnappingEnabled = surfaceSnappingUI.isOn;
739+
m_Preferences.surfaceSnappingEnabled = surfaceSnappingUI.isOn;
740740
Reset();
741741
});
742742

743743
var pivotSnappingUI = m_SnappingModuleSettingsUI.pivotSnappingEnabled;
744-
m_SnappingModuleSettingsUI.SetToggleValue(pivotSnappingUI, pivotSnappingEnabled);
744+
m_SnappingModuleSettingsUI.SetToggleValue(pivotSnappingUI, m_Preferences.pivotSnappingEnabled);
745745
pivotSnappingUI.onValueChanged.AddListener(b => { m_Preferences.pivotSnappingEnabled = pivotSnappingUI.isOn; });
746746

747747
var snapRotationUI = m_SnappingModuleSettingsUI.rotationSnappingEnabled;
748-
snapRotationUI.isOn = directSnappingEnabled;
749-
snapRotationUI.onValueChanged.AddListener(b => { directSnappingEnabled = snapRotationUI.isOn; });
748+
snapRotationUI.isOn = m_Preferences.rotationSnappingEnabled;
749+
snapRotationUI.onValueChanged.AddListener(b => { m_Preferences.rotationSnappingEnabled = snapRotationUI.isOn; });
750750

751751
var localOnlyUI = m_SnappingModuleSettingsUI.localOnly;
752-
localOnlyUI.isOn = localOnly;
753-
localOnlyUI.onValueChanged.AddListener(b => { localOnly = localOnlyUI.isOn; });
752+
localOnlyUI.isOn = m_Preferences.localOnly;
753+
localOnlyUI.onValueChanged.AddListener(b => { m_Preferences.localOnly = localOnlyUI.isOn; });
754754

755755
var manipulatorSnappingUI = m_SnappingModuleSettingsUI.manipulatorSnappingEnabled;
756-
manipulatorSnappingUI.isOn = manipulatorSnappingEnabled;
757-
manipulatorSnappingUI.onValueChanged.AddListener(b => { manipulatorSnappingEnabled = manipulatorSnappingUI.isOn; });
756+
manipulatorSnappingUI.isOn = m_Preferences.manipulatorSnappingEnabled;
757+
manipulatorSnappingUI.onValueChanged.AddListener(b => { m_Preferences.manipulatorSnappingEnabled = manipulatorSnappingUI.isOn; });
758758

759759
var directSnappingUI = m_SnappingModuleSettingsUI.directSnappingEnabled;
760-
directSnappingUI.isOn = directSnappingEnabled;
761-
directSnappingUI.onValueChanged.AddListener(b => { directSnappingEnabled = directSnappingUI.isOn; });
760+
directSnappingUI.isOn = m_Preferences.directSnappingEnabled;
761+
directSnappingUI.onValueChanged.AddListener(b => { m_Preferences.directSnappingEnabled = directSnappingUI.isOn; });
762762

763763
SetDependentTogglesGhosted();
764764

Tools/SelectionTool/SelectionTool.cs

+5-9
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeCon
9090
if (directSelectionCandidate)
9191
directHoveredObject = directSelectionCandidate;
9292

93-
if (!this.CanGrabObject(directHoveredObject, rayOrigin))
93+
if (!this.CanGrabObject(directHoveredObject, directRayOrigin))
9494
continue;
9595

9696
var directSelectInput = (DirectSelectInput)directSelectionData.input;
97-
98-
// Only add to selection, don't remove
99-
if (!Selection.objects.Contains(directHoveredObject))
97+
98+
// Only overwrite an existing selection if it does not contain the hovered object
99+
// In the case of multi-select, only add, do not remove
100+
if (directSelectInput.select.wasJustPressed && !Selection.objects.Contains(directHoveredObject))
100101
this.SelectObject(directHoveredObject, rayOrigin, directSelectInput.multiSelect.isHeld);
101102

102103
GameObject lastHover;
@@ -131,13 +132,8 @@ public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeCon
131132

132133
// Capture object on press
133134
if (selectionInput.select.wasJustPressed)
134-
{
135135
m_PressedObject = hoveredObject;
136136

137-
if (m_PressedObject)
138-
consumeControl(selectionInput.select);
139-
}
140-
141137
// Select button on release
142138
if (selectionInput.select.wasJustReleased)
143139
{

Tools/TransformTool/TransformTool.cs

+17-15
Original file line numberDiff line numberDiff line change
@@ -257,33 +257,33 @@ public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeCon
257257

258258
foreach (var kvp in directSelection)
259259
{
260-
var rayOrigin = kvp.Key;
261-
var selection = kvp.Value;
262-
var hoveredObject = selection.gameObject;
260+
var directRayOrigin = kvp.Key;
261+
var directSelectionData = kvp.Value;
262+
var directHoveredObject = directSelectionData.gameObject;
263263

264-
var selectionCandidate = this.GetSelectionCandidate(hoveredObject, true);
264+
var selectionCandidate = this.GetSelectionCandidate(directHoveredObject, true);
265265

266266
// Can't select this object (it might be locked or static)
267-
if (hoveredObject && !selectionCandidate)
267+
if (directHoveredObject && !selectionCandidate)
268268
continue;
269269

270270
if (selectionCandidate)
271-
hoveredObject = selectionCandidate;
271+
directHoveredObject = selectionCandidate;
272272

273-
if (!this.CanGrabObject(hoveredObject, rayOrigin))
273+
if (!this.CanGrabObject(directHoveredObject, directRayOrigin))
274274
continue;
275275

276-
var directSelectInput = (DirectSelectInput)selection.input;
276+
var directSelectInput = (DirectSelectInput)directSelectionData.input;
277277
if (directSelectInput.select.wasJustPressed)
278278
{
279-
this.ClearSnappingState(rayOrigin);
279+
this.ClearSnappingState(directRayOrigin);
280280

281281
if (objectGrabbed != null)
282-
objectGrabbed(hoveredObject);
282+
objectGrabbed(directHoveredObject);
283283

284284
consumeControl(directSelectInput.select);
285285

286-
var selectedNode = selection.node;
286+
var selectedNode = directSelectionData.node;
287287

288288
// Check if the other hand is already grabbing for two-handed scale
289289
foreach (var grabData in m_GrabData)
@@ -292,7 +292,7 @@ public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeCon
292292
if (otherNode != selectedNode)
293293
{
294294
var otherData = grabData.Value;
295-
m_ScaleStartDistance = (rayOrigin.position - otherData.rayOrigin.position).magnitude;
295+
m_ScaleStartDistance = (directRayOrigin.position - otherData.rayOrigin.position).magnitude;
296296
m_ScaleFirstNode = otherNode;
297297
for (int i = 0; i < otherData.grabbedObjects.Length; i++)
298298
{
@@ -302,10 +302,12 @@ public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeCon
302302
}
303303
}
304304

305-
m_GrabData[selectedNode] = new GrabData(rayOrigin, directSelectInput, Selection.transforms, this);
305+
var grabbedObjects = new HashSet<Transform> { directHoveredObject.transform };
306+
grabbedObjects.UnionWith(Selection.transforms);
307+
m_GrabData[selectedNode] = new GrabData(directRayOrigin, directSelectInput, grabbedObjects.ToArray(), this);
306308

307-
this.HideDefaultRay(rayOrigin, true); // This will also unhighlight the object
308-
this.LockRay(rayOrigin, this);
309+
this.HideDefaultRay(directRayOrigin, true); // This will also unhighlight the object
310+
this.LockRay(directRayOrigin, this);
309311

310312
// Wait a frame since OnSelectionChanged is called at the end of the frame, and will set m_DirectSelected to false
311313
EditorApplication.delayCall += () =>

0 commit comments

Comments
 (0)