Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] Separate game view in Unity EditorWindow

Discussion in 'Editor & General Support' started by TimCabbage, Feb 2, 2018.

  1. TimCabbage

    TimCabbage

    Joined:
    Feb 13, 2011
    Posts:
    66
    Hello :)

    I'm trying to render some models to the editor window without touching the current scene.
    You would then be able to change the objects settings and save the templates.

    How can I do it without impacting the scene at all?

    I'm currently using:

    Code (csharp):
    1.     // Add menu named "My Window" to the Window menu
    2.     [MenuItem("Window/My Window")]
    3.     static void Init() {
    4.         // Get existing open window or if none, make a new one:
    5.         MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
    6.         window.Show();
    7.  
    8.         cam = new GameObject();
    9.         cam.hideFlags = HideFlags.HideAndDontSave;
    10.         cam.transform.position = new Vector3(1.5f, 1.0f, 1.0f);
    11.         cam.transform.eulerAngles = new Vector3(19.0f, -5.0f, 0.0f);
    12.         ccam = cam.AddComponent<Camera>();
    13.         ccam.fieldOfView = 19;
    14.     }
    and then

    Code (csharp):
    1.  
    2.         // important: only render during the repaint event
    3.         if (Event.current.type == EventType.Repaint) {
    4.  
    5.             ccam.pixelRect = sceneRect;
    6.             ccam.Render(); // render the camera into the window
    7.         }
    8.  
    But what it does is it uses the current scene to render stuff.
    I would like a totally separate space to do this in.

    Possible?
     
  2. TimCabbage

    TimCabbage

    Joined:
    Feb 13, 2011
    Posts:
    66
  3. TimCabbage

    TimCabbage

    Joined:
    Feb 13, 2011
    Posts:
    66
    Solution:
    Code (csharp):
    1.  
    2.                             mesh = go.GetComponent<MeshFilter>().sharedMesh;
    3.                             mat = go.GetComponent<Renderer>().sharedMaterial;
    4.  
    this now extracts the needed properties.

    then in another location:

    Code (csharp):
    1.  
    2.     private void Update() {
    3.         if(mesh && mat) {
    4.             Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, mat, 30, ccam);
    5.         }
    6.     }
    7.  
    Draws the mesh for the layer 30. My camera is displaying only layer 30 of the game effectively removing all else.
    No need to define all the layers manually.
     
  4. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    339
    ermmmm, just make a new scene, you can even load 2 scenes at once so that you can play around on your second scene, but see the stuff in your game world without messing up your game world.

    This may not solve your exact issue, but then again I don't know exactly what you are trying to do. However this is how I set up my prefabs and make adjustments to things without risking clicking something nasty on my developed scene. If you need to see just that object, you can right click your main scene and unload it. It is still there in the heiarchy just hidden from view at that point.
     
    Last edited: Feb 2, 2018
  5. TimCabbage

    TimCabbage

    Joined:
    Feb 13, 2011
    Posts:
    66
    the point is not to have to have another scene but do the stuff within the current one. Changes to templates are reflected in the current scene so that you can see what you did to the template in a real life scenario
     
  6. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    339
    I may have read your OP wrong, I am sorry if so. Maybe prefabs would work for you? If you adjust a prefab in your project folder it updates all objects based on that prefab, as long as you do not break the prefab link (the scene objects are blue named).



    It is the whole purpose of prefabs. So you can make 1 change and update everything. Rather than try to go adjust every individual instance of it, or have to fiddle around inside your scene.

    Just in case I am still missing something, will note that you can put stuff on layer 30, have your main camera ignore that layer and have a second camera only render that layer without a lick of scripting, and you don't need to fill the other layers. The numbers are arbitrary, no need to fill them all just to put something in 30. But to get that camera to register the thing you want to look at, you have to put something there to look at. Which means touching your scene....which you wanted to avoid :) Just change the prefab does the same thing as changing the scene object and hitting apply, you just dont have an apply to hit.
     
    Last edited: Feb 2, 2018
  7. TimCabbage

    TimCabbage

    Joined:
    Feb 13, 2011
    Posts:
    66
    I've solved the problem already see post 3, will update the title.