public void Merge(MergableDictionary <T> obj)
        {
            if (this == obj)
            {
                return;
            }

            foreach (var pair in obj)
            {
                T srcV;
                if (!TryGetValue(pair.Key, out srcV))
                {
                    srcV = pair.Value.Copy();
                    Add(pair.Key, srcV);
                    if (onNewItemWhenMerge != null)
                    {
                        onNewItemWhenMerge(srcV);
                    }
                }
                else
                {
                    srcV.Merge(pair.Value);
                }
            }
        }
        protected override void OnAfterLoaded()
        {
            m_actionTable         = actions.ToMergableDictionary();
            m_actionSetTable      = action_sets.ToMergableDictionary();
            m_defaultBindingTable = default_bindings.ToMergableDictionary();
            m_localizationTable   = localization.ToMergableDictionary();

            m_actionTable.onNewItemWhenMerge         += item => actions.Add(item);
            m_actionSetTable.onNewItemWhenMerge      += item => action_sets.Add(item);
            m_defaultBindingTable.onNewItemWhenMerge += item => default_bindings.Add(item);
            m_localizationTable.onNewItemWhenMerge   += item => localization.Add(item);

            // load binding files
            m_bindingFiles = new MergableDictionary <VIUSteamVRBindingFile>();
            m_bindingFiles.onNewItemWhenMerge += item => item.dirPath = dirPath;
            foreach (var pair in m_defaultBindingTable)
            {
                var controllerType = pair.Key;
                var bindingUrl     = pair.Value.binding_url;

                VIUSteamVRBindingFile bindingFile;
                if (VIUSteamVRBindingFile.TryLoad(dirPath, bindingUrl, out bindingFile))
                {
                    m_bindingFiles.Add(controllerType, bindingFile);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Missing default bindings file for " + controllerType + ":" + System.IO.Path.Combine(dirPath, bindingUrl) + "!");
                }
            }
        }
        public static MergableDictionary <T> ToMergableDictionary <T>(this List <T> list) where T : IMergable <T>, IStringKey
        {
            var result = new MergableDictionary <T>();

            foreach (var item in list)
            {
                if (string.IsNullOrEmpty(item.stringKey))
                {
                    Debug.LogWarning("MergableDictionary key cannot be null");
                }
                else if (result.ContainsKey(item.stringKey))
                {
                    Debug.LogWarning("Duplicate key(" + item.stringKey + ") found");
                }
                else
                {
                    result.Add(item.stringKey, item);
                }
            }
            return(result);
        }
        public bool IsMerged(MergableDictionary <T> obj)
        {
            if (this == obj)
            {
                return(true);
            }

            foreach (var pair in obj)
            {
                T srcV;
                if (!TryGetValue(pair.Key, out srcV))
                {
                    return(false);
                }

                if (!srcV.IsMerged(pair.Value))
                {
                    return(false);
                }
            }

            return(true);
        }
 public MergableDictionary(MergableDictionary <T> src) : base(src)
 {
 }