Esempio n. 1
0
        public bool ContainsChanges()
        {
            foreach (SheetRow sheetRow in sheetPage.rows)
            {
                foreach (SheetCell sheetCell in sheetRow.cells)
                {
                    if (!sheetCell.dirty)
                    {
                        continue;
                    }

                    return(true);
                }
            }

            DatasheetType dataSheetType;

            if (!dataSheetIdentifier.TryGetIdentifierEnum(out dataSheetType))
            {
                return(true);
            }

            SheetPage oldPage = ModelGeneration.DeconstructDatasheetCode(dataSheetType);

            if (!oldPage.CheckIfSameCodebase(sheetPage))
            {
                return(true);
            }

            return(false);
        }
        private static void GenerateCode_Identifier(SheetPage sheetPage)
        {
            List <string> recordTemplate = new List <string>(File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_IDENTIFIER));

            for (int i = 0; i < recordTemplate.Count; i++)
            {
                string line = recordTemplate[i];
                recordTemplate[i] = line.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_MODEL_NAME, sheetPage.sheetNameTrimmedUpperCase);
            }

            string[] identifierLineTemplate = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_IDENTIFIER_LINE);

            List <string> recordProperties = new List <string>();

            foreach (SheetRow sheetRow in sheetPage.rows)
            {
                foreach (string templateLine in identifierLineTemplate)
                {
                    recordProperties.Add(templateLine.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_IDENTIFIER_NAME, sheetRow.identifier)
                                         .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_IDENTIFIER_NAME_TITLE_CASE, sheetRow.enumValue)
                                         .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_IDENTIFIER_INDEX, sheetRow.index.ToString()));
                }
            }

            int replaceIndex = recordTemplate.FindIndex(i => i.Contains(SheetStringDefinitions.TEMPLATE_INSERT_IDENTIFIERS));

            recordTemplate.InsertRange(replaceIndex, recordProperties);

            File.WriteAllLines(sheetPage.sheetIdentifierFileLocation, recordTemplate);
        }
Esempio n. 3
0
        public SheetColumn(SheetPage sheetPage, string serializationName, string propertyName, SheetDataType dataType, string referenceSheet, bool isCollection, int insertIndex)
        {
            if (insertIndex < sheetPage.columns.Count)
            {
                sheetPage.columns.Insert(insertIndex, this);
            }
            else
            {
                sheetPage.columns.Add(this);
            }

            this.serializationName = serializationName;
            this.propertyName      = propertyName;
            this.dataType          = dataType;
            this.isCollection      = isCollection;
            this.referenceSheet    = referenceSheet;

            object defaultData = dataType.GetDefaultValue(isCollection);

            foreach (SheetRow sheetRow in sheetPage.rows)
            {
                SheetCell sheetCell = new SheetCell(defaultData);
                if (insertIndex < sheetPage.columns.Count)
                {
                    sheetRow.cells.Insert(insertIndex, sheetCell);
                }
                else
                {
                    sheetRow.cells.Add(sheetCell);
                }
            }
        }
Esempio n. 4
0
 public void Initialize(SheetPage sheetPage, Action <SheetRow, int> callback, int insertIndex)
 {
     this.sheetPage   = sheetPage;
     this.callback    = callback;
     this.insertIndex = insertIndex;
     index            = sheetPage.GetAvailableRowIndex();
 }
Esempio n. 5
0
        public bool CheckIfSameCodebase(SheetPage other)
        {
            if (sheetName != other.sheetName)
            {
                return(false);
            }

            if (rows.Count != other.rows.Count)
            {
                return(false);
            }

            for (int i = 0; i < rows.Count; i++)
            {
                if (!rows[i].CheckIfSameCodebase(other.rows[i]))
                {
                    return(false);
                }
            }

            if (columns.Count != other.columns.Count)
            {
                return(false);
            }

            for (int i = 0; i < columns.Count; i++)
            {
                if (!columns[i].CheckIfSameCodebase(other.columns[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
        private static void UpdateModelData()
        {
            if (!File.Exists(SheetStringDefinitions.FILE_LOCATION_TARGET_DATASHEET))
            {
                return;
            }

            string json = File.ReadAllText(SheetStringDefinitions.FILE_LOCATION_TARGET_DATASHEET);

            string[]    updatedPagesJson = SheetDataType.String.GetDataValue(json, true) as string[];
            SheetPage[] updatedPages     = new SheetPage[updatedPagesJson.Length];
            for (int i = 0; i < updatedPagesJson.Length; i++)
            {
                updatedPages[i] = new SheetPage(JsonUtility.FromJson <SheetPageJsonable>(updatedPagesJson[i]));
            }

            foreach (SheetPage sheetPage in updatedPages)
            {
                CreateModelInstance(sheetPage);
            }

            File.Delete(SheetStringDefinitions.FILE_LOCATION_TARGET_DATASHEET);
            File.Delete(SheetStringDefinitions.FILE_LOCATION_TARGET_DATASHEET + SheetStringDefinitions.META_FILE_EXTENSION);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
 public void Initialize(DataSheet dataSheet, SheetPage sheetPage, Action <SheetColumn, int> callback, int insertIndex)
 {
     this.dataSheet   = dataSheet;
     this.sheetPage   = sheetPage;
     this.callback    = callback;
     this.insertIndex = insertIndex;
     string[] options = dataSheet.datasheetPages.Select(i => i.sheetName).ToArray();
     referenceSheet = options[0];
 }
Esempio n. 8
0
 public void Initialize(DataSheet dataSheet, SheetPage sheetPage, SheetRow sheetRow)
 {
     this.dataSheet = dataSheet;
     this.sheetPage = sheetPage;
     this.sheetRow  = sheetRow;
     identifier     = sheetRow.identifier;
     enumValue      = sheetRow.enumValue;
     index          = sheetRow.index;
 }
Esempio n. 9
0
        public SheetRow(SheetPage sheetPage, SheetRowJsonable sheetRowJson)
        {
            index      = sheetRowJson.index;
            identifier = sheetRowJson.identifier;

            cells = new List <SheetCell>(sheetPage.columns.Count);

            for (int i = 0; i < sheetPage.columns.Count; i++)
            {
                SheetColumn column = sheetPage.columns[i];
                object      value  = column.dataType.GetDataValue(sheetRowJson.data[i], column.isCollection);
                cells.Add(new SheetCell(value));
            }
        }
Esempio n. 10
0
        public void ChangeIdentifier(DataSheet dataSheet, SheetPage sheetPage, string newIdentifier)
        {
            foreach (SheetPage datasheetPage in dataSheet.datasheetPages)
            {
                for (int i = 0; i < datasheetPage.columns.Count; i++)
                {
                    SheetColumn datasheetColumn = datasheetPage.columns[i];

                    if (datasheetColumn.dataType != SheetDataType.Reference)
                    {
                        continue;
                    }

                    if (datasheetColumn.referenceSheet != sheetPage.sheetName)
                    {
                        continue;
                    }

                    if (datasheetColumn.isCollection)
                    {
                        for (int j = 0; j < datasheetPage.rows.Count; j++)
                        {
                            SheetRow  datasheetRow  = datasheetPage.rows[j];
                            SheetCell datasheetCell = datasheetRow.cells[i];
                            string[]  dataArray     = datasheetCell.data as string[];
                            for (int h = 0; h < dataArray.Length; h++)
                            {
                                if (dataArray[h] == identifier)
                                {
                                    dataArray[h] = newIdentifier;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < datasheetPage.rows.Count; j++)
                        {
                            SheetRow  datasheetRow  = datasheetPage.rows[j];
                            SheetCell datasheetCell = datasheetRow.cells[i];
                            if ((string)datasheetCell.data == identifier)
                            {
                                datasheetCell.data = newIdentifier;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        public SheetRowJsonable(SheetPage sheetPage, SheetRow sheetRow)
        {
            index          = sheetRow.index;
            identifier     = sheetRow.identifier;
            enumIdentifier = sheetRow.enumValue;

            data = new string[sheetPage.columns.Count];

            for (int i = 0; i < sheetPage.columns.Count; i++)
            {
                SheetColumn column = sheetPage.columns[i];
                SheetCell   cell   = sheetRow.cells[i];
                data[i] = column.dataType.GetStringValue(cell.data, column.isCollection);
            }
        }
Esempio n. 12
0
        public void Initialize(DataSheet dataSheet, Action <SheetPage> callback)
        {
            this.dataSheet = dataSheet;
            this.callback  = callback;

            sheetPage = new SheetPage();

            int highest = 0;

            if (dataSheet.datasheetPages.Length > 0)
            {
                highest = dataSheet.datasheetPages.Max(i => i.index);
            }
            sheetPage.index     = highest + 1;
            sheetPage.sheetName = string.Empty;
        }
        public SheetPageJsonable(SheetPage sheetPage)
        {
            index     = sheetPage.index;
            sheetName = sheetPage.sheetName;

            rows = new SheetRowJsonable[sheetPage.rows.Count];
            for (int i = 0; i < rows.Length; i++)
            {
                rows[i] = new SheetRowJsonable(sheetPage, sheetPage.rows[i]);
            }

            columns = new SheetColumnJsonable[sheetPage.columns.Count];
            for (int i = 0; i < columns.Length; i++)
            {
                columns[i] = new SheetColumnJsonable(sheetPage.columns[i]);
            }
        }
Esempio n. 14
0
        private static void GenerateCode_Model(SheetPage sheetPage)
        {
            if (!Directory.Exists(sheetPage.sheetDirectoryLocation))
            {
                Directory.CreateDirectory(sheetPage.sheetDirectoryLocation);
            }

            string[] modelTemplate = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_MODEL);

            for (int i = 0; i < modelTemplate.Length; i++)
            {
                string line = modelTemplate[i];
                modelTemplate[i] = line.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_MODEL_NAME, sheetPage.sheetNameTrimmedUpperCase);
            }

            File.WriteAllLines(sheetPage.sheetModelFileLocation, modelTemplate);
        }
Esempio n. 15
0
        public static LoadedPageData Initialize(DataSheet dataSheet, DatasheetType dataSheetType)
        {
            string         dataString = dataSheetType.GetIdentifier();
            SheetPage      sheetPage  = Array.Find(dataSheet.datasheetPages, i => i.sheetName == dataString);
            LoadedPageData pageData   = new LoadedPageData();

            pageData.dataSheetIdentifier = dataString;
            pageData.sheetPage           = sheetPage;

            if (!pageData.TryLoadStoredDimensions())
            {
                pageData.CalculateDimensions();
            }

            pageData.RecalculateTotalHeight();
            pageData.RecalculateTotalWidth();
            return(pageData);
        }
Esempio n. 16
0
        public void Initialize(DataSheet dataSheet, SheetPage sheetPage, SheetColumn sheetColumn, Action onColumnEdited)
        {
            this.dataSheet      = dataSheet;
            this.sheetPage      = sheetPage;
            this.sheetColumn    = sheetColumn;
            this.onColumnEdited = onColumnEdited;
            serializationName   = sheetColumn.serializationName;
            propertyName        = sheetColumn.propertyName;
            isCollection        = sheetColumn.isCollection;
            dataType            = sheetColumn.dataType;

            if (dataType != SheetDataType.Reference)
            {
                string[] options = dataSheet.datasheetPages.Select(i => i.sheetName).ToArray();
                referenceSheet = options[0];
            }
            else
            {
                referenceSheet = sheetColumn.referenceSheet;
            }
        }
Esempio n. 17
0
        public SheetRow(SheetPage sheetPage, int index, string identifier, string enumValue, int insertIndex)
        {
            this.index      = index;
            this.identifier = identifier;
            this.enumValue  = enumValue;

            cells = new List <SheetCell>(sheetPage.columns.Count);

            for (int i = 0; i < sheetPage.columns.Count; i++)
            {
                SheetColumn column = sheetPage.columns[i];
                object      value  = column.GetDefaultCellValue();
                cells.Add(new SheetCell(value));
            }

            if (insertIndex < sheetPage.rows.Count)
            {
                sheetPage.rows.Insert(insertIndex, this);
            }
            else
            {
                sheetPage.rows.Add(this);
            }
        }
Esempio n. 18
0
        private static void GenerateCode_Record(DataSheet dataSheet, List <SheetPage> newPages, SheetPage sheetPage)
        {
            List <string> recordTemplate = new List <string>(File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD));

            for (int i = 0; i < recordTemplate.Count; i++)
            {
                string line = recordTemplate[i];
                recordTemplate[i] = line.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_MODEL_NAME, sheetPage.sheetNameTrimmedUpperCase);
            }

            string[] propertyTemplate           = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_PROPERTY);
            string[] propertyCollectionTemplate = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_PROPERTY_COLLECTION);

            string[] referenceTemplate           = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_REFERENCE);
            string[] referenceCollectionTemplate = File.ReadAllLines(SheetStringDefinitions.TEMPLATE_DIRECTORY + SheetStringDefinitions.TEMPLATE_FILE_RECORD_REFERENCE_COLLECTION);

            List <string> recordProperties = new List <string>();

            foreach (SheetColumn sheetColumn in sheetPage.columns)
            {
                if (recordProperties.Count > 0)
                {
                    recordProperties.Add(string.Empty);
                }

                string[] matchingTemplate;
                if (sheetColumn.dataType == SheetDataType.Reference)
                {
                    matchingTemplate = sheetColumn.isCollection ? referenceCollectionTemplate : referenceTemplate;
                }
                else
                {
                    matchingTemplate = sheetColumn.isCollection ? propertyCollectionTemplate : propertyTemplate;
                }

                foreach (string templateLine in matchingTemplate)
                {
                    if (sheetColumn.dataType == SheetDataType.Reference)
                    {
                        string      referenceSheet;
                        SheetPage[] sheetPages = dataSheet.datasheetPages.Where(i => i.sheetName == sheetColumn.referenceSheet).ToArray();
                        if (sheetPages.Length > 0)
                        {
                            referenceSheet = sheetPages[0].sheetEnumCase;
                        }
                        else
                        {
                            referenceSheet = newPages.Find(i => i.sheetName == sheetColumn.referenceSheet).sheetEnumCase;
                        }

                        recordProperties.Add(templateLine.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_IDENTIFIER, sheetColumn.serializationName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_UPPER, sheetColumn.propertyName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_LOWER, sheetColumn.propertyName.FirstLetterToLower())
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_REFERENCE_MODEL_NAME, referenceSheet));
                    }
                    else
                    {
                        recordProperties.Add(templateLine.Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_IDENTIFIER, sheetColumn.serializationName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_UPPER, sheetColumn.propertyName)
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_NAME_LOWER, sheetColumn.propertyName.FirstLetterToLower())
                                             .Replace(SheetStringDefinitions.TEMPLATE_REPLACE_PROPERTY_TYPE, sheetColumn.dataType.GetIdentifier()));
                    }
                }
            }

            int replaceIndex = recordTemplate.FindIndex(i => i.Contains(SheetStringDefinitions.TEMPLATE_INSERT_PROPERTIES));

            recordTemplate.InsertRange(replaceIndex, recordProperties);

            File.WriteAllLines(sheetPage.sheetRecordFileLocation, recordTemplate);
        }
Esempio n. 19
0
        public static void UpdateModelCode(SheetPage[] updatedPages)
        {
            List <SheetPage> deletedSheetPages = new List <SheetPage>();
            List <SheetPage> newSheetPages     = new List <SheetPage>();
            List <SheetPage> changedPages      = new List <SheetPage>();

            DataSheet dataSheet = new DataSheet();

            foreach (SheetPage sheetPage in updatedPages)
            {
                SheetPage originalPage = Array.Find(dataSheet.datasheetPages, i => i.sheetName == sheetPage.sheetName);
                if (originalPage == null)
                {
                    newSheetPages.Add(sheetPage);
                    continue;
                }

                if (originalPage.CheckIfSameCodebase(sheetPage))
                {
                    continue;
                }

                changedPages.Add(sheetPage);
            }

            foreach (SheetPage sheetPage in dataSheet.datasheetPages)
            {
                if (updatedPages.Any(i => i.sheetName == sheetPage.sheetName))
                {
                    continue;
                }

                deletedSheetPages.Add(sheetPage);
            }

            int totalChanges = newSheetPages.Count + deletedSheetPages.Count + changedPages.Count;

            if (totalChanges > 0)
            {
                foreach (SheetPage sheetPage in newSheetPages)
                {
                    Directory.CreateDirectory(sheetPage.sheetDirectoryLocation);
                    GenerateCode_Model(sheetPage);
                    GenerateCode_Record(dataSheet, newSheetPages, sheetPage);
                    GenerateCode_Identifier(sheetPage);
                }

                foreach (SheetPage sheetPage in changedPages)
                {
                    GenerateCode_Record(dataSheet, newSheetPages, sheetPage);
                    GenerateCode_Identifier(sheetPage);
                }

                foreach (SheetPage sheetPage in deletedSheetPages)
                {
                    string directory = SheetStringDefinitions.MODEL_DIRECTORY + sheetPage.sheetEnumCase;
                    Directory.Delete(directory, true);
                    File.Delete(directory + SheetStringDefinitions.META_FILE_EXTENSION);
                    File.Delete(SheetStringDefinitions.SCRIPTABLEOBJECT_DIRECTORY + sheetPage.sheetEnumCase + SheetStringDefinitions.SCRIPTABLEOBJECT_FILE_EXTENSION);
                    File.Delete(SheetStringDefinitions.SCRIPTABLEOBJECT_DIRECTORY + sheetPage.sheetEnumCase + SheetStringDefinitions.SCRIPTABLEOBJECT_FILE_EXTENSION + SheetStringDefinitions.META_FILE_EXTENSION);
                }

                GenerateCode_ModelManager(updatedPages);
                GenerateCode_DataSheetType(updatedPages);

                string[] updatedPagesJson = new string[updatedPages.Length];
                for (int i = 0; i < updatedPages.Length; i++)
                {
                    updatedPagesJson[i] = JsonUtility.ToJson(new SheetPageJsonable(updatedPages[i]));
                }

                string json = SheetDataType.String.GetStringValue(updatedPagesJson, true);
                File.WriteAllText(SheetStringDefinitions.FILE_LOCATION_TARGET_DATASHEET, json);
            }
            else
            {
                foreach (SheetPage sheetPage in updatedPages)
                {
                    CreateModelInstance(sheetPage);
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Esempio n. 20
0
        private static void CreateModelInstance(SheetPage sheetPage)
        {
            ScriptableObject instance = AssetDatabase.LoadAssetAtPath <ScriptableObject>(sheetPage.scriptableObjectFileLocation);

            if (instance == null)
            {
                instance = ScriptableObject.CreateInstance(sheetPage.sheetModelNameUpperCase);
                Directory.CreateDirectory(SheetStringDefinitions.SCRIPTABLEOBJECT_DIRECTORY);
                AssetDatabase.CreateAsset(instance, sheetPage.scriptableObjectFileLocation);
            }

            Type      typeModel         = instance.GetType();
            FieldInfo recordsMemberInfo = typeModel.GetField(SheetStringDefinitions.RECORDS_PROPERTY_NAME, BindingFlags.NonPublic | BindingFlags.Instance);

            Type  typeRecord       = recordsMemberInfo.FieldType.GetElementType();
            Type  baseType         = typeRecord.BaseType;
            Array recordCollection = Array.CreateInstance(typeRecord, sheetPage.rows.Count);

            FieldInfo identifierFieldInfo = baseType.GetField(SheetStringDefinitions.RECORD_IDENTIFIER_VARIABLE, BindingFlags.NonPublic | BindingFlags.Instance);

            for (int i = 0; i < sheetPage.rows.Count; i++)
            {
                SheetRow sheetRow       = sheetPage.rows[i];
                object   recordInstance = Activator.CreateInstance(typeRecord);

                identifierFieldInfo.SetValue(recordInstance, sheetRow.identifier.GetIdentifierEnum(identifierFieldInfo.FieldType));

                for (int j = 0; j < sheetPage.columns.Count; j++)
                {
                    SheetColumn sheetColumn  = sheetPage.columns[j];
                    FieldInfo   propertyInfo = typeRecord.GetField("_" + sheetColumn.propertyName.FirstLetterToLower(), BindingFlags.NonPublic | BindingFlags.Instance);
                    object      data         = sheetRow.cells[j].data;
                    if (sheetColumn.dataType == SheetDataType.Reference)
                    {
                        if (sheetColumn.isCollection)
                        {
                            Type     identifierType = propertyInfo.FieldType.GetElementType();
                            string[] dataStrings    = data as string[];
                            Array    dataArray      = Array.CreateInstance(identifierType, dataStrings.Length);
                            for (int h = 0; h < dataStrings.Length; h++)
                            {
                                dataArray.SetValue(dataStrings[h].GetIdentifierEnum(identifierType), h);
                            }

                            data = dataArray;
                        }
                        else
                        {
                            Type identifierType = propertyInfo.FieldType;
                            data = ((string)data).GetIdentifierEnum(identifierType);
                        }
                    }
                    propertyInfo.SetValue(recordInstance, data);
                }

                recordCollection.SetValue(recordInstance, i);
            }

            recordsMemberInfo.SetValue(instance, recordCollection);
            EditorUtility.SetDirty(instance);
        }
Esempio n. 21
0
        public static SheetPage DeconstructDatasheetCode(DatasheetType datasheetType)
        {
            SheetPage sheetPage = new SheetPage();

            sheetPage.sheetName = datasheetType.GetIdentifier();
            sheetPage.index     = (int)datasheetType;

            Type recordType = Type.GetType(SheetStringDefinitions.NAMESPACE + "." + sheetPage.sheetRecordName + SheetStringDefinitions.ASSEMBLY_LOCATION);

            FieldInfo[] fieldInfos = recordType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            fieldInfos        = fieldInfos.Where(i => i.IsPublic || i.GetCustomAttribute <SerializeField>() != null).ToArray();
            sheetPage.columns = new List <SheetColumn>(fieldInfos.Length);
            for (int i = 0; i < fieldInfos.Length; i++)
            {
                FieldInfo fieldInfo = fieldInfos[i];

                SheetColumn column = new SheetColumn();
                sheetPage.columns.Add(column);
                ColumnName columnNameAttribute = fieldInfo.GetCustomAttribute <ColumnName>();
                column.serializationName = columnNameAttribute.columnName;
                column.propertyName      = fieldInfo.Name.Remove(0, 1).FirstLetterToUpper();
                column.isCollection      = fieldInfo.FieldType.IsArray;
                column.dataType          = GetDataType(fieldInfo.FieldType);
                if (column.dataType == SheetDataType.Reference)
                {
                    string typeName = fieldInfo.FieldType.Name;
                    string datasheetName;
                    if (column.isCollection)
                    {
                        datasheetName = typeName.Remove(typeName.Length - SheetStringDefinitions.IDENTIFIER_SUFFIX.Length - SheetStringDefinitions.ARRAY_VARIABLE_SUFFIX.Length);
                    }
                    else
                    {
                        datasheetName = typeName.Remove(typeName.Length - SheetStringDefinitions.IDENTIFIER_SUFFIX.Length);
                    }

                    column.referenceSheet = Enum.Parse(typeof(DatasheetType), datasheetName).GetIdentifier();
                }
            }

            Type      modelType        = Type.GetType(SheetStringDefinitions.NAMESPACE + "." + sheetPage.sheetModelNameUpperCase + SheetStringDefinitions.ASSEMBLY_LOCATION);
            object    modelObject      = AssetDatabase.LoadAssetAtPath(sheetPage.scriptableObjectFileLocation, modelType);
            FieldInfo recordsFieldInfo = modelType.GetField(SheetStringDefinitions.RECORDS_PROPERTY_NAME, BindingFlags.NonPublic | BindingFlags.Instance);
            Array     modelRecords     = (Array)recordsFieldInfo.GetValue(modelObject);

            Type      recordBaseType            = recordType.BaseType;
            FieldInfo recordIdentifierFieldInfo = recordBaseType.GetField(SheetStringDefinitions.RECORD_IDENTIFIER_VARIABLE, BindingFlags.NonPublic | BindingFlags.Instance);

            Type identifierType = Type.GetType(sheetPage.sheetIdentifierName + SheetStringDefinitions.ASSEMBLY_LOCATION);

            sheetPage.rows = new List <SheetRow>(modelRecords.Length);
            for (int i = 0; i < modelRecords.Length; i++)
            {
                object record = modelRecords.GetValue(i);

                SheetRow sheetRow = new SheetRow();
                sheetPage.rows.Add(sheetRow);

                object identifierEnumValue = recordIdentifierFieldInfo.GetValue(record);
                sheetRow.index      = (int)identifierEnumValue;
                sheetRow.identifier = identifierEnumValue.GetIdentifier();
                sheetRow.enumValue  = identifierEnumValue.ToString();

                sheetRow.cells = new List <SheetCell>(fieldInfos.Length);
                for (int j = 0; j < fieldInfos.Length; j++)
                {
                    FieldInfo   fieldInfo = fieldInfos[j];
                    SheetColumn column    = sheetPage.columns[j];
                    object      data      = fieldInfo.GetValue(record);
                    if (data == null)
                    {
                        data = column.GetDefaultCellValue();
                    }
                    if (column.dataType == SheetDataType.Reference)
                    {
                        if (column.isCollection)
                        {
                            Array    arrayData  = ((Array)data);
                            string[] stringData = new string[arrayData.Length];
                            for (int h = 0; h < arrayData.Length; h++)
                            {
                                stringData[h] = arrayData.GetValue(h).GetIdentifier();
                            }

                            data = stringData;
                        }
                        else
                        {
                            data = data.GetIdentifier();
                        }
                    }

                    SheetCell cell = new SheetCell(data);
                    sheetRow.cells.Add(cell);
                }
            }

            return(sheetPage);
        }