Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why is this not shown in the inspector?

Discussion in 'Scripting' started by topaz7, Sep 19, 2015.

  1. topaz7

    topaz7

    Joined:
    Dec 15, 2012
    Posts:
    76
    This list is not showing on the inspector and afaik inspector supports polymorphism. So I don't understand why it s not shown in the inspector.

    Code (CSharp):
    1. [Serializable]
    2.     public class ObservedList<T> : List<T>
    3.     {
    4.         public event Action<int> Changed = delegate { };
    5.         public event Action<T> Added = delegate { };
    6.         public event Action<T> Removed = delegate { };
    7.         public event Action Updated = delegate { };
    8.  
    9.         public new void Add(T item)
    10.         {
    11.             base.Add(item);
    12.             Added(item);
    13.             Updated();
    14.         }
    15.  
    16.         public new void Remove(T item)
    17.         {
    18.             Removed(item);
    19.             base.Remove(item);
    20.             Updated();
    21.         }
    22.  
    23.         public new void AddRange(IEnumerable<T> collection)
    24.         {
    25.             base.AddRange(collection);
    26.  
    27.             foreach (var item in collection)
    28.                 Added(item);
    29.  
    30.             Updated();
    31.         }
    32.  
    33.         public new void RemoveRange(int index, int count)
    34.         {
    35.             for (int i = index; i < count; i++)
    36.                 Remove(this[index]);
    37.  
    38.             base.RemoveRange(index, count);
    39.             Updated();
    40.         }
    41.  
    42.         public new void Clear()
    43.         {
    44.             foreach(var item in this)
    45.                 Remove(item);
    46.  
    47.             base.Clear();
    48.             Updated();
    49.         }
    50.  
    51.         public new void Insert(int index, T item)
    52.         {
    53.             base.Insert(index, item);
    54.             Added(item);
    55.             Updated();
    56.         }
    57.  
    58.         public new void InsertRange(int index, IEnumerable<T> collection)
    59.         {
    60.             base.InsertRange(index, collection);
    61.  
    62.             foreach (var item in collection)
    63.                 Added(item);
    64.  
    65.             Updated();
    66.         }
    67.  
    68.         public new void RemoveAll(Predicate<T> match)
    69.         {
    70.             base.RemoveAll(match);
    71.             Updated();
    72.         }
    73.  
    74.  
    75.         public new T this[int index]
    76.         {
    77.             get { return base[index]; }
    78.             set
    79.             {
    80.                 base[index] = value;
    81.                 Changed(index);
    82.             }
    83.         }
    84.     }
    Code (CSharp):
    1. public ObservedList<string> Test;
     
  2. topaz7

    topaz7

    Joined:
    Dec 15, 2012
    Posts:
    76
    Is there any other way to detect changes on a list on inspector?
     
  3. MadeThisName

    MadeThisName

    Joined:
    Mar 14, 2015
    Posts:
    115
  4. topaz7

    topaz7

    Joined:
    Dec 15, 2012
    Posts:
    76
    That was simple. Thanks a lot!
     
  5. MadeThisName

    MadeThisName

    Joined:
    Mar 14, 2015
    Posts:
    115