Camera view window

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Ratamorph)
Line 1: Line 1:
 +
[[Category: Editor]]
 +
[[Category: ScriptableObject]]
 +
[[Category: Javascript]]
 +
[[Category: Camera]]
 +
[[Category: Selection]]
 +
Original Author: Luis Correa (Ratamorph) <BR>
 +
==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==
 +
<javascript>
 +
@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>
 +
 +
==Javascript - SelectedCameraView.js==
 +
<javascript>
 +
@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);
 +
</javascript>

Revision as of 19:21, 19 October 2009

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

<javascript> @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>

Javascript - SelectedCameraView.js

<javascript> @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); </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox