Exemplo n.º 1
0
        private void CleanUpTable(TableConfig pTableConfig)
        {
            List <ColumnConfig> listColumnConfig = pTableConfig.listColumnConfig;

            listColumnConfig.RemoveAll(p => p.eTypeFlags == EColumnTypeFlags.None);

            if (listColumnConfig.Count == 0)
            {
                _listTableConfig.Remove(pTableConfig);
            }
        }
Exemplo n.º 2
0
        private static Dictionary <string, ColumnInfo> Generate_ColumnInfo(TableConfig pTableConfig, Type pType)
        {
            Dictionary <string, ColumnConfig> mapColumnConfig = pTableConfig.listColumnConfig.ToDictionary(p => p.strColumnName);
            Dictionary <string, FieldInfo>    mapFieldInfo    = pType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).ToDictionary(p => p.Name);
            Dictionary <string, ColumnInfo>   mapColumnInfo   = mapFieldInfo
                                                                .Where(p => mapColumnConfig.ContainsKey(p.Key))
                                                                .Select(p => new ColumnInfo(p.Key, mapColumnConfig[p.Key], p.Value))
                                                                .ToDictionary(p => p.strColumnName);

            return(mapColumnInfo);
        }
Exemplo n.º 3
0
        public TableConfig GetTableConfig(string strTypeName)
        {
            TableConfig pTableConfig = _listTableConfig.FirstOrDefault(p => p.strClassName == strTypeName);

            if (pTableConfig == null)
            {
                pTableConfig = new TableConfig(strTypeName);
            }

            return(pTableConfig);
        }
Exemplo n.º 4
0
        private static ColumnConfig GetOrNew_ColumnConfig(TableConfig pTableConfig, FieldInfo pFieldInfo)
        {
            ColumnConfig pColumnConfig = pTableConfig.listColumnConfig.FirstOrDefault(p => p.strColumnName == pFieldInfo.Name);

            if (pColumnConfig == null)
            {
                pColumnConfig = new ColumnConfig(pFieldInfo.Name);
                pTableConfig.listColumnConfig.Add(pColumnConfig);
            }

            return(pColumnConfig);
        }
Exemplo n.º 5
0
        private TableConfig GetOrNew_TableConfig(Type pDrawTarget)
        {
            TableConfig pTableConfig = _listTableConfig.FirstOrDefault(p => p.strClassName == pDrawTarget.Name);

            if (pTableConfig == null)
            {
                pTableConfig = new TableConfig(pDrawTarget.Name);
                _listTableConfig.Add(pTableConfig);
            }

            return(pTableConfig);
        }
Exemplo n.º 6
0
        private void DrawFields(TableConfig pTableConfig, FieldInfo[] arrMember, float fScrollHeight)
        {
            EditorGUILayout.BeginScrollView(_vecScroll_ForFields,
                                            GUILayout.ExpandHeight(true), GUILayout.MinHeight(fScrollHeight));

            ColumnConfig pPKColumn = pTableConfig.listColumnConfig.FirstOrDefault(p => p.eTypeFlags == EColumnTypeFlags.PK);

            for (int i = 0; i < arrMember.Length; i++)
            {
                FieldInfo pFieldInfo    = arrMember[i];
                var       pColumnConfig = GetOrNew_ColumnConfig(pTableConfig, pFieldInfo);

                bool bIsPK = (pColumnConfig.eTypeFlags & EColumnTypeFlags.PK) != 0;
                // bool bIsNN = (pColumnConfig.eTypeFlags & EColumnTypeFlags.NN) != 0;
                // bool bIsUQ = (pColumnConfig.eTypeFlags & EColumnTypeFlags.UQ) != 0;

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(pFieldInfo.FieldType.Name, GUILayout.MaxWidth(const_LabelSize[ELabelName.Type]));
                    EditorGUILayout.LabelField(pFieldInfo.Name, GUILayout.MaxWidth(const_LabelSize[ELabelName.Column]));

                    EColumnTypeFlags eColumnTypeFlags = EColumnTypeFlags.None;

                    bool bIgnoreSet_PK = pPKColumn != null && pPKColumn.strColumnName != pColumnConfig.strColumnName;
                    GUI.enabled = bIgnoreSet_PK == false;
                    {
                        if (EditorGUILayout.Toggle(bIsPK, GUILayout.MaxWidth(const_LabelSize[ELabelName.PK])))
                        {
                            if (bIgnoreSet_PK)
                            {
                                EditorUtility.DisplayDialog("Error", "this table already has PK", "ok");
                                continue;
                            }
                            eColumnTypeFlags |= EColumnTypeFlags.PK;
                        }
                    }
                    GUI.enabled = true;

                    // PK는 반드시 NN을 포함해야 합니다.
                    //if (EditorGUILayout.Toggle(bIsPK || bIsNN, GUILayout.MaxWidth(const_LabelSize[ELabelName.NN])))
                    //    eColumnTypeFlags |= EColumnTypeFlags.NN;

                    //if (EditorGUILayout.Toggle(bIsUQ, GUILayout.MaxWidth(const_LabelSize[ELabelName.UQ])))
                    //    eColumnTypeFlags |= EColumnTypeFlags.UQ;

                    pColumnConfig.eTypeFlags = eColumnTypeFlags;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();
        }
Exemplo n.º 7
0
        public void DoDrawTable(MonoScript pScript, float fScrollHeight, out TableConfig pTableConfig)
        {
            Record_LastScriptGUID(pScript);
            EditorGUILayout.LabelField("Columns");
            DrawHeader();

            Type pType = pScript.GetClass();

            pTableConfig = GetOrNew_TableConfig(pType);

            DrawFields(pTableConfig, pType.GetFields(BindingFlags.Public | BindingFlags.Instance), fScrollHeight);
            CleanUpTable(pTableConfig);
        }
Exemplo n.º 8
0
        /* protected & private - Field declaration  */

        // ========================================================================== //

        /* public - [Do~Something] Function             */

        public void DoInsert(string strCSV)
        {
            Type        pType        = typeof(T);
            TableConfig pTableConfig = SODB_Setting.instance.GetTableConfig(pType.Name);
            Dictionary <string, ColumnInfo> mapColumnInfo = Generate_ColumnInfo(pTableConfig, pType);
            List <T> listInsert = CSVUtility.FromCSVText_List <T>(strCSV, Debug.LogError);

            ProcessInsert(mapColumnInfo, listInsert, out bool bIsSuccess);
            if (bIsSuccess)
            {
                OnInsert(listInsert);
                rows.AddRange(listInsert);
            }

            Debug.Log($"ProcessInsert {strCSV}");
        }
Exemplo n.º 9
0
        private static string Generate_CSFileContents(MonoScript pScriptTarget, TableConfig pTableConfig)
        {
            Type pTypeClass = pScriptTarget.GetClass();
            Dictionary <string, FieldInfo> mapFields = pTypeClass.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).ToDictionary(p => p.Name);

            foreach (var pCodeGenerator in mapCodeGenerator.Values)
            {
                pCodeGenerator.pBuilder.Clear();
            }

            foreach (var pColumnConfig in pTableConfig.listColumnConfig)
            {
                if (pColumnConfig.eTypeFlags.ContainEnumFlag(EColumnTypeFlags.PK))
                {
                    if (mapFields.TryGetValue(pColumnConfig.strColumnName, out FieldInfo pFieldInfo) == false)
                    {
                        Debug.LogError("Error");
                        continue;
                    }

                    string strFieldName = "Dictionary_PK";
                    WriteMember_Dictionary(mapCodeGenerator[EditCodeWhere.Field].pBuilder, pFieldInfo, pTypeClass, strFieldName);
                    mapCodeGenerator[EditCodeWhere.Insert].pBuilder.AppendLine($"{const_strTabTwo}listInsert.ForEach(p => _{strFieldName}.Add(p.{pFieldInfo.Name}, p));");
                    mapCodeGenerator[EditCodeWhere.Clear].pBuilder.AppendLine($"{const_strTabTwo}_{strFieldName}.Clear();");
                }
            }


            MonoScript pMonoScript    = MonoScript.FromScriptableObject(ScriptableObject.CreateInstance <SODB_TableTemplate>());
            string     strFileContent = pMonoScript.text
                                        .Replace($"{nameof(SODB_TableTemplate)}", $"{pTableConfig.strClassName}{const_strTablePostfix}")
                                        .Replace($"{nameof(SOExample)}", $"{pTableConfig.strClassName}")
                                        .Replace(const_strDateTime, DateTime.Now.ToString("yy-MM-dd HH:mm:ss"));

            foreach (var pCodeGenerator in mapCodeGenerator.Values)
            {
                strFileContent = strFileContent.Replace(pCodeGenerator.strReplace, pCodeGenerator.pBuilder.ToString());
            }

            return(strFileContent);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Table과 TargetScript를 감싸는 Wrapper를 만듭니다.
        /// </summary>
        /// <param name="pTableConfig"></param>
        /// <param name="strAbsoluteFilePath"></param>
        public static void DoGenerate_CSFile(MonoScript pScriptTarget, TableConfig pTableConfig, string strAbsoluteFilePath)
        {
            // string.Format이 안됨;
            //string strFileContent = string.Format(const_strPrefix,
            //    nameof(CustomLogType),
            //    _strBuilder_Class.ToString());

            string strPath = $"{strAbsoluteFilePath}{const_strTablePostfix}.cs";

            string[] arrAlreadyExistGUID = AssetDatabase.FindAssets($"t:Script {pTableConfig.strClassName}{const_strTablePostfix}");
            if (arrAlreadyExistGUID.Length != 0)
            {
                strPath = $"{Application.dataPath.Replace("/Assets", "")}/" +
                          $"{(AssetDatabase.GUIDToAssetPath(arrAlreadyExistGUID.First()))}";
            }

            var strFileContent = Generate_CSFileContents(pScriptTarget, pTableConfig);

            try
            {
                File.WriteAllText(strPath, strFileContent, Encoding.UTF8);
            }
            catch (DirectoryNotFoundException e)
            {
                string strNewPath = $"{Application.dataPath}/{pTableConfig.strClassName}{const_strTablePostfix}.cs";
                File.WriteAllText(strNewPath, strFileContent, Encoding.UTF8);

                Debug.LogWarning("해당 경로에 .cs 파일 생성을 실패하여 다른 경로에 저장했습니다..\n" +
                                 $"원래 경로 :{strPath}\n" +
                                 $"저장한 경로 : {strNewPath}");
                strPath = strNewPath;
            }

#if UNITY_EDITOR
            AssetDatabase.Refresh();
            Selection.activeObject = AssetDatabase.LoadAssetAtPath(strPath.Replace(Application.dataPath, "Assets"), typeof(MonoScript));
#endif
        }