public SDictionaryDrawer(SDictionary <TKey, TValue> _targetDictionary, string _title, float _elementHeight, float _keyWidth,
                          Func <Rect, TKey, TKey> _drawKey, Func <Rect, TValue, TValue> _drawValue, Action _save) : this(_targetDictionary, _title,
                                                                                                                         _elementHeight, _keyWidth, _save)
 {
     drawKey   = _drawKey;
     drawValue = _drawValue;
 }
        private SDictionaryDrawer(SDictionary <TKey, TValue> _targetDictionary, string _title, float _elementHeight, float _keyWidth, Action _save)
        {
            source     = _targetDictionary;
            saveAction = _save;
            keyWidth   = _keyWidth;

            var dictionaryKeys = _targetDictionary.Keys;

            if (dictionaryKeys == null)
            {
                throw new Exception("目标Dictionary的Keys不应当为空");
            }

            this.keys = new List <KeyValuePair <TKey, TValue> >();

            for (int i = 0; i < dictionaryKeys.Count; ++i)
            {
                keys.Add(new KeyValuePair <TKey, TValue>(
                             dictionaryKeys[i],
                             _targetDictionary[dictionaryKeys[i]]
                             ));
            }

            keyList = keys.CreateList()
                      .SetAddFunction(Add)
                      .SetRemoveAtFunction(Remove)
                      .SetDrawEachFunction(Draw)
                      .SetElementHeight(_elementHeight)
                      .SetOnReordered(OnReorder)
                      .SetHeader(_title, null, null);
        }
 /// <summary>
 /// 给SDictionary创建一个可在面板中快速调用的界面
 /// Key和Value同时绘制
 /// </summary>
 /// <typeparam name="TKey">Key类型</typeparam>
 /// <typeparam name="TValue">Value类型</typeparam>
 /// <param name="_dictionary"></param>
 /// <param name="_title">标题</param>
 /// <param name="_elementHeight">单元素的高度</param>
 /// <param name="_keyWidth">Key的宽度百分比(0.0-1.0)</param>
 /// <param name="_save">保存</param>
 /// <param name="_drawKeyAndValue">同时绘制Key和Value的方法</param>
 /// <returns></returns>
 public static SDictionaryDrawer <TKey, TValue> CreateInspectorDrawer <TKey, TValue>(this SDictionary <TKey, TValue> _dictionary,
                                                                                     Func <Rect, TKey, TValue, KeyValuePair <TKey, TValue> > _drawKeyAndValue, Action _save,
                                                                                     string _title = "字典", float _elementHeight = 30)
 {
     if (_dictionary == null)
     {
         Debug.LogError("传入的Dictionary为空");
         return(null);
     }
     else
     {
         return(new SDictionaryDrawer <TKey, TValue>(_dictionary, _title, _elementHeight,
                                                     _drawKeyAndValue, _save));
     }
 }
 public SDictionaryDrawer(SDictionary <TKey, TValue> _targetDictionary, string _title, float _elementHeight,
                          Func <Rect, TKey, TValue, KeyValuePair <TKey, TValue> > _drawKeyAndValues, Action _save) : this(_targetDictionary, _title,
                                                                                                                          _elementHeight, 1.0f, _save)
 {
     drawKeyAndValues = _drawKeyAndValues;
 }