Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #42 from Merlin-san/build-event-corruption
Browse files Browse the repository at this point in the history
Add build callback to prevent corruption of assemblies now that VRC has updated the SDK.
  • Loading branch information
MerlinVR authored Jul 16, 2020
2 parents 3d37c8d + 9a28226 commit 48b0fc9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Assets/UdonSharp/Editor/BuildUtilities.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Assets/UdonSharp/Editor/BuildUtilities/UdonSharpBuildChecks.cs
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;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/UdonSharp/Editor/Editors/UdonSharpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void Start()
public bool includeInlineCode = true;
public bool listenForVRCExceptions = false;

public bool shouldForceCompile = false;

public static UdonSharpSettings GetSettings()
{
UdonSharpSettings settings = AssetDatabase.LoadAssetAtPath<UdonSharpSettings>(SettingsSavePath);
Expand Down Expand Up @@ -126,6 +128,7 @@ public class UdonSharpSettingsProvider
private static readonly GUIContent includeInlineCodeLabel = new GUIContent("Inline code", "Include C# inline in generated assembly");
private static readonly GUIContent listenForVRCExceptionsLabel = new GUIContent("Listen for client exceptions", "Listens for exceptions from Udon and tries to match them to scripts in the project");
private static readonly GUIContent scanningBlackListLabel = new GUIContent("Scanning blacklist", "Directories to not watch for source code changes and not include in class lookups");
private static readonly GUIContent forceCompileLabel = new GUIContent("Force compile on upload", "Forces Unity to synchronously compile scripts when a world build is started. Unity will complain and throw errors, but it seems to work. This is a less intrusive way to prevent Unity from corrupting assemblies on upload.");

[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
Expand Down Expand Up @@ -166,6 +169,11 @@ public static SettingsProvider CreateSettingsProvider()
EditorGUILayout.PropertyField(settingsObject.FindProperty(nameof(UdonSharpSettings.listenForVRCExceptions)), listenForVRCExceptionsLabel);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Experimental", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(settingsObject.FindProperty(nameof(UdonSharpSettings.shouldForceCompile)), forceCompileLabel);
if (EditorGUI.EndChangeCheck())
{
settingsObject.ApplyModifiedProperties();
Expand Down
7 changes: 4 additions & 3 deletions Assets/UdonSharp/Editor/UdonSharpEditorAssembly.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"references": [
"VRC.Udon",
"VRC.Udon.Editor",
"UdonSharp.Runtime",
"VRC.Udon.Serialization.OdinSerializer"
"VRC.Udon.Serialization.OdinSerializer",
"UdonSharp.Runtime"
],
"optionalUnityReferences": [],
"includePlatforms": [
Expand All @@ -25,7 +25,8 @@
"VRC.Udon.ClientBindings.dll",
"VRCSDK3.dll",
"VRCSDKBase.dll",
"System.Collections.Immutable.dll"
"System.Collections.Immutable.dll",
"VRCSDKBase-Editor.dll"
],
"autoReferenced": true,
"defineConstraints": []
Expand Down

0 comments on commit 48b0fc9

Please sign in to comment.