コード例 #1
0
        /// <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);
        }
コード例 #2
0
        private static void HandleScriptModifications()
        {
            UdonSharpSettings settings = UdonSharpSettings.GetSettings();

            if (!settings.autoCompileOnModify)
            {
                _modifiedScripts.Clear();
                return;
            }

            if (settings.waitForFocus && !UnityEditorInternal.InternalEditorUtility.isApplicationActive)
            {
                return;
            }

            if (_modifiedScripts.Count == 0)
            {
                return;
            }

            try
            {
                UdonSharpProgramAsset.CompileAllCsPrograms();
            }
            finally
            {
                _modifiedScripts.Clear();
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        private static void SetupWatchers()
        {
            if (_fileSystemWatchers != null)
            {
                UdonSharpSettings settings = UdonSharpSettings.GetSettings();

                bool watcherEnabled = settings.autoCompileOnModify;

                if (watcherEnabled == _lastEnabledState)
                {
                    return;
                }

                _lastEnabledState = watcherEnabled;
                foreach (FileSystemWatcher watcher in _fileSystemWatchers)
                {
                    if (watcher != null)
                    {
                        watcher.EnableRaisingEvents = watcherEnabled;
                    }
                }

                return;
            }

            AssemblyReloadEvents.beforeAssemblyReload += CleanupWatchers;

            // string[] blacklistedDirectories = UdonSharpSettings.GetScannerBlacklist();
            //
            // string[] directories = Directory.GetDirectories("Assets/", "*", SearchOption.AllDirectories).Append("Assets/")
            //     .Select(e => e.Replace('\\', '/'))
            //     .Where(e => !blacklistedDirectories.Any(name => name.TrimEnd('/') == e.TrimEnd('/') || e.StartsWith(name)))
            //     .ToArray();
            //
            // List<string> sourceDirectories = new List<string>();
            //
            // foreach (string directory in directories)
            // {
            //     if (Directory.GetFiles(directory, "*.cs").Length > 0)
            //         sourceDirectories.Add(directory);
            // }

            IEnumerable <string> sourcePaths = CompilationContext.GetAllFilteredSourcePaths(true);

            HashSet <string> sourceDirectoriesSet = new HashSet <string>();

            foreach (string sourcePath in sourcePaths)
            {
                sourceDirectoriesSet.Add(Path.GetDirectoryName(sourcePath));
            }

            string[] sourceDirectories = sourceDirectoriesSet.ToArray();

            _fileSystemWatchers = new FileSystemWatcher[sourceDirectories.Length];

            for (int i = 0; i < sourceDirectories.Length; ++i)
            {
                FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(sourceDirectories[i], "*.cs");
                fileSystemWatcher.IncludeSubdirectories = false;
                fileSystemWatcher.InternalBufferSize    = 512; // Someone would need to modify 32 files in a single directory at once to hit this

                fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
                fileSystemWatcher.Changed     += OnSourceFileChanged;

                _fileSystemWatchers[i] = fileSystemWatcher;
            }
        }