Esempio n. 1
0
        public void SyncData(T lineData)
        {
            var hash = lineData.GetHashCode();

            if (LineCacheContains(hash))
            {
                return;
            }

            var lineCache = new ConfigEditorLineCache <T>();

            lineCache.HashCode = hash;
            lineCache.RawData  = lineData;

            foreach (var schema in CurrentClassFieldsCache)
            {
                var columnData = schema.field_info.GetValue(lineData);

                var column = new ConfigEditorLineFieldCache();
                column.RawData       = columnData;
                column.CurrentSchema = schema;
                column.HashCode      = columnData.GetHashCode();
                column.IsGenericType = columnData.GetType().IsGenericType;
                column.Add           = columnData.GetType().GetMethod("Add");
                column.RemoveAt      = columnData.GetType().GetMethod("RemoveAt");
                column.Count         = columnData.GetType().GetProperty("Count");
                column.Item          = columnData.GetType().GetProperty("Item");

                if (column.IsGenericType && schema.config_editor_setting.OutCodeGenEditorID == 0)
                {
                    column.AttributeType = columnData.GetType().GetGenericArguments()[0];
                }

                lineCache.ColumnInfo.Add(column);
            }

            LinesCache.Add(lineCache);
        }
Esempio n. 2
0
        /// <summary>
        /// 反射原始数据 TODO: 加入缓存来优化反射  --Complete
        /// </summary>
        /// <param name="data"></param>
        /// <param name="value"></param>
        /// <param name="raw"></param>
        public virtual void RenderRawColumn(ConfigEditorLineFieldCache column, ConfigEditorLineCache <T> lineData)
        {
            if (column.RawData == null)
            {
                return;
            }

            var columnSchema  = column.CurrentSchema;
            var lineRawData   = lineData.RawData;
            var columnRawData = column.RawData = columnSchema.field_info.GetValue(lineRawData);

            // ---- Chache ----

            if (column.IsGenericType)
            {
                GUILayout.BeginVertical(GUIStyle.none,
                                        new GUILayoutOption[]
                {
                    GUILayout.Width(GetResizeWidth(columnSchema.config_editor_setting.Width,
                                                   columnSchema.config_editor_setting.MaxWidth))
                });

                int deleteIndex = -1;

                //Open Editor
                if (columnSchema.config_editor_setting.OutCodeGenEditorID != 0)
                {
                    //处理外联添加逻辑
                    var temp = columnRawData as List <int>;

                    for (int i = 0; i < temp.Count; i++)
                    {
                        GUILayout.BeginHorizontal();

                        //显示外联数据
                        GUILayout.Label(GetOutLinkDisplayField(
                                            temp[i],
                                            columnSchema.config_editor_setting.OutCodeGenEditorID,
                                            columnSchema.config_editor_setting.OutLinkDisplay),
                                        GUILayout.Width(
                                            GetResizeWidth(
                                                columnSchema.config_editor_setting.Width,
                                                columnSchema.config_editor_setting.MaxWidth,
                                                Data.currentEditorSetting.KitButtonWidth + Data.currentEditorSetting.ColumnSpan
                                                )
                                            )
                                        );

                        //删除子类型数据
                        if (GUILayout.Button(Language.Delete, GUILayout.Width(Data.currentEditorSetting.KitButtonWidth)))
                        {
                            deleteIndex = i;
                        }

                        GUILayout.EndHorizontal();
                    }
                    //处理外联添加逻辑

                    // -- 打开面板 --
                    if (GUILayout.Button(Language.Add))
                    {
                        //var test = data.config_editor_setting;
                        var e = OpenOutlinkWindow(columnSchema.config_editor_setting.OutCodeGenEditorID);
                        if (e == null)
                        {
                            ShowNotification(new GUIContent(Language.OutLinkIsNull));
                        }
                        else
                        {
                            e.UpdateSelectModel(columnRawData as List <int>, SetListItemValue);
                            e.ShowUtility();
                        }
                    }
                    // -- 打开面板 --



                    if (deleteIndex != -1)
                    {
                        temp.RemoveAt(deleteIndex);
                        //TODO 此处应该处理联动列需求
                    }
                }
                else
                {
                    //添加数据
                    if (GUILayout.Button(Language.Add))
                    {
                        column.Invoke_Add(
                            column.AttributeType == typeof(string)
                                ? string.Empty
                                : Activator.CreateInstance(column.AttributeType));
                    }

                    //添加数据


                    //处理数组逻辑
                    int count = column.Invoke_Count();

                    int removeIndex = -1;

                    for (int i = 0; i < count; i++)
                    {
                        object listItem = column.Invoke_GetItem(i); //.Item.GetValue(value, new object[] {i});


                        GUILayout.BeginHorizontal();
                        //alignment
                        RenderBaseControl(
                            GetResizeWidth(columnSchema.config_editor_setting.Width, columnSchema.config_editor_setting.MaxWidth,
                                           Data.currentEditorSetting.KitButtonWidth + Data.currentEditorSetting.ColumnSpan),
                            columnSchema.config_editor_setting.CanEditor,
                            listItem,
                            v => { column.Invoke_SetItem(v, i); });

                        if (GUILayout.Button(Language.Delete,
                                             new GUILayoutOption[] { GUILayout.Width(Data.currentEditorSetting.KitButtonWidth) }))
                        {
                            removeIndex = i;
                        }

                        GUILayout.EndHorizontal();
                    }

                    if (removeIndex != -1)
                    {
                        column.Invoke_RemoveAt(removeIndex);
                    }
                    //处理数组逻辑
                }

                GUILayout.EndVertical();
            }
            else
            {
                //Open Editor
                if (columnSchema.config_editor_setting.OutCodeGenEditorID != 0)
                {
//                    data.field_info.SetValue(raw,GetSelectValueByFlag(raw.ID, data.field_info.Name, (int) value));

                    string buttonName = GetOutLinkDisplayField((int)columnRawData,
                                                               columnSchema.config_editor_setting.OutCodeGenEditorID,
                                                               columnSchema.config_editor_setting.OutLinkDisplay);

                    if (GUILayout.Button(buttonName,
                                         new GUILayoutOption[]
                    {
                        GUILayout.Width(GetResizeWidth(columnSchema.config_editor_setting.Width,
                                                       columnSchema.config_editor_setting.MaxWidth))
                    }))
                    {
                        var e = OpenOutlinkWindow(columnSchema.config_editor_setting.OutCodeGenEditorID);

                        if (e == null)
                        {
                            ShowNotification(new GUIContent(Language.OutLinkIsNull));
                        }
                        else
                        {
                            e.UpdateSelectModel(lineRawData, columnSchema.field_info, SetListItemValue);
                            e.ShowUtility();
                        }
                    }
                }
                else
                {
                    RenderBaseControl(
                        GetResizeWidth(columnSchema.config_editor_setting.Width, columnSchema.config_editor_setting.MaxWidth),
                        columnSchema.config_editor_setting.CanEditor, columnRawData,
                        v => { columnSchema.field_info.SetValue(lineRawData, v); });
                }
            }

            //更新search key
            if (column.CurrentSchema.CurrentFiledProperty == FiledProperty.SEARCH_KEY)
            {
                lineData.SearchKey = columnRawData.ToString();
            }
        }