Compare commits
2 Commits
7bd7931196
...
29b37d91c1
Author | SHA1 | Date | |
---|---|---|---|
29b37d91c1 | |||
0353e6f2cf |
@ -238,24 +238,41 @@ namespace RoboidControl.Unity {
|
||||
}
|
||||
|
||||
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++) {
|
||||
// Thing thing = thingArray[thingIx];
|
||||
// GameObject foundObj = FindThingByName(thing, rootTransform);
|
||||
// if (foundObj != null && foundObj != thing.gameObject) {
|
||||
// Thing foundThing = foundObj.GetComponent<Thing>();
|
||||
// if (foundThing == null) {
|
||||
// allThings.Remove(thing);
|
||||
for (int thingIx = 0; thingIx < thingArray.Length; thingIx++) {
|
||||
RoboidControl.Thing thing = thingArray[thingIx];
|
||||
GameObject foundObj = FindThingByName(thing, rootTransform);
|
||||
if (foundObj != null && foundObj != thing.component.gameObject) {
|
||||
Thing foundThing = foundObj.GetComponent<Thing>();
|
||||
if (foundThing == null) {
|
||||
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>();
|
||||
// foundThing.networkId = thing.networkId;
|
||||
// foundThing.objectId = thing.objectId;
|
||||
// allThings.Add(foundThing);
|
||||
// Destroy(thing.gameObject);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Destroy(thing.component.gameObject);
|
||||
thing.component = foundThing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
protected virtual void HandlePose() {
|
||||
this.transform.localRotation = core.orientation.ToQuaternion();
|
||||
if (core.linearVelocity.distance == 0)
|
||||
this.transform.localPosition = core.position.ToVector3();
|
||||
if (core.angularVelocity.distance == 0)
|
||||
this.transform.localRotation = core.orientation.ToQuaternion();
|
||||
// if (core.linearVelocity.distance == 0)
|
||||
// this.transform.localPosition = core.position.ToVector3();
|
||||
// if (core.angularVelocity.distance == 0)
|
||||
// this.transform.localRotation = core.orientation.ToQuaternion();
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user