forked from cgvr/DeltaVR
Remove useless files, add hands
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d5e846dd9da0124db193022595abda8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,130 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!43 &4300000
|
||||
Mesh:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_Name: GrabConeVolume
|
||||
serializedVersion: 8
|
||||
m_SubMeshes:
|
||||
- serializedVersion: 2
|
||||
firstByte: 0
|
||||
indexCount: 30
|
||||
topology: 0
|
||||
firstVertex: 0
|
||||
vertexCount: 20
|
||||
localAABB:
|
||||
m_Center: {x: 0, y: 0.000000014901161, z: 1}
|
||||
m_Extent: {x: 0.5, y: 0.47552824, z: 1}
|
||||
m_Shapes:
|
||||
vertices: []
|
||||
shapes: []
|
||||
channels: []
|
||||
fullWeights: []
|
||||
m_BindPose: []
|
||||
m_BoneNameHashes:
|
||||
m_RootBoneNameHash: 0
|
||||
m_MeshCompression: 0
|
||||
m_IsReadable: 1
|
||||
m_KeepVertices: 1
|
||||
m_KeepIndices: 1
|
||||
m_IndexBuffer: 0a0000000b000b0001000c000c0002000d000d0003000e000e0004000f000f0005001000100006001100110007001200120008001300130009000a00
|
||||
m_Skin: []
|
||||
m_VertexData:
|
||||
m_CurrentChannels: 11
|
||||
m_VertexCount: 20
|
||||
m_Channels:
|
||||
- stream: 0
|
||||
offset: 0
|
||||
format: 0
|
||||
dimension: 3
|
||||
- stream: 0
|
||||
offset: 12
|
||||
format: 0
|
||||
dimension: 3
|
||||
- stream: 0
|
||||
offset: 0
|
||||
format: 0
|
||||
dimension: 0
|
||||
- stream: 0
|
||||
offset: 24
|
||||
format: 0
|
||||
dimension: 2
|
||||
- stream: 0
|
||||
offset: 0
|
||||
format: 0
|
||||
dimension: 0
|
||||
- stream: 0
|
||||
offset: 0
|
||||
format: 0
|
||||
dimension: 0
|
||||
- stream: 0
|
||||
offset: 0
|
||||
format: 0
|
||||
dimension: 0
|
||||
- stream: 0
|
||||
offset: 0
|
||||
format: 0
|
||||
dimension: 0
|
||||
m_DataSize: 640
|
||||
_typelessdata: 00000000000000000000000078336c3f257e993e425b78be000000000000803f000000000000000000000000f3fa113fb3ec483f425b78becdcccc3d0000803f000000000000000000000000312236b3425b783f425b78becdcc4c3e0000803f000000800000000000000000f2fa11bfb3ec483f425b78be9a99993e0000803f00000080000000000000000079336cbf1e7e993e425b78becdcccc3e0000803f00000080000000800000000078336cbf247e99be425b78be0000003f0000803f000000800000008000000000f0fa11bfb5ec48bf425b78be9a99193f0000803f00000080000000800000000044c04632425b78bf425b78be3333333f0000803f000000000000008000000000f7fa113fb0ec48bf425b78becdcc4c3f0000803f00000000000000800000000078336c3f237e99be425b78be6666663f0000803f0000003f0000000000000040425b783f00000000425b78be0000000000000000bd1bcf3e1879963e00000040b3ec483ff3fa113f425b78becdcccc3d0000000079371e3e7178f33e00000040247e993e78336c3f425b78becdcc4c3e000000007b371ebe7078f33e00000040267e99be77336c3f425b78be9a99993e00000000be1bcfbe1779963e00000040b4ec48bff2fa113f425b78becdcccc3e00000000000000bf2ebd3bb300000040425b78bf3122b6b3425b78be0000003f00000000bc1bcfbe1a7996be00000040b2ec48bff5fa11bf425b78be9a99193f000000007d371ebe7078f3be00000040287e99be77336cbf425b78be3333333f000000007e371e3e7078f3be00000040297e993e77336cbf425b78becdcc4c3f00000000c11bcf3e137996be00000040b7ec483feefa11bf425b78be6666663f00000000
|
||||
m_CompressedMesh:
|
||||
m_Vertices:
|
||||
m_NumItems: 0
|
||||
m_Range: 0
|
||||
m_Start: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_UV:
|
||||
m_NumItems: 0
|
||||
m_Range: 0
|
||||
m_Start: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_Normals:
|
||||
m_NumItems: 0
|
||||
m_Range: 0
|
||||
m_Start: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_Tangents:
|
||||
m_NumItems: 0
|
||||
m_Range: 0
|
||||
m_Start: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_Weights:
|
||||
m_NumItems: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_NormalSigns:
|
||||
m_NumItems: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_TangentSigns:
|
||||
m_NumItems: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_FloatColors:
|
||||
m_NumItems: 0
|
||||
m_Range: 0
|
||||
m_Start: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_BoneIndices:
|
||||
m_NumItems: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_Triangles:
|
||||
m_NumItems: 0
|
||||
m_Data:
|
||||
m_BitSize: 0
|
||||
m_UVInfo: 0
|
||||
m_LocalAABB:
|
||||
m_Center: {x: 0, y: 0.000000014901161, z: 1}
|
||||
m_Extent: {x: 0.5, y: 0.47552824, z: 1}
|
||||
m_MeshUsageFlags: 0
|
||||
m_BakedConvexCollisionMesh:
|
||||
m_BakedTriangleCollisionMesh:
|
||||
m_MeshOptimized: 0
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcd019dc7c1f92140963033f1669ec2f
|
||||
timeCreated: 1493752008
|
||||
licenseType: Store
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09ce999edb4163e418caa1a898504dff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0242aa8515b4bc947a945a5c6df83ee9
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 100100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fae51a9f4170334e8639e8dbfc0a54b
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 100100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21d53b55a473ecf42a069220fa2c8eab
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,101 +0,0 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
See SampleFramework license.txt for license terms. Unless required by applicable law
|
||||
or agreed to in writing, the sample code is provided <20>AS IS<49> WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied. See the license for specific
|
||||
language governing permissions and limitations under the license.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace OculusSampleFramework
|
||||
{
|
||||
// Simple component that changes color based on grab state.
|
||||
public class ColorGrabbable : OVRGrabbable
|
||||
{
|
||||
public static readonly Color COLOR_GRAB = new Color(1.0f, 0.5f, 0.0f, 1.0f);
|
||||
public static readonly Color COLOR_HIGHLIGHT = new Color(1.0f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
private Color m_color = Color.black;
|
||||
private MeshRenderer[] m_meshRenderers = null;
|
||||
private bool m_highlight;
|
||||
|
||||
public bool Highlight
|
||||
{
|
||||
get { return m_highlight; }
|
||||
set
|
||||
{
|
||||
m_highlight = value;
|
||||
UpdateColor();
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateColor()
|
||||
{
|
||||
if (isGrabbed) SetColor(COLOR_GRAB);
|
||||
else if (Highlight) SetColor(COLOR_HIGHLIGHT);
|
||||
else SetColor(m_color);
|
||||
|
||||
}
|
||||
|
||||
override public void GrabBegin(OVRGrabber hand, Collider grabPoint)
|
||||
{
|
||||
base.GrabBegin(hand, grabPoint);
|
||||
UpdateColor();
|
||||
}
|
||||
|
||||
override public void GrabEnd(Vector3 linearVelocity, Vector3 angularVelocity)
|
||||
{
|
||||
base.GrabEnd(linearVelocity, angularVelocity);
|
||||
UpdateColor();
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (m_grabPoints.Length == 0)
|
||||
{
|
||||
// Get the collider from the grabbable
|
||||
Collider collider = this.GetComponent<Collider>();
|
||||
if (collider == null)
|
||||
{
|
||||
throw new System.ArgumentException("Grabbables cannot have zero grab points and no collider -- please add a grab point or collider.");
|
||||
}
|
||||
|
||||
// Create a default grab point
|
||||
m_grabPoints = new Collider[1] { collider };
|
||||
|
||||
// Grab points are doing double-duty as a way to identify submeshes that should be colored.
|
||||
// If unspecified, just color self.
|
||||
m_meshRenderers = new MeshRenderer[1];
|
||||
m_meshRenderers[0] = this.GetComponent<MeshRenderer>();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_meshRenderers = this.GetComponentsInChildren<MeshRenderer>();
|
||||
}
|
||||
m_color = new Color(
|
||||
Random.Range(0.1f, 0.95f),
|
||||
Random.Range(0.1f, 0.95f),
|
||||
Random.Range(0.1f, 0.95f),
|
||||
1.0f
|
||||
);
|
||||
SetColor(m_color);
|
||||
}
|
||||
|
||||
private void SetColor(Color color)
|
||||
{
|
||||
for (int i = 0; i < m_meshRenderers.Length; ++i)
|
||||
{
|
||||
MeshRenderer meshRenderer = m_meshRenderers[i];
|
||||
for (int j = 0; j < meshRenderer.materials.Length; ++j)
|
||||
{
|
||||
Material meshMaterial = meshRenderer.materials[j];
|
||||
meshMaterial.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c470fb7e491d744eb9c02e6920182d4
|
||||
timeCreated: 1484774291
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,79 +0,0 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
See SampleFramework license.txt for license terms. Unless required by applicable law
|
||||
or agreed to in writing, the sample code is provided “AS IS” WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied. See the license for specific
|
||||
language governing permissions and limitations under the license.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using OVRTouchSample;
|
||||
|
||||
namespace OculusSampleFramework
|
||||
{
|
||||
public class DistanceGrabbable : OVRGrabbable
|
||||
{
|
||||
public string m_materialColorField;
|
||||
|
||||
GrabbableCrosshair m_crosshair;
|
||||
GrabManager m_crosshairManager;
|
||||
Renderer m_renderer;
|
||||
MaterialPropertyBlock m_mpb;
|
||||
|
||||
|
||||
public bool InRange
|
||||
{
|
||||
get { return m_inRange; }
|
||||
set
|
||||
{
|
||||
m_inRange = value;
|
||||
RefreshCrosshair();
|
||||
}
|
||||
}
|
||||
bool m_inRange;
|
||||
|
||||
public bool Targeted
|
||||
{
|
||||
get { return m_targeted; }
|
||||
set
|
||||
{
|
||||
m_targeted = value;
|
||||
RefreshCrosshair();
|
||||
}
|
||||
}
|
||||
bool m_targeted;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
m_crosshair = gameObject.GetComponentInChildren<GrabbableCrosshair>();
|
||||
m_renderer = gameObject.GetComponent<Renderer>();
|
||||
m_crosshairManager = FindObjectOfType<GrabManager>();
|
||||
m_mpb = new MaterialPropertyBlock();
|
||||
RefreshCrosshair();
|
||||
m_renderer.SetPropertyBlock(m_mpb);
|
||||
}
|
||||
|
||||
void RefreshCrosshair()
|
||||
{
|
||||
if (m_crosshair)
|
||||
{
|
||||
if (isGrabbed) m_crosshair.SetState(GrabbableCrosshair.CrosshairState.Disabled);
|
||||
else if (!InRange) m_crosshair.SetState(GrabbableCrosshair.CrosshairState.Disabled);
|
||||
else m_crosshair.SetState(Targeted ? GrabbableCrosshair.CrosshairState.Targeted : GrabbableCrosshair.CrosshairState.Enabled);
|
||||
}
|
||||
if (m_materialColorField != null)
|
||||
{
|
||||
m_renderer.GetPropertyBlock(m_mpb);
|
||||
if (isGrabbed || !InRange) m_mpb.SetColor(m_materialColorField, m_crosshairManager.OutlineColorOutOfRange);
|
||||
else if (Targeted) m_mpb.SetColor(m_materialColorField, m_crosshairManager.OutlineColorHighlighted);
|
||||
else m_mpb.SetColor(m_materialColorField, m_crosshairManager.OutlineColorInRange);
|
||||
m_renderer.SetPropertyBlock(m_mpb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d1a7708e76601b4ea829921c33bc624
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,363 +0,0 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
See SampleFramework license.txt for license terms. Unless required by applicable law
|
||||
or agreed to in writing, the sample code is provided “AS IS” WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied. See the license for specific
|
||||
language governing permissions and limitations under the license.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine.SceneManagement;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace OculusSampleFramework
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows grabbing and throwing of objects with the DistanceGrabbable component on them.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class DistanceGrabber : OVRGrabber
|
||||
{
|
||||
// Radius of sphere used in spherecast from hand along forward ray to find target object.
|
||||
[SerializeField]
|
||||
float m_spherecastRadius = 0;
|
||||
|
||||
// Distance below which no-snap objects won't be teleported, but will instead be left
|
||||
// where they are in relation to the hand.
|
||||
[SerializeField]
|
||||
float m_noSnapThreshhold = 0.05f;
|
||||
|
||||
[SerializeField]
|
||||
bool m_useSpherecast;
|
||||
public bool UseSpherecast
|
||||
{
|
||||
get { return m_useSpherecast; }
|
||||
set
|
||||
{
|
||||
m_useSpherecast = value;
|
||||
GrabVolumeEnable(!m_useSpherecast);
|
||||
}
|
||||
}
|
||||
|
||||
// Public to allow changing in demo.
|
||||
[SerializeField]
|
||||
public bool m_preventGrabThroughWalls;
|
||||
|
||||
[SerializeField]
|
||||
float m_objectPullVelocity = 10.0f;
|
||||
float m_objectPullMaxRotationRate = 360.0f; // max rotation rate in degrees per second
|
||||
|
||||
bool m_movingObjectToHand = false;
|
||||
|
||||
// Objects can be distance grabbed up to this distance from the hand.
|
||||
[SerializeField]
|
||||
float m_maxGrabDistance;
|
||||
|
||||
// Only allow grabbing objects in this layer.
|
||||
// NOTE: you can use the value -1 to attempt to grab everything.
|
||||
[SerializeField]
|
||||
int m_grabObjectsInLayer = 0;
|
||||
[SerializeField]
|
||||
int m_obstructionLayer = 0;
|
||||
|
||||
DistanceGrabber m_otherHand;
|
||||
|
||||
protected DistanceGrabbable m_target;
|
||||
// Tracked separately from m_target, because we support child colliders of a DistanceGrabbable.
|
||||
protected Collider m_targetCollider;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// Basic hack to guess at max grab distance based on player size.
|
||||
// Note that there's no major downside to making this value too high, as objects
|
||||
// outside the player's grabbable trigger volume will not be eligible targets regardless.
|
||||
Collider sc = m_player.GetComponentInChildren<Collider>();
|
||||
if(sc != null)
|
||||
{
|
||||
m_maxGrabDistance = sc.bounds.size.z * 0.5f + 3.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_maxGrabDistance = 12.0f;
|
||||
}
|
||||
|
||||
if(m_parentHeldObject == true)
|
||||
{
|
||||
Debug.LogError("m_parentHeldObject incompatible with DistanceGrabber. Setting to false.");
|
||||
m_parentHeldObject = false;
|
||||
}
|
||||
|
||||
DistanceGrabber[] grabbers = FindObjectsOfType<DistanceGrabber>();
|
||||
for (int i = 0; i < grabbers.Length; ++i)
|
||||
{
|
||||
if (grabbers[i] != this) m_otherHand = grabbers[i];
|
||||
}
|
||||
Debug.Assert(m_otherHand != null);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
OVRPlugin.SendEvent("distance_grabber", (SceneManager.GetActiveScene().name == "DistanceGrab").ToString(), "sample_framework");
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
Debug.DrawRay(transform.position, transform.forward, Color.red, 0.1f);
|
||||
|
||||
DistanceGrabbable target;
|
||||
Collider targetColl;
|
||||
FindTarget(out target, out targetColl);
|
||||
|
||||
if (target != m_target)
|
||||
{
|
||||
if (m_target != null)
|
||||
{
|
||||
m_target.Targeted = m_otherHand.m_target == m_target;
|
||||
}
|
||||
m_target = target;
|
||||
m_targetCollider = targetColl;
|
||||
if (m_target != null)
|
||||
{
|
||||
m_target.Targeted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GrabBegin()
|
||||
{
|
||||
DistanceGrabbable closestGrabbable = m_target;
|
||||
Collider closestGrabbableCollider = m_targetCollider;
|
||||
|
||||
GrabVolumeEnable(false);
|
||||
|
||||
if (closestGrabbable != null)
|
||||
{
|
||||
if (closestGrabbable.isGrabbed)
|
||||
{
|
||||
((DistanceGrabber)closestGrabbable.grabbedBy).OffhandGrabbed(closestGrabbable);
|
||||
}
|
||||
|
||||
m_grabbedObj = closestGrabbable;
|
||||
m_grabbedObj.GrabBegin(this, closestGrabbableCollider);
|
||||
SetPlayerIgnoreCollision(m_grabbedObj.gameObject, true);
|
||||
|
||||
m_movingObjectToHand = true;
|
||||
m_lastPos = transform.position;
|
||||
m_lastRot = transform.rotation;
|
||||
|
||||
// If it's within a certain distance respect the no-snap.
|
||||
Vector3 closestPointOnBounds = closestGrabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
|
||||
if(!m_grabbedObj.snapPosition && !m_grabbedObj.snapOrientation && m_noSnapThreshhold > 0.0f && (closestPointOnBounds - m_gripTransform.position).magnitude < m_noSnapThreshhold)
|
||||
{
|
||||
Vector3 relPos = m_grabbedObj.transform.position - transform.position;
|
||||
m_movingObjectToHand = false;
|
||||
relPos = Quaternion.Inverse(transform.rotation) * relPos;
|
||||
m_grabbedObjectPosOff = relPos;
|
||||
Quaternion relOri = Quaternion.Inverse(transform.rotation) * m_grabbedObj.transform.rotation;
|
||||
m_grabbedObjectRotOff = relOri;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set up offsets for grabbed object desired position relative to hand.
|
||||
m_grabbedObjectPosOff = m_gripTransform.localPosition;
|
||||
if (m_grabbedObj.snapOffset)
|
||||
{
|
||||
Vector3 snapOffset = m_grabbedObj.snapOffset.position;
|
||||
if (m_controller == OVRInput.Controller.LTouch) snapOffset.x = -snapOffset.x;
|
||||
m_grabbedObjectPosOff += snapOffset;
|
||||
}
|
||||
|
||||
m_grabbedObjectRotOff = m_gripTransform.localRotation;
|
||||
if (m_grabbedObj.snapOffset)
|
||||
{
|
||||
m_grabbedObjectRotOff = m_grabbedObj.snapOffset.rotation * m_grabbedObjectRotOff;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected override void MoveGrabbedObject(Vector3 pos, Quaternion rot, bool forceTeleport = false)
|
||||
{
|
||||
if (m_grabbedObj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Rigidbody grabbedRigidbody = m_grabbedObj.grabbedRigidbody;
|
||||
Vector3 grabbablePosition = pos + rot * m_grabbedObjectPosOff;
|
||||
Quaternion grabbableRotation = rot * m_grabbedObjectRotOff;
|
||||
|
||||
if (m_movingObjectToHand)
|
||||
{
|
||||
float travel = m_objectPullVelocity * Time.deltaTime;
|
||||
Vector3 dir = grabbablePosition - m_grabbedObj.transform.position;
|
||||
if(travel * travel * 1.1f > dir.sqrMagnitude)
|
||||
{
|
||||
m_movingObjectToHand = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
dir.Normalize();
|
||||
grabbablePosition = m_grabbedObj.transform.position + dir * travel;
|
||||
grabbableRotation = Quaternion.RotateTowards(m_grabbedObj.transform.rotation, grabbableRotation, m_objectPullMaxRotationRate * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
grabbedRigidbody.MovePosition(grabbablePosition);
|
||||
grabbedRigidbody.MoveRotation(grabbableRotation);
|
||||
}
|
||||
|
||||
static private DistanceGrabbable HitInfoToGrabbable(RaycastHit hitInfo)
|
||||
{
|
||||
if (hitInfo.collider != null)
|
||||
{
|
||||
GameObject go = hitInfo.collider.gameObject;
|
||||
return go.GetComponent<DistanceGrabbable>() ?? go.GetComponentInParent<DistanceGrabbable>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected bool FindTarget(out DistanceGrabbable dgOut, out Collider collOut)
|
||||
{
|
||||
dgOut = null;
|
||||
collOut = null;
|
||||
float closestMagSq = float.MaxValue;
|
||||
|
||||
// First test for objects within the grab volume, if we're using those.
|
||||
// (Some usage of DistanceGrabber will not use grab volumes, and will only
|
||||
// use spherecasts, and that's supported.)
|
||||
foreach (OVRGrabbable cg in m_grabCandidates.Keys)
|
||||
{
|
||||
DistanceGrabbable grabbable = cg as DistanceGrabbable;
|
||||
bool canGrab = grabbable != null && grabbable.InRange && !(grabbable.isGrabbed && !grabbable.allowOffhandGrab);
|
||||
if (canGrab && m_grabObjectsInLayer >= 0) canGrab = grabbable.gameObject.layer == m_grabObjectsInLayer;
|
||||
if (!canGrab)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < grabbable.grabPoints.Length; ++j)
|
||||
{
|
||||
Collider grabbableCollider = grabbable.grabPoints[j];
|
||||
// Store the closest grabbable
|
||||
Vector3 closestPointOnBounds = grabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
|
||||
float grabbableMagSq = (m_gripTransform.position - closestPointOnBounds).sqrMagnitude;
|
||||
|
||||
if (grabbableMagSq < closestMagSq)
|
||||
{
|
||||
bool accept = true;
|
||||
if(m_preventGrabThroughWalls)
|
||||
{
|
||||
// NOTE: if this raycast fails, ideally we'd try other rays near the edges of the object, especially for large objects.
|
||||
// NOTE 2: todo optimization: sort the objects before performing any raycasts.
|
||||
Ray ray = new Ray();
|
||||
ray.direction = grabbable.transform.position - m_gripTransform.position;
|
||||
ray.origin = m_gripTransform.position;
|
||||
RaycastHit obstructionHitInfo;
|
||||
Debug.DrawRay(ray.origin, ray.direction, Color.red, 0.1f);
|
||||
|
||||
if (Physics.Raycast(ray, out obstructionHitInfo, m_maxGrabDistance, 1 << m_obstructionLayer, QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
float distToObject = (grabbableCollider.ClosestPointOnBounds(m_gripTransform.position) - m_gripTransform.position).magnitude;
|
||||
if(distToObject > obstructionHitInfo.distance * 1.1)
|
||||
{
|
||||
accept = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(accept)
|
||||
{
|
||||
closestMagSq = grabbableMagSq;
|
||||
dgOut = grabbable;
|
||||
collOut = grabbableCollider;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dgOut == null && m_useSpherecast)
|
||||
{
|
||||
return FindTargetWithSpherecast(out dgOut, out collOut);
|
||||
}
|
||||
return dgOut != null;
|
||||
}
|
||||
|
||||
protected bool FindTargetWithSpherecast(out DistanceGrabbable dgOut, out Collider collOut)
|
||||
{
|
||||
dgOut = null;
|
||||
collOut = null;
|
||||
Ray ray = new Ray(m_gripTransform.position, m_gripTransform.forward);
|
||||
RaycastHit hitInfo;
|
||||
|
||||
// If no objects in grab volume, raycast.
|
||||
// Potential optimization:
|
||||
// In DistanceGrabbable.RefreshCrosshairs, we could move the object between collision layers.
|
||||
// If it's in range, it would move into the layer DistanceGrabber.m_grabObjectsInLayer,
|
||||
// and if out of range, into another layer so it's ignored by DistanceGrabber's SphereCast.
|
||||
// However, we're limiting the SphereCast by m_maxGrabDistance, so the optimization doesn't seem
|
||||
// essential.
|
||||
int layer = (m_grabObjectsInLayer == -1) ? ~0 : 1 << m_grabObjectsInLayer;
|
||||
if (Physics.SphereCast(ray, m_spherecastRadius, out hitInfo, m_maxGrabDistance, layer))
|
||||
{
|
||||
DistanceGrabbable grabbable = null;
|
||||
Collider hitCollider = null;
|
||||
if (hitInfo.collider != null)
|
||||
{
|
||||
grabbable = hitInfo.collider.gameObject.GetComponentInParent<DistanceGrabbable>();
|
||||
hitCollider = grabbable == null ? null : hitInfo.collider;
|
||||
if(grabbable)
|
||||
{
|
||||
dgOut = grabbable;
|
||||
collOut = hitCollider;
|
||||
}
|
||||
}
|
||||
|
||||
if (grabbable != null && m_preventGrabThroughWalls)
|
||||
{
|
||||
// Found a valid hit. Now test to see if it's blocked by collision.
|
||||
RaycastHit obstructionHitInfo;
|
||||
ray.direction = hitInfo.point - m_gripTransform.position;
|
||||
|
||||
dgOut = grabbable;
|
||||
collOut = hitCollider;
|
||||
if (Physics.Raycast(ray, out obstructionHitInfo, m_maxGrabDistance, 1 << m_obstructionLayer, QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
DistanceGrabbable obstruction = null;
|
||||
if(hitInfo.collider != null)
|
||||
{
|
||||
obstruction = obstructionHitInfo.collider.gameObject.GetComponentInParent<DistanceGrabbable>();
|
||||
}
|
||||
if (obstruction != grabbable && obstructionHitInfo.distance < hitInfo.distance)
|
||||
{
|
||||
dgOut = null;
|
||||
collOut = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dgOut != null;
|
||||
}
|
||||
|
||||
protected override void GrabVolumeEnable(bool enabled)
|
||||
{
|
||||
if(m_useSpherecast) enabled = false;
|
||||
base.GrabVolumeEnable(enabled);
|
||||
}
|
||||
|
||||
// Just here to allow calling of a protected member function.
|
||||
protected override void OffhandGrabbed(OVRGrabbable grabbable)
|
||||
{
|
||||
base.OffhandGrabbed(grabbable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b388ff4c8d1f3644a143b16d45403ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 201
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,75 +0,0 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
See SampleFramework license.txt for license terms. Unless required by applicable law
|
||||
or agreed to in writing, the sample code is provided “AS IS” WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied. See the license for specific
|
||||
language governing permissions and limitations under the license.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
|
||||
Quick implementation notes:
|
||||
|
||||
Grab candidates and grab range:
|
||||
-------------------------------
|
||||
The trigger volume on the OVRPlayerController, which also has a GrabManager component,
|
||||
determines whether an object is in range or out of range.
|
||||
|
||||
Hands (via the DistanceGrabber component) determine the target object in one of two
|
||||
ways, depending on bool m_useSpherecast:
|
||||
true: cast a sphere of radius m_spherecastRadius at distance m_maxGrabDistance. Select
|
||||
the first collision.
|
||||
false: from all objects within the grab volume, select the closest object that can be
|
||||
hit by a ray from the player's hand.
|
||||
|
||||
IMPORTANT NOTE: if you change the radius of the trigger volume on the
|
||||
OVRPlayerController, you must ensure the spherecast or the grab volume on the grabbers
|
||||
is big enough to reach all objects within that radius! Keep in mind the hand may be a
|
||||
little behind or two the side of the player, so you need to make it somewhat larger
|
||||
than the radius. There is no major concern with making it too large (aside from minor
|
||||
performance questions), because if an object is not in range according to the
|
||||
OVRPlayerController's trigger volume, it will not be considered for grabbing.
|
||||
|
||||
Crosshairs and Outlines:
|
||||
------------------------
|
||||
|
||||
Objects with a DistanceGrabbable component draw their own in range / targeted
|
||||
highlight. How these states are best presented is highly app-specific.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace OculusSampleFramework
|
||||
{
|
||||
public class GrabManager : MonoBehaviour
|
||||
{
|
||||
Collider m_grabVolume;
|
||||
|
||||
public Color OutlineColorInRange;
|
||||
public Color OutlineColorHighlighted;
|
||||
public Color OutlineColorOutOfRange;
|
||||
|
||||
void OnTriggerEnter(Collider otherCollider)
|
||||
{
|
||||
DistanceGrabbable dg = otherCollider.GetComponentInChildren<DistanceGrabbable>();
|
||||
if(dg)
|
||||
{
|
||||
dg.InRange = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider otherCollider)
|
||||
{
|
||||
DistanceGrabbable dg = otherCollider.GetComponentInChildren<DistanceGrabbable>();
|
||||
if(dg)
|
||||
{
|
||||
dg.InRange = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2d153878a9f7eb45b0e02c0c739029a
|
||||
timeCreated: 1492207162
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
See SampleFramework license.txt for license terms. Unless required by applicable law
|
||||
or agreed to in writing, the sample code is provided <20>AS IS<49> WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied. See the license for specific
|
||||
language governing permissions and limitations under the license.
|
||||
|
||||
************************************************************************************/
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace OculusSampleFramework
|
||||
{
|
||||
public class GrabbableCrosshair : MonoBehaviour
|
||||
{
|
||||
public enum CrosshairState { Disabled, Enabled, Targeted }
|
||||
|
||||
CrosshairState m_state = CrosshairState.Disabled;
|
||||
Transform m_centerEyeAnchor;
|
||||
|
||||
[SerializeField]
|
||||
GameObject m_targetedCrosshair = null;
|
||||
[SerializeField]
|
||||
GameObject m_enabledCrosshair = null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_centerEyeAnchor = GameObject.Find("CenterEyeAnchor").transform;
|
||||
}
|
||||
|
||||
public void SetState(CrosshairState cs)
|
||||
{
|
||||
m_state = cs;
|
||||
if (cs == CrosshairState.Disabled)
|
||||
{
|
||||
m_targetedCrosshair.SetActive(false);
|
||||
m_enabledCrosshair.SetActive(false);
|
||||
}
|
||||
else if (cs == CrosshairState.Enabled)
|
||||
{
|
||||
m_targetedCrosshair.SetActive(false);
|
||||
m_enabledCrosshair.SetActive(true);
|
||||
}
|
||||
else if (cs == CrosshairState.Targeted)
|
||||
{
|
||||
m_targetedCrosshair.SetActive(true);
|
||||
m_enabledCrosshair.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_state != CrosshairState.Disabled)
|
||||
{
|
||||
transform.LookAt(m_centerEyeAnchor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ffe6c14f054b624d8a61df503f21c73
|
||||
timeCreated: 1494265117
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,35 +0,0 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
See SampleFramework license.txt for license terms. Unless required by applicable law
|
||||
or agreed to in writing, the sample code is provided <20>AS IS<49> WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied. See the license for specific
|
||||
language governing permissions and limitations under the license.
|
||||
|
||||
************************************************************************************/
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OculusSampleFramework
|
||||
{
|
||||
public class PauseOnInputLoss : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
OVRManager.InputFocusAcquired += OnInputFocusAcquired;
|
||||
OVRManager.InputFocusLost += OnInputFocusLost;
|
||||
}
|
||||
|
||||
private void OnInputFocusLost()
|
||||
{
|
||||
Time.timeScale = 0.0f;
|
||||
}
|
||||
|
||||
private void OnInputFocusAcquired()
|
||||
{
|
||||
Time.timeScale = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f71ea22b736c3c4fa9f6b17401f974d
|
||||
timeCreated: 1516390854
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user