Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Tim-Michels · Sep 03, 2012 at 01:29 PM · camerasizeviewportpreview

How to change size of camera preview in Editor?

Hi,

When you have a camera selected within the editor, a small screen is shown with the "Camera Preview".

I was wondering if it's possible to change the size of that window, because it's really small for what I have to do.

Thanks in advance

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by save · Sep 03, 2012 at 02:09 PM

I'm not sure if you can resize it, it seems rather static. You could however script your own camera preview.

Make a folder called Editor, create a Javascript within that folder and name it CameraPreview.

Paste this code:

 #pragma strict
 
 class CameraPreview extends EditorWindow {
     var camera : Camera = Camera.main;
     var renderTexture : RenderTexture;
     
     @MenuItem("Window/Preview Selected Camera #c")
     
     static function Init () {
         var editorWindow : EditorWindow = GetWindow(typeof(CameraPreview));
         editorWindow.autoRepaintOnSceneChange = true;
         editorWindow.Show();
         editorWindow.title = "Camera Preview";
     }
     
     function Awake () {
         CreateRenderTexture();
     }
     
     function Update () {
         if(camera != null) {
             camera.targetTexture = renderTexture;
             camera.Render();
             camera.targetTexture = null;    
         }
         if(renderTexture.width != position.width || renderTexture.height != position.height)
             renderTexture = new RenderTexture(position.width, position.height, RenderTextureFormat.ARGB32);
     }
     
     function OnSelectionChange () {
         var obj : GameObject = Selection.activeGameObject;
         if (obj!=null && obj.camera) camera = obj.camera;
         CreateRenderTexture();
     }
     
     function CreateRenderTexture () {
         renderTexture = new RenderTexture(position.width, position.height, RenderTextureFormat.ARGB32);
     }
     
     function OnGUI () {
         GUI.DrawTexture(new Rect(.0, .0, position.width, position.height), renderTexture);    
     }
 }

You will find the new window by pressing Shift+C or in Window/Preview Selected Camera.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image save · Sep 03, 2012 at 02:31 PM 0
Share

$$anonymous$$ade some small changes as the render texture went unassigned when playing/stopping. Good luck!

avatar image
11

Answer by ChrisVD · Sep 05, 2013 at 07:28 PM

Why not just undock the "Game" view tab, which always shows the camera view, and resize it to as large or small as you wish or move it to another monitor, etc.?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eelstork · Jun 17, 2014 at 02:26 PM 0
Share

Awesome tip, really wish I could upvote it.

avatar image Andrew_Soulside · Jul 10, 2019 at 09:53 PM 0
Share

This is not an effective solution if you are running multiple cameras in your game and especially if you are generating a lot of things at runtime and need to make edits outside of runtime.

avatar image
4

Answer by Aranda · Mar 29, 2016 at 12:14 PM

Thanks @save for the solution. I've made it resize correctly and converted to C# in case somebody prefers that:

 using UnityEngine;
 using UnityEditor;
 
 class CameraPreview : EditorWindow
 {
      Camera camera;
      RenderTexture renderTexture;
      
      [MenuItem("Custom Menu/Preview Camera")]     
      static void Init ()
      {
          var editorWindow = (EditorWindow)GetWindow<CameraPreview>(typeof(CameraPreview));
          editorWindow.autoRepaintOnSceneChange = true;
          editorWindow.titleContent = new GUIContent("Cam Preview");
          editorWindow.Show();
      }
      
      void Awake()
      {
          camera = Camera.main;
      }
      
      void Update()
      {
          if (camera != null)
          {
              EnsureRenderTexture();
 
              camera.renderingPath = RenderingPath.UsePlayerSettings;
              camera.targetTexture = renderTexture;
              camera.Render();
              camera.targetTexture = null;
          }
      }
      
      void OnSelectionChange()
      {
          var obj = Selection.activeGameObject;
          if (obj == null)
              return;
 
          var cam = obj.GetComponent<Camera>();
          if (cam == null)
              return;
 
          camera = cam;
      }
 
      void EnsureRenderTexture()
      {
          if (renderTexture == null 
              || (int)position.width != renderTexture.width 
              || (int)position.height != renderTexture.height)
          {
              renderTexture = new RenderTexture((int)position.width, (int)position.height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
          }
      }
      
      void OnGUI()
      {
          if (renderTexture != null)
             GUI.DrawTexture(new Rect(0.0f, 0.0f, position.width, position.height), renderTexture);
      }
  }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by stefanseibert · Nov 25, 2014 at 09:12 AM

If you want to use that solution today, be aware that you have to add a depth argument for constructing a RenderTexture. See http://docs.unity3d.com/ScriptReference/RenderTexture-ctor.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Torx · May 05, 2015 at 03:13 AM

Hi, i don't know if it's your solution, it's not perfect but very simple (it's an exemple for phone application between portrait and landspace) :

 void Start()
 {
     #if UNITY_EDITOR
         Camera.main.rect = new Rect(0.3f, 0.0f, 0.4f, 1.0f);
     #else
         Screen.orientation = ScreenOrientation.Portrait;
     #endif
 }
 
 void OnDestroy()
 {
     #if UNITY_EDITOR
         Camera.main.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
     #else
         Screen.orientation = ScreenOrientation.LandSpace;
     #endif
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fixing a Camera viewport rect to a certain size? (So it doesn't change with the size of the gamewindow) 1 Answer

How to resize a camera's orthoSize for an object to fit inside its rect viewport? 1 Answer

How I get sizeof pixels of object 1 Answer

is it possible to set the view port rect at both ends 1 Answer

Move an object in world space on the viewport 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges