Compare commits

...

2 Commits

View File

@ -238,24 +238,41 @@ namespace RoboidControl.Unity {
} }
private void ScanForThings(Transform rootTransform) { private void ScanForThings(Transform rootTransform) {
// Thing[] thingArray = allThings.ToArray(); RoboidControl.Thing[] thingArray = this.core.owner.things.ToArray();
// for (int thingIx = 0; thingIx < thingArray.Length; thingIx++) { for (int thingIx = 0; thingIx < thingArray.Length; thingIx++) {
// Thing thing = thingArray[thingIx]; RoboidControl.Thing thing = thingArray[thingIx];
// GameObject foundObj = FindThingByName(thing, rootTransform); GameObject foundObj = FindThingByName(thing, rootTransform);
// if (foundObj != null && foundObj != thing.gameObject) { if (foundObj != null && foundObj != thing.component.gameObject) {
// Thing foundThing = foundObj.GetComponent<Thing>(); Thing foundThing = foundObj.GetComponent<Thing>();
// if (foundThing == null) { if (foundThing == null) {
// allThings.Remove(thing); Debug.Log($"move thing [{thing.owner.networkId}/{thing.id}] to {foundObj.name}");
foundThing = foundObj.AddComponent<Thing>();
foundThing.core = thing;
foundThing.core.position = LinearAlgebra.Spherical.FromVector3(foundObj.transform.localPosition);
foundThing.core.orientation = LinearAlgebra.SwingTwist.FromQuaternion(foundObj.transform.localRotation);
// foundThing = foundObj.AddComponent<Thing>(); Destroy(thing.component.gameObject);
// foundThing.networkId = thing.networkId; thing.component = foundThing;
// foundThing.objectId = thing.objectId; }
// allThings.Add(foundThing); }
// Destroy(thing.gameObject); }
// } }
// }
// } private GameObject FindThingByName(RoboidControl.Thing thing, Transform rootTransform) {
if (rootTransform == null || thing == null)
return null;
if (rootTransform.name == thing.name)
return rootTransform.gameObject;
for (int childIx = 0; childIx < rootTransform.childCount; childIx++) {
Transform child = rootTransform.GetChild(childIx);
GameObject foundObj = FindThingByName(thing, child);
if (foundObj != null)
return foundObj;
}
return null;
} }
@ -266,10 +283,11 @@ namespace RoboidControl.Unity {
/// If a velocity is not zero, the position and/or orientation update will be ignored /// If a velocity is not zero, the position and/or orientation update will be ignored
protected virtual void HandlePose() { protected virtual void HandlePose() {
this.transform.localRotation = core.orientation.ToQuaternion(); this.transform.localRotation = core.orientation.ToQuaternion();
if (core.linearVelocity.distance == 0) this.transform.localPosition = core.position.ToVector3();
this.transform.localPosition = core.position.ToVector3(); // if (core.linearVelocity.distance == 0)
if (core.angularVelocity.distance == 0) // this.transform.localPosition = core.position.ToVector3();
this.transform.localRotation = core.orientation.ToQuaternion(); // if (core.angularVelocity.distance == 0)
// this.transform.localRotation = core.orientation.ToQuaternion();
} }