Skip to content

Instantly share code, notes, and snippets.

@naojitaniguchi
Created November 28, 2016 22:56
Show Gist options
  • Save naojitaniguchi/58afae51ee98c5da38718bc70b2a609d to your computer and use it in GitHub Desktop.
Save naojitaniguchi/58afae51ee98c5da38718bc70b2a609d to your computer and use it in GitHub Desktop.
Get OSC message sample script for UniOSC
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
using System.Collections.Generic;
using System;
using OSCsharp.Data;
namespace UniOSC{
public class UniOSCGetMessageSample : UniOSCEventTarget {
Vector3 pos ;
Quaternion rot ;
void Awake(){
}
public override void OnEnable(){
base.OnEnable();
}
public override void OnOSCMessageReceived(UniOSCEventArgs args){
Debug.Log ( "Address:" + args.Address );
// args.Address
OscMessage msg = (OscMessage)args.Packet;
if ( args.Address == "/someting"){
// do someting
}
if ( msg.Data.Count >= 2 ){
if ( args.Address == "/pos"){
float x = (float)msg.Data[0];
float y = (float)msg.Data[1];
float z = (float)msg.Data[2];
pos = new Vector3( x, y, z ) ;
}
if ( args.Address == "/rot"){
float x = (float)msg.Data[0];
float y = (float)msg.Data[1];
float z = (float)msg.Data[2];
float w = (float)msg.Data[3];
rot = new Quaternion( x, y, z, w );
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment