Example #1
0
 private void Update()
 {
     //Rate Limit it to doing a cull-calculation every 10 physics-second frames, which should be plenty.  These are very heavy.
     counter++;
     if (counter > 500)
     {
         counter = 0;
         if (maxdistance == -1)
         {
             maxdistance = Kopernicus.RuntimeUtility.RuntimeUtility.KopernicusConfig.ScatterCullDistance;
         }
         //if 0 abort.
         if (maxdistance == 0)
         {
             return;
         }
         surfaceObjectQuad = GetComponentInParent <PQSMod_LandClassScatterQuad>();
         kopSurfaceObjects = surfaceObjectQuad.GetComponentsInChildren <KopernicusSurfaceObject>(true);
         if (kopSurfaceObjects.Length == 0)
         {
             return;
         }
         int distance = 15000;
         if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel)
         {
             distance = (int)Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, surfaceObjectQuad.transform.position);
         }
         else
         {
             distance = 0;
         }
         //Optimization checks
         if ((distance > maxdistance) && (kopSurfaceObjects[0].GetComponent <MeshRenderer>().enabled == false))
         {
             return;
         }
         if ((distance <= maxdistance) && (kopSurfaceObjects[0].GetComponent <MeshRenderer>().enabled == true))
         {
             return;
         }
         for (int i = 0; i < kopSurfaceObjects.Length; i++)
         {
             MeshRenderer surfaceObject = kopSurfaceObjects[i].GetComponent <MeshRenderer>();
             if (distance > maxdistance)
             {
                 surfaceObject.enabled = false;
             }
             else
             {
                 surfaceObject.enabled = true;
             }
         }
     }
     else
     {
         return;
     }
 }
Example #2
0
 private void Update()
 {
     //Rate Limit it to doing a cull-calculation every 120 frames, which should be plenty since we don't update more anyways.  These are very heavy.
     counter++;
     if (counter > 120)
     {
         if (!init)
         {
             init        = true;
             maxdistance = Kopernicus.RuntimeUtility.RuntimeUtility.KopernicusConfig.ScatterCullDistance;
         }
         surfaceObjectQuad = GetComponentInParent <PQSMod_LandClassScatterQuad>();
         surfaceObjects    = surfaceObjectQuad.GetComponentsInChildren <MeshRenderer>(true);
         counter           = 0;
         int distance = 15000;
         if (HighLogic.LoadedSceneIsFlight)
         {
             distance = (int)Vector3.Distance(Camera.current.transform.position, surfaceObjectQuad.transform.position);
         }
         else
         {
             distance = 0;
         }
         for (int i = 0; i < surfaceObjects.Length; i++)
         {
             MeshRenderer surfaceObject = surfaceObjects[i];
             if (distance > maxdistance)
             {
                 surfaceObject.enabled = false;
             }
             else
             {
                 surfaceObject.enabled = true;
             }
         }
     }
     else
     {
         return;
     }
 }