public void Log(string text)
 {
     this.logs.Add(LogItem.Log(text));
 }
 private void Log(string text)
 {
     this.logs.Add(LogItem.Log(text));
 }
Exemple #3
0
        private IEnumerator LoadAll(SerializedProperty paths, bool forceUpdate)
        {
            this.inProgress = true;
            var visitedConfigs = new HashSet <ConfigInfo>();
            var visitedFiles   = new HashSet <string>();

            var list            = new List <DataConfigGenerator>();
            var newConfigs      = new List <string>();
            var pathsStr        = new string[paths.arraySize];
            var captions        = new string[paths.arraySize];
            var behaviours      = new GeneratorBehaviour[paths.arraySize];
            var versions        = new int[paths.arraySize];
            var dirs            = new Object[paths.arraySize];
            var visitedFilesArr = new string[paths.arraySize];

            for (int i = 0; i < paths.arraySize; ++i)
            {
                captions[i]        = paths.GetArrayElementAtIndex(i).FindPropertyRelative("caption").stringValue;
                pathsStr[i]        = paths.GetArrayElementAtIndex(i).FindPropertyRelative("path").stringValue;
                versions[i]        = paths.GetArrayElementAtIndex(i).FindPropertyRelative("version").intValue;
                dirs[i]            = paths.GetArrayElementAtIndex(i).FindPropertyRelative("directory").objectReferenceValue;
                visitedFilesArr[i] = paths.GetArrayElementAtIndex(i).FindPropertyRelative("visitedFiles").stringValue;
                behaviours[i]      = paths.GetArrayElementAtIndex(i).FindPropertyRelative("behaviour").objectReferenceValue as GeneratorBehaviour;
            }

            for (int i = 0; i < pathsStr.Length; ++i)
            {
                var path             = pathsStr[i];
                var caption          = captions[i];
                var behaviour        = behaviours[i];
                var currentVersion   = versions[i];
                var visitedFilesStr  = visitedFilesArr[i];
                var dir              = dirs[i];
                var configsDirectory = DataConfigGeneratorSettingsEditor.GetDir(dir);
                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"=========================="));
                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"** {caption}"));
                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"** Version: {currentVersion}"));
                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"=========================="));
                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.Log($"Output directory: {configsDirectory}"));
                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.Log($"Mode: {(forceUpdate == true ? "FORCE UPDATE" : "VERSION UPDATE")}"));

                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"Receiving data from {path}"));
                DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"Connecting {this.progressSymbol}"));
                var fileSize = 0L;
                var isDone   = false;
                EditorCoroutines.StartCoroutine(this.GetFileSize(path, () => {
                    DataConfigGeneratorSettingsEditor.logs[DataConfigGeneratorSettingsEditor.logs.Count - 1] = LogItem.LogSystem($"Connecting {this.progressSymbol}");
                }, (size) => {
                    fileSize = size;
                    isDone   = true;
                }));
                while (isDone == false)
                {
                    yield return(null);
                }
                var request = UnityEngine.Networking.UnityWebRequest.Get(path);
                request.SendWebRequest();
                while (request.isDone == false)
                {
                    yield return(null);

                    DataConfigGeneratorSettingsEditor.logs[DataConfigGeneratorSettingsEditor.logs.Count - 1] = LogItem.LogSystem($"Downloading: {request.downloadedBytes}/{fileSize} bytes ({(request.downloadProgress >= 0f ? Mathf.FloorToInt(request.downloadProgress * 100f).ToString() : "0")}%) {this.progressSymbol}");
                }

                DataConfigGeneratorSettingsEditor.logs[DataConfigGeneratorSettingsEditor.logs.Count - 1] = LogItem.LogSystem($"Downloaded: {request.downloadedBytes}/{fileSize} bytes ({(request.downloadProgress >= 0f ? Mathf.FloorToInt(request.downloadProgress * 100f).ToString() : "0")}%)");

                var isOk = (request.result == UnityEngine.Networking.UnityWebRequest.Result.Success && request.responseCode > 0);
                if (isOk == true)
                {
                    DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"Response: {request.responseCode} OK"));
                }
                else
                {
                    DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogError($"Response error: {request.error}"));
                }

                if (isOk == true)
                {
                    var generator = new DataConfigGenerator(forceUpdate == false ? currentVersion : -1, request.downloadHandler.text, visitedConfigs, visitedFiles)
                    {
                        configsDirectory = configsDirectory,
                        behaviour        = behaviour,
                    };
                    if (generator.status == Status.OK)
                    {
                        generator.AddConfigs(newConfigs);
                        generator.Run();
                        newConfigs.AddRange(generator.GetCreatedConfigs());

                        if (paths.serializedObject != null)
                        {
                            paths.serializedObject.Update();
                            paths.GetArrayElementAtIndex(i).FindPropertyRelative("version").intValue         = generator.version;
                            paths.GetArrayElementAtIndex(i).FindPropertyRelative("visitedFiles").stringValue = string.Join(";", visitedFiles);
                            paths.serializedObject.ApplyModifiedProperties();
                        }

                        list.Add(generator);
                    }
                    else if (generator.status == Status.UpToDate)
                    {
                        var splitted = visitedFilesStr.Split(';');
                        foreach (var sp in splitted)
                        {
                            visitedFiles.Add(sp);
                        }

                        list.Add(generator);
                    }

                    var logs = generator.GetLogs();
                    DataConfigGeneratorSettingsEditor.logs.AddRange(logs);
                }
            }

            DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"Linking..."));

            foreach (var generator in list)
            {
                generator.AddConfigs(generator.GetCreatedConfigs());
            }

            foreach (var generator in list)
            {
                generator.ClearLogs();
                generator.UpdateConfigs();

                var logs = generator.GetLogs();
                DataConfigGeneratorSettingsEditor.logs.AddRange(logs);
            }

            DataConfigGeneratorSettingsEditor.logs.Add(LogItem.LogSystem($"Linking complete"));

            UnityEditor.AssetDatabase.SaveAssets();
            this.inProgress = false;
        }