Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

New TreeView API

Discussion in '5.6 Beta' started by Mads-Nyholm, Dec 20, 2016.

  1. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    In the just released 5.6 beta 2 we have included new API for creating TreeViews in the Editor. It is a powerful feature that we use throughout Unity's own tools and we believe it will be useful for those of you that are building Editor extensions for the Asset Store or for your in-house tooling.

    The TreeView API is somewhat different from our 'traditional' IMGUI controls which mainly are static method calls. The TreeView is a control you allocate an instance of up front and that can have internal state (selection, expanded items etc).

    To help you get started we have included links below to the Manual draft and to a Unity project which has several examples of how to use the TreeView; from simple tree views to more complex multi-column tables. When opening that project the main menu will have a 'TreeView Examples' menu where the windows can be opened from.

    Regarding our HTML documentation for the TreeView: our documentation tool does not currently include protected classes/structs nor protected properties in the HTML. This is being worked on. For the time being use the API Documentation links below which includes these protected properties and classes.

    Links:
    TreeView Examples project: here
    TreeView Manual: here
    TreeView API Documentation: here
    MultiColumnHeader API Documentation: here
     
    Novack, Xarbrough, rakkarage and 3 others like this.
  2. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    The manual link seems to be requesting access on gdocs...
     
  3. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    Manual link fixed
     
    tatoforever likes this.
  4. landon91235

    landon91235

    Joined:
    Nov 8, 2011
    Posts:
    1,545
    Nice, can we expect the future to entail more of things like this?
     
  5. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    Yes indeed. In the 5.6 we are also exposing the BoxBoundsHandle, SphereBoundsHandle and CapsuleBoundsHandle that can be used in the SceneView. They are also placed in the UnityEditor.IMGUI.Controls namespace. More controls will be exposed in this namespace in the future.
     
    Novack, landon91235 and rakkarage like this.
  6. landon91235

    landon91235

    Joined:
    Nov 8, 2011
    Posts:
    1,545
    Awesome! Will be a big help. I assume it's in C++ and we have no chance of getting it open source?
     
  7. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    531
    Is almost all C#. Right now there's no plans specifically to make this open source. In general we'd like to make this happen, but first step right now is to clean up our legacy controls. But I'll poke the team to let them know there's interest in seeing the source be made available.
     
    theolagendijk and landon91235 like this.
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,151
    The example doesn't work
    I tried the example that was linked in the first post and it's not working in b10, a few things with Searchfield, do you have any updated example?

    Assets/Editor/TreeViewExamples/BackendData/MyTreeAssetEditor.cs(13,3): error CS0246: The type or namespace name `SearchField' could not be found. Are you missing an assembly reference?
    in 5.6b4
     
  9. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    I have updated the examples link. Try downloading the examples project again.
    The SearchField is coming in beta11, I pulled the trigger too early.
     
  10. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,151
    Wow that's pretty awesome how much it does with that little code. It makes the editing of an entity database very easy and icing on the cake: it even handle OS gesture rename!

    Search field widget does work and I'm using b10, what's the difference with SearchField?

    I see that "collapse all" and "expand all" are instant, whereas Clicking on an arrow goes through a transition animation, Looking at the code, treeView.CollapseAll() has no parameter and the TreeView class doesn't give any control over transition animation. Is there some API stuff missing, the transition is hard coded I guess?
     
    Last edited: Mar 8, 2017
  11. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    You are probably using the SearchField static method that was included in the examples project? In beta11 I have added a builtin public SearchField class (in the IMGUI.Controls namespace) that has extended functionality: Cmd/Ctrl+F gives keyfocus to the SearchField and while typing in the search field the Arrow down key event will fire a callback that can give key-focus to other controls (e.g the TreeView). Try the new Examples project after b10.

    The transition animation cannot be changed from API to ensure consistency between all TreeViews in Unity.
     
  12. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,151
    All good in 5.6f1, very clean how you added added .downOrUpArrowKeyPressed

    That's a shame you guys roll out such a great API and always end up ignoring users that don't want bells and whistle - kind of arrogant.
     
  13. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    The UX team is discussing how we should add more flexibility in configuring the UI in Unity in the future. Until we have that solution use the following API.

    To disable animation globally for all TreeViews call (only needed to be called once):
    Code (CSharp):
    1. EditorPrefs.SetBool("TreeViewExpansionAnimation", false);

    or drop the following c# script into your project and select the menuitem: TreeViewUtility/Toggle Animation
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditorInternal;
    3. using UnityEngine;
    4.  
    5. static class TreeViewUtils
    6. {
    7.     [MenuItem("TreeViewUtility/Toggle Animation")]
    8.     static void ToggleAnimation()
    9.     {
    10.         const string prefKey = "TreeViewExpansionAnimation";
    11.         bool newValue = !EditorPrefs.GetBool(prefKey, true);
    12.         EditorPrefs.SetBool(prefKey, newValue);
    13.         InternalEditorUtility.RequestScriptReload();
    14.         Debug.Log("TreeView animation is now " + (newValue ? "enabled" : "disabled"));
    15.     }
    16. }
     
    laurentlavigne, CDF and Peter77 like this.
  14. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,151
    I haven't seen the UX team adding customization since the backlash of the color picker and that was around 3.0 !
    It makes a huge difference so thank you.

    I've never seen this EditorPrefs, is this new?
    Is there a similar keyword for switching off the zoom animation?
     
  15. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    What do you mean by 'the zoom animation'?
     
  16. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,151
    When pressing 'f' the camera animates to frame the selection.
     
  17. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    Ah in the SceneView. We call that 'Frame Selected' as you also mention.
    No option for disabling the animation for that one at the moment.
     
    Last edited: Mar 29, 2017
    laurentlavigne likes this.
  18. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    145
    @Mads-Nyholm

    I've taken a look at the simple example from the manual in google docs.
    This new tree view is a god sent!

    I just have one question:
    How can I make it so the user can rename elements like in the normal scene view hierarchy like this:

    [​IMG]

    I found BeginRename() and EndRename() and it starts the renaming, but it's not really like in the normal hierarchy.
    Sometimes the renaming starts when anything is clicked, and I don't get when I'd call EndRename manually...
    Is there a way to easily get the same "look and feel" as the normal hierarchy editor in the scene view has?

    If not, when exactly does the default hierarchy window call BeginRename and EndRename?
    How exactly do its checks look to figure out when to do BeginRename()?
    And how does it get work with the renamed element then? (I assume you'd just take `args.label` and then write that back to the linked object?, But how do know when the editting ends / is commited?)
     
  19. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    40
    Hi,
    So for a TreeView you only have to override CanRename and return true for the elements that support renaming (by default renaming is disabled because CanRename returns false) AND override RenameEnded to handle the result of the rename.

    Seems you missed the RenameEnded method. Basically you do not need to call BeginRename nor EndRename yourself (this is only if you want to start renaming from code). Normally you would just press F2 (Win) or Enter (OSX) when the TreeView have focus (selection is rendered blue), or click an already selected item to automatically begin a rename. Renaming ends when clicking outside or pressing Enter while renaming.

    You can search for 'RenameEnded' in the examples project to see how I use the information there to set the backend data.
     
    laurentlavigne likes this.
  20. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    145
    Thanks for the information, that works perfectly!
     
  21. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,151
    Is there a place I can find a list of prefKeys?