/// <summary> /// If you're considering commenting any section of this out, try enabling the force compile in the U# settings first. /// This is here to prevent you from corrupting your project files. /// If scripts are left uncompiled from Unity's side when uploading, there is a chance to corrupt your assemblies which can cause all of your UdonBehaviours to lose their variables if handled wrong. /// </summary> /// <param name="requestedBuildType"></param> /// <returns></returns> public bool OnBuildRequested(VRCSDKRequestedBuildType requestedBuildType) { UdonSharpSettings settings = UdonSharpSettings.GetSettings(); bool shouldForceCompile = settings.shouldForceCompile; // Unity doesn't like this and will throw errors if it ends up compiling scripts. But it seems to work. // This is marked experimental for now since I don't know if it will break horribly in some case. if (shouldForceCompile) { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); } else { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); if (EditorApplication.isCompiling) { UdonSharpUtils.LogWarning("Scripts are in the process of compiling, please retry build after scripts have compiled."); UdonSharpUtils.ShowEditorNotification("Scripts are in the process of compiling, please retry build after scripts have compiled."); return(false); } } return(true); }
public bool OnBuildRequested(VRCSDKRequestedBuildType requestedBuildType) { if (requestedBuildType == VRCSDKRequestedBuildType.Avatar) { return(true); } if (UdonSharpSettings.GetSettings().disableUploadCompile) { return(true); } UdonSharpCompilerV1.CompileSync(new UdonSharpCompileOptions() { IsEditorBuild = false }); UdonSharpEditorCache.SaveAllCache(); if (UdonSharpProgramAsset.AnyUdonSharpScriptHasError()) { UdonSharpUtils.LogError("Failed to compile UdonSharp scripts for build, check error log for details."); UdonSharpUtils.ShowEditorNotification("Failed to compile UdonSharp scripts for build, check error log for details."); return(false); } if (UdonSharpEditorManager.RunAllUpgrades()) { UdonSharpUtils.LogWarning(UdonSharpEditorManager.UPGRADE_MESSAGE); return(false); } return(true); }
static void OnChangePlayMode(PlayModeStateChange state) { // Prevent people from entering play mode when there are compile errors, like normal Unity C# // READ ME // -------- // If you think you know better and are about to edit this out, be aware that you gain nothing by doing so. // If a script hits a compile error, it will not update until the compile errors are resolved. // You will just be left wondering "why aren't my scripts changing when I edit them?" since the old copy of the script will be used until the compile errors are resolved. // -------- if (state == PlayModeStateChange.EnteredPlayMode || state == PlayModeStateChange.ExitingEditMode) { if (UdonSharpProgramAsset.AnyUdonSharpScriptHasError()) { EditorApplication.isPlaying = false; UdonSharpUtils.ShowEditorNotification("All U# compile errors have to be fixed before you can enter playmode!"); } else if (state == PlayModeStateChange.EnteredPlayMode) { CreateProxyBehaviours(GetAllUdonBehaviours()); } } if (state == PlayModeStateChange.EnteredEditMode) { UdonSharpEditorCache.ResetInstance(); if (UdonSharpEditorCache.Instance.LastBuildType == UdonSharpEditorCache.DebugInfoType.Client) { UdonSharpProgramAsset.CompileAllCsPrograms(true); } RunAllUpdates(); } else if (state == PlayModeStateChange.ExitingEditMode) { if (UdonSharpEditorCache.Instance.LastBuildType == UdonSharpEditorCache.DebugInfoType.Client) { UdonSharpProgramAsset.CompileAllCsPrograms(true); } } UdonSharpEditorCache.SaveOnPlayExit(state); }