Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Example code for PropertyDrawer doesn't work

Discussion in 'Documentation' started by Baste, Apr 13, 2017.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,331
    This popped up in a thread recently. The C# version of the example code for PropertyDrawer dosn't work:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public enum IngredientUnit { Spoon, Cup, Bowl, Piece }
    6.  
    7. // Custom serializable class
    8. public class Ingredient
    9. {
    10.     public string name;
    11.     public int amount = 1;
    12.     public IngredientUnit unit;
    13. }
    14.  
    15. public class ExampleClass : MonoBehaviour
    16. {
    17.     public Ingredient potionResult;
    18.     public Ingredient[] potionIngredients;
    19. }
    The example goes on to write a customPropertyDrawer for Ingredient, but since Ingredient isn't marked as [Serializable], it won't show up in the inspector, with or without the drawer.

    Probably caused by automatic translation from UnityScript, where the [Serializable] tag is not neccessary.
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Thanks as always... bug reported.