//---------------------------------------------------------------------------------------------------------------------

    static void OnPackageListRequestSuccess(Request <PackageCollection> req)
    {
        //Check if HDRP hasn't been installed and add it if that's the case
        const string HDRP_PACKAGE_NAME = "com.unity.render-pipelines.high-definition";
        PackageInfo  packageInfo       = req.FindPackage(HDRP_PACKAGE_NAME);

        if (null == packageInfo)
        {
            UnityEditor.EditorApplication.LockReloadAssemblies();
            RequestJobManager.CreateAddRequest(HDRP_PACKAGE_NAME, OnHDRPPackageAdded, OnHDRPPackageAddFailed);
        }
        else
        {
            ImportHDRPSample();
        }

        //update json
        RenderStreamingSettings settings = LoadSettings();

        if (null != settings)
        {
            PackageInfo renderStreamingPackageInfo = req.FindPackage("com.unity.renderstreaming");
            if (null != renderStreamingPackageInfo)
            {
                settings.Version = renderStreamingPackageInfo.version;
                SaveSettings(settings);
            }
        }

        //Change the C# file to trigger recompilation next time "Import in project" is pushed again
        File.AppendAllText(m_codePath, System.Environment.NewLine + "//Automatically Modified to trigger recompilation");
        UnityEditor.AssetDatabase.ImportAsset(m_codePath);
    }
//---------------------------------------------------------------------------------------------------------------------

    static void SaveSettings(RenderStreamingSettings settings)
    {
        //Make sure the settings is not set as ReadOnly (might happen when importing sample in older versions of Unity)
        FileAttributes attributes = File.GetAttributes(m_settingsPath);

        if (attributes.HasFlag(FileAttributes.ReadOnly))
        {
            File.SetAttributes(m_settingsPath, attributes & ~FileAttributes.ReadOnly);
        }

        File.WriteAllText(m_settingsPath, JsonUtility.ToJson(settings));
    }
//---------------------------------------------------------------------------------------------------------------------

    public static void TryAddHDRPPackageAndImportSample()
    {
        m_sampleImported = false;

        //Some steps are necessary to "hack" so that Unity will execute this file everytime we click "Import in project"
        //In the package manager UI.
        //1. Import the json to make sure that we are dealing with the new settings
        //2. Change the C# code (this file) a bit to trigger C# compilation, even though the file content is the same
        //3. One additional requirement that the asset must be in the same path as this C# file

        Init();
        RenderStreamingSettings settings = LoadSettings();

        if (null != settings && !string.IsNullOrEmpty(settings.Version))
        {
            m_sampleImported = true;
            return;
        }

        RequestJobManager.CreateListRequest(false, true, OnPackageListRequestSuccess, null);
        UnityEditor.EditorUtility.DisplayProgressBar(PROGRESS_BAR_TITLE, PROGRESS_BAR_INFO, 0.1f);
    }
Ejemplo n.º 4
0
//---------------------------------------------------------------------------------------------------------------------

    static void OnPackageListRequestSuccess(Request <PackageCollection> req)
    {
        UnityEditor.EditorApplication.LockReloadAssemblies();
        ImportLegacyRPSample();
        UnityEditor.EditorApplication.UnlockReloadAssemblies();
        m_sampleImported = true;

        //update json
        RenderStreamingSettings settings = LoadSettings();

        if (null != settings)
        {
            PackageInfo renderStreamingPackageInfo = req.FindPackage("com.unity.renderstreaming");
            if (null != renderStreamingPackageInfo)
            {
                settings.Version = renderStreamingPackageInfo.version;
                SaveSettings(settings);
            }
        }

        //Change the C# file to trigger recompilation next time "Import in project" is pushed again
        File.AppendAllText(m_codePath, System.Environment.NewLine + "//Automatically Modified to trigger recompilation");
        UnityEditor.AssetDatabase.ImportAsset(m_codePath);
    }
//---------------------------------------------------------------------------------------------------------------------

    static void SaveSettings(RenderStreamingSettings settings)
    {
        File.WriteAllText(m_settingsPath, JsonUtility.ToJson(settings));
    }