public static void SaveVariableAsset(VariablesAsset asset, string fileName)
        {
            var path = Path.Combine(BoltCore.Paths.variableResources, fileName + ".asset");

            if (String.IsNullOrEmpty(AssetDatabase.GetAssetPath(asset)))
            {
                var assetDatabasePath = PathUtility.FromProject(path);
                PathUtility.CreateParentDirectoryIfNeeded(path);
                AssetDatabase.CreateAsset(asset, assetDatabasePath);
                AssetDatabase.SaveAssets();
            }
        }
Пример #2
0
        public static void Build()
        {
            var progressTitle = "Building unit database...";

            lock (@lock)
            {
                using (ProfilingUtility.SampleBlock("Update Unit Database"))
                {
                    using (NativeUtility.Module("sqlite3.dll"))
                    {
                        SQLiteConnection database = null;

                        try
                        {
                            ProgressUtility.DisplayProgressBar(progressTitle, "Creating database...", 0);

                            if (File.Exists(BoltFlow.Paths.unitOptions))
                            {
                                VersionControlUtility.Unlock(BoltFlow.Paths.unitOptions);
                                File.Delete(BoltFlow.Paths.unitOptions);
                            }

                            PathUtility.CreateParentDirectoryIfNeeded(BoltFlow.Paths.unitOptions);
                            database = new SQLiteConnection(BoltFlow.Paths.unitOptions);
                            database.CreateTable <UnitOptionRow>();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Updating codebase...", 0);

                            UpdateCodebase();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Updating type mappings...", 0);

                            UpdateTypeMappings();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Converting codebase to unit options...", 0);

                            options = new HashSet <IUnitOption>(GetStaticOptions());

                            var rows = new HashSet <UnitOptionRow>();

                            var progress          = 0;
                            var lastShownProgress = 0f;

                            foreach (var option in options)
                            {
                                try
                                {
                                    var shownProgress = (float)progress / options.Count;

                                    if (shownProgress > lastShownProgress + 0.01f)
                                    {
                                        ProgressUtility.DisplayProgressBar(progressTitle, "Converting codebase to unit options...", shownProgress);
                                        lastShownProgress = shownProgress;
                                    }

                                    rows.Add(option.Serialize());
                                }
                                catch (Exception ex)
                                {
                                    Debug.LogError($"Failed to save option '{option.GetType()}'.\n{ex}");
                                }

                                progress++;
                            }

                            ProgressUtility.DisplayProgressBar(progressTitle, "Writing to database...", 1);

                            try
                            {
                                database.CreateTable <UnitOptionRow>();
                                database.InsertAll(rows);
                            }
                            catch (Exception ex)
                            {
                                Debug.LogError($"Failed to write options to database.\n{ex}");
                            }
                        }
                        finally
                        {
                            database?.Close();
                            ProgressUtility.ClearProgressBar();
                            AssetDatabase.Refresh();
                            //ConsoleProfiler.Dump();
                        }
                    }
                }
            }
        }