Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Advanced Inspector - Never Write An Editor Again

Discussion in 'Assets and Asset Store' started by LightStriker, May 4, 2014.

  1. Froghuto

    Froghuto

    Joined:
    Oct 4, 2012
    Posts:
    60
    Would it be possible to add a "DontAllowAssetObjectAttribute" that prevents asset objects to be assigned to fields, so only scene objects can be used?
     
    XaneFeather likes this.
  2. XaneFeather

    XaneFeather

    Joined:
    Sep 4, 2013
    Posts:
    90
    I'm looking for the reverse, actually. So maybe both? If possible, that is.
     
  3. Froghuto

    Froghuto

    Joined:
    Oct 4, 2012
    Posts:
    60
    AdvancedInspector already has a "DontAllowSceneObjectAttribute" :)
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Sadly, how Unity handle an object field, makes it impossible with stock Unity methods.

    https://docs.unity3d.com/ScriptReference/EditorGUI.ObjectField.html

    This method has a "AllowSceneObject" parameter, but not the other way around. I'll see what I can do, I would have to handle it on Advanced Inspector sides.
     
    Froghuto likes this.
  5. blue_mc

    blue_mc

    Joined:
    Dec 6, 2016
    Posts:
    7
    I use DrawAdvancedInspector() to make custom editor for scriptable object. But the change that i made on the field inspector don't immediately saved. I have to select another object and then reselect the scriptable object to see the change.
    How to fix this?

    i tried to add
    Code (CSharp):
    1. AssetDatabase.Refresh();
    2. EditorUtility.SetDirty(serializedObject.targetObject);
    3. AssetDatabase.SaveAssets();
    at the end of OnInspectorGUI() function, but it doesn't work either.

    also tried
    Code (CSharp):
    1. serializedObject.ApplyModifiedProperties();
    still doesn't work
     
    Last edited: Feb 3, 2017
  6. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    @blue_mc: have you tried with ... ?

    Code (CSharp):
    1. serializedObject.Update();
    2.  
    3. ... your code ...
    4.  
    5. serializedObject.ApplyModifiedProperties();
     
  7. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    What is your custom editor for? Could you show us the whole thing?
     
  8. c0ffeeartc

    c0ffeeartc

    Joined:
    Jul 23, 2015
    Posts:
    33
    Hello,
    "public List<IComponent> Components" displays each element in inspector titled according to preferences "[0],[1]" or "Element 0, Element 1".
    I'd like to see which type is stored in each element, how can this be done?
     
    Last edited: Feb 4, 2017
  9. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Have you tried to add to your object;

    Code (CSharp):
    1.         public override string ToString()
    2.         {
    3.             return GetType().Name;
    4.         }
     
  10. c0ffeeartc

    c0ffeeartc

    Joined:
    Jul 23, 2015
    Posts:
    33
    Haha, thanks it works now.
     
  11. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Version 1.71 submitted to the Asset Store. (Sorry for being so slow lately)

    If I missed anything, please let me know! I've got quite some requests in the last 2 months.

    [CHANGES]
    • Introducing Menu Attribute, a way to add option menu to a field from an attribute.
    • TabAttribute is now a IRuntimeAttribute, which means the tab description can be changed per derived type or as you wish.
    • Derive from "AIStateMachineBehaviour" if you want your StateMachineBehaviour to be displayed by Advanced Inspector.
    [FIXES]
    • Performance improvements; 20% refresh speed boost and -40% memory allocation.
    • Property drawers bound by attributes were not being recongnized anymore. Fixed!
    • Changed how Apply/Revert works with prefabs, since the data was reverted, but not the link to the prefabs. Some issues still need to be resolved.
    • DescriptorAttribute applied directly to Enum can now target a static method delegate.
    • Apply "SetDirty" when a Method attribute has a undo message so that Prefabs can be considered modified.
    • Namespaced some classes that weren't previously.
    • Fixed an issue when a field is UnityEngine.Object and targets is hosting a MonoBehaviour.
    • Added an "inversing" condition similar to Inspect Attribute to the ReadOnly Attribute.
    • Extracted the Selection Tracker from the DLL so that people can change its shortcut, if wanted.
    The Menu Attribute;



    Code (CSharp):
    1.         [Menu("Reset To Zero", "ResetToZero")]
    2.         public float value = 10;
    3.  
    4.         private void ResetToZero()
    5.         {
    6.             value = 0;
    7.         }
     
    NeatWolf and PedroGV like this.
  12. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    46
    I sometimes write a Custom Property Drawer for small nested classes -- but I've found that AdvancedInspector somehow overrides their use. I *love* the way AdvancedInspector improves Arrays -- I'd just like the content of the array elements to use my script. Is there a way to do that?

    ...hey wait a second...
    • Property drawers bound by attributes were not being recognized anymore. Fixed!
    ...is that what I'm asking for?
     
  13. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    If you look at the post just before your;
    • Property drawers bound by attributes were not being recognized anymore. Fixed!
    If you want version 1.71 before the Asset Store release it, you can mail me at admin@lightstrikersoftware.com
     
  14. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    v1.71 is now out.
     
  15. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    46
    Thank you!
    :)
     
  16. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Damn... They really did something to the Asset Store review process. Never been that quick before.
     
  17. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    Told you ... one day, or two at most.
     
  18. Froghuto

    Froghuto

    Joined:
    Oct 4, 2012
    Posts:
    60
    I think I found a bug, when collections get bigger than the "Large Collection" setting Lists will show small arrows to "scroll" through the entries, but for UDictionaries the arrows are not shown.
     
  19. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Hello, how do you disable Advanced Inspector on a specific MonoBehaviour?
     
  20. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    The "easy" way is to have a custom editor. Advanced Inspector never override existing custom editor.
     
    noanoa likes this.
  21. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Thanks, I'll look into it.
     
  22. doougles

    doougles

    Joined:
    Mar 30, 2015
    Posts:
    12
    Hi there, just bought Advanced Inspector and excited to try it out, but:

    1. On import, I get a popup telling me "This project contains scripts and/or assemblies that use obsolete APIs" and then asks me to upgrade. I'm using 5.5.0p3. Any ideas?

    2. Trying the "Collection" example I get a warning whenever I try to reorder the list:
    "Event.Use() should not be called for events of type Repaint"
     
  23. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Hey,

    1) I would advice to not select "upgrade", as Unity's API have shown to do error when trying to update DLLs.

    2) Odd. I assume they added that warning in 5.5.

    In both case, I'll download the latest version of Unity and check it out, but in both case it shouldn't affect your experience. (Except the warning, if there's many of those it could slow down redraw).
     
  24. doougles

    doougles

    Joined:
    Mar 30, 2015
    Posts:
    12
    Hey thanks for so quick a reply! Yeah, would be curious to know if it's me or Unity 5.5.

    I try to keep my project Warning free (so I don't miss new Warnings) so do let us know if you're able to address them!
     
  25. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    896
    Thanks! This update fixes 95% of my previous issues, and is perceivably faster!
    Some custom drawers are still duplicated under certain circumstances, I'll send you the required files to fix it as soon as I can (yeah, I know, a month has passed, but I didn't stop coding a single day. Deadlines!)

    My experience with Advanced Inspector has improved dramatically with this update! Thanks again!
     
  26. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    This one is a breaking change for my editors:
     
    Last edited: Feb 14, 2017
  27. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    896
    @LightStriker here's some info you may already know I've stumbled upon, reporting it just because I think may be useful:
    http://answers.unity3d.com/questions/395852/script-for-revert-value-to-prefab.html

    Would it be possible to have dummy variables or equivalent system just to add more titles, separators and elements to the inspector?

    I'd love to be able to change Text/Background colors of the fields/labels/headers/everything textual, but I only found a single property able to do that, and on a specific case.
    Could you possible extend the feature? (Maybe it's a separate attribute, like [TextColor(value)] or even dynamic [BackgroundColor("FunctionName")], other attributes could refer to this one, if present, for showing the data.

    Is there a way to hide the label of a variable completely, thus showing only the editable field?

    (@PedroGV : multiple licenses insta-buy! Also, works nicely with Advanced Inspector! (has some issues with Script Inspector 3 tho :-/ ) )
     
    Last edited: Feb 15, 2017
    PedroGV likes this.
  28. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    @NeatWolf: thanks for the insta-buy! I don't have Script Inspector 3, so to avoid hijacking this thread please PM me to see what can be done.
     
    NeatWolf likes this.
  29. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    @LightStriker: is it possible for you to declare AddAttribute method as public again?
     
  30. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    I'm looking into it. It should still be public... Dunno what happened. I just checked on here and it is still public. (I hope I didn't forget to submit my latest change from home on my SVN...)

    As soon as I'm home I'll double check. Would be weird if I changed it, since I'm using that method outside the DLL.
     
    PedroGV likes this.
  31. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    I'm really not sure what you mean by "dummy variables". Can you explain more?

    [Style] allows you to change the GUIStyle of a field.

    [BackgroundColor] changes the background of a collapsable item.

    [Descriptor] allows you to change the name, tooltip, URL and color of a field.

    To hide the label of a variable completely, do [Descriptor(" ", " ")]. Should give you a white space as a label. :)

    I'm not sure what else could be changed. Have anything in mind?
     
  32. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Submitted a fix to the asset store. No clue why I flagged that method as internal.
     
    PedroGV likes this.
  33. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    It's been a little while, so I just wanted to bring this up again (probably got lost in the shuffle, no biggie).
    And the explanation on how to make "empty" tabs:
    Also, one more thing, this seems to still be happening:
    It seems like this happened in the last six or seven releases, as I distinctly remember things being fine in an earlier version. It's been messed up for a little while, though.

    Sorry to bring everything up at once, but I figured it'd be better to bring them back up instead of letting them be forgotten.
     
  34. TurboNuke

    TurboNuke

    Joined:
    Dec 20, 2014
    Posts:
    69
    I often find myself setting up objects in a list, each of which might have internal variables which allow for dragging, eg. a sprite list.

    In this case I have to keep opening up each item in the list to drag the sprite in. As the expanded lists dont keep their open / closed state, this can happen a lot.

    The ability to add a drag receiver to the topmost object, with a function which could re-direct the dragged object somewhere else in the class would be ideal.

    Just wondering if this is possible and I've missed it, or if it could be something of interest:
     
  35. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596

    Sorry for the slow answer.

    For the tabs... I have no idea how I would do that. Because when the tabs are drawn, it has no idea what's "inside", because it's not a container. Tabs works by simply turning on/off the visibility of an item. So I would have to parse all items to see if one is visible for every tabs. Which is also a problem because an item visibility can also be turn on/off using [Inspect] or InspectorLevel. So a tabs could disappear/reappear?

    I'll look into the [Title] issue. Sounds like an error an alignment. There's so many of those. :p
     
  36. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    List - or any expandable item - should keep the open/close state just fine. I just tried with the example classes, and it works fine.

    You know you can drag a file/object to the collection label and it adds it to the list? You can also drag multi-selection in a label.
     
  37. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    Hm, in that case I don't think there's anything you can do, unfortunately. It's strange having empty Tabs, but I can work around it with per-class Tab enums and not relying on inheritance to take care of the Tabs for me. More work, but better than having empty tabs on some objects.

    Sounds good, thanks for taking a look. For reference, though, everything's usually aligned really well. The Title issue seems to be a one-off. :)
     
  38. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Is it possible to display the "name" property of an list item instead of the type of an item when the item is folded on the inspector? (Like the unity default inspector does)

    currently, advanced inspector shows like this
    List
    ▶ = [0] | Nameplace.Type
    ▶ = [1] | Nameplace.Type
    ▶ = [2] | Nameplace.Type

    I'd like
    List
    ▶ = [0] | name (from property)
    ▶ = [1] | name (from property)
    ▶ = [2] | name (from property)
     
    NeatWolf likes this.
  39. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    Have you looked at the Example 35? AIExample35_ToString?
     
    NeatWolf likes this.
  40. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Thanks, the example is just what I was looking for.
     
  41. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    This has been fixed in v2.0.1.0. A few code modifications have to be introduced in SI3. Please go the SI's thread for more details. Thanks.
     
  42. doougles

    doougles

    Joined:
    Mar 30, 2015
    Posts:
    12

    Hey, any news about those upgrade warnings and other warnings in Unity 5.5? Or that might take a while? Just wondering if I should start exploring this plugin now or wait until it's ready for 5.5 and later.
     
  43. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    I haven't found anything critical in 5.5 yet... but I would advice you to still wait until next version of AI.
     
  44. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    Hi @LightStriker, I'm having a problem with field.GetValue() on FieldEditor derived class.

    Basically, if you add a field to a script like:

    [Inspect]
    public EventSystem myES;

    When you assign a null (or empty) reference to that field on the editor, save the scene, close the editor. re-open it on the project and same scene, when field.GetValue() returns a value is not a null value but an event editor with the following ToString representation "<b>Selected:</b>null\r\n\r\n\r\nNo module\r\n".

    Is this a bug with Unity's serializer or a problem with field.GetValue() and fieldEditor.GetValue() operations in AI?
     
  45. Astro75

    Astro75

    Joined:
    Dec 18, 2014
    Posts:
    45
    There is a bug with CreateDerived and copy component.

    Steps to reproduce:
    Open example scene.
    Select "AIExample27_CreateDerived"
    Click gear box next to "AIExample27_CreateDerived" script -> "Copy Component"
    Use "Paste component as new". Can do on the same object or any other.
    Remove / change anything named "Sub Derived".
    Notice it changes in the original component.

    It should not change the original.
    What happens is the copied begaviour references the same hidden components as the original.
     
  46. Astro75

    Astro75

    Joined:
    Dec 18, 2014
    Posts:
    45
    Code (CSharp):
    1.       [Serializable] public class TestClass { public string sub; }
    2.       [Serializable] public class TestArray {
    3.         [Collection(AlwaysExpanded = true)] public string[] sub;
    4.       }
    5.       public string[] a1;
    6.       public TestClass[] a2;
    7.       public TestArray[] a3;
    1. Is it possible to add some attributes that a2 would display exactly the same as a1?
    2. This is probably related. On a3, could I remove the line saying "Sub" from displaying? [Collection(AlwaysExpanded = true)] helps a little but there is still some visual noise that gives no information.
    Tried [DisplayAsParent] but it only negates the effect of [Collection(AlwaysExpanded = true)] and does nothing in return.
     
  47. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    I would assume you're getting the normal behaviour of Unity and null serialization. Unity cannot - and never had - been able to serialized null. In case of System.Object, it simply creates an instance. In case of UnityEngine.Object, it returns a dummy object that when compared to null (myObject == null) return true. But the value isn't null.

    Not much I can do there.
     
    PedroGV likes this.
  48. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    While it can be considered a bug, it's not something I can fix. Sadly, Unity offers no hook into the copy/pasting mechanisms.

    However, what you can do is once you copied your component over, you can right-click the field hosting the derived object, select "Copy", and paste in over. The copy/paste in Advanced Inspector performs a deep copy when it encounters a ComponentMonoBehaviour.
     
  49. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,596
    1. It is possible, but you would need to write your own FieldEditor. Sadly, there is no automatic way to tell Advanced Inspector how it should draw a totally custom class, except explicitly telling it how to. You should look into the FieldEditors folder, it contains every FieldEditor for every base type. (Like int, bool, float, Vector3, DateTime, etc.)

    2. How would you edit the "string[] sub" array if you remove all the controls around?
     
    noanoa likes this.
  50. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Hi, when using UDictionary<string, Sprite[]>, Unity gives following error on enter play mode.

    ArgumentOutOfRangeException: Argument is out of range.
    AdvancedInspector.UDictionary`2[TKey,TValue].OnAfterDeserialize () (at Assets/Plugins/AdvancedInspector/Core/UDictionary.cs:66)

    Is there any way to quickly fix it? Thanks.
     
unityunity