예제 #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);
        }
예제 #2
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();
        }