資源簡介
硬件為HTC-VIVE,使用Unity3D V5.6.4搭建室內(nèi)小場景。功能包括拾取、拋扔物體;射線相交位置瞬移等功能。
代碼片段和文件信息
using?System.Collections;
using?System.Collections.Generic;
using?UnityEngine;
public?class?ControllerGrabobject?:?MonoBehaviour?
{
private?SteamVR_Trackedobject?trackedObj;
//?1
private?Gameobject?collidingobject;?
//?2
private?Gameobject?objectInHand;
private?SteamVR_Controller.Device?Controller
{
get?{?return?SteamVR_Controller.Input((int)trackedObj.index);?}
}
void?Awake()
{
trackedObj?=?GetComponentject>();
}
private?void?SetCollidingobject(Collider?col)
{
//?1
if?(collidingobject?||?!col.GetComponent())
{
return;
}
//?2
collidingobject?=?col.gameobject;
}
//?1
public?void?OnTriggerEnter(Collider?other)
{
SetCollidingobject(other);
}
//?2
public?void?OnTriggerStay(Collider?other)
{
SetCollidingobject(other);
}
//?3
public?void?OnTriggerExit(Collider?other)
{
if?(!collidingobject)
{
return;
}
collidingobject?=?null;
}
private?void?Grabobject()
{
//?1
objectInHand?=?collidingobject;
collidingobject?=?null;
//?2
var?joint?=?AddFixedJoint();
joint.connectedBody?=?objectInHand.GetComponent();
}
//?3
private?FixedJoint?AddFixedJoint()
{
FixedJoint?fx?=?gameobject.AddComponent();
fx.breakForce?=?20000;
fx.breakTorque?=?20000;
return?fx;
}
private?void?Releaseobject()
{
//?1
if?(GetComponent())
{
//?2
GetComponent().connectedBody?=?null;
Destroy(GetComponent());
//?3
objectInHand.GetComponent().velocity?=?Controller.velocity;
objectInHand.GetComponent().angularVelocity?=?Controller.angularVelocity;
}
//?4
objectInHand?=?null;
}
//?Update?is?called?once?per?frame
void?Update?()?
{
//?1
if?(Controller.GetHairTriggerDown())
{
if?(collidingobject)
{
Grabobject();
}
}
//?2
if?(Controller.GetHairTriggerUp())
{
if?(objectInHand)
{
Releaseobject();
}
}
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????8506??2017-11-23?19:58??Introduction-To-HTC-Vive-Starter\Assembly-CSharp-Editor.csproj
?????文件??????14945??2017-11-23?19:19??Introduction-To-HTC-Vive-Starter\Assembly-CSharp.csproj
????I.A....??????5016??2017-11-23?18:57??Introduction-To-HTC-Vive-Starter\Assets\Materials\Laser.mat
?????文件????????208??2017-11-23?16:05??Introduction-To-HTC-Vive-Starter\Assets\Materials\Laser.mat.me
?????文件???????5024??2016-12-05?05:31??Introduction-To-HTC-Vive-Starter\Assets\Materials\ShinyBall.mat
?????文件????????180??2016-12-05?05:27??Introduction-To-HTC-Vive-Starter\Assets\Materials\ShinyBall.mat.me
?????文件???????5032??2016-12-05?07:42??Introduction-To-HTC-Vive-Starter\Assets\Materials\TransparentViveMap.mat
?????文件????????180??2016-12-05?07:39??Introduction-To-HTC-Vive-Starter\Assets\Materials\TransparentViveMap.mat.me
?????文件???????5020??2016-12-05?08:46??Introduction-To-HTC-Vive-Starter\Assets\Materials\ViveMap.mat
?????文件????????180??2016-12-04?07:31??Introduction-To-HTC-Vive-Starter\Assets\Materials\ViveMap.mat.me
?????文件????????192??2016-12-04?06:19??Introduction-To-HTC-Vive-Starter\Assets\Materials.me
?????文件??????20748??2016-12-06?23:02??Introduction-To-HTC-Vive-Starter\Assets\Models\Brick.fbx
?????文件???????1924??2016-12-06?23:02??Introduction-To-HTC-Vive-Starter\Assets\Models\Brick.fbx.me
?????文件??????29996??2016-12-05?04:52??Introduction-To-HTC-Vive-Starter\Assets\Models\Level.fbx
?????文件???????2300??2016-12-05?00:34??Introduction-To-HTC-Vive-Starter\Assets\Models\Level.fbx.me
?????文件??????20396??2016-12-05?04:51??Introduction-To-HTC-Vive-Starter\Assets\Models\RwCube.fbx
?????文件???????2076??2016-12-05?04:50??Introduction-To-HTC-Vive-Starter\Assets\Models\RwCube.fbx.me
?????文件??????19276??2016-12-05?07:41??Introduction-To-HTC-Vive-Starter\Assets\Models\TeleportReticle.fbx
?????文件???????1926??2016-12-05?07:41??Introduction-To-HTC-Vive-Starter\Assets\Models\TeleportReticle.fbx.me
?????文件????????192??2016-12-04?06:08??Introduction-To-HTC-Vive-Starter\Assets\Models.me
?????文件???????4156??2016-12-05?05:34??Introduction-To-HTC-Vive-Starter\Assets\Physics?Materials\Bouncy.physicMaterial
?????文件????????180??2016-12-05?05:25??Introduction-To-HTC-Vive-Starter\Assets\Physics?Materials\Bouncy.physicMaterial.me
?????文件????????192??2016-12-05?05:25??Introduction-To-HTC-Vive-Starter\Assets\Physics?Materials.me
?????文件???????7488??2016-12-05?06:54??Introduction-To-HTC-Vive-Starter\Assets\Prefabs\Ball.prefab
?????文件????????180??2016-12-05?05:27??Introduction-To-HTC-Vive-Starter\Assets\Prefabs\Ball.prefab.me
?????文件??????27968??2016-12-06?23:16??Introduction-To-HTC-Vive-Starter\Assets\Prefabs\Bricks.prefab
?????文件????????180??2016-12-06?23:08??Introduction-To-HTC-Vive-Starter\Assets\Prefabs\Bricks.prefab.me
????I.A....??????5996??2017-11-23?16:07??Introduction-To-HTC-Vive-Starter\Assets\Prefabs\Laser.prefab
?????文件????????210??2017-11-23?16:07??Introduction-To-HTC-Vive-Starter\Assets\Prefabs\Laser.prefab.me
?????文件???????7512??2016-12-05?06:54??Introduction-To-HTC-Vive-Starter\Assets\Prefabs\RwCube.prefab
............此處省略2452個(gè)文件信息
評論
共有 條評論