Created
May 24, 2016 10:07
-
-
Save tm8r/f5e547d6659e403c0292356c80bf6893 to your computer and use it in GitHub Desktop.
UnityでUDP受信するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UniRx; | |
using UdpReceiverUniRx; | |
using System.IO; | |
namespace Viewer | |
{ | |
public class UDPManager : SingletonMonoBehaviour<UDPManager> | |
{ | |
public UdpReceiverRx _udpReceiverRx; | |
private IObservable<UdpState> myUdpSequence; | |
void Start () | |
{ | |
myUdpSequence = _udpReceiverRx._udpSequence; | |
myUdpSequence | |
.ObserveOnMainThread () | |
.Subscribe (x => ReceiveAction (x.UdpMsg)) | |
.AddTo (this); | |
} | |
void ReceiveAction (string message) | |
{ | |
UdpMessage data = null; | |
try { | |
data = JsonUtility.FromJson<UdpMessage> (message); | |
} catch { | |
Debug.LogFormat ("[invalid format] message:{0}", message); | |
return; | |
} | |
switch (data.action) { | |
case "Load": | |
LoadModel (data); | |
break; | |
default: | |
Debug.LogFormat ("[not implemented action] message:{0}", message); | |
break; | |
} | |
} | |
void LoadModel (UdpMessage message) | |
{ | |
var path = Directory.GetParent (message.path).Name + "/" + Path.GetFileNameWithoutExtension (message.path); | |
StartCoroutine (MenuPresenter.Instance.LoadModel (path)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment