private void ConfigManeuver(ManeuverObject mo, Vector3 physPosition, Vector3 velocity) { mo.parent.transform.position = GravityEngine.Instance().MapPhyPosToWorld(physPosition); Vector3 endPoint = physPosition + lineLengthScale * velocity; // May need separate velocity scale?? mo.line.SetPositions(new Vector3[] { physPosition, endPoint }); mo.line.widthMultiplier = lineWidthScale; mo.line.positionCount = 2; mo.cone.transform.localPosition = lineLengthScale * velocity; mo.cone.transform.rotation = Quaternion.FromToRotation(Vector3.forward, velocity.normalized); mo.cone.transform.localScale = Vector3.one * coneScale * velocity.magnitude; }
void Start() { maneuverObjects = new List <ManeuverObject>(); // create an object pool of maneuverArrows at the start for (int i = 0; i < MAX_ARROWS; i++) { GameObject go = Instantiate(maneuverArrowPrefab); go.SetActive(false); // make it a child of this object go.transform.SetParent(transform); ManeuverObject mo = new ManeuverObject(go); maneuverObjects.Add(mo); } }
/// <summary> /// Show each maneuver in the list using an in-scene vector made from the maneuverArrowPreb. /// Optionally update on-screen text. /// /// Position is determined from the maneuver Nbody (if present) or taken from the maneuver /// physical location, scaled and mapped to the scene. /// </summary> /// <param name="maneuvers"></param> public void ShowManeuvers(List <Maneuver> maneuvers) { int i = 0; foreach (Maneuver m in maneuvers) { ManeuverObject mo = maneuverObjects[i]; mo.parent.SetActive(true); Vector3 pos = m.physPosition.ToVector3(); // TODO - need to scale and map position Vector3 vel = Vector3.zero; if (m.mtype == Maneuver.Mtype.vector) { vel = m.velChange; } ConfigManeuver(mo, pos, vel); i++; } // inactivate the rest of the cached maneuver objects for (int j = i; j < MAX_ARROWS; j++) { maneuverObjects[j].parent.SetActive(false); } }