Constructor Cleanup
This commit is contained in:
parent
9305cad6d6
commit
f9867fc015
@ -55,7 +55,7 @@ namespace RoboidControl.Unity {
|
||||
this.transform.SetParent(core.parent.component.transform, false);
|
||||
this.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
else {
|
||||
else if (core.owner.component != null) {
|
||||
this.transform.SetParent(core.owner.component.transform, false);
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,11 @@ namespace RoboidControl.Unity {
|
||||
// Use resource prefab when available
|
||||
GameObject gameObj = Instantiate(prefab);
|
||||
Wheel component = gameObj.GetComponent<Wheel>();
|
||||
if (component != null)
|
||||
component.core = new RoboidControl.Thing(RoboidControl.Thing.Type.UncontrolledMotor);
|
||||
if (component != null) {
|
||||
component.core = new RoboidControl.Thing {
|
||||
type = RoboidControl.Thing.Type.UncontrolledMotor
|
||||
};
|
||||
}
|
||||
return component;
|
||||
}
|
||||
else {
|
||||
@ -48,9 +51,14 @@ namespace RoboidControl.Unity {
|
||||
Wheel component = gameObj.AddComponent<Wheel>();
|
||||
SiteServer participant = FindAnyObjectByType<SiteServer>();
|
||||
RoboidControl.Thing core = participant.coreParticipant.Get(thingId);
|
||||
if (core == null)
|
||||
if (core == null) {
|
||||
//core = new(participant.coreParticipant, RoboidControl.Thing.Type.UncontrolledMotor, thingId, false);
|
||||
core = RoboidControl.Thing.CreateRemote(participant.coreParticipant, RoboidControl.Thing.Type.UncontrolledMotor, thingId);
|
||||
//core = RoboidControl.Thing.CreateRemote(participant.coreParticipant, thingId);
|
||||
core = new RoboidControl.Thing(participant.coreParticipant.root) {
|
||||
id = thingId,
|
||||
type = RoboidControl.Thing.Type.UncontrolledMotor
|
||||
};
|
||||
}
|
||||
else {
|
||||
;
|
||||
}
|
||||
|
@ -131,12 +131,14 @@ namespace RoboidControl {
|
||||
}
|
||||
|
||||
protected virtual Thing ProcessNewThing(Participant sender, ThingMsg msg) {
|
||||
return msg.thingType switch {
|
||||
//Thing.Type.TouchSensor => new TouchSensor(sender, msg.thingId),
|
||||
//Thing.Type.DifferentialDrive => new DifferentialDrive(sender, msg.thingId),
|
||||
_ => Thing.CreateRemote(sender, msg.thingType, msg.thingId)
|
||||
Thing newThing = msg.thingType switch {
|
||||
Thing.Type.TouchSensor => new TouchSensor(sender.root),
|
||||
Thing.Type.DifferentialDrive => new DifferentialDrive(sender.root),
|
||||
_ => new Thing(sender.root)
|
||||
};
|
||||
|
||||
newThing.id = msg.thingId;
|
||||
newThing.type = msg.thingType;
|
||||
return newThing;
|
||||
}
|
||||
|
||||
#endregion Receive
|
||||
|
16
src/Thing.cs
16
src/Thing.cs
@ -105,8 +105,8 @@ namespace RoboidControl {
|
||||
this.parent = parent;
|
||||
}
|
||||
*/
|
||||
public Thing(byte thingType = Type.Undetermined, Thing parent = default) {
|
||||
this.type = thingType;
|
||||
public Thing(Thing parent = default) {
|
||||
this.type = Type.Undetermined;
|
||||
|
||||
this.positionUpdated = true;
|
||||
this.orientationUpdated = true;
|
||||
@ -127,12 +127,12 @@ namespace RoboidControl {
|
||||
this.owner.updateQueue.Enqueue(e);
|
||||
}
|
||||
|
||||
public static Thing CreateRemote(Participant owner, byte thingType, byte thingId) {
|
||||
Thing remoteThing = new(thingType, owner.root) {
|
||||
id = thingId
|
||||
};
|
||||
return remoteThing;
|
||||
}
|
||||
// public static Thing CreateRemote(Participant owner, byte thingId) {
|
||||
// Thing remoteThing = new(owner.root) {
|
||||
// id = thingId
|
||||
// };
|
||||
// return remoteThing;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Function which can be used to create components in external engines.
|
||||
|
@ -40,7 +40,9 @@ namespace RoboidControl {
|
||||
/// <param name="parent">The parent thing</param>
|
||||
/// <param name="thingId">The ID of the thing, leave out or set to zero to generate an ID</param>
|
||||
/// <param name="invokeEvent">Invoke a OnNewThing event when the thing has been created</param>
|
||||
public DifferentialDrive(Thing parent) : base(Type.DifferentialDrive, parent) { }
|
||||
public DifferentialDrive(Thing parent) : base(parent) {
|
||||
this.type = Type.DifferentialDrive;
|
||||
}
|
||||
|
||||
/// @brief Configures the dimensions of the drive
|
||||
/// @param wheelDiameter The diameter of the wheels in meters
|
||||
|
@ -26,7 +26,9 @@ namespace RoboidControl {
|
||||
/// <param name="parent">The parent thing</param>
|
||||
/// <param name="thingId">The ID of the thing, leave out or set to zero to generate an ID</param>
|
||||
/// <param name="invokeEvent">Invoke a OnNewThing event when the thing has been created</param>
|
||||
public DigitalSensor(Thing parent) : base(Type.Switch, parent) { }
|
||||
public DigitalSensor(Thing parent) : base(parent) {
|
||||
this.type = Type.Switch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Value which is true when the sensor is touching something, false otherwise
|
||||
|
@ -24,7 +24,9 @@ namespace RoboidControl {
|
||||
/// <param name="thingId">The ID of the thing</param>
|
||||
public DistanceSensor(Participant owner, byte thingId) : base(owner, Type.TemperatureSensor, thingId) {}
|
||||
*/
|
||||
public DistanceSensor(Thing parent): base(Type.DistanceSensor, parent) {}
|
||||
public DistanceSensor(Thing parent) : base(parent) {
|
||||
this.type = Type.DistanceSensor;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
|
@ -4,7 +4,9 @@ namespace RoboidControl {
|
||||
|
||||
public class Motor : Thing {
|
||||
//public Motor(bool invokeEvent = true) : base(Type.UncontrolledMotor, invokeEvent) { }
|
||||
public Motor(Thing parent) : base(Type.UncontrolledMotor, parent) { }
|
||||
public Motor(Thing parent) : base(parent) {
|
||||
this.type = Type.UncontrolledMotor;
|
||||
}
|
||||
|
||||
/// @brief Motor turning direction
|
||||
public enum Direction {
|
||||
|
@ -12,8 +12,8 @@ namespace RoboidControl {
|
||||
/*
|
||||
public RelativeEncoder(bool invokeEvent = true) : base(Type.IncrementalEncoder, invokeEvent) { }
|
||||
*/
|
||||
public RelativeEncoder(Thing parent = default) : base(Type.RelativeEncoder, parent) {
|
||||
|
||||
public RelativeEncoder(Thing parent = default) : base(parent) {
|
||||
this.type = Type.RelativeEncoder;
|
||||
}
|
||||
|
||||
protected float _rotationSpeed = 0;
|
||||
|
@ -26,7 +26,9 @@ namespace RoboidControl {
|
||||
/// <param name="parent">The parent thing</param>
|
||||
/// <param name="thingId">The ID of the thing, leave out or set to zero to generate an ID</param>
|
||||
/// <param name="invokeEvent">Invoke a OnNewThing event when the thing has been created</param>
|
||||
public TemperatureSensor(Thing parent) : base(Type.TemperatureSensor, parent) { }
|
||||
public TemperatureSensor(Thing parent) : base(parent) {
|
||||
this.type = Type.TemperatureSensor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The measured temperature
|
||||
|
@ -24,11 +24,10 @@ namespace RoboidControl {
|
||||
/// Create a new child touch sensor
|
||||
/// </summary>
|
||||
/// <param name="parent">The parent thing</param>
|
||||
/// <param name="thingId">The ID of the thing, leave out or set to zero to generate an ID</param>
|
||||
/// <param name="invokeEvent">Invoke a OnNewThing event when the thing has been created</param>
|
||||
public TouchSensor(Thing parent) : base(Type.TouchSensor, parent) {
|
||||
public TouchSensor(Thing parent) : base(parent) {
|
||||
this.type = Type.TouchSensor;
|
||||
this.name = "TouchSensor";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Value which is true when the sensor is touching something, false otherwise
|
||||
|
Loading…
x
Reference in New Issue
Block a user