|
| 1 | +using System.IO; |
| 2 | +using UnityEditor.PackageManager; |
1 | 3 | using UnityEngine;
|
| 4 | +using UnityEngine.Assertions; |
2 | 5 | using UnityEngine.Rendering;
|
3 | 6 |
|
4 | 7 | namespace UnityEditor.Rendering
|
@@ -153,7 +156,13 @@ public override void OnInspectorGUI()
|
153 | 156 | // Duplicate the currently assigned profile and save it as a new profile
|
154 | 157 | var origin = profileRef;
|
155 | 158 | var path = AssetDatabase.GetAssetPath(m_Profile.objectReferenceValue);
|
156 |
| - path = AssetDatabase.GenerateUniqueAssetPath(path); |
| 159 | + |
| 160 | + path = IsAssetInReadOnlyPackage(path) |
| 161 | + // We may be in a read only package, in that case we need to clone the volume profile in an |
| 162 | + // editable area, such as the root of the project. |
| 163 | + ? AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", Path.GetFileName(path))) |
| 164 | + // Otherwise, duplicate next to original asset. |
| 165 | + : AssetDatabase.GenerateUniqueAssetPath(path); |
157 | 166 |
|
158 | 167 | var asset = Instantiate(origin);
|
159 | 168 | asset.components.Clear();
|
@@ -202,5 +211,12 @@ public override void OnInspectorGUI()
|
202 | 211 |
|
203 | 212 | serializedObject.ApplyModifiedProperties();
|
204 | 213 | }
|
| 214 | + |
| 215 | + static bool IsAssetInReadOnlyPackage(string path) |
| 216 | + { |
| 217 | + Assert.IsNotNull(path); |
| 218 | + var info = PackageManager.PackageInfo.FindForAssetPath(path); |
| 219 | + return info != null && (info.source != PackageSource.Local && info.source != PackageSource.Embedded); |
| 220 | + } |
205 | 221 | }
|
206 | 222 | }
|
0 commit comments