subere23

Untitled

Sep 5th, 2017
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. using HoloToolkit.Unity;
  5.  
  6.  
  7. public class NRSRManager : Singleton<NRSRManager> {
  8.  
  9.     public Renderer[] ObjectsInScene;
  10.     public List<GameObject> FilterObjectsInScene = new List<GameObject>();
  11.     //Used to trigger next object update
  12.     public int TotalNumberOfObjects = 0;
  13.     public int PreviousFrameObjectCount = 0;
  14.  
  15.     //just in case we need - these numbers added together should always = total number of objects
  16.     public int numberofVisibleObjects;
  17.     public int numberOfFilteredObjects;
  18.  
  19.     void FixedUpdate()
  20.     {
  21.  
  22.         FindObjectsInScene(); //Likely expensive to do every frame, dynamic systems tend to come at a cost.
  23.  
  24.         TotalNumberOfObjects = ObjectsInScene.Length;
  25.  
  26.  
  27.         if (TotalNumberOfObjects != PreviousFrameObjectCount)
  28.         {
  29.             FilterUnneededObjects();
  30.             numberofVisibleObjects = FilterObjectsInScene.Count;
  31.  
  32.             foreach (GameObject go in FilterObjectsInScene)
  33.             {
  34.                //Todo later
  35.             }
  36.  
  37.         }
  38.  
  39.         PreviousFrameObjectCount = ObjectsInScene.Length;
  40.  
  41.     }
  42.  
  43.  
  44.     void FindObjectsInScene()
  45.     {
  46.         ObjectsInScene = null;
  47.         ObjectsInScene = FindObjectsOfType<Renderer>();
  48.     }
  49.  
  50.     void FilterUnneededObjects()
  51.     {
  52.  
  53.         FilterObjectsInScene.Clear();
  54.         numberOfFilteredObjects = 0;
  55.  
  56.         for (int i = 0; i < ObjectsInScene.Length; i++)
  57.         {
  58.             if (ObjectsInScene[i].gameObject.tag != "NRSRTools")
  59.             {
  60.                 FilterObjectsInScene.Add(ObjectsInScene[i].gameObject);
  61.             }
  62.             else
  63.             {
  64.  
  65.                 numberOfFilteredObjects++;
  66.  
  67.             }
  68.         }
  69.  
  70.     }
  71.  
  72.  
  73. }
Add Comment
Please, Sign In to add comment