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;
- using HoloToolkit.Unity.InputModule;
- 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;
- public RaycastHit hitInfo;
- public static bool holdSelectedObject_LookingAtTransformTool;
- public static bool holdSelectedObject_UsingTransformTool;
- LayerMask layerMask;
- public static Vector3 menuPosition;
- private void Start()
- {
- layerMask = 1 << 23;
- layerMask = ~layerMask;
- }
- private void Update()
- {
- if (holdSelectedObject_UsingTransformTool)
- {
- return;
- }
- RayCastToHoldFocusedObject();
- menuPosition = hitInfo.point;
- if (holdSelectedObject_LookingAtTransformTool)
- {
- if (ObjectFocused != null)
- {
- ObjectFocused();
- }
- return;
- }
- else
- {
- FocusedObject = null;
- if (ObjectUnFocused != null)
- {
- ObjectUnFocused();
- }
- }
- }
- public void RayCastToHoldFocusedObject()
- {
- if (Physics.Raycast(Camera.main.transform.position,
- Camera.main.transform.forward,
- out hitInfo,
- Mathf.Infinity,
- layerMask))
- {
- Debug.Log(hitInfo.transform.root.name);
- if (hitInfo.transform == null)
- {
- Debug.Log("hitInfo Transform null");
- NRSRManager.holdSelectedObject_LookingAtTransformTool = false;
- return;
- }
- if (FocusedObject != null)
- {
- if (FocusedObject.transform.root.name == hitInfo.transform.root.name)
- {
- NRSRManager.holdSelectedObject_LookingAtTransformTool = true;
- }
- else
- {
- NRSRManager.holdSelectedObject_LookingAtTransformTool = false;
- }
- }
- }
- else
- {
- NRSRManager.holdSelectedObject_LookingAtTransformTool = false;
- }
- }
- public static void SendFocusedObjectToManager(GameObject go)
- {
- if (holdSelectedObject_LookingAtTransformTool)
- {
- return;
- }
- FocusedObject = go;
- Debug.Log(go.name + " to NRSRManager");
- }
- public static void ClearFocusedObjectFromManager()
- {
- if (holdSelectedObject_LookingAtTransformTool)
- {
- return;
- }
- 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