Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using HoloToolkit.Unity;
- public class NRSRManager : Singleton<NRSRManager> {
- public Renderer[] ObjectsInScene;
- public List<GameObject> FilterObjectsInScene = new List<GameObject>();
- //Used to trigger next object update
- public int TotalNumberOfObjects = 0;
- public int PreviousFrameObjectCount = 0;
- //just in case we need - these numbers added together should always = total number of objects
- public int numberofVisibleObjects;
- public int numberOfFilteredObjects;
- void FixedUpdate()
- {
- FindObjectsInScene(); //Likely expensive to do every frame, dynamic systems tend to come at a cost.
- TotalNumberOfObjects = ObjectsInScene.Length;
- if (TotalNumberOfObjects != PreviousFrameObjectCount)
- {
- FilterUnneededObjects();
- numberofVisibleObjects = FilterObjectsInScene.Count;
- foreach (GameObject go in FilterObjectsInScene)
- {
- //Todo later
- }
- }
- PreviousFrameObjectCount = ObjectsInScene.Length;
- }
- void FindObjectsInScene()
- {
- ObjectsInScene = null;
- ObjectsInScene = FindObjectsOfType<Renderer>();
- }
- void FilterUnneededObjects()
- {
- FilterObjectsInScene.Clear();
- numberOfFilteredObjects = 0;
- for (int i = 0; i < ObjectsInScene.Length; i++)
- {
- if (ObjectsInScene[i].gameObject.tag != "NRSRTools")
- {
- FilterObjectsInScene.Add(ObjectsInScene[i].gameObject);
- }
- else
- {
- numberOfFilteredObjects++;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment