Camera view window

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
Line 79: Line 79:
 
}
 
}
 
}
 
}
</javascript>
+
</syntaxhighlight>
  
 
==Javascript - SelectedCameraView.js==
 
==Javascript - SelectedCameraView.js==
Line 89: Line 89:
 
var showView : boolean = true;
 
var showView : boolean = true;
 
var ViewRect : Rect = Rect(0,0,100,100);
 
var ViewRect : Rect = Rect(0,0,100,100);
</javascript>
+
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

Original Author: Luis Correa (Ratamorph)

Contents

[edit] 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.

[edit] 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.


[edit] 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;
 
    	} 
 
	}
}

[edit] 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