Advertisement
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;
- public static GameObject FocusedObject;
- public delegate void OnObjectFocused();
- public static event OnObjectFocused ObjectFocused;
- public static event OnObjectFocused ObjectUnFocused;
- //just in case we need - these numbers added together should always = total number of objects
- public int numberofVisibleObjects;
- public int numberOfFilteredObjects;
- public Material BoundingBoxMat;
- private void Update()
- {
- if(FocusedObject == null)
- {
- if (ObjectUnFocused != null)
- {
- ObjectUnFocused();
- }
- return;
- }
- if (FocusedObject != null)
- {
- if (ObjectFocused != null)
- {
- ObjectFocused();
- }
- }
- }
- public static void SendFocusedObjectToManager(GameObject go)
- {
- FocusedObject = go;
- Debug.Log(go.name + " to NRSRManager");
- }
- public static void ClearFocusedObjectFromManager()
- {
- FocusedObject = null;
- }
- 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)
- {
- if (go.transform.root.gameObject.GetComponent<BoundingBox>() == null)
- {
- BoundingBox box = go.transform.root.gameObject.AddComponent<BoundingBox>();
- go.transform.root.gameObject.AddComponent<FadeObjectNotActive>();
- box.isRootObject = true;
- }
- }
- }
- 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++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement