Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Serializable Dictionary Pro

Discussion in 'Assets and Asset Store' started by Rotary-Heart, Apr 16, 2020.

  1. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Serializable Dictionary Pro
    CoverImage_1950x1300.png

    Website: RotaryHeart.com
    Product Wiki: Online

    Version 3.3.9

    Available Now: Asset Store
    Release Notes


    Lite Version: Thread

    Serialized Dictionary Pro is an easy to use system that allows to make serializable dictionaries on Unity. There are no limitations on key or value types other than Unitys own serialization limitations.

    Main Pro Features
    • Now with 6 different data types, not just Dictionaries
    • System has been completely modified to use way less memory
    • Can now be converted to Json without including any extra data or any extra step
    • No reflection and required references field used for keys
    • Editor callbacks for ItemRemoved, ItemAdded, ElementDrawn, ItemsReordered, and EntryEdited
    • New constructor values to block adding items, removing items, items reorder, and make it read only
    • Faster deserialization logic thanks to not using reflection
    Features
    • Reordering of items (Drag & Drop)
    • Pages System
    • Custom key or value drawer
    Data structures are separated into their own class:
    Code (CSharp):
    1. [System.Serializable]
    2. public class MyDictionary : SerializableDictionary<Key, Value> { }
    3. [System.Serializable]
    4. public class MyDictionary : SerializableOrderedDictionary<Key, Value> { }
    5. [System.Serializable]
    6. public class MyDictionary : SerializableSortedDictionary<Key, Value> { }
    7. [System.Serializable]
    8. public class MyDictionary : SerializableHashSet<Key> { }
    9. [System.Serializable]
    10. public class MyDictionary : SerializableBiDictionary<Key, Value> { }
    11. [System.Serializable]
    12. public class MyDictionary : SerializableLinkedList<Key> { }
    Screenshot_2048x1152- No more req reference needed_.png Screenshot_2048x1152- better data management.png
     
    Last edited: Dec 10, 2022
  2. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Awesome and it came out on my birthday too. Looking forward to checking it out. =)
     
    Rotary-Heart likes this.
  3. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Happy birthday! I will make sure to update the thread once it has been acepted
     
    Stexe likes this.
  4. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
  5. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.0.1 has been submitted to the asset store for review. This version includes:
    • Fix for BinaryFormatter that was serializing editor only actions.
    • Implemented missing functionality for SerializableHashSet
    • Fixed with code documentation for better readability
     
  6. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.0.1 is now live on the store
     
    Stexe likes this.
  7. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.0.2 has been submitted to the asset store for review. This version includes:

    • Modified definer for a more generic method.
    • Fixed editor drawer indenting bug.
     
  8. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.0.2 is now live on the store
     
    GilbertoBitt likes this.
  9. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.1.0 has been submitted to the asset store for review. This version includes:

    • Fixed documentation
    • New attribute that allows to specify what default value to use for a dictionary key for new elements
     
  10. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.1.0 is now live on the store
     
  11. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    30% off with the new year sale!

    Don't miss your opportunity!
     
    Stexe likes this.
  12. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Sale ending soon, don't miss the opportunity!
     
  13. Timmy-Hsu

    Timmy-Hsu

    Joined:
    Aug 27, 2015
    Posts:
    51
    Hi,

    I find Lite ver and Pro ver operation is not the same
    The Lite ver when add new Data will auto gray used item, and select not used item,
    but Pro ver when add new Data not auto gray item, and seems select first itme , may only except null.
    Could you take a look?

    Lite ver
    Lite.png

    Pro ver
    Pro.png


    Code (CSharp):
    1. public enum Side
    2.     {
    3.         Null = -1,
    4.         Right = 0,
    5.         TopRight = 1,
    6.         Top = 2,
    7.         TopLeft = 3,
    8.         Left = 4,
    9.         BottomLeft = 5,
    10.         Bottom = 6,
    11.         BottomRight = 7
    12.     }
    13.  
    14.     [System.Serializable]
    15.     public class DictionarySideHitLimits : SerializableDictionaryBase<Side, int> { }
    16.     [SerializeField]
    17.     DictionarySideHitLimits _SideHitLimits;
    18.     public IDictionary<Side, int> m_SideHitLimits
    19.     {
    20.         get { return _SideHitLimits; }
    21.         set { _SideHitLimits.CopyFrom(value); }
    22.     }
     
  14. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Thanks for the report, will be taking a look at that.
     
  15. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.1.1 has been submitted to the asset store for review. This version includes:

    • Fix for enum limitation while adding a new element
    @Timmy-Hsu This update fixes the issue you reported.
     
    Timmy-Hsu likes this.
  16. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.1.1 is now live on the store!
     
  17. Oniromancer

    Oniromancer

    Joined:
    Aug 2, 2013
    Posts:
    6
    Hi:
    I recently bought your Pro version and I'm having a strange behavior when I try to remove things from the dictionary by code:
    I have:
    public class myClass: SerializableDictionary<Vector2,int>{}


    Then i have:

    myClass myOwnDict = new myClass(){
    { Vector2.zero,7 },
    { Vector2.one,9 },
    { Vector2.one*2,11 }
    };


    But if I try:

     myOwnDict.Remove(Vector2.one)


    It removes the last key I added (in this case, the Vector2.one*2)

    It seems to depend on the order of the dictionary in the editor, which is not what is to be expected. Am I doing something wrong?

    Thanks
     
  18. Oniromancer

    Oniromancer

    Joined:
    Aug 2, 2013
    Posts:
    6
    I now managed to make it work properly. What changed is that I was using 2 inspectors, one locked on the Scriptable object containing the dictionary, and the other (unlocked) inspecting the object that I use in the editor to read the scene events and modify the dictionary accordingly. I unlocked both inspectors, and It worked.

    Very strange, but in any case, I know how to make it work now.
     
    Rotary-Heart likes this.
  19. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Interesting behaviour. I will keep an eye on that, thanks for your report.
     
  20. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    I have successfully created and added to a serializedDictionary:

    Code (CSharp):
    1. using RotaryHeart.Lib.SerializableDictionary;
    2. using UnityEngine;
    3.  
    4. namespace Optkl.Data
    5. {
    6.     [CreateAssetMenu()]
    7.     public class SingleStrike : ScriptableObject
    8.     {
    9.         [SerializeField]
    10.         private MainDict strikeData;
    11.  
    12.         public MainDict StrikeData
    13.         {
    14.             get
    15.             {
    16.                 return strikeData;
    17.             }
    18.             set
    19.             {
    20.                 strikeData = value;
    21.             }
    22.         }
    23.  
    24.         [System.Serializable]
    25.         public class StrikeMinMax
    26.         {
    27.             public float maxStrike;
    28.             public float minStrike;
    29.         }
    30.  
    31.         [System.Serializable]
    32.         public class MainDict : SerializableDictionaryBase<string, StrikeMinMax> { }
    33.  
    34.         public void Add (string expireDate, StrikeMinMax strikeMinMax)
    35.         {
    36.             strikeData.Add(expireDate, strikeMinMax);
    37.         }
    38.     }
    39. }
    40.  
    Code (CSharp):
    1. SingleStrike.StrikeMinMax strikeValues = new SingleStrike.StrikeMinMax();
    2. strikeValues.maxStrike = maxStrike;
    3. strikeValues.minStrike = minStrike;
    4. strike.Add(prevDateTime, strikeValues);
    I have also successfully converted this to a nested dictionary:

    Code (CSharp):
    1. using RotaryHeart.Lib.SerializableDictionary;
    2. using UnityEngine;
    3.  
    4. namespace Optkl.Data
    5. {
    6.     [CreateAssetMenu()]
    7.     public class DataStrike : ScriptableObject
    8.     {
    9.  
    10.         [SerializeField]
    11.         public MainDict tradeDate;
    12.     }
    13.  
    14.     [System.Serializable]
    15.     public class StrikeData
    16.     {
    17.         public NestedDict expireDate;
    18.     }
    19.  
    20.     [System.Serializable]
    21.     public class StrikeMinMax
    22.     {
    23.         public float strikeMax;
    24.         public float strikeMin;
    25.     }
    26.  
    27.     [System.Serializable]
    28.     public class MainDict : SerializableDictionaryBase<string, StrikeData> { }
    29.  
    30.     [System.Serializable]
    31.     public class NestedDict : SerializableDictionaryBase<string, StrikeMinMax> { }
    32.  
    33.  
    34. }
    But I can't figure out the steps to add data to the nested database. It's quite a bit more complex than I thought it would be. How do I modify my code from the single entry to the nested one?

    Thank you

    Dan

    Thank you
     
    Last edited: Jun 4, 2021
  21. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Hello

    That's an unfortunate known bug that I'm working on. For now I would recommend you to move your child dictionary to a separate ScriptableObject instead.

    This is the second report I got for it so I'm working on finding a fix for it.
     
  22. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    I just did that but this brings up another issue. I don't think this will work either. It will overwrite or add to the child element on every iteration of my loop. I would have to create a new child scriptable object for each parent right? That defeats the purpose of what I'm trying to do.
     
  23. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Wait, your issue is not about the inspector bugging out on a nested dictionary? You just want to know how to add data to your nested dictionary?

    The bug report I have is that for nested dictionaries the inspector bugs out and won't let you add elements using the inspector, but it works without problems by adding them via code.
     
  24. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    Well that's interesting, because I can add data in the inspector but I haven't figured out the way to add data via code...go figure!!!

    To answer your question - yes I need some help in how to add the data via code

    Let me be more specific about the inspector issue, I can add strings and ints to the inspector, I don't have a need to add gameobjects or other components and haven't tried.
     
    Last edited: Jun 4, 2021
  25. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Now I see the confusion. The bug report is for the PRO version of the asset. The LITE version doesn't have the bug.

    Now regarding your question, if you want to add a new element to your dictionary you just need to generate the data via code. Here's a quick example following your
    ScriptableObject
    provided above:

    Code (CSharp):
    1.  
    2. StrikeData customStrike = new StrikeData();
    3. customStrike.expireDate = new NestedDict();
    4. StrikeMinMax newData = new StrikeMinMax()
    5. {
    6.     strikeMin = .52f,
    7.     strikeMax = .85f
    8. };
    9. customStrike.expireDate.Add("NewDataFromCode", newData);
    10.  
    11. strike.tradeDate.Add("NewElement", customStrike);
    12. strike.tradeDate["Parent1"].expireDate.Add("NewDataFromCode", newData);
    13.  
    Here's the output I get with that code, note that the Parent1 was added from the inspector
    Screen Shot 2021-06-04 at 2.58.15 PM.png

    EDIT:
    Added the data to the existing element
     
  26. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    Couple more things, It's not very often that you see a "Lite" version of an asset. I really didn't understand how your code would work in my project until I started tinkering with it...not sure if I would have paid the $15 to buy something that I wasn't sure would work or not. Then on top of that, you provided your expertise to solve my problem very quickly even though I was using the Lite version, again, I would not have figured out that structure on my own.

    You definitely have my gratitude and support - just bought and installed the pro version - don't think I really needed the extra features, but it's the least I could do.

    Thank you

    Dan
     
    Rotary-Heart likes this.
  27. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    I'm glad that we resolved your issue. I really appreciate your support.
     
  28. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    I keep losing my link to the library in Visual Studio.

    I tried restarting everything, then I rebooted. Any ideas why the namespace would disappear?

    Screen Shot 2021-06-05 at 1.12.29 PM.png

    It still works in Unity, but I'm getting all kinds of red in Visual Studio


    hmmm - 45 minutes later it magically works again.

    Then it disappeared again tonight over a day later...
     
    Last edited: Jun 7, 2021
  29. xindexer2

    xindexer2

    Joined:
    Nov 30, 2013
    Posts:
    78
    If anybody else comes across this issue I found a solution - remove the RotoryHeart folder and re-import it. This forces VS to reset its reference list. Apparently this is a known bug in VS - way to go Microsoft
     
  30. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Thank you for posting your solution. Indeed VS has linking issues so this can happen with any asset using asmdef files.
     
  31. Xafir

    Xafir

    Joined:
    Sep 19, 2013
    Posts:
    1
    I have been using the lite version for awhile and it has worked fairly well except for trying to edit really large dictionaries in the editor ie. one with 704 entires. In this case opening the dictionary takes about 5 seconds and opening an entry takes about 10 seconds. So I decided to get the pro version since it mentioned being more optimized and I have run into a few fairly serious issues.

    First I have an editor script for importing which adds items to a SerializedDictionary that is on a ScriptableObject. In the lite version this works fine, but in Pro it fails to serialize because the OnBeforeSerialize() in SerializableDictionary returns if you are not in play mode. I tested by removing the return and it results in the dictionary serializing properly. Is there a particular reason being able to do this was disabled in pro?

    The 2nd issue is that opening the dictionary of 704 items in the editor is significantly slower in the pro version 1-5 minutes instead of 5 seconds and while it is opened the editor is basically unusable.

    I have a 2 simple test scripts I made in an empty project to showcase both of these issues which I have included below.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using RotaryHeart.Lib.SerializableDictionaryPro;
    5.  
    6. public class Collectible
    7. {
    8.     public string m_name;
    9. }
    10.  
    11. [CreateAssetMenu]
    12. public class SerializedDictionaryTest : ScriptableObject
    13. {
    14.     [System.Serializable]
    15.     public class Collectibles : SerializableDictionary<string, Collectible> { }
    16.  
    17.     public void Clear() => m_collectibles.Clear();
    18.  
    19.     [SerializeField] private Collectibles m_collectibles;
    20.  
    21.     public void AddCollectible(Collectible item)
    22.     {
    23.         if (item != null)
    24.         {
    25.             m_collectibles[item.m_name] = item;
    26.         }
    27.     }
    28. }

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. public class ImporterTest : MonoBehaviour
    7. {
    8.     static SerializedDictionaryTest s_collectibleDatabase;
    9.     [MenuItem("Import/Collectibles")]
    10.     public static void ImportCharacterRecipes()
    11.     {
    12.         s_collectibleDatabase = AssetDatabase.LoadAssetAtPath("Assets/New Serialized Dictionary Test.asset", typeof(SerializedDictionaryTest)) as SerializedDictionaryTest;
    13.         s_collectibleDatabase.Clear();
    14.  
    15.         int numCollectibles = 704;
    16.  
    17.         for (int i = 0; i < numCollectibles; i++)
    18.         {
    19.             Collectible collectible = new Collectible();
    20.             collectible.m_name = "Collectible" + i;
    21.             s_collectibleDatabase.AddCollectible(collectible);
    22.         }
    23.  
    24.         EditorUtility.SetDirty(s_collectibleDatabase);
    25.         AssetDatabase.SaveAssets();
    26.         AssetDatabase.Refresh();
    27.     }
    28. }
     
  32. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Hello

    There is currently an update, that is almost done, that addresses the issue with huge amount of data. Note that while it addresses it massively, Unity will still lag while showing that massive amount of UI. I recommend you to use the page option to be able to use it correctly. You can send me an email with your invoice number if you want to have the changes faster.

    Also, for your other issue, you should call
    m_collectibles.Add(item.m_name, item);
    instead to add your elements since that way the editor code is executed. Currently you are changing the dictionary directly.

    Here you can see how fast it opens with the new changes and using your provided code
    GIF.gif
     
  33. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.1.2 has been submitted to the asset store for review. This version includes:
    • Tweaks for faster inspector performance
    • Warning for trying to add an element with an already used key
    • Minor bug fixing
     
    Timmy-Hsu likes this.
  34. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.1.2 is now live on the store!
     
  35. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.1.3 has been submitted to the asset store for review. This version includes:
    • Fixes for HashSet serialization
    • SerializableHashSet now contains all the same logic as a HashSet (was missing a couple of functions)
     
  36. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.1.3 is now live on the store!
     
    jGate99 likes this.
  37. Timmy-Hsu

    Timmy-Hsu

    Joined:
    Aug 27, 2015
    Posts:
    51
    Hi,

    I use Unity 2020.3.18f1 (64-bit),
    Serialized Dictionary PRO 3.1.2(Also in 3.1.3)

    I have an issue, I create a serializableDictionary, then I try switch Id to another from unity editor inspector, but it not work, still set to the first item.

    Serialized Dictionary PRO Issue.png

    Error Log
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. RotaryHeart.Lib.SerializableDictionaryPro.DictionaryPropertyDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/Rotary Heart/SerializableDictionaryPro/Editor/DictionaryPropertyDrawer.cs:656)
    3. UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <5ad584e208e14caaa9e6b2e6027e9204>:0)
    4. UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <5ad584e208e14caaa9e6b2e6027e9204>:0)
    5. UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at <5ad584e208e14caaa9e6b2e6027e9204>:0)
    6. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <98effce1f3cf489fb7ce6830410f351c>:0)
    7. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    Attached Files is the Project can reproducible issue.
     
    Last edited: Sep 28, 2021
  38. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.1.4 has been submitted to the asset store for review. This version includes:
    • Fixes for enum key Type
    @Timmy-Hsu This version will fix your the issue you noted above. Thanks for the repro project.
     
    Timmy-Hsu likes this.
  39. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.1.4 is now live on the store!
     
    Timmy-Hsu likes this.
  40. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.2.0 has been submitted to the asset store for review. This version includes:
    • Tweaks for better handling internal dictionary data (prevents edge cases null exceptions)
    • Some code cleanup
     
    Timmy-Hsu likes this.
  41. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.2.1 has been submitted to the asset store for review. This version includes:
    • Quick patch to fix null exception on adding elements
     
    Timmy-Hsu likes this.
  42. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.2.1 is now live on the store!
     
  43. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Version 3.3.0 has been submitted to the asset store for review. This version includes:

    New serializable data structures:
    • Bi-directional dictionary
    • LinkedList
     
  44. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    Great News! Version 3.3.0 is now live on the store!
     
    jGate99 likes this.
  45. thomas_superFASTgames

    thomas_superFASTgames

    Joined:
    Jul 15, 2017
    Posts:
    23
    Does the pro version support drawing/serializing keys as tuples?
     
  46. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    No, the system doesn't use any custom serialization. If Unity can't serialize it, then the system will not be able to serialize it either.
     
  47. Raseru

    Raseru

    Joined:
    Oct 4, 2013
    Posts:
    87
    Is converting from Lite to Pro pretty easy? Like will it result in any dictionary data loss?
     
  48. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    It shouldn't erase any data, all you need is to update your using namespace and modify your dictionary classes from
    SerializableDictionaryBase to SerializableDictionary. I've received a couple of emails indicating that the transition didn't erase ScriptableObject or Scene data.
     
    Last edited: Jan 26, 2022
    Raseru likes this.
  49. wozniaxen

    wozniaxen

    Joined:
    Oct 31, 2018
    Posts:
    16
    Hello, I updated to Pro and now when I try to add entries from script, with a scriptable object reference as value, dictionary is empty when I look in the inspector. If I add them by hand it works. What can I do to fix this?

    Edit
    --------
    I managed to fix it but i had to edit the SerializableDictionary.cs code like this:

    Code (CSharp):
    1.  
    2. #if UNITY_EDITOR
    3.  
    4.         public TValue this[TKey key]
    5.         {
    6.             get
    7.             {
    8.                 return m_values[m_keys.IndexOf(key)];
    9.             }
    10.             set
    11.             {
    12.                 Dict[key] = value;
    13.  
    14.                 if (m_keys == null)
    15.                     m_keys = new List<TKey>();
    16.                 if (m_values == null)
    17.                     m_values = new List<TValue>();
    18.  
    19.                 int index = m_keys.IndexOf(key);
    20.                 if (index < 0)
    21.                 {
    22.                     m_keys.Add(key);
    23.                     m_values.Add(value);
    24.                 }
    25.                 else
    26.                 {
    27.                     m_values[m_keys.IndexOf(key)] = value;
    28.                 }
    29.             }
    30.         }
    31.  
    32. #else
    33.         public TValue this[TKey key]
    34.         {
    35.             get
    36.             {
    37.                 return Dict[key];
    38.             }
    39.             set
    40.             {
    41.                 Dict[key] = value;
    42.             }
    43.         }
    44. #endif
    45.  
     
    Last edited: Mar 29, 2022
    Rotary-Heart likes this.
  50. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    809
    I see, so you are not using the add function to add an element, I forgot to add that logic there too. This will be fixed once I'm back from vacations. Thanks for the report and posting the fix you found.
     
    wozniaxen likes this.