45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace RoboidControl.Unity {
|
|
|
|
public class Participant : MonoBehaviour {
|
|
public string ipAddress;
|
|
public int port;
|
|
|
|
public RoboidControl.Participant coreParticipant;
|
|
|
|
protected virtual void Update() {
|
|
if (coreParticipant == null)
|
|
return;
|
|
|
|
if (coreParticipant.updateQueue.TryDequeue(out RoboidControl.Participant.UpdateEvent e))
|
|
HandleUpdateEvent(e);
|
|
}
|
|
|
|
private void HandleUpdateEvent(RoboidControl.Participant.UpdateEvent e) {
|
|
switch (e.messageId) {
|
|
case ThingMsg.id:
|
|
HandleThingEvent(e);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void HandleThingEvent(RoboidControl.Participant.UpdateEvent e) {
|
|
switch (e.thing) {
|
|
case RoboidControl.TouchSensor coreTouchSensor:
|
|
GameObject touchObj = new("Touch Sensor");
|
|
touchObj.transform.SetParent(this.transform);
|
|
TouchSensor touchSensor = touchObj.AddComponent<TouchSensor>();
|
|
touchSensor.coreSensor = coreTouchSensor;
|
|
break;
|
|
case RoboidControl.Thing coreThing:
|
|
GameObject thingObj = new("Thingg");
|
|
thingObj.transform.SetParent(this.transform);
|
|
Thing thing = thingObj.AddComponent<Thing>();
|
|
thing.core = coreThing;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |