Пример #1
0
        public void Update()
        {
            // dont do anything when its not in flight
            if (HighLogic.LoadedScene != GameScenes.FLIGHT)
            {
                SetAllOff();
                return;
            }

            // hmm no vessel found.. thats bad because you are not flying...
            if (FlightGlobals.ActiveVessel == null)
            {
                SetAllOff();
                return;
            }

            // the vessel is not active?!? we don't deal with such alien spacecraft.
            if (FlightGlobals.ActiveVessel.state != Vessel.State.ACTIVE)
            {
                SetAllOff();
                return;
            }

            // Only deal with flying things.
            if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.FLYING)
            {
                SetAllOff();
                return;
            }

            // from here it should be save to do acually some things.

            touchDownPoint    = staticInstance.gameObject.transform.position + (directionsMult * staticInstance.gameObject.transform.forward.normalized * touchDownOffset);
            vesselPosition    = FlightGlobals.ActiveVessel.GetWorldPos3D();
            fromVesseltoPoint = (touchDownPoint - FlightGlobals.ActiveVessel.GetWorldPos3D());
            horizontalVector  = Vector3.ProjectOnPlane(fromVesseltoPoint, staticInstance.gameObject.transform.up);

            if (Vector3d.Dot(horizontalVector, directionsMult * staticInstance.gameObject.transform.forward.normalized) < 0)
            {
                // we are behind the lights. no need to update them anymore.
                SetAllOff();
                return;
            }

            currentDistance = horizontalVector.magnitude;

            // Do nothing if too far away
            if (currentDistance > maxDist)
            {
                SetAllOff();
                return;
            }

            if (showDebug)
            {
                DebugDrawer.DebugVector(touchDownPoint, -horizontalVector, new Color(0.2f, 0.2f, 0.7f));
                DebugDrawer.DebugLine(touchDownPoint, vesselPosition, new Color(0.2f, 0.7f, 0.2f));
            }

            currentState = GetCurrentGlideState();

            if (lastState != currentState)
            {
                //Log.Normal("PAPI: Switching State: " + lastState.ToString() + " to " + currentState.ToString());
                lastState = currentState;

                switch (currentState)
                {
                case GlideState.TooHigh:
                    if (animTooHigh != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetWhite(animRight, AnimNameRight);
                        SetWhite(animHigh, AnimNameHigh);
                        SetWhite(animTooHigh, AnimNameTooHigh);
                    }

                    break;

                case GlideState.High:
                    if (animHigh != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetWhite(animRight, AnimNameRight);
                        SetWhite(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }

                    break;

                case GlideState.Right:
                    if (animRight != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetWhite(animRight, AnimNameRight);
                        SetRed(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }

                    break;

                case GlideState.Low:
                    if (animLow != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetRed(animRight, AnimNameRight);
                        SetRed(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }
                    break;

                case GlideState.TooLow:
                    if (animLow != null)
                    {
                        SetRed(animLow, AminNameTooLow);
                        SetRed(animRight, AnimNameRight);
                        SetRed(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }
                    break;
                }
            }
        }