Example #1
0
        static IEnumerator RunEnvironmentCheck()
        {
            //INSTALL THE NECESSARY PACKAGES
            var listRequest   = PackageClient.List();
            var searchRequest = PackageClient.Search("com.unity.scriptablebuildpipeline");

            yield return(WaitForRequest(listRequest));

            if (listRequest.Status == StatusCode.Failure)
            {
                Debug.LogError($"Failed to get a package listing with error code [{listRequest.Error.errorCode}], {listRequest.Error.message}");
            }
            yield return(WaitForRequest(searchRequest));

            if (searchRequest.Status == StatusCode.Failure)
            {
                Debug.LogError($"Failed to do a package search with the error code [{searchRequest.Error.errorCode}], {searchRequest.Error.message}");
            }

            var buildPipelineLatestVersion = searchRequest.Result[0].versions.latestCompatible;

            bool makingChanges          = false;
            bool latestVersionInstalled = false;

            foreach (var package in listRequest.Result)
            {
                if (package.name == "com.unity.textmeshpro")
                {
                    Debug.ClearDeveloperConsole();
                    Debug.Log("Removing Text Mesh Pro package, since WeaverCore provides a version that is compatible with Hollow Knight");
                    makingChanges = true;
                    PackageClient.Remove(package.name);
                    //Break - since we can only do one request at a time
                    break;
                }
                else if (package.name == "com.unity.scriptablebuildpipeline")
                {
                    //If it isn't the latest compatible version
                    if (package.version != buildPipelineLatestVersion)
                    {
                        Debug.ClearDeveloperConsole();
                        Debug.Log($"Updating the Scriptable Build Pipeline from [{package.version}] -> [{buildPipelineLatestVersion}]");
                        PackageClient.Remove(package.name);
                        makingChanges = true;
                        //Break - since we can only do one request at a time
                        break;
                    }
                    else
                    {
                        latestVersionInstalled = true;
                    }
                }
            }

            if (!makingChanges && !latestVersionInstalled)
            {
                PackageClient.Add("com.unity.scriptablebuildpipeline@" + buildPipelineLatestVersion);
                makingChanges = true;
            }

            if (!makingChanges)
            {
                if (PlayerSettings.GetApiCompatibilityLevel(BuildTargetGroup.Standalone) != ApiCompatibilityLevel.NET_4_6)
                {
                    PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Standalone, ApiCompatibilityLevel.NET_4_6);
                }
            }


            IEnumerator WaitForRequest <T>(Request <T> request) => new WaitUntil(() => request.IsCompleted);
        }