在上一遍 我们大概了解TUIO协议 和雷达 都是什么鬼,这篇主要是介绍一下 unity 与 tuio 的通信 

首先我们是在Unity 中引入了两个库 OSCsharp  TUIOsharp进行接收数据

具体库中信息可查看 https://github.com/valyard/TUIOsharp

/*Simple TUIO v1.1 / OSC v1.1 network listener.Listen for TUIO or OSC network traffic and output it to the console. Useful for quickly checking/debugging data sent from TUIO server apps.Defaults to listening for TUIO on port 3333. Output radians/degrees using rads/degs options. Invert X/Y axis values in TUIO data using the invertx/y/xy options.Usage:> mono TUIOListener [port] [tuio|osc] [rads|degs] [invertx|inverty|invertxy]> mono TUIOListener -helpLibraries:https://github.com/valyard/TUIOsharp (v1.1 development branch)https://github.com/valyard/OSCsharpAuthor:Greg Harding greg@flightless.co.nzwww.flightless.co.nzCopyright 2015 Flightless Ltd.The MIT License (MIT)Copyright (c) 2015 Flightless LtdPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.*/using System;
using System.Threading;
using System.Collections.Generic;
using System.Text;using TUIOsharp;
using TUIOsharp.DataProcessors;
using TUIOsharp.Entities;using OSCsharp;
using OSCsharp.Data;
using OSCsharp.Net;
using OSCsharp.Utils;
using UnityEngine;namespace TUIOListener
{class Program : MonoBehaviour{//public enum MessageType//{//    TUIO,//    OSC//};public static int port = 3333;//public static MessageType messageType = MessageType.TUIO;public static bool degs = false;public static bool invertX = false;public static bool invertY = false;private static TuioServer tuioServer;private int screenWidth;private int screenHeight;private void connect(){if (!Application.isPlaying) return;if (tuioServer != null) disconnect();tuioServer = new TuioServer(port);Debug.Log("TUIO Port" + port);tuioServer.Connect();Debug.Log("TUIO Connect");}private void OnEnable(){Debug.Log(string.Format("TUIO listening on port {0}... (Press escape to quit)", port));screenWidth = Screen.width;screenHeight = Screen.height;// tuioCursorProcessor cursorProcessor = new CursorProcessor();cursorProcessor.CursorAdded += OnCursorAdded;cursorProcessor.CursorUpdated += OnCursorUpdated;cursorProcessor.CursorRemoved += OnCursorRemoved;BlobProcessor blobProcessor = new BlobProcessor();blobProcessor.BlobAdded += OnBlobAdded;blobProcessor.BlobUpdated += OnBlobUpdated;blobProcessor.BlobRemoved += OnBlobRemoved;ObjectProcessor objectProcessor = new ObjectProcessor();objectProcessor.ObjectAdded += OnObjectAdded;objectProcessor.ObjectUpdated += OnObjectUpdated;objectProcessor.ObjectRemoved += OnObjectRemoved;// listen...connect();tuioServer.AddDataProcessor(cursorProcessor);tuioServer.AddDataProcessor(blobProcessor);tuioServer.AddDataProcessor(objectProcessor);Debug.Log("connect");}protected void OnDisable(){disconnect();}private void OnCursorAdded(object sender, TuioCursorEventArgs e){var entity = e.Cursor;lock (tuioServer){//var x = invertX ? (1 - entity.X) : entity.X;//var y = invertY ? (1 - entity.Y) : entity.Y;var x = entity.X * screenWidth;var y = (1 - entity.Y) * screenHeight;Debug.Log(string.Format("{0} Cursor Added {1}:{2},{3}", ((CursorProcessor)sender).FrameNumber, entity.Id, x, y));}Debug.Log("OnCursorAdded");}private void OnCursorUpdated(object sender, TuioCursorEventArgs e){var entity = e.Cursor;lock (tuioServer){//var x = invertX ? (1 - entity.X) : entity.X;//var y = invertY ? (1 - entity.Y) : entity.Y;var x = Mathf.Round(entity.X * screenWidth);var y = (1 - entity.Y) * screenHeight;Debug.Log(string.Format("{0} Cursor Moved {1}:{2},{3}", ((CursorProcessor)sender).FrameNumber, entity.Id, x, y));//MyTest.Instance.LimitGetPos(remapCoordinates(new Vector2(x, y)));//项目中测试方法 //MyTest.Instance.LimitGetPos(new Vector2(x, y));}Debug.Log("OnCursorUpdated");}private void OnCursorRemoved(object sender, TuioCursorEventArgs e){var entity = e.Cursor;lock (tuioServer){Debug.Log(string.Format("{0} Cursor Removed {1}", ((CursorProcessor)sender).FrameNumber, entity.Id));}}private static void OnBlobAdded(object sender, TuioBlobEventArgs e){var entity = e.Blob;lock (tuioServer){var x = invertX ? (1 - entity.X) : entity.X;var y = invertY ? (1 - entity.Y) : entity.Y;var angle = degs ? (entity.Angle * (180f / Math.PI)) : entity.Angle;Debug.Log(string.Format("{0} Blob Added {1}:{2},{3} {4:F3}", ((BlobProcessor)sender).FrameNumber, entity.Id, x, y, angle));}Debug.Log("OnBlobAdded");}private static void OnBlobUpdated(object sender, TuioBlobEventArgs e){var entity = e.Blob;lock (tuioServer){var x = invertX ? (1 - entity.X) : entity.X;var y = invertY ? (1 - entity.Y) : entity.Y;var angle = degs ? (entity.Angle * (180f / Math.PI)) : entity.Angle;Debug.Log(string.Format("{0} Blob Moved {1}:{2},{3} {4:F3}", ((BlobProcessor)sender).FrameNumber, entity.Id, x, y, angle));}Debug.Log("OnBlobUpdated");}private static void OnBlobRemoved(object sender, TuioBlobEventArgs e){var entity = e.Blob;lock (tuioServer){Debug.Log(string.Format("{0} Blob Removed {1}", ((BlobProcessor)sender).FrameNumber, entity.Id));}Debug.Log("OnBlobRemoved");}private static void OnObjectAdded(object sender, TuioObjectEventArgs e){var entity = e.Object;lock (tuioServer){var x = invertX ? (1 - entity.X) : entity.X;var y = invertY ? (1 - entity.Y) : entity.Y;var angle = degs ? (entity.Angle * (180f / Math.PI)) : entity.Angle;Debug.Log(string.Format("{0} Object Added {1}/{2}:{3},{4} {5:F3}", ((ObjectProcessor)sender).FrameNumber, entity.ClassId, entity.Id, x, y, angle));}Debug.Log("OnObjectAdded");}private static void OnObjectUpdated(object sender, TuioObjectEventArgs e){var entity = e.Object;lock (tuioServer){var x = invertX ? (1 - entity.X) : entity.X;var y = invertY ? (1 - entity.Y) : entity.Y;var angle = degs ? (entity.Angle * (180f / Math.PI)) : entity.Angle;Debug.Log(string.Format("{0} Object Moved {1}/{2}:{3},{4} {5:F3}", ((ObjectProcessor)sender).FrameNumber, entity.ClassId, entity.Id, x, y, angle));}}private static void OnObjectRemoved(object sender, TuioObjectEventArgs e){var entity = e.Object;lock (tuioServer){Debug.Log(string.Format("{0} Object Removed {1}/{2}", ((ObjectProcessor)sender).FrameNumber, entity.ClassId, entity.Id));}}void disconnect(){if (tuioServer != null){tuioServer.RemoveAllDataProcessors();tuioServer.Disconnect();tuioServer = null;}}}}

这样你就可以与雷达正常互动了,当然了 你光有雷达是不行的,你需要一个终端软件,这个你谷歌一下就可以搜出来,一般这个软件都是有厂家开发的 有一款是用Unity 做了一个客户端,里面融入了一个dll,如果想使用的话,基本上是一个加密狗 + 软件进行使用,而雷达厂商提供c的demo代码是纯c的,但是可以被认c语法的编程环境认,就从雷达厂商给的代码是c的都能看出来他们主要给单片机用和stm32用。

目前项目还在实践ing~~~~~~

下一篇将介绍tuio + 雷达 + Unity 的探坑之旅

【Unity】雷达+Unity +TUIO 介绍二相关推荐

  1. Unity C# Job System介绍(二) 安全性系统和NativeContainer

    C# Job System中的安全性系统 https://docs.unity3d.com/Manual/JobSystemSafetySystem.html​docs.unity3d.com 资源竞 ...

  2. Unity中的shadows(二)cast shadows

    Unity中的shadows(二)cast shadows 投射阴影(平行光,聚光灯) UnityApplyLinearShadowBias UnityClipSpaceShadowCasterPos ...

  3. Unity4.x 2D游戏开发基础教程第1章Unity及其组成的介绍

    Unity4.x 2D游戏开发基础教程第1章Unity及其组成的介绍 本书主要讲解的是,如何使用Unity开发2D游戏.但在开始讲解之前,最好先熟悉一下Unity这个工具.本章会首先介绍Unity的下 ...

  4. Unity学习笔记(一)~介绍以及入门

    1.简单的个人介绍 在介绍Unity前,容许我介绍一个自己吧,毕竟自我介绍是每一个码农,咳咳,每一个求职人员必备的一项工作,虽然感觉就是一个开场白吧. 本人呢就是普通的本科毕业,既不是985也不是21 ...

  5. 如何使用Unity制作虚拟导览(二)

    在这个教程里面,我们将介绍如何将SketchUp制作的建筑模型导入Unity,这里面使用的是SketchUp 2014的最新版本,关于SketchUp的相关介绍请参考: SketchUp 2014 模 ...

  6. Unity面试题加强版之二《unity编辑器基础》

    Unity面试题加强版之二Unity编辑器基础 unity超全面试题,掌握轻轻松松拿Offer,码住学习 40.请描述游戏动画有几种,以及其原理. 主要有关节动画.单一网格模型动画(关键帧动画).骨骼 ...

  7. 【Unity】Unity Shader学习笔记(二)渲染管线

    文章目录 渲染管线(Randering Pipeline) 渲染流程 可编程渲染管线 应用阶段 把数据加载到显存中 设置渲染状态 调用DrawCall 几何阶段.光栅化阶段 渲染管线(Randerin ...

  8. Unity编辑器UnityEditor基础(二)

    Unity编辑器UnityEditor基础(二) 终极目标 利用学到的东西制作自己的工具(自定义的窗口.Inspector.菜单.插件等等). 准备工作 还是使用上一篇的 Unity 工程,然后在 S ...

  9. 【Unity】Unity 基本介绍

    什么是Unity引擎 Unity是一款跨平台的游戏引擎,包含以下系统:渲染引擎.物理引擎.碰撞检测系统.音效引擎.脚本引擎.动画系统.人工智能.网络引擎.场景管理等.Unity提供了丰富且强大的各类功 ...

  10. Unity学习 — Unity与LeanCloud数据存储

    Unity 使用LeanCloud存取数据 一:LeanCloud 介绍 二:LeanCloud 特点 1:数据存储,替代传统数据库的高效云端存储 2:云引擎+云缓存 3:即时通讯 4:游戏解决方案 ...

最新文章

  1. java reference详解_Java Reference详解
  2. pythonscrapy爬虫_python爬虫scrapy之如何同时执行多个scrapy爬行任务
  3. 对check list理解
  4. PHP第一天 ① 重置端口命令 netsh winsock reset
  5. LeetCode 592
  6. 计算机丢失OX0000007B,win10系统应用程序无法正常启动0x000007b的解决办法
  7. outlook一直显示尝试连接服务器,OUTLOOK EXPRESS老是连接不上服务器怎么办?
  8. 语言识别之根据字典矫正文本及其c++代码实现
  9. 手把手教你备份 nvidia jetson agx xavier 系统(亲测有效、超详细)
  10. 【老九学堂】【C++】编码命名规范
  11. 同轴电缆传输容易出现哪些干扰?
  12. CPU—Time Profiler
  13. 使用高德地图的逆向地址,获取坐标点
  14. buu Crypto学习记录(36) 还原大师
  15. 泊松分布的“入最大似然估计
  16. 分享一个免费储存视频的地方、公司的小视频可以随便的上传
  17. Windows上搭建rtsp-simple-server流媒体服务器实现rtsp、rtmp等推流以及转流、前端html与Vue中播放hls(m3u8)视频流
  18. Python: 阶乘计算
  19. java序列化编码_java IO操作(输入,输出,序列化,编码方式)示例代码 第一部分...
  20. java super关键字的作用_详解Java编程中super关键字的用法

热门文章

  1. 如何编写自己的python包,并进行安装和发布
  2. 前端技术-HTML5与CSS
  3. 计算机添加usb网络打印机,路由器openWrt固件使用USB打印机设置电脑添加网络USB打印机方法...
  4. 关于网络超时时间那些事
  5. tensorflow中常用的激活函数
  6. vue 多个组件动态加载(动态组件的使用)
  7. 计算机视觉的发展历程
  8. js定义对象的多个属性值
  9. 手机卫星定位系统_真的可以通过手机号码,准确定位对方信息吗?
  10. 直流可逆调速控制系统matlab,逻辑无环流直流可逆调速系统的Matlab仿真