-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Diffusion Profile and Material references in HDRP materials are now c…
…orrectly exported to unity packages. (#136) * Added external references inside a material to diffusion profiles and materials in order to handle Material export to a package correctly. * Update changelog * Removed useless test * Updated changelog message to add more info
- Loading branch information
1 parent
3b168b4
commit 7c3662d
Showing
8 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
com.unity.render-pipelines.high-definition/Editor/Material/MaterialExternalReferences.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using UnityEngine; | ||
using UnityEngine.Rendering.HighDefinition; | ||
|
||
namespace UnityEditor.Rendering.HighDefinition | ||
{ | ||
// This class only purpose is to be used as a sub-asset to a material and store references to other assets. | ||
// The goal is to be able to export the material as a package and not miss those referenced assets. | ||
class MaterialExternalReferences : ScriptableObject | ||
{ | ||
[SerializeField] | ||
DiffusionProfileSettings[] m_DiffusionProfileReferences = new DiffusionProfileSettings[0]; | ||
[SerializeField] | ||
Material[] m_MaterialReferences = new Material[0]; | ||
|
||
public void SetDiffusionProfileReference(int index, DiffusionProfileSettings profile) | ||
{ | ||
if (index >= m_DiffusionProfileReferences.Length) | ||
{ | ||
var newList = new DiffusionProfileSettings[index + 1]; | ||
for (int i = 0; i < m_DiffusionProfileReferences.Length; ++i) | ||
newList[i] = m_DiffusionProfileReferences[i]; | ||
|
||
m_DiffusionProfileReferences = newList; | ||
} | ||
|
||
m_DiffusionProfileReferences[index] = profile; | ||
EditorUtility.SetDirty(this); | ||
} | ||
|
||
public void SetMaterialReference(int index, Material mat) | ||
{ | ||
if (index >= m_MaterialReferences.Length) | ||
{ | ||
var newList = new Material[index + 1]; | ||
for (int i = 0; i < m_MaterialReferences.Length; ++i) | ||
newList[i] = m_MaterialReferences[i]; | ||
|
||
m_MaterialReferences = newList; | ||
} | ||
|
||
m_MaterialReferences[index] = mat; | ||
EditorUtility.SetDirty(this); | ||
} | ||
|
||
public static MaterialExternalReferences GetMaterialExternalReferences(Material material) | ||
{ | ||
var subAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(material)); | ||
MaterialExternalReferences matExternalRefs = null; | ||
foreach (var subAsset in subAssets) | ||
{ | ||
if (subAsset.GetType() == typeof(MaterialExternalReferences)) | ||
{ | ||
matExternalRefs = subAsset as MaterialExternalReferences; | ||
break; | ||
} | ||
} | ||
|
||
if (matExternalRefs == null) | ||
{ | ||
matExternalRefs = CreateInstance<MaterialExternalReferences>(); | ||
matExternalRefs.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable; | ||
AssetDatabase.AddObjectToAsset(matExternalRefs, material); | ||
EditorUtility.SetDirty(matExternalRefs); | ||
EditorUtility.SetDirty(material); | ||
} | ||
|
||
return matExternalRefs; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...unity.render-pipelines.high-definition/Editor/Material/MaterialExternalReferences.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters