Remote thing
This commit is contained in:
parent
765231588f
commit
ba81b9f71d
@ -22,12 +22,14 @@ namespace RoboidControl.Unity {
|
|||||||
/// If this is not available, a default representation is created.
|
/// If this is not available, a default representation is created.
|
||||||
public static DifferentialDrive Create(RoboidControl.DifferentialDrive coreDrive) {
|
public static DifferentialDrive Create(RoboidControl.DifferentialDrive coreDrive) {
|
||||||
DifferentialDrive differentialDrive;
|
DifferentialDrive differentialDrive;
|
||||||
|
Rigidbody rb = null;
|
||||||
GameObject prefab = (GameObject)Resources.Load("DifferentialDrive");
|
GameObject prefab = (GameObject)Resources.Load("DifferentialDrive");
|
||||||
if (prefab != null) {
|
if (prefab != null) {
|
||||||
// Use resource prefab when available
|
// Use resource prefab when available
|
||||||
GameObject gameObj = Instantiate(prefab);
|
GameObject gameObj = Instantiate(prefab);
|
||||||
differentialDrive = gameObj.GetComponent<DifferentialDrive>();
|
differentialDrive = gameObj.GetComponent<DifferentialDrive>();
|
||||||
differentialDrive.Init(coreDrive);
|
differentialDrive.Init(coreDrive);
|
||||||
|
rb = gameObj.GetComponent<Rigidbody>();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Default implementation
|
// Default implementation
|
||||||
@ -35,10 +37,14 @@ namespace RoboidControl.Unity {
|
|||||||
differentialDrive = gameObj.AddComponent<DifferentialDrive>();
|
differentialDrive = gameObj.AddComponent<DifferentialDrive>();
|
||||||
differentialDrive.Init(coreDrive);
|
differentialDrive.Init(coreDrive);
|
||||||
|
|
||||||
Rigidbody rb = gameObj.AddComponent<Rigidbody>();
|
rb = gameObj.AddComponent<Rigidbody>();
|
||||||
rb.isKinematic = false;
|
rb.isKinematic = false;
|
||||||
rb.mass = 0.1f;
|
rb.mass = 0.1f;
|
||||||
}
|
}
|
||||||
|
if (coreDrive.isRemote) {
|
||||||
|
if (rb != null)
|
||||||
|
rb.isKinematic = true;
|
||||||
|
}
|
||||||
return differentialDrive;
|
return differentialDrive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,8 +463,18 @@ namespace RoboidControl {
|
|||||||
this.updateQueue.Enqueue(e);
|
this.updateQueue.Enqueue(e);
|
||||||
Console.WriteLine("Added Participant");
|
Console.WriteLine("Added Participant");
|
||||||
}
|
}
|
||||||
|
|
||||||
Thing thing = owner.Get(msg.networkId, msg.thingId);
|
Thing thing = owner.Get(msg.networkId, msg.thingId);
|
||||||
thing ??= ProcessNewThing(owner, msg);
|
if (sender.networkId != owner.networkId) {
|
||||||
|
// Sender forwarded this thing msg
|
||||||
|
// So this is a remote thing
|
||||||
|
thing ??= ProcessNewThing(owner, msg, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Sender is the owner of the thing
|
||||||
|
// So this is a simulated thing
|
||||||
|
thing ??= ProcessNewThing(owner, msg, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.parentId != 0) {
|
if (msg.parentId != 0) {
|
||||||
thing.parent = owner.Get(msg.networkId, msg.parentId);
|
thing.parent = owner.Get(msg.networkId, msg.parentId);
|
||||||
@ -479,7 +489,7 @@ namespace RoboidControl {
|
|||||||
ForwardMessage(sender, msg);
|
ForwardMessage(sender, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Thing ProcessNewThing(Participant owner, ThingMsg msg) {
|
protected virtual Thing ProcessNewThing(Participant owner, ThingMsg msg, bool isRemote) {
|
||||||
Console.WriteLine("--- New Thing");
|
Console.WriteLine("--- New Thing");
|
||||||
Thing newThing = msg.thingType switch {
|
Thing newThing = msg.thingType switch {
|
||||||
Thing.Type.TouchSensor => new TouchSensor(owner.root),
|
Thing.Type.TouchSensor => new TouchSensor(owner.root),
|
||||||
@ -488,6 +498,7 @@ namespace RoboidControl {
|
|||||||
};
|
};
|
||||||
newThing.id = msg.thingId;
|
newThing.id = msg.thingId;
|
||||||
newThing.type = msg.thingType;
|
newThing.type = msg.thingType;
|
||||||
|
newThing.isRemote = isRemote;
|
||||||
return newThing;
|
return newThing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +136,8 @@ namespace RoboidControl {
|
|||||||
/// This can be either a \ref RoboidControl::Thing::Type "Thing.Type" or a byte value for custom types.
|
/// This can be either a \ref RoboidControl::Thing::Type "Thing.Type" or a byte value for custom types.
|
||||||
public byte type = Type.Undetermined;
|
public byte type = Type.Undetermined;
|
||||||
|
|
||||||
|
public bool isRemote = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The participant owning this thing
|
/// The participant owning this thing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user