Pico老版SDK为我们提供了很多的API,但是手柄上的很多功能需要我们自己编写。这篇文章记录一下手柄的一些常用控制功能。

1.手柄射线以及射线检测。

2.手柄的触碰。

3.主手柄切换。

using System;
using UnityEngine;
using System.Collections;
using Pvr_UnitySDKAPI;
using UnityEngine.SceneManagement;public class Pvr_ControllerHand : MonoBehaviour
{public GameObject controller0;public GameObject controller1;[HideInInspector]public GameObject currentController;private GameObject rayLine;private GameObject dot;private GameObject ray_alpha;void Start(){Sensor.UPvr_OptionalResetSensor(0, 1, 1);SetMainHand(controller1);Controller.UPvr_SetMainHandNess(1);}void Update(){if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TRIGGER)|| Input.GetKeyDown(KeyCode.A)|| Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.X)|| Controller.UPvr_GetJoystickUp(0)){Debug.Log("切换==========" + 0);Controller.UPvr_SetMainHandNess(0);SetMainHand(controller0);}if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TRIGGER)|| Input.GetKeyDown(KeyCode.B)|| Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.A)|| Controller.UPvr_GetJoystickUp(1)){Debug.Log("切换==========" + 1);Controller.UPvr_SetMainHandNess(1);SetMainHand(controller1);}if (Controller.UPvr_GetJoystickUp(1)|| Controller.UPvr_GetJoystickUp(0)|| Input.GetMouseButton(0)){if (dot != null)dot.SetActive(false);if (rayLine != null)rayLine.SetActive(false);if (ray_alpha != null)ray_alpha.SetActive(false);}if (!Controller.UPvr_GetJoystickUp(1)&& !Controller.UPvr_GetJoystickUp(0)|| Input.GetMouseButtonUp(0)){if (dot != null)dot.SetActive(true);if (rayLine != null)rayLine.SetActive(true);if (ray_alpha != null)ray_alpha.SetActive(true);}if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.APP)|| Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.APP)){SceneManager.LoadSceneAsync("Start");}RayCast();}/// <summary>/// 设置主手柄/// </summary>/// <param name="hand"></param>void SetMainHand(GameObject hand){if (dot != null)dot.SetActive(false);if (rayLine != null)rayLine.SetActive(false);if (ray_alpha != null)ray_alpha.SetActive(false);currentController = hand;dot = hand.transform.Find("dot").gameObject;dot.SetActive(true);rayLine = hand.transform.Find("ray_LengthAdaptive").gameObject;rayLine.SetActive(true);ray_alpha = hand.transform.Find("ray_alpha").gameObject;ray_alpha.SetActive(true);}GameObject RayCastObj(){if (Controller.UPvr_GetMainHandNess() == 0){if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TRIGGER) || Input.GetMouseButtonDown(0)){return RayCast();}elsereturn null;}else if (Controller.UPvr_GetMainHandNess() == 1){if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TRIGGER) || Input.GetMouseButtonDown(0)){return RayCast();}elsereturn null;}elsereturn null;}/// <summary>/// 物体是否点击/// </summary>/// <param name="go"></param>/// <returns></returns>public bool SelectObj(GameObject go){if (RayCastObj() == go)return true;elsereturn false;}/// <summary>/// 拿取/// </summary>/// <param name="go"></param>public void TakeUpObj(GameObject go){if (Controller.UPvr_GetMainHandNess() == 0){if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.Left) && RayCast() == go){go.transform.SetParent(currentController.transform);}if (Controller.UPvr_GetKeyUp(0, Pvr_KeyCode.Left) && RayCast() == go){go.transform.SetParent(null);}}if (Controller.UPvr_GetMainHandNess() == 1){if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.Right) && RayCast() == go){go.transform.SetParent(currentController.transform);}if (Controller.UPvr_GetKeyUp(1, Pvr_KeyCode.Right) && RayCast() == go){go.transform.SetParent(null);}}}/// <summary>/// 射线绘制/// </summary>/// <returns></returns>GameObject RayCast(){Ray ray = new Ray(currentController.transform.position, currentController.transform.forward - currentController.transform.up * 0.25f);RaycastHit hit;rayLine.GetComponent<LineRenderer>().SetPosition(0, currentController.transform.TransformPoint(0, 0, 0.072f));rayLine.GetComponent<LineRenderer>().SetPosition(1, dot.transform.position);if (Physics.Raycast(ray, out hit, Mathf.Infinity)){//    Debug.Log("碰撞对象: " + hit.collider.name);Debug.DrawLine(ray.origin, hit.point, Color.red);dot.transform.position = hit.point;return hit.collider.gameObject;}elsereturn null;}
}

Unity Pico老版SDK手柄功能编写相关推荐

  1. unity pico串流与打包时手柄配置细节

    1.改动select action时 选择"Pico Live Preview Controller"方可在串流时使用手柄功能键位(左右手柄改法相同) 且在select value ...

  2. Java版基于springboot+maven海康摄像头sdk抓拍功能的二次开发

    相信在用Java开发海康摄像头的小袁袁都很苦恼官网给的SDK,官方的SDK中有demo,有文档,可那大多都是基于C写的文档,找了半天终于找到一个java版本的,进去一看还是用Jfream写的C/S版的 ...

  3. 《C++ Primer 第五版》(第2.5节,第3.1-3.4节) ——采用预处理功能编写头文件,string初始化和字符操作,vector初始化和迭代器

    1.采用预处理功能编写头文件 在头文件定义(头文件中的内容是只能被定义一次的实体)过程中,为了防止头文件重复包含的情况,采用预处理器的一个头文件保护符功能,格式为:{  #ifndef 预处理变量(通 ...

  4. Unity的HTC VIVE SDK研究(手柄按键功能的研究,比较详细)

    http://blog.csdn.net/ystistheking/article/details/51553237 想交流的朋友我们可以微博互粉,我的微博黑石铸造厂厂长 ,缺粉丝啊 .....求粉求 ...

  5. 老子云SDK免费使用,实现3D开发自由

    随着3D元素在日常生活的广泛应用,3D可视化也开始承载越来越多的功能,这意味着更细致的交互要求.更复杂的逻辑关系,也意味着更庞大的开发工作量. 为了减轻用户开发压力,老子云团队一直致力于3D可视化底层 ...

  6. 企业微信会话内容存档PHP版SDK编译详细步骤

    感谢这位老哥编写的SDK: https://github.com/pangdahua/php7-wxwork-finance-sdkhttps://github.com/pangdahua/php7- ...

  7. 万普平台Android版SDK开发者手册

    万普平台Android版SDK开发者手册 (标准版Ver1.8.4) 平台简介 万普世纪移动营销服务平台(以下称为"万普平台")的Android 版SDK 提供了一套现成的开发包及 ...

  8. python模拟足球射门_[转载]博客园仿真足球竞赛平台Python版SDK

    为了方便喜欢Python的同学能使用Python开发自己的球队,所以编写了此SDK.这个SDK 基本上是参照C#版SDK改过来的,除了一些复杂的几何算法没有实现外,其他功能都已实现.喜欢的朋友可以自己 ...

  9. Unity 华为HMS/AGC SDK集成简介(以接入华为广告流量变现服务为例)

    本篇以接入华为广告为例,介绍如何使Unity项目直接集成 Huawei HMS /AGC 服务. 内容概述 中国Unity封装了基于华为HMS/AGC服务的SDK,对于移动端项目开发,可以直接在Uni ...

最新文章

  1. date oracle 显示毫秒_oracle数据库to_date日期格式化到毫秒 | 学步园
  2. IPHONE 64位和32位
  3. pytorch Tensor的操作和Numpy之间的转化(三)
  4. leetCode #26 Remove Duplicates from Sorted Array
  5. (一)数据结构与算法简介
  6. Tekson的数据结构程序9——搜索
  7. Linux的SWAP分区空间不够用的情况下,如何添加SWAP分区
  8. apktool 在mac下的使用 -反编译安卓apk文件
  9. python控制结构实验结果分析_实验1_Python语法及控制结构
  10. python人脸识别防小偷_Python人脸识别
  11. java 6 损坏,Java 异常处理六
  12. form和ajax同时提交吗,form表单提交与ajax消息传递
  13. 网络间谍在2017年被列为全球企业最为严重的威胁
  14. Linux中常用命令(文件)
  15. 7. Nginx 预定义变量
  16. ERP原理:第一节 ERP的总体结构
  17. Win32DiskImager写入U盘容量变小 提示格式化
  18. MyBatis 大于小于符号表示
  19. 公考复盘(二)——第五季第六季
  20. 假冒Macbook充电器拆解:外表令人信服但内部却非常危险

热门文章

  1. python - 03【列表/元组/字符串】
  2. 基于Python,从零开始,裸写一套期权定价程序
  3. 【附源码】Python计算机毕业设计社区志愿者管理系统
  4. React打包出现:The project was built assuming it is hosted at ./.
  5. mathtype 7.4安装教程
  6. 用html制作chm,用HTML Help Workshop制作chm.doc
  7. 大学生创新创业项目管理系统
  8. 计算机科学导论-绪论
  9. 为什么需要工单系统?
  10. 前端插件日常问题 整理