Camera view window

From Unify Community Wiki
Revision as of 20:52, 10 January 2012 by NCarter (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Original Author: Luis Correa (Ratamorph)

Contents

Description

Sometimes you have multiple cameras in your scene each looking at a different place, toggling between those cameras is a bit tedious. This is where this set of scripts come in handy. You can look at the rendered image of any selected camera that has the SelectedCameraView script.

Usage

1.Place the SelectedCameraViewScene script in YourProject/Assets/Editor. 2.Place the SelectedCameraView script on any camera you want to view.

Now when you select a camera that has the SelectedCameraView a window on the scene view window will display the rendered image from that camera. You can turn the window on/off for each camera aswell as modify the position and size of the view window.


Javascript - SelectedCameraViewScene.js

@CustomEditor (SelectedCameraView)
class SelectedCameraViewScene extends Editor {
 
  	function OnInspectorGUI()
  	{
  		EditorGUILayout.BeginHorizontal();
  		GUILayout.Label("Display camera view");
  		target.showView = EditorGUILayout.Toggle(target.showView);
  	  	EditorGUILayout.EndHorizontal();	
 
  		target.ViewRect = EditorGUILayout.RectField("View Rect", target.ViewRect);
 
  		if (GUI.changed)
 
            EditorUtility.SetDirty (target);  		
  	}
 
    function OnSceneGUI () {
 
        if(!target.showView)
        	return;
 
        if(target.camera)
        {
        	Handles.BeginGUI();
        	GUILayout.BeginArea(target.ViewRect);
 
        	GUILayout.Box(target.name);
 
        	var viewCameraRect : Rect = target.ViewRect;
        	viewCameraRect.y = target.ViewRect.y + 80;
        	DrawCamera(viewCameraRect, target.transform.camera);
 
        	GUILayout.EndArea();
        	Handles.EndGUI();	
        }
    }
 
    private function DrawCamera (position : Rect, camera : Camera) 
 
	{ 
 
    	if (Event.current.type == EventType.Repaint) 
 
   		{ 
 
        	var cameraRect : Rect = new Rect (position.xMin, Screen.height - position.yMax, position.width, position.height);
 
        	var cameraOriginalRect : Rect = camera.pixelRect;
 
 
        	camera.pixelRect = cameraRect; 
 
 
 
        	camera.Render ();
 
        	camera.pixelRect = cameraOriginalRect;
 
    	} 
 
	}
}

Javascript - SelectedCameraView.js

@script ExecuteInEditMode()
@script RequireComponent(Camera)
 
//YES, it only holds a couple of variables...
var showView : boolean = true;
var ViewRect : Rect = Rect(0,0,100,100);
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox