Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Commit 7959ec3

Browse files
author
Thomas O Fredericks
committed
Unity 2018, fixed float to int, fixed EditorApplication.playmodeStateChanged
1 parent 3b70188 commit 7959ec3

File tree

7 files changed

+31
-50
lines changed

7 files changed

+31
-50
lines changed

Assets/OSC/OSC.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,16 @@ public override string ToString() {
334334

335335
public int GetInt(int index) {
336336

337-
if (values [index].GetType() == typeof(int) || values [index].GetType() == typeof(float) ) {
337+
if (values [index].GetType() == typeof(int) ) {
338338
int data = (int)values[index];
339339
if (Double.IsNaN(data)) return 0;
340340
return data;
341-
} else {
341+
}
342+
else if (values[index].GetType() == typeof(float)) {
343+
int data = (int)((float)values[index]);
344+
if (Double.IsNaN(data)) return 0;
345+
return data;
346+
} else {
342347
Debug.Log("Wrong type");
343348
return 0;
344349
}
@@ -405,22 +410,23 @@ public class OSC : MonoBehaviour
405410
bool paused = false;
406411

407412

408-
409-
void HandleOnPlayModeChanged()
410-
{
413+
#if UNITY_EDITOR
414+
415+
private void HandleOnPlayModeChanged(UnityEditor.PlayModeStateChange state) //FIX FOR UNITY POST 2017
416+
{
411417
// This method is run whenever the playmode state is changed.
412418

413-
#if UNITY_EDITOR
419+
414420
paused = UnityEditor.EditorApplication.isPaused;
415421
//print ("editor paused "+paused);
416422
// do stuff when the editor is paused.
417-
#endif
423+
418424
}
425+
#endif
419426

420427

421428

422-
423-
void Awake() {
429+
void Awake() {
424430
//print("Opening OSC listener on port " + inPort);
425431

426432
OscPacketIO = new UDPPacketIO(outIP, outPort, inPort);
@@ -436,11 +442,12 @@ void Awake() {
436442
ReadThread.IsBackground = true;
437443
ReadThread.Start();
438444

439-
#if UNITY_EDITOR
440-
UnityEditor.EditorApplication.playmodeStateChanged = HandleOnPlayModeChanged;
441-
#endif
445+
#if UNITY_EDITOR
446+
//UnityEditor.EditorApplication.playmodeStateChanged = HandleOnPlayModeChanged;
447+
UnityEditor.EditorApplication.playModeStateChanged += HandleOnPlayModeChanged; //FIX FOR UNITY POST 2017
448+
#endif
442449

443-
}
450+
}
444451

445452
void OnDestroy() {
446453
Close();

Assets/ReceivePosition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ void Update () {
2020
}
2121

2222
void OnReceiveXYZ(OscMessage message){
23-
float x = message.GetFloat(0);
24-
float y = message.GetFloat(1);
25-
float z = message.GetFloat(2);
23+
float x = message.GetInt(0);
24+
float y = message.GetInt(1);
25+
float z = message.GetInt(2);
2626

2727
transform.position = new Vector3(x,y,z);
2828
}

OSC max example.maxpat

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"appversion" : {
55
"major" : 7,
66
"minor" : 3,
7-
"revision" : 1,
8-
"architecture" : "x86",
7+
"revision" : 5,
8+
"architecture" : "x64",
99
"modernui" : 1
1010
}
1111
,
12-
"rect" : [ 355.0, 285.0, 586.0, 497.0 ],
12+
"rect" : [ 924.0, 253.0, 586.0, 497.0 ],
1313
"bglocked" : 0,
1414
"openinpresentation" : 0,
1515
"default_fontsize" : 12.0,
@@ -253,134 +253,104 @@
253253
"lines" : [ {
254254
"patchline" : {
255255
"destination" : [ "obj-2", 0 ],
256-
"disabled" : 0,
257-
"hidden" : 0,
258256
"source" : [ "obj-1", 0 ]
259257
}
260258

261259
}
262260
, {
263261
"patchline" : {
264262
"destination" : [ "obj-17", 0 ],
265-
"disabled" : 0,
266-
"hidden" : 0,
267263
"source" : [ "obj-16", 0 ]
268264
}
269265

270266
}
271267
, {
272268
"patchline" : {
273269
"destination" : [ "obj-18", 0 ],
274-
"disabled" : 0,
275-
"hidden" : 0,
276270
"source" : [ "obj-16", 1 ]
277271
}
278272

279273
}
280274
, {
281275
"patchline" : {
282276
"destination" : [ "obj-19", 0 ],
283-
"disabled" : 0,
284-
"hidden" : 0,
285277
"source" : [ "obj-17", 0 ]
286278
}
287279

288280
}
289281
, {
290282
"patchline" : {
291283
"destination" : [ "obj-19", 1 ],
292-
"disabled" : 0,
293-
"hidden" : 0,
294284
"source" : [ "obj-18", 0 ]
295285
}
296286

297287
}
298288
, {
299289
"patchline" : {
300290
"destination" : [ "obj-22", 0 ],
301-
"disabled" : 0,
302-
"hidden" : 0,
303291
"source" : [ "obj-19", 0 ]
304292
}
305293

306294
}
307295
, {
308296
"patchline" : {
309297
"destination" : [ "obj-5", 0 ],
310-
"disabled" : 0,
311-
"hidden" : 0,
312298
"source" : [ "obj-2", 0 ]
313299
}
314300

315301
}
316302
, {
317303
"patchline" : {
318304
"destination" : [ "obj-6", 0 ],
319-
"disabled" : 0,
320-
"hidden" : 0,
321305
"source" : [ "obj-2", 1 ]
322306
}
323307

324308
}
325309
, {
326310
"patchline" : {
327311
"destination" : [ "obj-23", 0 ],
328-
"disabled" : 0,
329-
"hidden" : 0,
330312
"source" : [ "obj-22", 0 ]
331313
}
332314

333315
}
334316
, {
335317
"patchline" : {
336318
"destination" : [ "obj-11", 0 ],
337-
"disabled" : 0,
338-
"hidden" : 0,
339319
"source" : [ "obj-5", 1 ]
340320
}
341321

342322
}
343323
, {
344324
"patchline" : {
345325
"destination" : [ "obj-12", 0 ],
346-
"disabled" : 0,
347-
"hidden" : 0,
348326
"source" : [ "obj-5", 2 ]
349327
}
350328

351329
}
352330
, {
353331
"patchline" : {
354332
"destination" : [ "obj-8", 0 ],
355-
"disabled" : 0,
356-
"hidden" : 0,
357333
"source" : [ "obj-5", 0 ]
358334
}
359335

360336
}
361337
, {
362338
"patchline" : {
363339
"destination" : [ "obj-13", 0 ],
364-
"disabled" : 0,
365-
"hidden" : 0,
366340
"source" : [ "obj-6", 2 ]
367341
}
368342

369343
}
370344
, {
371345
"patchline" : {
372346
"destination" : [ "obj-14", 0 ],
373-
"disabled" : 0,
374-
"hidden" : 0,
375347
"source" : [ "obj-6", 1 ]
376348
}
377349

378350
}
379351
, {
380352
"patchline" : {
381353
"destination" : [ "obj-15", 0 ],
382-
"disabled" : 0,
383-
"hidden" : 0,
384354
"source" : [ "obj-6", 0 ]
385355
}
386356

Packages/manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dependencies": {
3+
}
4+
}
14.9 KB
Binary file not shown.

ProjectSettings/ProjectVersion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
m_EditorVersion: 5.5.1f1
1+
m_EditorVersion: 2018.1.6f1

0 commit comments

Comments
 (0)