public void Update()
 {
     lock (newSamples)
     {
         while (newSamples.Count > 0)
         {
             PIDSample pidSample = newSamples.Dequeue();
             int       nextX     = (currentX + 1) % drawTexture.width;
             for (int y = 0; y < drawTexture.height; y++)
             {
                 drawTexture.SetPixel(currentX, y, Color.black);
             }
             for (int y = 0; y < drawTexture.height; y++)
             {
                 drawTexture.SetPixel(nextX, y, Color.red);
             }
             int offset = drawTexture.height / 2;
             int pPix   = Clamp((int)(pidSample.p * offset + offset));
             int iPix   = Clamp((int)(pidSample.i * offset + offset));
             int dPix   = Clamp((int)(pidSample.d * offset + offset));
             int tPix   = Clamp((int)(pidSample.total * offset + offset));
             drawTexture.SetPixel(currentX, pPix, Color.red);
             drawTexture.SetPixel(currentX, iPix, Color.green);
             drawTexture.SetPixel(currentX, dPix, Color.blue);
             drawTexture.SetPixel(currentX, tPix, Color.white);
             drawTexture.SetPixel(currentX, offset, Color.gray);
             drawTexture.Apply();
             currentX = nextX;
             currentY = (currentY + 1) % (drawTexture.height);
         }
     }
 }
 public void ReportSample(PIDSample pidSample)
 {
     lock (newSamples)
     {
         newSamples.Enqueue(pidSample);
     }
 }
        //Called once per frame
        public void Update()
        {
            if (GameLogic.CurrentScene == GameScenes.FLIGHT && GameLogic.LocalPlayerVehicle != null)
            {
                Vehicle            v  = GameLogic.LocalPlayerVehicle;
                AutopilotComponent ac = v.GetComponent <AutopilotComponent>();
                if (ac != null)
                {
                    PIDSample pidSample = null;
                    switch (pidWindow.GetMode())
                    {
                    case 0:
                        pidSample = new PIDSample(ac.pitchPid);
                        pidWindow.SetPID(ac.pitchPid);
                        break;

                    case 1:
                        pidSample = new PIDSample(ac.rollPid);
                        pidWindow.SetPID(ac.rollPid);
                        break;

                    case 2:
                        pidSample = new PIDSample(ac.speedPid);
                        pidWindow.SetPID(ac.speedPid);
                        break;

                    case 3:
                        pidSample = new PIDSample(ac.verticalSpeedPid);
                        pidWindow.SetPID(ac.verticalSpeedPid);
                        break;

                    case 4:
                        pidSample = new PIDSample(ac.altitudePid);
                        pidWindow.SetPID(ac.altitudePid);
                        break;

                    case 5:
                        pidSample = new PIDSample(ac.headingPid);
                        pidWindow.SetPID(ac.headingPid);
                        break;
                    }
                    pidWindow.ReportSample(pidSample);
                }
            }
            if (pidWindow == null && GameLogic.CurrentScene == GameScenes.FLIGHT)
            {
                pidWindow = new PIDWindow();
            }
            if (pidWindow != null)
            {
                pidWindow.Update();
            }
        }