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

Official Editor window to open scenes

Discussion in 'Open Projects' started by dotsquid, Dec 10, 2020.

  1. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Hey there.

    I was keeping an eye on this project since the begining but just found some time to participate.
    There is a task "Editor window to quickly open scenes" marked with a tag "good-first-task" so I think it's a good starting point for me.

    Before implementing this task I believe it's better to discuss the details.
    The project contains GameSceneSO assets which are kind of wrappers around the scenes. So I think we could use them in this Scene Selector as a source of information which scenes to show (as it's said in the description of the task that not every scene in the project is required to be shown). This way we don't need any extra scriptable objects to contain the list of the scenes to show since it would make the workflow harder.

    Also I plan to add an option to hide specific scenes from the listing. Each entry will contain a toggle button which will control the visibility (similar to a visibility toggle in a Hierarchy window)

    A very rough draft:
    upload_2020-12-10_14-23-23.png
     
  2. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    Must be exist a possibility to unhide entry

    And do you know that exist the \UOP1_Project\Assets\Scripts\Editor\GameSceneSOEditor.cs which contain CustomEditor(typeof(GameSceneSO)...)

    Yes, I was thinking did the same

    P.S>
    I think good style to add to your post the blue mark Official, it can be set after creation thread also.
     
    Last edited: Dec 10, 2020
  3. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Yep, there will be a global visibility button which will unhide hidden items (or to be more precise it will just make the window ignore per-item visibility settings and show them all). I just did not reflect it on the draft.

    Yes, I'm aware of that. However I don't realize how does it relate to Scene Selector.

    I guess it must be set by forum admin, no?
     
  4. shuttle127

    shuttle127

    Joined:
    Oct 1, 2020
    Posts:
    183
    You're correct, @cirocontinisio is usually the one that marks threads "Official" or not.
     
  5. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    Yes, but when he create the thread self, :) He is the very powerful man, but i think he doesn't have possibility to edit somebody else threads.
     
  6. shuttle127

    shuttle127

    Joined:
    Oct 1, 2020
    Posts:
    183
    He does, and here's an example in the Outline Effect thread. :)
     
  7. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    This prefix is marked as one for admins. So let's just stop this off topic discussion.
    upload_2020-12-10_21-54-27.png
     
    cirocontinisio likes this.
  8. canchen_unity

    canchen_unity

    Joined:
    Mar 13, 2018
    Posts:
    12
    This is unrelated but @dotsquid your game looks great
     
    cirocontinisio and dotsquid like this.
  9. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
  10. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    IMHO Your PR doesn't correspond to this open task - "Editor window to quickly open scenes".
    Must be create separate thread to discuss your proposal regrading "to make GameSceneSO more reliable".
     
  11. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    It's ok, the change to the scene retrieval is probably a PR that has a short life, we generally create a thread for features that are going to be long in development.

    @dotsquid I like your idea with the change in how we fetch the scene files. I'll leave a comment on the PR before analising it!
     
  12. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Hello, I also created a editor window to quickly open scenes which is scalable also, but seems that @dotsquid already created. I was ready to open a P.R but went offline for few days back.

    Should I explain my working?
     
  13. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    So I was working on my idea of the 'visibility' toggle buttons and encountered an undesired behaviour of UnityEditorInternal.ReorderableList which I use to draw the list of scenes.
    What I was thinking to do is just make the ReorderableList not draw hidden items but keeping them untouched in the list. The only way to do that is return zero height in `elementHeightCallback` and do nothing in `drawElementCallback`. Unfortunately this leads to visual issues:
    upload_2020-12-14_16-12-2.png
    1. An item being dragged has no content.
    2. Dragging handles of hidden items are still being drawn.

    I have inspected the source code of ReorderableList and it seems there is no way to get this problem around.
    If someone have any idea how to make ReorderableList not draw specific items, please speak :)
    Otherwise the only way to implement this is to have 2 lists: one for visible items and one for hidden items, which complicates things a lot.
     
  14. canchen_unity

    canchen_unity

    Joined:
    Mar 13, 2018
    Posts:
    12
    For learning purpose, I also attempted this task, and here's my PR:
    https://github.com/UnityTechnologies/open-project-1/pull/267.

    I actually didn't know about ReorderableList but searched it up and used it after seeing your screenshot. @dotsquid
    So what I did is that I have two modes, one for edit and one for view. (kind of like iPhone?)
    The edit mode uses ReorderableList and always shows all the scenes and their visibility. The view mode only uses GUI buttons and doesn't show the scenes with visibility turned off.

    You can check the gifs in my PR to see the details.
     
    Last edited: Dec 15, 2020
  15. canchen_unity

    canchen_unity

    Joined:
    Mar 13, 2018
    Posts:
    12
  16. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    @cirocontinisio @canchen_unity That's kinda disappointing that your work (which I actually appreciate and what to thank for the idea of the 'edit mode') was merged without any discussion.
    Anyway, here is what I came up with (though it needs some polishing).

    scene_selector.gif
    As I proposed earlier my implementation uses GameSceneSO's to populate the list of scenes to display. I believe it has benefits against the version which retrieves the scenes from the BuildSettings: it still can display the testing scenes which should not appear in the BuildSettings list. Beside that there is no need for manual filling and clearing the list of scenes.
    Another major difference is that I use EditorPrefs to store the data instead of a ScriptableObject in the Resources folder. I think this is much more preferred way to store this kind of data for 2 reasons:
    1) this data may differ for different users: someone wants to see test scenes, someone does not. Every change in the data will lead to the change in staged files in git and will require either declining those changes or committing them. Either way it will be mess.
    2) since those data are stored in Resources they will be included to the build which is not a good idea.

    Since this PR is still not approved and merged I can't create a PR for this feature.
     
    Last edited: Dec 16, 2020
    canchen_unity likes this.
  17. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    The situation when someone begin new work, when others working on that case, isn't good and also if I remember the main idea of forum use was to avoid these issues.
    And I think in the future it will be good to present some procedures for organizing the work of several people on one issue. @cirocontinisio @Amel-Unity (And you didn't mark this thread as Official? May be good idea - recommend members to set the status themselves if that's the proper topic. You always have the right not to accept it later
    I didn't check the solution of @canchen_unity yet, but the idea @dotsquid - doesn't base the "Scene selector" especial on Build Settings (possibility to add link not only on scenes from Build Settings) is very good and his proposal regarding the visual of "Scene selector" GUI is more interesting and have more possibilities (color marking) for future development.
    But the idea of @canchen_unity to populate list from Build Settings (for init it) also very good also as "clear list".
    This idea also interesting (I didn't see the code) but Idea is right - I spent some time with SO and believe that use it everywhere to store different data isn't a good programming style, because it a very specific "data object: with some benefits and some limitations.
     
    Last edited: Dec 17, 2020
    dotsquid likes this.
  18. canchen_unity

    canchen_unity

    Joined:
    Mar 13, 2018
    Posts:
    12
    @dotsquid, sorry for making this messy.
    I really like the look of your version and those color markings. And yes, the two points you mentioned really make sense. I think I'm learning a lot from you, so sorry again for causing this situation. I'll look into the PR and see what we can do.
    I'd love to see your version of the tool and learn how you implemented it.
     
    dotsquid likes this.
  19. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    I was also working on this Task and I would like to show my approach too.
    Images:
    WindowOpen.png
    ScenesIndex.png

    My approach is we can create a AllScenesHolderSO scriptable object and assign SceneAssets to it. Then we can open the window and assign the scriptable object into the Scene Data field. Then buttons will populate for all scenes (except for currently open scene, if it is also in the SO). We can, obviously change scenes by clicking those.
    When we close the window, the reference persists. But closing the Unity editor removes the reference, for now.
    If we update the SO index, the editor window automatically updates its button, no need to reassign.
    This way we can create several indexes and assign them in window.
    My implementation also does not uses Scenes from build settings. So there's no need of adding Test scenes to build settings.
    feel free to ask any questions.

    I also created a Video on this, but it seems i cannot upload it here like images, nor I can do on YouTube. How will I upload that Video?

    PR: https://github.com/UnityTechnologies/open-project-1/pull/272
     
  20. Amel-Unity

    Amel-Unity

    Unity Technologies

    Joined:
    Jan 30, 2020
    Posts:
    62
    Hey everyone!

    I tested and merged the PR from @canchen_unity because the tool does what was required in an independent way and I liked the window made for the tool. I also saw that you both discussed the solutions on the forum and even though It wasn't @dotsquid who opened the PR, you both contributed by giving feedback and discussing it here and I would like to thank you both for that. Merging the PR doesn't mean that it is final, we can still open another PR to improve the current solution.

    Now I saw the updates from you all during these last 2 days after the merge, here on the forum and in the comments section in Github on the GameSceneSO PR and I can see that what @dotsquid is suggesting is really a great solution. The fact that we don't rely on BuildSettings is really a good point. For instance, we are using a lot of test scenes that we want to access via the open scenes tool, but without adding them to the build because we don't really need them in the game. So here is what I suggest: let's keep the discussion going on the GameSceneSO PR and once it's fully working (We are almost there), we can merge it. Then, feel free to open a new PR for the scenes tool to make it read the SOs instead of taking it from BuildSettings and we can merge it if all is good.
     
    canchen_unity likes this.
  21. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
  22. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    @Amel-Unity
    Thanks for clarification.
    I guess that PR is ready for approvement and merging. After that I will be able to create another PR for Scene Selector.
     
    Last edited: Dec 18, 2020
  23. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    @Harsh-099
    Your solution looks a little bit overcomplicated and it seems it requires unnecessary manual work to use it. At first it needs a manually created list of scenes inside ScriptableObject. So when someone creates a new scene, he/she will need to find that SO and add that scene to the list. Then this SO should be manually added to the corresponding scene inside the window (and this procedure has to be repeated every time the editor is reloaded). And, I could be wrong, but it seems that the internal list of buttons is populated from that SO only when the window is created, so it won't automatically reflect the changes made to the list of scenes. That's not a very convenient workflow. Keep up practicing though ;)
     
  24. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    What I did notice is that all proposed solutions don't take into account the possibility that the currently open scene is modified and requires saving before opening another one. In all cases unsaved changes will be lost.
     
    canchen_unity likes this.
  25. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    I showed in the video, that:

    1. The window will update the buttons (and also order of button as in the reorderable list) as the SO is changed
    Note: And if any case, that is not updated, i will add a button in window to manually update the buttons.

    2. I made the SO field static, so it will persist the reference of SO on closing and reopening.

    3. The reference is lost though when Unity is closed, but I'm working on it.

    Ask me any other questions if you wish to, and also do watch the video. I have explained things in it.
     
  26. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    There are functions in EditorSceneManager. I will also work on it.
     
  27. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    It's Customization

    I will try to make finiding the SO easier. Thanks for pointing out bugs. I was feeling it convenient.

    And yes, mine system uses SceneAsset path relative to the Asset directory
     
    Last edited: Dec 19, 2020
  28. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hey @Harsh-099, it's great that you're rolling your own solution but we already have 2 working ones that are functional and fully-featured, so just so you know we might end up closing the PR eventually!
     
  29. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Yeh, I know. My main goal is just learning. So there are two things:
    1. My all PRs yet are not successful. So I will not give up trying and try for every thing I can do.
    2. I learnt a many things (Such as we can search and load assets from project and open, close, save and modify scenes programmatically.
    Thanks for support.
     
    dotsquid likes this.
  30. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
  31. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    While we are waiting for the final decision (@cirocontinisio @Amel-Unity) regarding this issue, which solution will be finally implement in project (@canchen_unity || @dotsquid || may be @Harsh-099) I decide to make improvement to the current code of PR (@canchen_unity), which was merged in main branch at December 17.
    This improvement based on current code, include the next changes & features:
    Minor changes:
    - separated code of SO "SceneAccessHolderSO" (SceneAccessHolderSO.cs) on:
    -- ReadOnlyPropertyDrawer.cs (It must be in Editor folder - "// The property drawer class should be placed in an editor script, inside a folder called Editor." from Unity Doc)
    -- SceneAccessHolderSOReadOnlyAttribute.cs (It must be not in Editor folder, now in folder with corresponding SO)
    -- now "SceneAccessHolderSO.cs" contain only clean SO.

    Major changes:
    - SceneAccessTool.cs
    -- Not demand initial creation of SceneAccessHolderSO, if it absent will create automatically
    -- Fully sync the window "SceneAccessTool" and SceneAccessHolderSO, The user can simultaneously change the SceneListing values and window display parameters directly in the window itself or in the inspector (by change SO).
    - added SceneAccessSOEditor : Editor, which update window if SO changed.
    - window display parameters save to SO and will restored, if window was closed
    - optimized OnGUI () to reduce the number of method calls
    - corrected work with ReorderableList (ToggleEditMode()/OnGui()/OnEnable())

    I made draft PR Request for someone who interested in it (can load as common PR).
    I made the draft PR request because it is not entirely clear what will be on this issue.
    Now we have 3 PR which does't correlate with each other ... and I don't want to create another one, but I don't know other possibilities to share my code with teammates.

    I think that the optimal way will be a combine the functionality @canchen_unity (with my updates) with functionality @dotsquid based on his code:
    PROPOSAL @dotsquid May be it will be a good solution, If You create new "big" PR, which will be include the your current PR & your QuickSceneSelector. In that case you can share it now and we can load and test it (by the way in your new PR you can put link on your previous PR for mention that it will replace/include him)
     
    Last edited: Dec 25, 2020
    canchen_unity likes this.
  32. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Done https://github.com/UnityTechnologies/open-project-1/pull/285
     
  33. Amel-Unity

    Amel-Unity

    Unity Technologies

    Joined:
    Jan 30, 2020
    Posts:
    62
    Hey everyone!

    Thanks a lot for all of you for these great discussion and contributions!
    I would like to start by answering this

    I will merge this PR now. We definitely like this approach and the idea of relying on GameSceneSOs.

    Now building on top of this, @dotsquid 's solution for the scene selector tool does more and is more long-term ready. Again the current solution that we merged from @canchen_unity looks great and works but as I mentioned dotsquid's solution will work better in the long term.
    So I suggest that we also merge the solution from @dotsquid for the scene selector tool since we want to take the functionality of his PR, but maybe use @canchen_unity window which is simple and well-made. What do you both think of this? We also don't want to end up with 2 windows for the same tool in the project so we can either remove the currently merged solution or maybe @canchen_unity would you be interested to implement the window you made with the solution proposed by dotsquid? that way we can keep the best of both worlds! :)

    @Harsh-099 I also really would like to thank you for your solution but as Ciro mentioned we already have 2 solutions working for this tool and they are both already functional. Still, as you said, the main purpose is to learn and I am really happy to hear that you learnt a lot while making this PR and I hope it was helpful for you to get feedback from others on the tool.
     
    cirocontinisio likes this.
  34. Amel-Unity

    Amel-Unity

    Unity Technologies

    Joined:
    Jan 30, 2020
    Posts:
    62
    Hey everyone :)
    For now the tool that is currently merged has a bug which makes it not really possible to use the tool easily. dotsquid's solution for the scene selector works already perfectly with the new implementation of GameSceneSO so I will merge his solution to replace the previous tool.
     
    canchen_unity and DSivtsov like this.
  35. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224