diff --git a/Assets/Scripts/Catalog.cs b/Assets/Scripts/Catalog.cs index dbf9c14..243918a 100644 --- a/Assets/Scripts/Catalog.cs +++ b/Assets/Scripts/Catalog.cs @@ -107,7 +107,7 @@ public class Catalog : MonoBehaviour public void ReleaseObject(GameObject furniture, Valve.VR.InteractionSystem.Hand hand) { - hand.DetachObject(currentSphere); + hand.DetachObject(currentSphere); currentSphere = null; } diff --git a/Assets/Scripts/MovableFurniture.cs b/Assets/Scripts/MovableFurniture.cs index ae042ae..da7d680 100644 --- a/Assets/Scripts/MovableFurniture.cs +++ b/Assets/Scripts/MovableFurniture.cs @@ -70,7 +70,7 @@ public class MovableFurniture : Furniture } } - /*public void SnapTo(Vector3 position, LayerMask layerMask, Vector3 direction) + /*public void SnapTo(Vector3 position, LayerMask layerMask, Vector3 direction) { Vector3 displacement = Vector3.zero; this.transform.position = position + centerOffset; @@ -91,62 +91,62 @@ public class MovableFurniture : Furniture this.transform.Translate(displacement, Space.World); }*/ - public void SnapTo(Vector3 position, LayerMask layerMask, Vector3 direction) - { - Vector3 previousPosition = transform.position; - Vector3 offset = Vector3.zero; - if (wallMount) - { - transform.position = position; + public void SnapTo(Vector3 position, LayerMask layerMask, Vector3 direction) + { + Vector3 previousPosition = transform.position; + Vector3 offset = Vector3.zero; + if (wallMount) + { + transform.position = position; // check if object has objectBounds, if not combine the bounds of its children Bounds objectBounds; - if (combinedBounds == null) - { - objectBounds = new Bounds(); - foreach (Transform child in children) - { - objectBounds.Encapsulate(child.GetComponent().bounds); - } - } - else - { - objectBounds = (Bounds)combinedBounds; - } + if (combinedBounds == null) + { + objectBounds = new Bounds(); + foreach (Transform child in children) + { + objectBounds.Encapsulate(child.GetComponent().bounds); + } + } + else + { + objectBounds = (Bounds)combinedBounds; + } - Vector3 objectSize = objectBounds.size; - offset = new Vector3(objectSize.x / 2, objectSize.y / 2, objectSize.z / 2); - Collider[] colliders = Physics.OverlapBox(transform.position + offset, offset, transform.rotation, layerMask); - if (colliders.Length > 0) - { - for (int i = 0; i < colliders.Length; i++) - { - offset += colliders[i].bounds.ClosestPoint(transform.position) - transform.position; - } - offset /= colliders.Length; - transform.position += offset; - } - } - else - { - Vector3 newPosition = new Vector3(position.x, transform.position.y, position.z); - transform.position = newPosition; - Bounds objectBounds = GetComponent().bounds; - Vector3 objectSize = objectBounds.size; - offset = new Vector3(objectSize.x / 2, objectSize.y / 2, objectSize.z / 2); - Collider[] colliders = Physics.OverlapBox(transform.position + offset, offset, transform.rotation, layerMask); - if (colliders.Length > 0) - { - for (int i = 0; i < colliders.Length; i++) - { - offset += colliders[i].bounds.ClosestPoint(transform.position) - transform.position; - } - offset /= colliders.Length; - transform.position += offset; - } - } - } + Vector3 objectSize = objectBounds.size; + offset = new Vector3(objectSize.x / 2, objectSize.y / 2, objectSize.z / 2); + Collider[] colliders = Physics.OverlapBox(transform.position + offset, offset, transform.rotation, layerMask); + if (colliders.Length > 0) + { + for (int i = 0; i < colliders.Length; i++) + { + offset += colliders[i].bounds.ClosestPoint(transform.position) - transform.position; + } + offset /= colliders.Length; + transform.position += offset; + } + } + else + { + Vector3 newPosition = new Vector3(position.x, transform.position.y, position.z); + transform.position = newPosition; + Bounds objectBounds = GetComponent().bounds; + Vector3 objectSize = objectBounds.size; + offset = new Vector3(objectSize.x / 2, objectSize.y / 2, objectSize.z / 2); + Collider[] colliders = Physics.OverlapBox(transform.position + offset, offset, transform.rotation, layerMask); + if (colliders.Length > 0) + { + for (int i = 0; i < colliders.Length; i++) + { + offset += colliders[i].bounds.ClosestPoint(transform.position) - transform.position; + } + offset /= colliders.Length; + transform.position += offset; + } + } + } - void OnDrawGizmos() + void OnDrawGizmos() { // Draw a yellow sphere at the transform's position Gizmos.color = Color.red;