SHARE
TWEET

CH6NRSRManager

subere23 Sep 16th, 2017 (edited) 876 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     public static GameObject FocusedObject;
  16.  
  17.     public delegate void OnObjectFocused();    
  18.     public static event OnObjectFocused ObjectFocused;
  19.     public static event OnObjectFocused ObjectUnFocused;
  20.  
  21.  
  22.     //just in case we need - these numbers added together should always = total number of objects
  23.     public int numberofVisibleObjects;
  24.     public int numberOfFilteredObjects;
  25.  
  26.     public Material BoundingBoxMat;
  27.    
  28.     private void Update()
  29.     {
  30.         if(FocusedObject == null)
  31.         {
  32.  
  33.             if (ObjectUnFocused != null)
  34.             {
  35.                
  36.                 ObjectUnFocused();
  37.             }
  38.  
  39.             return;
  40.         }
  41.  
  42.         if (FocusedObject != null)
  43.         {
  44.             if (ObjectFocused != null)
  45.             {
  46.                
  47.                 ObjectFocused();
  48.  
  49.             }
  50.         }
  51.              
  52.     }
  53.  
  54.     public static void SendFocusedObjectToManager(GameObject go)
  55.     {
  56.         FocusedObject = go;
  57.         Debug.Log(go.name + " to NRSRManager");
  58.  
  59.     }
  60.     public static void ClearFocusedObjectFromManager()
  61.     {
  62.  
  63.         FocusedObject = null;
  64.  
  65.     }
  66.    
  67.     void FixedUpdate()
  68.     {
  69.  
  70.         FindObjectsInScene(); //Likely expensive to do every frame, dynamic systems tend to come at a cost.
  71.  
  72.         TotalNumberOfObjects = ObjectsInScene.Length;
  73.  
  74.         if (TotalNumberOfObjects != PreviousFrameObjectCount)
  75.         {
  76.             FilterUnneededObjects();
  77.             numberofVisibleObjects = FilterObjectsInScene.Count;
  78.  
  79.             foreach (GameObject go in FilterObjectsInScene)
  80.             {
  81.                 if (go.transform.root.gameObject.GetComponent<BoundingBox>() == null)
  82.                 {
  83.                     BoundingBox box = go.transform.root.gameObject.AddComponent<BoundingBox>();
  84.                     go.transform.root.gameObject.AddComponent<FadeObjectNotActive>();
  85.                     box.isRootObject = true;
  86.  
  87.  
  88.                 }
  89.             }
  90.         }
  91.         PreviousFrameObjectCount = ObjectsInScene.Length;
  92.     }
  93.  
  94.  
  95.     void FindObjectsInScene()
  96.     {
  97.         ObjectsInScene = null;
  98.         ObjectsInScene = FindObjectsOfType<Renderer>();
  99.     }
  100.  
  101.     void FilterUnneededObjects()
  102.     {
  103.         FilterObjectsInScene.Clear();
  104.         numberOfFilteredObjects = 0;
  105.  
  106.         for (int i = 0; i < ObjectsInScene.Length; i++)
  107.         {
  108.             if (ObjectsInScene[i].gameObject.tag != "NRSRTools")
  109.             {
  110.                 FilterObjectsInScene.Add(ObjectsInScene[i].gameObject);
  111.             }
  112.             else
  113.             {
  114.                 numberOfFilteredObjects++;
  115.             }
  116.         }
  117.     }
  118. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top