public void Start() { // try to catch any exception if compatibility issues with KSP occur try { var gaugesObject = (GameObject)MonoBehaviour.FindObjectOfType <LinearControlGauges>().gameObject; var gaugesClass = gaugesObject.GetComponent <LinearControlGauges>(); KSP.UI.Screens.LinearGauge roll = gaugesClass.roll; KSP.UI.Screens.LinearGauge pitch = gaugesClass.pitch; KSP.UI.Screens.LinearGauge yaw = gaugesClass.yaw; // create gauges this.trimRollGauge = CreateGauge("GaugeRollTrimPointer", roll); this.trimPitchGauge = CreateGauge("GaugePitchTrimPointer", pitch); this.trimYawGauge = CreateGauge("GaugeYawTrimPointerw", yaw); } catch (Exception e) { Debug.Log("exception caught in trim indicator init"); disabled = true; throw e; } }
private void Awake() { GameObject mask = new GameObject("GuageTWR"); mask.transform.SetParent(transform, false); mask.layer = 5; RectTransform maskRect = mask.AddComponent <RectTransform>(); mask.AddComponent <RectMask2D>(); _tooltip = mask.AddComponent <TooltipController_Text>(); _tooltip.continuousUpdate = true; _tooltip.prefab = BasicDeltaV_Loader.TooltipPrefab.prefab; _tooltip.RequireInteractable = false; _tooltip.TooltipPrefabType = BasicDeltaV_Loader.TooltipPrefab.TooltipPrefabType; maskRect.anchorMin = new Vector2(0.5f, 0.5f); maskRect.anchorMax = new Vector2(0.5f, 0.5f); maskRect.pivot = new Vector2(0.5f, 0.5f); maskRect.sizeDelta = new Vector2(31, 111.5f); maskRect.anchoredPosition = new Vector2(0, 0); var gauges = FlightUIModeController.Instance.stagingQuadrant.GetComponentsInChildren <KSP.UI.Screens.LinearGauge>(); for (int i = gauges.Length - 1; i >= 0; i--) { if (gauges[i].gameObject.name == "GaugePitchPointer") { //BasicDeltaV.BasicLogging("Pitch Gauge Located\nMin Position: {0:F3} - Max Position: {1:F3}", gauges[i].minValuePosition, gauges[i].maxValuePosition); _gauge = Instantiate(gauges[i], mask.transform); break; } } _gauge.gameObject.name = "GaugeTWRPointer"; _gauge.minValue = 0; _gauge.maxValue = 3; _gauge.logarithmic = 10; _gauge.exponential = 0; _gauge.minValuePosition = new Vector2(-1.3f, -55.5f); _gauge.maxValuePosition = new Vector2(-1.3f, 52); _gauge.Value = 1; GameEvents.onTooltipSpawned.Add(TooltipSpawned); GameEvents.onTooltipDespawned.Add(TooltipDespawned); GameEvents.OnMapEntered.Add(OnMapEnter); GameEvents.OnMapExited.Add(OnMapExit); GameEvents.OnFlightUIModeChanged.Add(OnFlightModeChange); }
/// <summary> /// Initialize some fields to safe values (or expected unchanging values). /// The vessel fields of VesselComputer doesn't have good values yet, so this /// step is only good for non-specific initial values. /// </summary> public void Awake() { if (HighLogic.LoadedSceneIsFlight == false) { Utility.LogWarning(this, "Someone is creating a vessel computer outside of flight!"); } vessel = gameObject.GetComponent <Vessel>(); if (vessel == null) { throw new ArgumentNullException("[MASVesselComputer] Awake(): Could not find the vessel!"); } //Utility.LogMessage(this, "Awake() for {0}", vessel.id); navBall = UnityEngine.Object.FindObjectOfType <KSP.UI.Screens.Flight.NavBall>(); if (navBall == null) { Utility.LogError(this, "navBall was null!"); } LinearAtmosphereGauge linearAtmosGauge = UnityEngine.Object.FindObjectOfType <KSP.UI.Screens.Flight.LinearAtmosphereGauge>(); if (linearAtmosGauge == null) { Utility.LogError(this, "linearAtmosGauge was null!"); atmosphereDepthGauge = new KSP.UI.Screens.LinearGauge(); } else { atmosphereDepthGauge = linearAtmosGauge.gauge; } mainBody = vessel.mainBody; vesselId = vessel.id; orbit = vessel.orbit; universalTime = Planetarium.GetUniversalTime(); InitResourceData(); UpdateReferenceTransform(vessel.ReferenceTransform, true); vesselCrewed = (vessel.GetCrewCount() > 0); vesselActive = ActiveVessel(vessel); if (vesselCrewed) { RefreshData(); } PilotInitialize(); GameEvents.OnCameraChange.Add(onCameraChange); GameEvents.onStageActivate.Add(onStageActivate); GameEvents.onVesselChange.Add(onVesselChange); GameEvents.onVesselSOIChanged.Add(onVesselSOIChanged); GameEvents.onVesselWasModified.Add(onVesselWasModified); }
/// <summary> /// This vessel is being scrapped. Release modules. /// </summary> private void OnDestroy() { //Utility.LogMessage(this, "OnDestroy for {0}", vesselId); GameEvents.OnCameraChange.Remove(onCameraChange); GameEvents.onStageActivate.Remove(onStageActivate); GameEvents.onVesselChange.Remove(onVesselChange); GameEvents.onVesselSOIChanged.Remove(onVesselSOIChanged); GameEvents.onVesselWasModified.Remove(onVesselWasModified); TeardownResourceData(); vesselId = Guid.Empty; orbit = null; atmosphereDepthGauge = null; mainBody = null; navBall = null; activeTarget = null; }
private KSP.UI.Screens.LinearGauge CreateGauge(String name, KSP.UI.Screens.LinearGauge component) { GameObject indicator = (GameObject)MonoBehaviour.Instantiate(component.gameObject, Vector3.zero, Quaternion.identity); indicator.name = name; // set parent indicator.transform.SetParent(component.transform.parent); // set rotations indicator.transform.rotation = component.transform.rotation; indicator.transform.position = component.transform.position; indicator.transform.localPosition = component.transform.localPosition; indicator.transform.localScale = component.transform.localScale; indicator.transform.localRotation = component.transform.localRotation; KSP.UI.Screens.LinearGauge gauge = indicator.GetComponent <KSP.UI.Screens.LinearGauge>(); indicator.transform.localScale = Vector3.Scale(component.transform.localScale, new Vector3(-SIZE, SIZE, SIZE)); if (name == "GaugePitchTrimPointer") { // set size of the indicator by scaling them down and inverting the direction float origWidth = gauge.pointer.rect.width / SIZE + 2; indicator.transform.localPosition += new Vector3(gauge.pointer.rect.width, 0); gauge.minValuePosition -= new Vector2(origWidth, 0); gauge.maxValuePosition -= new Vector2(origWidth, 0); } else { // set size of the indicator by scaling them down and inverting the direction float origHeight = gauge.pointer.rect.height + 2; gauge.minValuePosition -= new Vector2(0, origHeight); gauge.maxValuePosition -= new Vector2(0, origHeight); } return(gauge); }