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