怎么加u3d场景中添加u3d中如何链接vr手柄柄抓取

关于用暴风SDK在unity中加入VR效果和利用暴风手柄进行操作 - 萨瓦迪卡麦兜兜 - 博客园
随笔 - 22, 文章 - 0, 评论 - 2, 引用 - 0
首先在暴风魔镜开发平台下载SDK。地址:/sdk/download?pid=2& 下载unity的工具 MojingSDK。,
然后我用的是unity5.42的版本然后将SDK导入unity中。文件夹中包含
接口说明文档说的也比较清楚。
在unity中搭建一个简单的场景需要放入Prefab的MojingMain。并将场景摄像机放入其中并挂上MojingEye脚本 Eye枚举选项为Center
并且添加prefab Overlay。
如果要进行手柄UI交互的话需要更改EvenSystem。并添加IntegratIpnutManager。
然后你就需要制作UI了。Canvas中需要设置为WorldSpace。并添加你的MainCamera摄像机。
Mydemo脚本中我写的是Button的点击事件
1 public class MyDemo : MonoBehaviour {
public Text text1;
public bool isok = false;
public bool isok1 = false;
public void MyText()
<span style="color: #
<span style="color: #
text.text = "hahah";
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
text.text = "xxxx";
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
public void MyText1()
<span style="color: #
<span style="color: #
isok1 = !isok1;
<span style="color: #
if (isok1)
<span style="color: #
<span style="color: #
text1.text = "<span style="color: #";
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
text1.text = "<span style="color: #";
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: # }
GameController脚本中则是它Demo中的手柄上下左右控制的显示事件
1 public class gameController : MonoBehaviour {
public GameObject[] Button_O
private int buttonCurIndex = -<span style="color: #;
public MyD
void Start()
public void HoverNext()
buttonCurIndex++;
buttonCurIndex = buttonCurIndex % Button_Object.L
for (int i = <span style="color: #; i & Button_Object.L i++)
if (i != buttonCurIndex)
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.0f, <span style="color: #.0f, <span style="color: #.0f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
//ExecuteEvents.Execute(Button_Object[i], null, ExecuteEvents.pointerClickHandler);
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.5f, <span style="color: #.0f, <span style="color: #.5f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
public void HoverPrev()
buttonCurIndex--;
if (buttonCurIndex & <span style="color: #)
buttonCurIndex = Button_Object.Length - <span style="color: #;
for (int i = <span style="color: #; i & Button_Object.L i++)
if (i != buttonCurIndex)
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.0f, <span style="color: #.0f, <span style="color: #.0f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
//ExecuteEvents.Execute(Button_Object[i], null, ExecuteEvents.pointerClickHandler);
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.5f, <span style="color: #.0f, <span style="color: #.5f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
public void HoverRight()
if (buttonCurIndex & Button_Object.Length / <span style="color: #)
buttonCurIndex = buttonCurIndex + Button_Object.Length / <span style="color: #;
for (int i = <span style="color: #; i & Button_Object.L i++)
if (i != buttonCurIndex)
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.0f, <span style="color: #.0f, <span style="color: #.0f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.5f, <span style="color: #.0f, <span style="color: #.5f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
public void HoverLeft()
if (buttonCurIndex &= Button_Object.Length / <span style="color: #)
buttonCurIndex = buttonCurIndex - Button_Object.Length / <span style="color: #;
for (int i = <span style="color: #; i & Button_Object.L i++)
if (i != buttonCurIndex)
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.0f, <span style="color: #.0f, <span style="color: #.0f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
Button_Object[i].GetComponent&Image&().color = new Color(<span style="color: #.5f, <span style="color: #.0f, <span style="color: #.5f);
Button_Object[i].GetComponent&RectTransform&().sizeDelta = new Vector2(<span style="color: #0, <span style="color: #);
<span style="color: #0
<span style="color: #1
<span style="color: #2
public void PressCurrent()
<span style="color: #3
<span style="color: #4
switch (buttonCurIndex)
<span style="color: #5
<span style="color: #6
case <span style="color: #:
<span style="color: #7
demo.MyText();
<span style="color: #8
<span style="color: #9
<span style="color: #0
<span style="color: #1
switch (buttonCurIndex)
<span style="color: #2
<span style="color: #3
case <span style="color: #:
<span style="color: #4
demo.MyText1();
<span style="color: #5
<span style="color: #6
<span style="color: #7
<span style="color: #8
<span style="color: #9
<span style="color: #0 }
而最后Lkll脚本中则是它手柄时间的接口,在接口绑定你的点击时间就可以了
public class lkll : MonoBehaviour
public gameController menu_
// public GlassesList glass_
void Update()
if (CrossPlatformInputManager.GetButtonLongPressed("OK") || CrossPlatformInputManager.GetButtonLongPressed("A"))
Debug.Log("OK-----Long GetButtonDown");
if (CrossPlatformInputManager.GetButtonDown("OK"))
Debug.Log("OK-----GetButtonDown");
if (CrossPlatformInputManager.GetButton("OK"))
Debug.Log("OK-----GetButton");
else if (CrossPlatformInputManager.GetButtonUp("OK") || CrossPlatformInputManager.GetButtonUp("A"))
menu_controller.PressCurrent();
if (CrossPlatformInputManager.GetButtonDown("C"))
Debug.Log("C-----GetButtonDown");
if (CrossPlatformInputManager.GetButton("C"))
Debug.Log("C-----GetButton");
else if (CrossPlatformInputManager.GetButtonUp("C") || CrossPlatformInputManager.GetButtonUp("B"))
#if !UNITY_EDITOR && UNITY_ANDROID
Application.Quit();
if (CrossPlatformInputManager.GetButtonDown("MENU"))
Debug.Log("MENU-----GetButtonDown");
if (CrossPlatformInputManager.GetButton("MENU"))
Debug.Log("MENU-----GetButton");
else if (CrossPlatformInputManager.GetButtonUp("MENU") || CrossPlatformInputManager.GetButtonUp("X"))
Debug.Log("MENU-----GetButtonUp");
MojingSDK.Unity_ResetSensorOrientation();
if (CrossPlatformInputManager.GetButton("UP"))
Debug.Log("UP-----GetButton");
else if (CrossPlatformInputManager.GetButtonUp("UP"))
menu_controller.HoverPrev();
if (CrossPlatformInputManager.GetButton("DOWN"))
Debug.Log("DOWN-----GetButton");
else if (CrossPlatformInputManager.GetButtonUp("DOWN"))
Debug.Log("DOWN-----GetButtonUp");
menu_controller.HoverNext();
if (CrossPlatformInputManager.GetButton("LEFT"))
Debug.Log("LEFT-----GetButton");
else if (CrossPlatformInputManager.GetButtonUp("LEFT"))
menu_controller.HoverLeft();
if (CrossPlatformInputManager.GetButton("RIGHT"))
Debug.Log("RIGHT-----GetButton");
else if (CrossPlatformInputManager.GetButtonUp("RIGHT"))
menu_controller.HoverRight();
if (CrossPlatformInputManager.GetButton("CENTER"))
else if (CrossPlatformInputManager.GetButtonUp("CENTER"))
&然后打包apk包并倒入到安卓手机中,在运行Demo之前需要先打开手机蓝牙并与暴风蓝牙手柄对接,对接完成后运行Demo就可以进行操控了。鏌ョ湅: 19556|鍥炲?: 9
Unity 5.1 VR 鍏ラ棬鎸囧崡
褰撳墠绂荤嚎
涓婚?甯栧瓙璐$尞
鐢垫?鐩磋揪
濡傛灉鎮ㄦ?鍦ㄤ娇鐢║nity寮}

我要回帖

更多关于 u3d vr教程 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信