/// <summary> /// Called when the window finishes intializing. Registers the camera. /// </summary> private void Awake() { if (!CameraDataNode.GUIcam) { CameraDataNode.CreateGUICam(); //when the window is opened, make sure there's a camera } }
/// <summary> /// A callback function that draws the contents of a custom GUI window. /// </summary> /// <param name="id">The ID # of the window being drawn</param> void DrawSceneViewerWindow(int id) { CameraDataNode.CreateGUICam(); //draw the camera's view (offsets compensate for window name bar and border) Handles.DrawCamera(new Rect(0, 16, camWindowRect.width - 1, camWindowRect.height - 17), CameraDataNode.GUIcam.GetComponent <Camera>(), DrawCameraMode.Normal); GUI.DragWindow();//allows the window to be dragged around the scene view. }
/// <summary> /// Called every frame to draw GUI elements. Draws the camera view in the window. /// </summary> private void OnGUI() { if (!CameraDataNode.GUIcam) { CameraDataNode.CreateGUICam(); //instantiate a GUI-use camera if one isn't in use. } Rect camRect = new Rect(0, 0, Screen.width, Screen.height); //use the size of the window, can be dynamically resized. Handles.DrawCamera(camRect, CameraDataNode.GUIcam.GetComponent <Camera>()); Repaint();//manually repaints the window }