Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Assets [WIP] Odin Inspector & Serializer Looking for Feedback

Discussion in 'Works In Progress' started by jorisshh, Feb 22, 2017.

  1. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    123
    You can use OnInspectorGUI and property ordering to achieve this. Essentially, just put a method like this anywhere in your class, and it will draw an info box at the very top of your inspector.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.     [OnInspectorGUI, PropertyOrder(int.MinValue)]
    3.     private void DrawInfoBox()
    4.     {
    5.         Sirenix.Utilities.Editor.SirenixEditorGUI.InfoMessageBox("Message here");
    6.     }
    7. #endif
     
    zzzzzz789 likes this.
  2. SuneT

    SuneT

    Joined:
    Feb 29, 2016
    Posts:
    41
    A bit of news
    We've decided to turn our own forums at forum.devdog.io to "read-only" and instead switch to our own Discord server.

    The Discord server will allow for faster support and quicker messaging back and forth! ;)

    So if you're experiencing any issues, have feedback, or just want to show-off whatever you've made using any of our tools and hang out with us, come join: https://discord.gg/zjNj5zZ
     
  3. jorisshh

    jorisshh

    Joined:
    Oct 6, 2009
    Posts:
    1,455
    Great news, everyone!

    First of all, Odin is on sale in case you haven't noticed.
    We're going to increase the price after this sale, so Odin will never be cheaper than this (even during future sales).

    And also - Odin is a finalist in the Unity Awards, and we need YOUR help!
    You can go vote for Odin right here: https://awards.unity.com/
     
  4. MaddoScientisto

    MaddoScientisto

    Joined:
    Jan 30, 2015
    Posts:
    59
    Hello, first I got to say that I really like this addon, it quickly became one of my essential assets for any new project of mine.
    So I've been wondering if there's any way to do the following custom editor field with just an attribute:
    m_DefaultSprite = EditorGUILayout.ObjectField("Default Sprite", tile.m_DefaultSprite, typeof(Sprite), false) as Sprite;

    basically showing the sprite field rather than the generic one
     
  5. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    123
    That sounds like it would be something like this:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. #if UNITY_EDITOR
    5. using Sirenix.OdinInspector.Editor;
    6. using UnityEditor;
    7. #endif
    8.  
    9. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    10. public class DrawSpriteFieldAttribute : Attribute { }
    11.  
    12. #if UNITY_EDITOR
    13. [OdinDrawer]
    14. public class SpriteDrawer : OdinAttributeDrawer<DrawSpriteFieldAttribute, Sprite>
    15. {
    16.     protected override void DrawPropertyLayout(IPropertyValueEntry<Sprite> entry, DrawSpriteFieldAttribute attribute, GUIContent label)
    17.     {
    18.         entry.SmartValue = EditorGUILayout.ObjectField("Default Sprite", entry.SmartValue, typeof(Sprite), false) as Sprite;
    19.     }
    20. }
    21. #endif
    And then you would just put [DrawSpriteField] on your member. It's a little odd that Odin isn't doing that correctly, though - it should. We'll have to look into that. Thanks for the heads up!
     
  6. MaddoScientisto

    MaddoScientisto

    Joined:
    Jan 30, 2015
    Posts:
    59
    Thank you that did the trick, on the plus side now I know how to make attributes for custom things!

    While I'm here another thing: is there a way to expand serialized scriptableobjects instead of editing them in a separate window?

    Also I noticed that all the elements in a BoxGroup are hidden (for instance with ShowIf) the box still shows, is there a way to hide it?
     
    Last edited: Oct 11, 2017 at 4:57 PM
  7. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    123
    If you mean when you have a reference to them, and you want to draw the whole ScriptableObject instead of just the object field, you can use [InlineEditor] for that - draws inspectors for Unity object values inline in the inspector itself. Works on anything - Meshes, Materials, Components, ScriptableObjects, AudioClips, etc.
     
  8. MaddoScientisto

    MaddoScientisto

    Joined:
    Jan 30, 2015
    Posts:
    59
    Very nice! I love this asset more and more! I have more questions but I guess I'll get on the discord and ask there so I don't end up cluttering the thread too much
     
  9. Celtc

    Celtc

    Joined:
    Jan 19, 2014
    Posts:
    3
    Is there any way to serialize Stack<> and Queue<> classes? Thanks! Great asset!

    PD.: When using UnityEvents inside of non monobehaviour classes, I can't get them to be drawn properly (as Unity does).

    Here is my code:

    Code (CSharp):
    1. [SerializeField]
    2. [PropertyOrder(0)]
    3. [DrawWithUnity]
    4. [TabGroup("Events")]
    5. public UnityEvent_GameObject OnSpawn = new UnityEvent_GameObject();
    6.  
    7. [SerializeField]
    8. [PropertyOrder(1)]
    9. [TabGroup("Events")]
    10. public UnityEvent_GameObject OnRecycle = new UnityEvent_GameObject();
    And this is how it gets drawn:

    [​IMG]
     
    Last edited: Oct 13, 2017 at 11:54 PM
  10. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    123
    This is a known issue, and is related to limitations how Unity draws UnityEvents. It's a hard one to fix, and it looks like we're essentially just going to have to make our very own UnityEvent drawer, which I'm afraid is a little bit in the future. For now, you'll have to make sure that your UnityEvents are serialized by Unity, and are in a Component. The next patch does have an improved error message that essentially states this, though.