diff --git a/NavBallDockingAlignmentIndicator.cs b/NavBallDockingAlignmentIndicator.cs index e850377..b8cb1c7 100644 --- a/NavBallDockingAlignmentIndicator.cs +++ b/NavBallDockingAlignmentIndicator.cs @@ -6,19 +6,24 @@ [KSPAddon(KSPAddon.Startup.Flight, false)] public class NavBallDockingAlignmentIndicator : MonoBehaviour { - + private NavBall navBall; - + private GameObject indicator; PluginConfiguration cfg; - + Color color; + void Start() { Debug.Log (" ======== AWAKE ======== "); this.cfg = KSP.IO.PluginConfiguration.CreateForType(); this.cfg.load(); - } + Vector3 tmp = cfg.GetValue("alignmentmarkercolor", new Vector3(1f, 0f, 0f)); // default: red + this.color = new Color(tmp.x, tmp.y, tmp.z); + this.cfg.save (); + } + void LateUpdate() { if (this.navBall == null) @@ -31,23 +36,23 @@ void LateUpdate() && FlightGlobals.fetch.VesselTarget != null && FlightGlobals.fetch.VesselTarget.GetTargetingMode() == VesselTargetModes.DirectionVelocityAndOrientation) { /// Targeted a Port if I am not mistaken o__o - + if (this.indicator == null) { SetupIndicator(); } - - + + #region "legacy" Code ITargetable targetPort = FlightGlobals.fetch.VesselTarget; Transform targetTransform = targetPort.GetTransform(); Transform selfTransform = FlightGlobals.ActiveVessel.ReferenceTransform; - + // Position Vector3 targetPortOutVector = targetTransform.forward.normalized; Vector3 rotatedTargetPortInVector = navBall.attitudeGymbal * -targetPortOutVector; this.indicator.transform.localPosition = rotatedTargetPortInVector * navBall.progradeVector.localPosition.magnitude; - + // Rotation Vector3 v1 = Vector3.Cross(selfTransform.up, -targetTransform.up); Vector3 v2 = Vector3.Cross(selfTransform.up, selfTransform.forward); @@ -56,24 +61,25 @@ void LateUpdate() ang = -ang; this.indicator.transform.rotation = Quaternion.Euler(90 + ang, 90, 270); #endregion - + // Set opacity float value = Vector3.Dot(indicator.transform.localPosition.normalized, Vector3.forward); value = Mathf.Clamp01(value); this.indicator.GetComponent().materials[0].SetFloat("_Opacity", value); - + this.indicator.SetActive(indicator.transform.localPosition.z > 0.0d); return; } - + if (this.indicator != null) this.indicator.SetActive (false); } - + void SetupIndicator() { this.indicator = GameObject.Instantiate(navBall.progradeVector.gameObject); this.indicator.transform.parent = navBall.progradeVector.parent; this.indicator.transform.position = navBall.progradeVector.position; + this.indicator.GetComponent().materials[0].SetColor("_TintColor", this.color); } } \ No newline at end of file diff --git a/NavBallDockingAlignmentIndicator.dll b/NavBallDockingAlignmentIndicator.dll index 581ad12..b71f81c 100644 Binary files a/NavBallDockingAlignmentIndicator.dll and b/NavBallDockingAlignmentIndicator.dll differ