public References() { _screenSafeUi = ScreenSafeUI.fetch; _flightUiController = _screenSafeUi.GetComponent <FlightUIController>(); GameObject navballGameObject = GameObject.Find("NavBall"); _navball = navballGameObject.GetComponent <NavBall>(); _navBallTexture = _navball.navBall.renderer.sharedMaterial; _vectorsPivotTransform = navballGameObject.transform.FindChild("vectorsPivot"); _antiNormalVector = _navball.antiNormalVector.gameObject; _normalVector = _navball.normalVector.gameObject; _radialInVector = _navball.radialInVector.gameObject; _radialOutVector = _navball.radialOutVector.gameObject; ManeuverGizmo maneuverGizmo = MapView.ManeuverNodePrefab.GetComponent <ManeuverGizmo>(); _maneuverTexture = maneuverGizmo.handleNormal.flag.renderer.sharedMaterial; var maneuverVector = GameObject.Find("maneuverVector"); _navBallBurnVector = maneuverVector.GetComponent <NavBallBurnVector>(); _manueverIndicationarrow = GameObject.Find("Indicationarrow"); }
//Draws the digital readouts to the gauge private void drawNumbers(ManeuverNode myNode) { //dv = Isp * ln (m0 / m1) //e^(dv/ISP) = m0/m1 //m1 = m0/e^(dv/ISP) ...I think. //mass flow = thrust/isp deltaV = myNode.DeltaV.magnitude; //The burn's ΔV deltaVRem = myNode.GetBurnVector(FlightGlobals.ActiveVessel.orbit).magnitude; //Remaining ΔV in the burn //res r = calculateThrust(FlightGlobals.ActiveVessel); //Actually calculates thrust, mass, and Isp //Log.Info("Mass: " + Math.Round(r.mass, 2) + " Thrust: " + Math.Round(r.thrust, 2) + " ISP: " + Math.Round(r.isp, 2)); //double mass = SteamShip.Mass / Math.Pow(Math.E, (deltaVRem / (SteamShip.ISP*9.82))); //Mass after burn Changed from 9.821 //Log.Info("Final Mass: " + Math.Round(mass, 2)+" Burn Mass: "+Math.Round(r.mass-mass,2)); //double rate = SteamShip.MaxThrust / (SteamShip.ISP*9.82); //Mass flow rate, rounded to 5 digits //double burnTime = (SteamShip.Mass - mass)/rate; //Mass to burn over rate should give time, but doesn't //burnTime += SteamShip.EngineAccel+SteamShip.EngineDecel; //Compensate for slow throttles double burnTime = SteamShip.BurnTime; NavBallBurnVector bv = UnityEngine.Object.FindObjectsOfType <NavBallBurnVector>()[0]; double bt2 = bv.estimatedBurnTime; if (double.IsInfinity(bt2) || double.IsNaN(bt2)) { bt2 = 0; //Assume its good if not infinity or NaN } //Draw values drawDigits(182, 131, deltaV); //If we are past the node time, time until burn is 0 if (Planetarium.GetUniversalTime() < myNode.UT) { if (useCalculatedBurn) { timeToBurn = (long)((myNode.UT - Planetarium.GetUniversalTime()) - (burnTime / 2.0)); drawTime(219, 198, timeToBurn); //draw actual time to burn start } else { timeToBurn = (long)((myNode.UT - Planetarium.GetUniversalTime()) - (bt2 / 2)); drawTime(219, 198, timeToBurn); //draw actual time to KSP's burn start } } else { drawTime(219, 198, 0); //Use 0 as time to burn if past node } if (useCalculatedBurn) { drawTime(219, 261, burnTime); //Draw burn time. } else { drawTime(219, 261, bt2); //Draw KSP's burn time } }
public References() { _screenSafeUi = ScreenSafeUI.fetch; _flightUiController = _screenSafeUi.GetComponent<FlightUIController>(); GameObject navballGameObject = GameObject.Find("NavBall"); _navball = navballGameObject.GetComponent<NavBall>(); _navBallTexture = _navball.navBall.renderer.sharedMaterial; _vectorsPivotTransform = navballGameObject.transform.FindChild("vectorsPivot"); _antiNormalVector = _navball.antiNormalVector.gameObject; _normalVector = _navball.normalVector.gameObject; _radialInVector = _navball.radialInVector.gameObject; _radialOutVector = _navball.radialOutVector.gameObject; ManeuverGizmo maneuverGizmo = MapView.ManeuverNodePrefab.GetComponent<ManeuverGizmo>(); _maneuverTexture = maneuverGizmo.handleNormal.flag.renderer.sharedMaterial; var maneuverVector = GameObject.Find("maneuverVector"); _navBallBurnVector = maneuverVector.GetComponent<NavBallBurnVector>(); _manueverIndicationarrow = GameObject.Find("Indicationarrow"); }
/// <summary> /// Try to initialize the needed components. Returns true if initialized, false if not. /// If this function returns true, you're guaranteed that burn vector and the needed GUI /// text objects are available and non-null. /// </summary> /// <returns></returns> private bool AttemptInitialize() { if (isInitialized) { return(true); // already initialized } DateTime now = DateTime.Now; if (lastUpdate + UPDATE_INTERVAL > now) { return(false); // too soon to try again } lastUpdate = now; // Try to get the navball's burn vector. This check is needed because it turns // out that the timing of when this object becomes available isn't super reliable, // so various MonoBehaviour implementations in the mod can't just initialize at // Start() time and use it. NavBallBurnVector theBurnVector = GameObject.FindObjectOfType <NavBallBurnVector>(); if (theBurnVector == null) { return(false); // nope, couldn't get it yet! } // Make sure the burn vector components that we need are there if (theBurnVector.ebtText == null) { return(false); } if (theBurnVector.TdnText == null) { return(false); } TextMeshProUGUI theClonedDurationText = CloneBehaviour(theBurnVector.ebtText); if (theClonedDurationText == null) { return(false); } TextMeshProUGUI theClonedTimeUntilText = CloneBehaviour(theBurnVector.TdnText); if (theClonedTimeUntilText == null) { Destroy(theClonedDurationText); return(false); } TextMeshProUGUI theCountdownText = CloneBehaviour(theBurnVector.ebtText); if (theCountdownText == null) { Destroy(theClonedDurationText); Destroy(theClonedTimeUntilText); return(false); } theCountdownText.enabled = false; theCountdownText.transform.position = Interpolate( theBurnVector.TdnText.transform.position, theBurnVector.ebtText.transform.position, 2.0F); // Got everything we need! burnVector = theBurnVector; originalDurationText = SafeText.of(burnVector.ebtText); originalTimeUntilText = SafeText.of(burnVector.TdnText); alternateDurationText = SafeText.of(theClonedDurationText); alternateTimeUntilText = SafeText.of(theClonedTimeUntilText); countdownText = SafeText.of(theCountdownText); isInitialized = true; return(true); }