void CreatePackageForExampleMaterials()
    {
        // Check if examples folder is "Assets/MeshBaker/Examples"
        // Get all materials in examples.
        string unityPackageFilename;
        string examplesPathRelative = GetRelativeExamplesPath();

        if (examplesPathRelative == null)
        {
            Debug.LogError("Cannot package example materials as no Mesh Baker Example scenes were found. Renaming example scenes may cause this error.");
            return;
        }

        MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();
        if (pipelineType == MBVersion.PipelineType.Default)
        {
            unityPackageFilename = examplesPathRelative + "/Examples_Default.unitypackage";
        }
        else if (pipelineType == MBVersion.PipelineType.HDRP)
        {
            unityPackageFilename = examplesPathRelative + "/Examples_HDRP.unitypackage";
        }
        else if (pipelineType == MBVersion.PipelineType.URP)
        {
            unityPackageFilename = examplesPathRelative + "/Examples_URP.unitypackage";
        }
        else
        {
            Debug.LogError("Unknown pipeline type.");
            return;
        }

        string[]      matGIDs            = AssetDatabase.FindAssets("t:Material", new string[] { examplesPathRelative });
        string[]      assetPathNames     = new string[matGIDs.Length];
        List <string> assetPathNamesList = new List <string>();

        for (int i = 0; i < matGIDs.Length; i++)
        {
            string path = AssetDatabase.GUIDToAssetPath(matGIDs[i]);
            if (!path.Contains("SceneBasicTextureArrayAssets") && !path.EndsWith(".fbx")) // don't do texture array assets.
            {
                assetPathNamesList.Add(path);
                // Debug.Log(path);
            }
        }
        assetPathNames = assetPathNamesList.ToArray();

        Debug.Log("Found " + assetPathNames.Length + " materials in " + examplesPathRelative);

        AssetDatabase.ExportPackage(assetPathNames, unityPackageFilename);

        Debug.Log("Create Unity Package: " + unityPackageFilename);
    }
    public string GetShaderNameForPipeline()
    {
        if (MBVersion.DetectPipeline() == MBVersion.PipelineType.URP)
        {
            return("Universal Render Pipeline/Lit");
        }
        else if (MBVersion.DetectPipeline() == MBVersion.PipelineType.HDRP)
        {
            return("HDRP/Lit");
        }

        return("Diffuse");
    }
        public static string ValidatePlayerSettingsDefineSymbols()
        {
            // Check that the needed defines exist or are present when they should not be.
            MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();
            BuildTargetGroup       targetGroup  = EditorUserBuildSettings.selectedBuildTargetGroup;
            string scriptDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);

            string s = "";

            if (pipelineType == MBVersion.PipelineType.HDRP)
            {
                if (!scriptDefines.Contains(MBVersion.MB_USING_HDRP))
                {
                    s += "The GraphicsSettings -> Render Pipeline Asset is configured to use HDRP. Please add 'MB_USING_HDRP' to PlayerSettings -> Scripting Define Symbols for all the build platforms " +
                         " that you are targeting. If there are compile errors check that the MeshBakerCore.asmdef file has references for:\n\n" +
                         "   Unity.RenderPipelines.HighDefinition.Runtime\n" +
                         "   Unity.RenderPipelines.HighDefinition.Config.Runtime (Unity 2019.3+)\n";
                }

                /*
                 * Type tp = Type.GetType("UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData");
                 * if (tp == null)
                 * {
                 *  s += "The class 'HDAdditionalCameraData' cannot be found by the MeshBaker assembly. Ensure that the following assemblies are referenced by the MeshBaker.asmdef file: \n" +
                 *      "    Unity.RenderPipelines.HighDefinition.Runtime\n" +
                 *      "    Unity.RenderPipelines.HighDefinition.Config.Runtime (Unity 2019.3+)\n\n"+
                 *      "Or download the HDRP version of the package from the asset store.";
                 * }
                 */
            }
            else
            {
                if (scriptDefines.Contains(MBVersion.MB_USING_HDRP))
                {
                    s += "Please remove 'MB_USING_HDRP' from PlayerSettings -> Scripting Define Symbols for the current build platform. If this define is present there may be compile errors because Mesh Baker tries to access classes which only exist in the HDRP API.";
                }
            }

            if (s.Length > 0)
            {
                return(s);
            }
            else
            {
                return(null);
            }
        }
    void Start()
    {
#if UNITY_2018_4_OR_NEWER
        MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();
        int materialPipeline = GetMaterialPipelineType();
        // Do not prompt if example materials cannot be found, are using an unsupported shader, or are already suitable for the current pipeline
        if (materialPipeline != -1 && pipelineType != (MBVersion.PipelineType)materialPipeline)
        {
            if (pipelineType != MBVersion.PipelineType.Unsupported)
            {
                bool convert = EditorUtility.DisplayDialog(
                    "Different Pipline Detected",
                    "Would you like to try converting the default Mesh Baker example scene materials to suit the " + pipelineType + " pipeline?",
                    "Yes",
                    "No");

                if (convert)
                {
                    MigrateMaterials();
                    if (pipelineType == MBVersion.PipelineType.HDRP)
                    {
                        Debug.LogWarning("If the Mesh Baker Example Scenes appear dark, try adding an Empty GameObject to the scene, adding a 'Volume' component to it, and assigning that volume one of the default profiles.");
                    }
                }
            }
            else
            {
                Debug.LogWarning("Mesh Baker's example scenes only support the Default Pipeline, URP, and HDRP.");
            }
        }
#endif
#if !MB_ALLOW_ADD_MIGRATE_MAT_SCRIPT
        // Add the MB_ALLOW_ADD_MIGRATE_MAT_SCRIPT to script defines to add this to scenes.
        DestroyImmediate(this.gameObject);
#endif
    }
    void MigrateMaterials()
    {
        HashSet <string> shaderNames = new HashSet <string>();

        string examplesPathRelative = GetRelativeExamplesPath();

        if (examplesPathRelative == null)
        {
            Debug.LogError("Cannot convert example materials as no Mesh Baker Example scenes were found. Renaming example scenes may cause this error.");
            return;
        }

        Debug.Log("Found Mesh Baker Examples at: " + examplesPathRelative);

        MBVersion.PipelineType pipelineType = MBVersion.DetectPipeline();

        Material[] mats;
        {
            string[]        matGIDs = AssetDatabase.FindAssets("t:Material", new string[] { examplesPathRelative });
            List <Material> matList = new List <Material>();
            for (int i = 0; i < matGIDs.Length; i++)
            {
                string path = AssetDatabase.GUIDToAssetPath(matGIDs[i]);
                if (!path.Contains("SceneBasicTextureArrayAssets") && !path.EndsWith(".fbx")) // don't do texture array assets.
                {
                    matList.Add(AssetDatabase.LoadAssetAtPath <Material>(path));
                    string shaderName = matList[matList.Count - 1].shader.name;
                    shaderNames.Add(shaderName);

                    if (MapDefault2OtherShader(shaderName, pipelineType) == null)
                    {
                        Debug.LogError("Could not find mapping for shader " + shaderName + " in mat " + path);
                        return;
                    }
                }
            }
            mats = matList.ToArray();
        }

        string nn = "";

        foreach (string n in shaderNames)
        {
            if (MapDefault2OtherShader(n, pipelineType) == null)
            {
                Debug.LogError("Could not find mapping for shader " + n);
                return;
            }

            nn += "'" + n + "' will map to '" + MapDefault2OtherShader(n, pipelineType) + "',\n";
        }

        Debug.Log(examplesPathRelative + " Found Mats: " + mats.Length + " Shaders Found " + nn);
        for (int i = 0; i < mats.Length; i++)
        {
            Material m = mats[i];
            RemapTextures_Default2OtherPipeline(m, pipelineType);
            EditorUtility.SetDirty(m);
        }

        AssetDatabase.SaveAssets();
    }