资源简介

硬件为HTC-VIVE,使用Unity3D V5.6.4搭建室内小场景。功能包括拾取、抛扔物体;射线相交位置瞬移等功能。

资源截图

代码片段和文件信息

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();
}
}
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       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.meta

     文件       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.meta

     文件       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.meta

     文件       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.meta

     文件        192  2016-12-04 06:19  Introduction-To-HTC-Vive-Starter\Assets\Materials.meta

     文件      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.meta

     文件      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.meta

     文件      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.meta

     文件      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.meta

     文件        192  2016-12-04 06:08  Introduction-To-HTC-Vive-Starter\Assets\Models.meta

     文件       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.meta

     文件        192  2016-12-05 05:25  Introduction-To-HTC-Vive-Starter\Assets\Physics Materials.meta

     文件       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.meta

     文件      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.meta

    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.meta

     文件       7512  2016-12-05 06:54  Introduction-To-HTC-Vive-Starter\Assets\Prefabs\RwCube.prefab

............此处省略2452个文件信息

评论

共有 条评论