Search Unity

Advanced Inspector - WIP/Feature requests

Discussion in 'Works In Progress - Archive' started by LightStriker, May 26, 2014.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Advanced Inspector was just accepted over the AssetStore.

    However, since it's a fairly large and complex package, it means that I don't assume development is done yet. There's obviously lot of feature I could have forgot, not thought about, or simply never heard of that people would like to see being part of this kind of Inspector re-write package. Of course, there could also be bug I didn't catch.

    Things currently in work;

    - 2D/3D preview without the need of custom editor.
    - Non-selectable object field (System.Object and derive created) to show ToString of the instance.
    - Pre-expansion field creation instead of post-expansion. Right now it affects how prefab overridden value are displayed in nested object.
    - More Unity type converted to Advanced Inspector*.

    However, the big question would be, what do you want to see in your Inspector?

    I know a lot of people would like Dictionary and Interface support, but I'm not ready just yet to jump into alternative serialization when I know another package out there is doing just that. I might add way for editing Dictionary properly, even if Unity doesn't support its serialization yet, if people have a need for it.
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    With the release of 4.5 and the new interface "ISerializationCallbackReceiver", should this package support alternative serialization, or is that new interface enough for people to make their own?

    And if now that people can have their own serialization, should the priority shift to displaying interface and dictionary properly, independently of the serialization used?
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Version 1.1 will soon be submitted to the Asset Store.

    As seen here; http://www.youtube.com/watch?v=EOX6itCuKOc&feature=player_detailpage#t=1180 Unity is rolling out in 4.6 "Action" field as a way to bind an event to a method. We heard lot of people being excited by the features... We wondered if we could do the same, with maybe more option and features, without having to code a custom editor.

    So... we did.


    Those "ActionBinding" can be placed in a collection too;


    Code (csharp):
    1.  
    2. [AdvancedInspector]
    3. public class AIExample_Binding : MonoBehaviour
    4. {
    5.     [Inspect]
    6.     public ActionBinding onClick = new ActionBinding(new Type[] { typeof(Material) } );
    7.  
    8.     [Inspect]
    9.     [CollectionConstructor("OnReleaseConstructor")]
    10.     public ActionBinding[] onRelease = new ActionBinding[0];
    11.  
    12.     private object OnReleaseConstructor()
    13.     {
    14.         return new ActionBinding(new Type[] { typeof(Material) });
    15.     }
    16.  
    17.     private void OnMouseDown()
    18.     {
    19.         onClick.Invoke();
    20.     }
    21.  
    22.     private void OnMouseUp()
    23.     {
    24.         foreach (ActionBinding action in onRelease)
    25.             action.Invoke();
    26.     }
    27. }
    28.  
    They can have an unlimited number of parameters. They support all the types Unity serializes.
    Each parameter can work in 3 modes;

    - Internal; the argument is passed by the class invoking the action in the Invoke method.
    - Static; the argument is manually set in the inspector.
    - External; the argument is retrieved from an other method invoked. Only parameterless methods with the proper return type are listed.

    And other fixes and modifications coming with 1.1;

    - Fixed the Camera preview
    - Fixed the Camera perspective/orthographic drop down with new RestrictedAttribute option.
    - Added a way to decouple data from description in the RestrictedAttribute. Just pass DescriptorPair instead of the object directly.
    - Added a missing constructor in ReadOnlyAttribute.
    - Changed the constraint field in the RigidBody because "I prefer the checkboxes".
    - Non-editable expandable field - such as object deriving from System.Object - now display info in the format "ToString() [Class Name]". Overriding ToString becomes useful.
    - Fixed a null in the Restricted > Toolbox.
    - SizeAttribute can now flag a collection as not-sortable.
    - Added a new Attribute; RuntimeResolve which display a field editor based on the object's type or a type returned by a delegate, instead of the field type. It can also be used to restrict a Object field to a specific type. For example, you can make a UnityEngine.Object field only display Material.
    - Added a new Attribute; CollectionConstructor which let you create a collection item with the constructor and parameter of your choice.

    Copy/Paste;
     
    Last edited: Jun 2, 2014
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    If you ever worked with Cloth, you probably found the kinds of "tabs" at the top useful and rather cool looking. Collection of information sorted by tabs.



    Once again, this was done without any custom editor.

    Code (csharp):
    1.  
    2. [AdvancedInspector(false)]
    3. public class AIExample_Tabs : MonoBehaviour
    4. {
    5.   [Inspect]
    6.   [Tab(MyTabs.TabA)]
    7.   public Bounds itemOfTabA;
    8.  
    9.   [Inspect]
    10.   [Tab(MyTabs.TabB)]
    11.   public Material itemOfTabB;
    12.  
    13.   [Inspect]
    14.   [Tab(MyTabs.TabC)]
    15.   public string itemOfTabC;
    16. }
    17.  
    18. public enum MyTabs
    19. {
    20.   TabA,
    21.   TabB,
    22.   TabC
    23. }
    24.  
    For future release...
     
    Last edited: Jun 3, 2014
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    With Unity 4.5 and the Serialization Callback, it's now possible to serialize Dictionary without having to rely on an external serialization. Which means, it's time to roll out a way for the Inspector to display and edit dictionary properly.

    You can see an example of a Dictionary implementation that works right now with Unity 4.5; http://forum.unity3d.com/threads/4-5-dictionary.250494/

    However, Unity is unable to display that data by itself. In Advanced Inspector 1.2;


    Full support to display of any class implementing the IDictionary interface.

    The same features existing on all other fields - copy, paste, apply, revert - also works on Dictionaries. All the IList attributes are properly past down to the Dictionary "value" field.

    The "value" is also expandable and editable "inline" like on any other reference field.
     
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I've added the class "Mesh" to the supported types;



    However, as I implemented it, I encountered out some common issue to all property grids; large or extra large array.

    When you try to sort, handle and draw hundred or thousand of items, performance can take a dive and become unusable. A mesh can have thousand vertices! Listing them can kill your editor.

    So I added automatic support for large array, and since an image is worth a lot of explaining;



    It makes those array a bit more manageable, and doesn't kill your performance.
     
  7. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Today's WIP update; preview with ease;



    This is - again - done without any custom editor!

    Here's the code of that class;
    Code (csharp):
    1. [AdvancedInspector]
    2. public class AIExample_Preview : MonoBehaviour, IPreview
    3. {
    4.     [Inspect]
    5.     public bool showPreview = true;
    6.  
    7.     [Inspect]
    8.     public GameObject previewGO;
    9.  
    10.     #region IPreview Implementation
    11.     public bool HasPreview
    12.     {
    13.         get { return showPreview; }
    14.     }
    15.  
    16.     public UnityEngine.Object[] Preview
    17.     {
    18.         get { return new UnityEngine.Object[] { previewGO }; }
    19.     }
    20.     #endregion
    21. }
    Implementing the IPreview interface can't be easier; you just return the objects you want previewed.

    When released, the Advanced Inspector will support types of GameObject, Mesh, Material and Texture.

    The HasPreview property allow to turn the preview on and off.
     
    Last edited: Jun 23, 2014
  8. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Small update on the preview panel;


    Can support multiple object being previewed at the same time from the same script. Support currently GameObject/Prefab, Mesh, Material and Texture.

    Added a third light setting to the preview to give a better sense of depth; a Red/Green/Blue light setup.

    (Why do I have the feeling I'm talking to myself here...)
     
    Last edited: Jun 23, 2014
    shkar-noori likes this.
  9. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    We discovered there's a GUI that is used to display a range between two value, but Unity does not offer any type that take advantage of this. At least, none we could find.



    So we made some.

    Again, done in the most painless integration possible;

    Code (csharp):
    1.  
    2. [AdvancedInspector]
    3. public class AIExample_Range : MonoBehaviour
    4. {
    5.   [Inspect, RangeValue(0, 100)]
    6.   public RangeInt rangeInt = new RangeInt(25, 75);
    7.  
    8.   [Inspect, RangeValue(0, 100)]
    9.   public RangeFloat rangeFloat = new RangeFloat(25, 75);
    10. }
    When using this in 4.5, the RangeInt and RangeFloat are structs, while in previous Unity version, they are classes.
     
    Last edited: Jun 25, 2014
  10. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    While 1.2 is in validation, we noticed we forgot to support one obvious type in the Preview window; Cubemap.



    Might do a 1.21 version with that missing type support.
     
  11. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    We received feedback that the Advanced Inspector was hard to read in the context of multiple object/multiple nested level. (Big thanks to "_brain" for his ideas)

    You can see some of the above images and see what that means.

    We were proposed that we should find some way to "box" the nested context, so to be able to structure the values more properly.

    Here's what we are going towards;



    We hope this way will make nested context much easier to read.

    Version 1.3 will be more of a visual/layout update more than anything else. We fixed ton of layout/alignment issue.
     
  12. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    One request we got was to be able to dump the "[class name]" part of the field of an expandable item.

    So it looks like this;


    The "4" showing up there is taken from the ToString overriden method.

    Code (csharp):
    1. public override string ToString()
    2. {
    3.     return value.ToString();
    4. }
    You can write whatever you want on that label.

    We are also working on a Header/Footer zone at the top and bottom of the inspector. We already had a header for the tabs, but we decided to add more to it, such as element independent from fields;



    Help attribute can now be tagged on a class, and shows up before or after all the fields in a header/footer zone.

    The header and footer are accessible by using the IInspectorRunning interface, which expose "OnHeaderGUI" and "OnFooterGUI". So in the above image, the "This is a header" and "This is a footer" is actually drawn from the script itself using GUILayout.Label.

    So you could draw image, control or anything you wish in those top and bottom zone, once again, without a custom editor.
     
  13. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    The Light editor was surprisingly difficult to replicate because 2 of the values displayed on the default Inspector are not exposed in the backing type. What it means is, if you look at the Light type, you won't find a "Draw Halo" or "Lightmapping" properties. For this reason, it meant the InspectorField had to be rewritten in part to be able to wrap around SerializedProperty; the only way to reach those hidden values. Let's just say I'm really not a fan of that particular class.

    Another reason that specific editor have been challenging to recreate is the number of variable that can be hidden and the number of warnings that can be displayed.



    But even then, if you can look at LightEditor.cs in UnityEditor assembly, the class takes 340 lines. The AdvancedInspector version, who perform exactly the same job - while giving more features than the stock version - takes only 202 lines,.
     
    Last edited: Jul 8, 2014
    IvanAuda likes this.
  14. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Because there is no such thing as being too lazy;



    Drag and drop of labels perform automatic copy/paste.
     
  15. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    The version 1.32 have been submitted for review to the Asset Store, with the "object picker";



    Frankly, I'm starting to run out of idea. I would be happy if someone had some. :)
     
  16. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    One feature that was requested was the ability to color the background;



    And another was to be able to only display 1 item from a collection at a time, which in return eliminates one level of indentation.

    This is a list;

     
  17. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    The next version will finally be 1.4 instead of 1.33, since it has some major definition changes in some attributes. Here's others that have been requested...

    Here's an example;


    Every atttribute controlling enums are merge into a single attribute. Same thing with attributes handling collection.
    The EnumAttribute, CollectionAttribute and RestrictAttribute now have each a Display enum to control how the item is being displayed.

    Enum currently can be displayed as a drop down list, a collection of button or a collection of checkboxes.
    Restricted item can be displayed as drop down, botton or toolbox invoke.
    Collection can be displayed as their default behaviour - expandable list, as a drop down list or as button. Note that when collection displays only one item at a time, copy/paste feature of that index/key becomes impossible.

    Dictionary doesn't currently support different display type because of the fact it has to render a complete field for adding items.
     
  18. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Tiny feature; draggable modal window.

     
  19. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717


    This feature is rather simple; it binds a collection to the values of an enum.

    It makes more sense when we look at the code example;

    Code (CSharp):
    1.     [Inspect, Collection(typeof(CollectionName)), RangeValue(0, 10)]
    2.     public float[] range;
    3.  
    4.     public enum CollectionName
    5.     {
    6.         First,
    7.         Second,
    8.         Third,
    9.         Forth
    10.     }
     
    shkar-noori likes this.