/// <summary> /// Loads the asset using <see cref="PackagePath.ExtensionSourcesAssetPath"/>. /// Will create the asset if it doesn't exist. /// </summary> public static ExtensionSources Load() { var assetPath = PackagePath.ExtensionSourcesAssetPath; var relativeAssetPath = PackagePath.ToAssetsPath(assetPath); if (!File.Exists(assetPath)) { var extensionSources = CreateInstance <ExtensionSources>(); PackagePath.CreateDirectoryAsset(Path.GetDirectoryName(assetPath)); AssetDatabase.CreateAsset(extensionSources, relativeAssetPath); AssetDatabase.SaveAssets(); return(extensionSources); } else { return(AssetDatabase.LoadAssetAtPath <ExtensionSources>(relativeAssetPath)); } }
/// <summary> /// Adds references to all the currently installed shader extensions to the <see cref="ShaderResources"/> asset. /// Will create the resources asset if it doesn't exist. /// </summary> public static void UpdateShaderResources() { ShaderResources resources; if (!File.Exists(PackagePath.ShaderResourcesAssetPath)) { resources = ScriptableObject.CreateInstance <ShaderResources>(); PackagePath.CreateDirectoryAsset(Path.GetDirectoryName(PackagePath.ShaderResourcesAssetPath)); AssetDatabase.CreateAsset(resources, PackagePath.ToAssetsPath(PackagePath.ShaderResourcesAssetPath)); AssetDatabase.SaveAssets(); } else { resources = ShaderResources.Load(); } resources.RemoveAllShaders(); var shaderPaths = Directory.GetFiles(PackagePath.ShaderExtensionsPath, "*.shader", SearchOption.AllDirectories).ToList(); foreach (var additionalPath in resources.GetAdditionalPaths()) { var fullPath = Path.GetFullPath(additionalPath); if (!Directory.Exists(fullPath)) { continue; } shaderPaths.AddRange(Directory.GetFiles(fullPath, "*.shader", SearchOption.AllDirectories)); } foreach (var shaderPath in shaderPaths) { var relativeShaderPath = PackagePath.ToAssetsPath(shaderPath); var shader = AssetDatabase.LoadAssetAtPath <Shader>(relativeShaderPath); if (IsValidShader(shader)) { resources.AddShader(shader); } } EditorUtility.SetDirty(resources); AssetDatabase.SaveAssets(); }