generated from VR-Sexe/Unity3DTemplate
+
This commit is contained in:
parent
002e7278a1
commit
4b5b691e6b
@ -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;
|
||||
|
||||
}
|
||||
|
||||
@ -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<Renderer>().bounds);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
objectBounds = (Bounds)combinedBounds;
|
||||
}
|
||||
if (combinedBounds == null)
|
||||
{
|
||||
objectBounds = new Bounds();
|
||||
foreach (Transform child in children)
|
||||
{
|
||||
objectBounds.Encapsulate(child.GetComponent<Renderer>().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<Collider>().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<Collider>().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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user