This repository has been archived by the owner on Jan 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Merlin-san/build-event-corruption
Add build callback to prevent corruption of assemblies now that VRC has updated the SDK.
- Loading branch information
Showing
5 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
Assets/UdonSharp/Editor/BuildUtilities/UdonSharpBuildChecks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
| ||
using UnityEditor; | ||
using UnityEngine; | ||
using VRC.SDKBase.Editor.BuildPipeline; | ||
|
||
namespace UdonSharp | ||
{ | ||
public class UdonSharpBuildChecks : IVRCSDKBuildRequestedCallback | ||
{ | ||
public int callbackOrder => -1; | ||
|
||
/// <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 != null && 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) | ||
{ | ||
//EditorUtility.DisplayDialog("Udon# build error", "Scripts are in the process of compiling, please retry build after scripts have compiled.", "OK"); | ||
Debug.LogError("[UdonSharp] Scripts are in the process of compiling, please retry build after scripts have compiled."); | ||
typeof(SceneView).GetMethod("ShowNotification", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).Invoke(null, new object[] { "Scripts are in the process of compiling, please retry build after scripts have compiled." }); | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/UdonSharp/Editor/BuildUtilities/UdonSharpBuildChecks.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters