public static void Bake([NotNull] MeshAnimationAsset asset) { if (asset == null) { throw new ArgumentNullException(nameof(asset)); } var error = asset.GetValidationMessage(); if (error != null) { throw new InvalidOperationException(error); } try { AssetDatabase.DisallowAutoRefresh(); EditorUtility.DisplayProgressBar("Mesh Animator", "Baking", 0f); DestroyObject(ref asset.bakedTexture); CreateTexture(asset, out var aborted); if (!aborted) { CreateMaterial(asset); BakeAnimations(asset); } SaveAsset(asset); } finally { EditorUtility.ClearProgressBar(); AssetDatabase.AllowAutoRefresh(); } }
///--------------------------------------------------------------------- /// Called at 10 frames per second private void OnInspectorUpdate() { var startWork = false; if (startMarkUp > 0) { var progress = Math.Max(0, Math.Min(1, (EditorApplication.timeSinceStartup - startMarkUp) / startDuration)); if (EditorUtility.DisplayCancelableProgressBar("Work start in:", string.Empty, (float)progress)) { startMarkUp = -1; EditorUtility.ClearProgressBar(); } else if (progress >= 1) { startWork = true; } } if (startWork) { startMarkUp = -1; EditorUtility.ClearProgressBar(); foreach (var builder in activeCodeBuilders) { builder.RunInTestMode = runInTestMode.value; builder.Init(); builder.StartWork(); } isWorking = true; AssetDatabase.DisallowAutoRefresh(); } if (isWorking) { isWorking = false; rootVisualElement.SetEnabled(true); if (activeCodeBuilders.Count > 0) { activeCodeBuilders.RemoveAll((x) => { return(x == null); }); for (int b = 0; b < activeCodeBuilders.Count; b++) { var builder = activeCodeBuilders[b]; if (builder.IsWorking) { rootVisualElement.SetEnabled(false); builder.Update(); isWorking = true; } } } if (!isWorking) { AssetDatabase.AllowAutoRefresh(); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } } }
private static void DidFinishBuildProcess(object sender, EventArgs e) { Debug.Log("---->>> Finished C++ project build"); EditorUtility.ClearProgressBar(); AssetDatabase.AllowAutoRefresh(); AssetDatabase.Refresh(); _isAnythingRunning = false; }
public static async Task Execute() { AssetDatabase.DisallowAutoRefresh(); progress = 0; UpdateProgressBar(0.1f, nameof(Execute)); await DownloadSubmoduleAsync(); AssetDatabase.Refresh(); UpdateProgressBar(1 - progress, "Finish"); AssetDatabase.AllowAutoRefresh(); EditorUtility.ClearProgressBar(); }
internal void DownloadRepositoryToPathIfNeeded( string cloudRepository, string cloudOrganization, string projectPath, string unityAccessToken) { AssetDatabase.DisallowAutoRefresh(); try { BuildProgressSpeedAndRemainingTime.ProgressData progressData = new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now); ThreadPool.QueueUserWorkItem( DownloadRepository, new DownloadRepositoryParameters() { CloudOrganization = cloudOrganization, CloudRepository = cloudRepository, ProjectPath = projectPath, AccessToken = unityAccessToken }); while (!mOperationFinished) { if (mDisplayProgress) { DisplayProgress( mUpdateNotifier.GetUpdateStatus(), progressData, cloudRepository); } Thread.Sleep(150); } } finally { EditorUtility.ClearProgressBar(); AssetDatabase.AllowAutoRefresh(); RefreshAsset.UnityAssetDatabase(); if (!mOperationFailed) { AssetMenuItems.Enable(); ShowWindow.PlasticAfterDownloadingProject(); } } }
public override void OnInspectorGUI() { serializedObject.Update(); var type = typeof(InkCompiler); EditorGUILayout.Toggle("Executing Compilation Stack", InkCompiler.executingCompilationStack); EditorGUILayout.PropertyField(serializedObject.FindProperty("pendingCompilationStack")); EditorGUILayout.PropertyField(serializedObject.FindProperty("compilationStack")); // this.DrawDefaultInspector(); var buildBlockedInfo = type.GetField("buildBlocked", BindingFlags.NonPublic | BindingFlags.Static); bool buildBlocked = (bool)buildBlockedInfo.GetValue(null); EditorGUILayout.Toggle("Build Blocked", buildBlocked); var playModeBlockedInfo = type.GetField("playModeBlocked", BindingFlags.NonPublic | BindingFlags.Static); bool playModeBlocked = (bool)playModeBlockedInfo.GetValue(null); EditorGUILayout.Toggle("Play Mode Blocked", playModeBlocked); var hasLockedUnityCompilationInfo = type.GetField("hasLockedUnityCompilation", BindingFlags.NonPublic | BindingFlags.Static); bool hasLockedUnityCompilation = (bool)hasLockedUnityCompilationInfo.GetValue(null); EditorGUILayout.Toggle("Has Locked Compilation", hasLockedUnityCompilation); EditorGUILayout.BeginHorizontal(); var disallowedAutoRefreshInfo = type.GetProperty("disallowedAutoRefresh", BindingFlags.NonPublic | BindingFlags.Static); bool disallowedAutoRefresh = (bool)disallowedAutoRefreshInfo.GetValue(null); EditorGUILayout.Toggle("DisallowedAutoRefresh", disallowedAutoRefresh); #if UNITY_2019_4_OR_NEWER if (GUILayout.Button("AllowAutoRefresh")) { AssetDatabase.AllowAutoRefresh(); } EditorGUILayout.EndHorizontal(); #endif if (GUI.changed && target != null) { EditorUtility.SetDirty(target); } serializedObject.ApplyModifiedProperties(); }
public static void CompileInk(params InkFile[] inkFiles) { _postAssetDataBaseRefreshActions.Clear(); AssetDatabase.DisallowAutoRefresh(); try { CompileInk(inkFiles, true, null); //use immediate=true to avoid thread access issues. } finally { AssetDatabase.AllowAutoRefresh(); } AssetDatabase.Refresh(); foreach (var action in _postAssetDataBaseRefreshActions) { action(); } _postAssetDataBaseRefreshActions.Clear(); InkLibrary.Save(); InkMetaLibrary.Save(); }
static void OnProjectLoadedInEditor() { #if UNITY_2017_1_OR_NEWER EditorApplication.playModeStateChanged += OnPlayModeChange; #else EditorApplication.playmodeStateChanged += LegacyOnPlayModeChange; #endif EditorApplication.update += Update; // I really don't know if this can fire, since it assumes that it compiled so can't have been locked. But safety first! EditorApplication.UnlockReloadAssemblies(); #if UNITY_2019_4_OR_NEWER // This one, on the other hand, seems to actually occur sometimes - presumably because c# compiles at the same time as the ink. if (InkEditorUtils.disallowedAutoRefresh) { InkEditorUtils.disallowedAutoRefresh = false; try { AssetDatabase.AllowAutoRefresh(); } catch (Exception e) { Debug.LogWarning("Failed AllowAutoRefresh " + e); } } #endif }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUI.BeginDisabledGroup(InkCompiler.compiling); if (GUILayout.Button(new GUIContent("Rebuild Library", "Rebuilds the ink library. Do this if you're getting unusual errors"), EditorStyles.miniButton)) { InkLibrary.Rebuild(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.Toggle("HasLockedUnityCompilation", InkCompiler.hasLockedUnityCompilation); if (GUILayout.Button("Unlock")) { EditorApplication.UnlockReloadAssemblies(); } #if UNITY_2019_4_OR_NEWER if (GUILayout.Button("AllowAutoRefresh")) { AssetDatabase.AllowAutoRefresh(); } #endif if (InkCompiler.compiling) { Rect r = EditorGUILayout.BeginVertical(); EditorGUI.ProgressBar(r, InkCompiler.GetEstimatedCompilationProgress(), "Compiling..."); GUILayout.Space(EditorGUIUtility.singleLineHeight); EditorGUILayout.EndVertical(); GUILayout.Space(EditorGUIUtility.standardVerticalSpacing); } else { var filesRequiringRecompile = InkLibrary.GetFilesRequiringRecompile(); if (filesRequiringRecompile.Any()) { var files = string.Join("\n", filesRequiringRecompile.Select(x => x.filePath).ToArray()); if (EditorApplication.isPlaying && InkSettings.Instance.delayInPlayMode) { EditorGUILayout.HelpBox("Some Ink files marked to compile on exiting play mode.\n" + files, MessageType.Info); } else { EditorGUILayout.HelpBox("Some Ink files marked to compile automatically are not compiled! Check they don't have compile errors, or else try compiling now.\n" + files, MessageType.Warning); } } else { EditorGUILayout.HelpBox("All Ink files marked to compile automatically are compiled", MessageType.Info); } } EditorGUI.BeginDisabledGroup(InkCompiler.compiling); if (GUILayout.Button(new GUIContent("Recompile All", "Recompiles all files marked to compile automatically."))) { InkEditorUtils.RecompileAll(); } if (EditorApplication.isPlaying && InkSettings.Instance.delayInPlayMode) { var filesRequiringRecompile = InkLibrary.GetFilesRequiringRecompile(); if (filesRequiringRecompile.Any()) { var files = string.Join("\n", filesRequiringRecompile.Select(x => x.filePath).ToArray()); if (GUILayout.Button(new GUIContent("Recompile Pending", "Recompiles all files marked to compile on exiting play mode."))) { InkEditorUtils.RecompileAll(); } } } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.PropertyField(serializedObject.FindProperty("inkLibrary"), true); EditorGUILayout.PropertyField(serializedObject.FindProperty("pendingCompilationStack"), true); EditorGUILayout.PropertyField(serializedObject.FindProperty("compilationStack"), true); EditorGUI.EndDisabledGroup(); if (GUILayout.Button(new GUIContent("Clear Compilation Stacks"))) { InkLibrary.ClearCompilationStacks(); } if (GUI.changed && target != null) { EditorUtility.SetDirty(target); } serializedObject.ApplyModifiedProperties(); }
internal void DownloadRepositoryToPathIfNeeded( string cloudRepository, string cloudOrganization, string projectPath) { var allowAutoRefreshFeature = new AssetDatabase().GetType().GetMethod("DisallowAutoRefresh") != null; #if allowAutoRefreshFeature AssetDatabase.DisallowAutoRefresh(); #endif try { BuildProgressSpeedAndRemainingTime.ProgressData progressData = new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now); ThreadPool.QueueUserWorkItem( DownloadRepository, new DownloadRepositoryParameters() { CloudOrganization = cloudOrganization, CloudRepository = cloudRepository, ProjectPath = projectPath, AccessToken = CloudProjectSettings.accessToken }); while (!mOperationFinished) { if (mDisplayProgress) { DisplayProgress( mUpdateNotifier.GetUpdateStatus(), progressData, cloudRepository); } Thread.Sleep(150); } } finally { EditorUtility.ClearProgressBar(); #if allowAutoRefreshFeature AssetDatabase.AllowAutoRefresh(); #endif DisableCollabIfEnabled(projectPath); RefreshAsset.UnityAssetDatabase(); if (!mOperationFailed) { // we just download a cloud project, // so let's assume we're going to use Cloud Edition SetupUnityEditionToken.ToCloud(); ShowWindow.Plastic(); } } }
// When all files in stack have been compiled. This is called via update because Process events run in another thread. private static void DelayedComplete() { if (InkLibrary.NumFilesInCompilingStackInState(CompilationStackItem.State.Compiling) > 0) { Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning."); return; } bool errorsFound = false; StringBuilder filesCompiledLog = new StringBuilder("Files compiled:"); // Create and import compiled files AssetDatabase.StartAssetEditing(); foreach (var compilingFile in InkLibrary.Instance.compilationStack) { // Complete status is also set when an error occured, in these cases 'compiledJson' will be null so there's no import to process if (compilingFile.compiledJson == null) { continue; } // Write new compiled data to the file system File.WriteAllText(compilingFile.jsonAbsoluteFilePath, compilingFile.compiledJson, Encoding.UTF8); AssetDatabase.ImportAsset(compilingFile.inkFile.jsonPath); } AssetDatabase.StopAssetEditing(); foreach (var compilingFile in InkLibrary.Instance.compilationStack) { // Load and store a reference to the compiled file compilingFile.inkFile.FindCompiledJSONAsset(); filesCompiledLog.AppendLine().Append(compilingFile.inkFile.filePath); filesCompiledLog.Append(string.Format(" ({0}s)", compilingFile.timeTaken)); if (compilingFile.unhandledErrorOutput.Count > 0) { filesCompiledLog.Append(" (With unhandled error)"); StringBuilder errorLog = new StringBuilder(); errorLog.Append("Unhandled error(s) occurred compiling Ink file "); errorLog.Append("'"); errorLog.Append(compilingFile.inkFile.filePath); errorLog.Append("'"); errorLog.AppendLine("! Please report following error(s) as a bug:"); foreach (var error in compilingFile.unhandledErrorOutput) { errorLog.AppendLine(error); } Debug.LogError(errorLog); compilingFile.inkFile.metaInfo.unhandledCompileErrors = compilingFile.unhandledErrorOutput; errorsFound = true; } else { SetOutputLog(compilingFile); bool errorsInEntireStory = false; bool warningsInEntireStory = false; foreach (var inkFile in compilingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy) { if (inkFile.metaInfo.hasErrors) { errorsInEntireStory = true; } if (inkFile.metaInfo.hasWarnings) { warningsInEntireStory = true; } } if (errorsInEntireStory) { filesCompiledLog.Append(" (With error)"); errorsFound = true; } if (warningsInEntireStory) { filesCompiledLog.Append(" (With warning)"); } } } foreach (var compilingFile in InkLibrary.Instance.compilationStack) { if (OnCompileInk != null) { OnCompileInk(compilingFile.inkFile); } } StringBuilder outputLog = new StringBuilder(); if (errorsFound) { outputLog.Append("Ink compilation completed with errors at "); outputLog.AppendLine(DateTime.Now.ToLongTimeString()); outputLog.Append(filesCompiledLog.ToString()); Debug.LogError(outputLog); } else { outputLog.Append("Ink compilation completed at "); outputLog.AppendLine(DateTime.Now.ToLongTimeString()); outputLog.Append(filesCompiledLog.ToString()); Debug.Log(outputLog); } InkLibrary.Instance.compilationStack.Clear(); InkLibrary.SaveToFile(); InkMetaLibrary.Save(); #if !UNITY_EDITOR_LINUX EditorUtility.ClearProgressBar(); #endif #if UNITY_2019_4_OR_NEWER if (InkLibrary.Instance.disallowedAutoRefresh) { InkLibrary.Instance.disallowedAutoRefresh = false; InkLibrary.SaveToFile(); try { AssetDatabase.AllowAutoRefresh(); } catch (Exception e) { Debug.LogWarning("Failed AllowAutoRefresh " + e); } } #endif // This is now allowed, if compiled manually. I've left this code commented out because at some point we might want to track what caused a file to compile. // if(EditorApplication.isPlayingOrWillChangePlaymode && InkSettings.Instance.delayInPlayMode) { // Debug.LogError("Ink just finished recompiling while in play mode. This should never happen when InkSettings.Instance.delayInPlayMode is true!"); // } buildBlocked = false; if (playModeBlocked) { playModeBlocked = false; if (!errorsFound) { // Delaying gives the editor a frame to clear the progress bar. EditorApplication.delayCall += () => { Debug.Log("Compilation completed, entering play mode."); EditorApplication.isPlaying = true; }; } else { Debug.LogWarning("Play mode not entered after ink compilation because ink had errors."); } } foreach (var onCompleteAction in onCompleteActions) { if (onCompleteAction != null) { onCompleteAction(); } } onCompleteActions.Clear(); }
private static void GenerateForDataTypes(Type[] dataTypes) { var @namespace = $"{typeof(DataContainer).Namespace}.GeneratedClasses"; var codeFileInfos = GenerateCodeFiles(@namespace, GenerateTypeDeclarations(dataTypes)); var directory = new DirectoryInfo(Path.Combine(Application.dataPath, "Generated", "JakePerry", "ScriptableData")); directory.Create(); // Get reference to the project folder (one up from Assets). var projectDirFullName = directory.Parent.Parent.Parent.Parent.FullName; int trimCount = projectDirFullName.Length + 1; if (projectDirFullName.EndsWith("/") || projectDirFullName.EndsWith("\\")) { trimCount++; } AssetDatabase.DisallowAutoRefresh(); try { int debugCount = 0; foreach (var codeFileInfo in codeFileInfos) { var file = WriteCodeFile(codeFileInfo, directory); var fileFullName = file.FullName; Debug.Assert(fileFullName.StartsWith(projectDirFullName)); var projectRelativePath = fileFullName.Substring(trimCount).Replace('\\', '/'); AssetDatabase.ImportAsset(projectRelativePath); var monoScript = AssetDatabase.LoadAssetAtPath <MonoScript>(projectRelativePath); if (monoScript == null) { Logger.LogError($"Failed to find generated file at path {projectRelativePath}"); continue; } EditorAssetUtilities.AddLabel(monoScript, GENERATED_SCRIPT_LABEL); debugCount++; } AssetDatabase.Refresh(); if (debugCount == codeFileInfos.Length) { Logger.Log($"Successfully generated {debugCount.ToString()} code files."); } else { Logger.Log($"{debugCount.ToString()} of {codeFileInfos.Length.ToString()} files were successfully generated."); } } finally { AssetDatabase.AllowAutoRefresh(); } }