public object DrawerListItem <T>(IListDrawerInfo <T> pInfo)
        {
            var tValues = pInfo.Sources as IList <string>;

            var tDrawer = new Func <FuncInfo <string, T>, FuncInfo <string, T> >(pFuncInfo =>
            {
                EditorGUILayout.BeginHorizontal();
                pFuncInfo.value = EditorGUILayout.TextField(pFuncInfo.value);
                GUI.color       = (pFuncInfo.verIndex & 1) == 0 ? Color.yellow : Color.magenta;
                if (GUILayout.Button("x", ConstHelper.GetButtonStyle(ButtonSizeType.Normal)))
                {
                    pInfo.Sources.Remove(pFuncInfo.value);
                    pFuncInfo.refreshImmediate = true;
                }
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();
                return(pFuncInfo);
            });

            GUIHelper.ListField(tValues, false, pInfo, (pIndex, pVal) =>
            {
                tValues[pIndex] = pVal;
            }, pDrawer: tDrawer, pDefaultVal: () => string.Empty);

            return(tValues);
        }
        public object DrawerListItem <T>(IListDrawerInfo <T> pInfo)
        {
            var tValues = pInfo.Sources as IList <TestInfo>;
            var tDrawer = new Func <FuncInfo <TestInfo, T>, FuncInfo <TestInfo, T> >(pFuncInfo =>
            {
                if (pFuncInfo.value == null)
                {
                    return(pFuncInfo);
                }
                EditorGUILayout.BeginHorizontal();
                pFuncInfo.value.a = EditorGUILayout.TextField(pFuncInfo.value.a);
                pFuncInfo.value.b = EditorGUILayout.FloatField(pFuncInfo.value.b);
                pFuncInfo.value.c = EditorGUILayout.Toggle(pFuncInfo.value.c);
                GUI.color         = (pFuncInfo.verIndex & 1) == 0 ? Color.yellow : Color.magenta;
                if (GUILayout.Button("x", ConstHelper.GetButtonStyle(ButtonSizeType.Normal)))
                {
                    pInfo.Sources.Remove(pFuncInfo.value);
                    pFuncInfo.refreshImmediate = true;
                }
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();
                return(pFuncInfo);
            });

            GUIHelper.ListField(tValues, false, pInfo, (pIndex, pVal) =>
            {
                tValues[pIndex] = pVal;
            }, pDrawer: tDrawer, pDefaultVal: () => new TestInfo(), pNewList: () =>
            {
                var tInfo    = pInfo as IListDrawerInfo <Field>;
                var tNewList = Activator.CreateInstance(tInfo.info.info.FieldType) as IList;
                if (tNewList != null)
                {
                    tInfo.info.SetValue(tNewList);
                }
            });

            return(tValues);
        }
Exemplo n.º 3
0
        static public void ListField <T, Drawer>(IList <T> pSources, bool pDisable, IListDrawerInfo <Drawer> pInfo, Action <int, T> pOnValueChange, Func <T> pDefaultVal, Func <FuncInfo <T, Drawer>, FuncInfo <T, Drawer> > pDrawer, Action pNewList = null)
        {
            if (pSources == null)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("list is null", GUILayout.Width(100));
                if (GUILayout.Button("New List", GUILayout.MinWidth(100), GUILayout.ExpandWidth(true)))
                {
                    if (pNewList != null)
                    {
                        pNewList();
                    }
                }
                EditorGUILayout.EndHorizontal();
                return;
            }

            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();
            GUI.enabled = !pDisable;
            EditorGUILayout.LabelField("size", GUILayout.Width(30));
            var tNewCount = EditorGUILayout.IntField(pSources.GetCountIgnoreNull());

            GUI.enabled = true;
            EditorGUILayout.LabelField("show index", GUILayout.Width(70));
            pInfo.ShowIndex = EditorGUILayout.Toggle(pInfo.ShowIndex);

            GUI.enabled = !pDisable;
            if (GUILayout.Button("+", ConstHelper.GetButtonStyle(ButtonSizeType.Normal)))
            {
                ++tNewCount;
            }
            if (GUILayout.Button("-", ConstHelper.GetButtonStyle(ButtonSizeType.Normal)))
            {
                --tNewCount;
            }
            GUI.enabled = true;

            EditorGUILayout.EndHorizontal();
            while (pSources.GetCountIgnoreNull() > 0 && tNewCount < pSources.GetCountIgnoreNull())
            {
                pSources.RemoveAt(pSources.GetCountIgnoreNull() - 1);
            }
            while (tNewCount > pSources.GetCountIgnoreNull())
            {
                pSources.Add(pDefaultVal());
            }

            GUI.enabled = !pDisable;
            bool tBreak = false;

            for (int i = 0, imax = pSources.GetCountIgnoreNull(); i < imax; i++)
            {
                EditorGUILayout.BeginHorizontal();
                if (pInfo.ShowIndex)
                {
                    GUI.enabled = true;
                    EditorGUILayout.LabelField(new GUIContent(i.ToString()), GUILayout.MaxWidth(20));
                    GUI.enabled = !pDisable;
                }

                T tResult = default(T);
                if (pDrawer != null)
                {
                    var tFuncInfo = pDrawer(new FuncInfo <T, Drawer>()
                    {
                        value = pSources[i], verIndex = i, drawerInfo = pInfo
                    });
                    if (tFuncInfo.refreshImmediate)
                    {
                        tBreak = true;
                        GUI.FocusControl("");
                        break;
                    }
                    tResult = tFuncInfo.value;
                }

                if (tBreak)
                {
                    break;
                }
                if (GUI.changed)
                {
                    if (pOnValueChange != null)
                    {
                        pOnValueChange(i, tResult);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            GUI.enabled = true;
            EditorGUILayout.EndVertical();
        }