Exemplo n.º 1
0
        public object OnGUI(string label, object value, System.Type type, out bool isDirty)
        {
            System.Collections.IDictionary current = value as System.Collections.IDictionary;
            isDirty = false;
            int hashcode  = current.GetHashCode();
            var isFoldout = false;

            if (!isFoldouts.TryGetValue(hashcode, out isFoldout))
            {
                isFoldouts.Add(hashcode, isFoldout);
            }

            isFoldout            = EditorGUILayout.Foldout(isFoldout, label);
            isFoldouts[hashcode] = isFoldout;
            if (!isFoldout)
            {
                return(value);
            }

            using (new IndentLevel())
            {
                KV kv = Get(value);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("增加"))
                {
                    kv.keys.Add(IL.Help.Create(keyType));
                    kv.values.Add(IL.Help.Create(valueType));
                }
                if (GUILayout.Button("同步"))
                {
                    kv.Sync();
                    isDirty = true;
                }
                if (GUILayout.Button("清除"))
                {
                    kv.keys.Clear();
                    kv.values.Clear();
                    kv.Sync();
                    isDirty = true;
                }
                EditorGUILayout.EndHorizontal();

                int size  = kv.Count;
                int begin = 0;
                int end   = size;
                if (size >= 30)
                {
                    var epb = GetOrCreate(hashcode);
                    epb.total   = current.Count;
                    epb.pageNum = 30;
                    epb.OnRender();

                    begin = epb.beginIndex;
                    end   = epb.endIndex;
                }

                ColorQueue cq       = new ColorQueue();
                int        removeId = -1;
                for (int i = begin; i < end; ++i)
                {
                    bool cdk = false;
                    bool cdv = false;

                    cq.Next();
                    object k = keyTypeGUI.OnGUI("key", kv.keys[i], keyType, out cdk);
                    object v = valueTypeGUI.OnGUI("value", kv.values[i], valueType, out cdv);

                    kv.keys[i]   = k;
                    kv.values[i] = v;
                    if (GUILayout.Button("删除"))
                    {
                        removeId = i;
                    }
                }
                cq.Recover();
                if (removeId != -1)
                {
                    kv.RemoveAt(removeId);
                }
            }
            return(current);
        }