diff --git a/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_AssetUpdater.cs b/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_AssetUpdater.cs
index e66bfb88..d4c16591 100644
--- a/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_AssetUpdater.cs
+++ b/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_AssetUpdater.cs
@@ -74,6 +74,8 @@ static HEU_AssetUpdater( ) {
}
static void OnBeforeAssemblyReload( ) {
+ HEU_Logger.Log( $"{nameof(HEU_AssetUpdater)}.{nameof(OnBeforeAssemblyReload)} :: " +
+ $"Rebuilding assemblies ..." ) ;
// Save the session before code domain reload so
// that the session file has the latest session state.
HEU_SessionManager.SaveAllSessionData( ) ;
diff --git a/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_HoudiniAssetRoot.cs b/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_HoudiniAssetRoot.cs
index 4d310d01..7a186d65 100644
--- a/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_HoudiniAssetRoot.cs
+++ b/Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_HoudiniAssetRoot.cs
@@ -36,27 +36,32 @@
[assembly: InternalsVisibleTo("HoudiniEngineUnityPlayModeTests")]
#endif
-namespace HoudiniEngineUnity
-{
+namespace HoudiniEngineUnity {
+
///
/// The root object of a Houdini Engine asset.
/// Used for organizing hierarchy, and more importantly displaying custom UI.
///
- [SelectionBase]
- [ExecuteInEditMode] // Needed to get OnDestroy callback when deleted in Editor
+ [SelectionBase, ExecuteInEditMode]
public class HEU_HoudiniAssetRoot: MonoBehaviour {
+ static readonly HashSet< HEU_HoudiniAssetRoot > _allRootAssets = new( ) ;
+
// Reference to the actual Houdini Engine asset gamebobject which contains
// all the data and logic to work with Houdini Engine
- [SerializeField] internal HEU_HoudiniAsset _houdiniAsset ;
- public HEU_HoudiniAsset HoudiniAsset => _houdiniAsset ;
+ [SerializeField] internal HEU_HoudiniAsset? _houdiniAsset ;
+ public HEU_HoudiniAsset? HoudiniAsset => _houdiniAsset ;
[SerializeField] internal List< GameObject > _bakeTargets = new( ) ;
public List< GameObject > BakeTargets => _bakeTargets ;
+
+ void OnEnable( ) => _allRootAssets.Add( this ) ;
+
/// Callback when asset is deleted. Removes assset from Houdini session if in Editor.
void OnDestroy( ) {
- if ( _houdiniAsset && _houdiniAsset.PauseCooking ) return ;
-
+ _allRootAssets.Remove( this ) ;
+ if ( _houdiniAsset && _houdiniAsset!.PauseCooking ) return ;
+
// Destroy the asset from session or permanently.
// The following checks make sure to only delete if the scene is closing,
// or asset has been user deleted.
@@ -66,7 +71,7 @@ void OnDestroy( ) {
// Delete mesh data if this asset hasn't been saved and it is a user invoked delete event.
// Otherwise just remove from session.
// TODO: for saved assets, we need to handle case where user deletes but does not save scene after
- if ( !_houdiniAsset.IsAssetSavedInScene( ) &&
+ if ( !_houdiniAsset!.IsAssetSavedInScene( ) &&
( Event.current != null && ( Event.current.commandName.Equals( "Delete" ) ||
Event.current.commandName.Equals( "SoftDelete" ) ) ) ) {
_houdiniAsset.DeleteAssetCacheData( bRegisterUndo: true ) ;
@@ -94,7 +99,7 @@ internal void RemoveHoudiniEngineAssetData( ) {
// No need to destroy the object, geo nodes, and parts
// since Unity's GC will handle them.
- GameObject tempGO = _houdiniAsset.gameObject ;
+ GameObject tempGO = _houdiniAsset!.gameObject ;
_houdiniAsset = null ;
HEU_GeneralUtility.DestroyImmediate( tempGO, bRegisterUndo: true ) ;
}
@@ -109,7 +114,7 @@ internal void ClearHoudiniEngineReferences( ) {
_bakeTargets.Clear( ) ;
}
- internal static void DestroyRootComponent( HEU_HoudiniAssetRoot assetRoot ) =>
+ internal static void DestroyRootComponent( HEU_HoudiniAssetRoot assetRoot ) =>
HEU_GeneralUtility.DestroyImmediate( assetRoot, bRegisterUndo: true ) ;
internal void Reset( ) {
@@ -125,7 +130,6 @@ internal void Reset( ) {
_houdiniAsset!.RequestResetParameters( false ) ;
}
}
- }
-
-
-} // HoudiniEngineUnity
\ No newline at end of file
+
+ } ;
+} // HoudiniEngineUnity
diff --git a/Plugins/HoudiniEngineUnity/Scripts/HEU_HoudiniVersion.cs.meta b/Plugins/HoudiniEngineUnity/Scripts/HEU_HoudiniVersion.cs.meta
index ed59cdad..7d327297 100644
--- a/Plugins/HoudiniEngineUnity/Scripts/HEU_HoudiniVersion.cs.meta
+++ b/Plugins/HoudiniEngineUnity/Scripts/HEU_HoudiniVersion.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 505f0a2512985c34eaa1446c37661e2e
+guid: 7071d44f8837c5d428c9c22b5acb8d08
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Plugins/HoudiniEngineUnity/Scripts/Render/HEU_MaterialData.cs b/Plugins/HoudiniEngineUnity/Scripts/Render/HEU_MaterialData.cs
index ef6ee405..3f53afc2 100644
--- a/Plugins/HoudiniEngineUnity/Scripts/Render/HEU_MaterialData.cs
+++ b/Plugins/HoudiniEngineUnity/Scripts/Render/HEU_MaterialData.cs
@@ -74,7 +74,7 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
HEU_SessionBase session = HEU_SessionManager.GetOrCreateDefaultSession( ) ;
- HAPI_NodeInfo nodeInfo = new HAPI_NodeInfo( ) ;
+ HAPI_NodeInfo nodeInfo = new( ) ;
if ( !session.GetNodeInfo( materialInfo.nodeId, ref nodeInfo ) ) {
return false ;
}
@@ -123,17 +123,15 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
false ) ;
}
- Color diffuseColor ;
if ( !HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_OGL_DIFF_ATTR, Color.white,
- out diffuseColor ) ) {
+ out Color diffuseColor ) ) {
HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_DIFF_ATTR, Color.white,
out diffuseColor ) ;
}
- float alpha ;
- GetMaterialAlpha( session, materialInfo.nodeId, parmInfos, 1f, out alpha ) ;
+ GetMaterialAlpha( session, materialInfo.nodeId, parmInfos, 1f, out float alpha ) ;
if ( isTransparent ) {
int opacityMapParmIndex =
@@ -162,11 +160,10 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
_material.SetColor( HEU_Defines.UNITY_SHADER_COLOR, diffuseColor ) ;
if ( HEU_PluginSettings.UseSpecularShader ) {
- Color specular ;
- Color defaultSpecular = new Color( 0.2f, 0.2f, 0.2f, 1 ) ;
+ Color defaultSpecular = new( 0.2f, 0.2f, 0.2f, 1 ) ;
if ( !HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_OGL_SPEC_ATTR, defaultSpecular,
- out specular ) ) {
+ out Color specular ) ) {
HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_SPEC_ATTR, defaultSpecular,
out specular ) ;
@@ -196,10 +193,9 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
}
}
else {
- float metallic = 0 ;
if ( !HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_OGL_METALLIC_ATTR, 0f,
- out metallic ) ) {
+ out float metallic ) ) {
HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_METALLIC_ATTR, 0f, out metallic ) ;
}
@@ -218,7 +214,7 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
}
- if ( metallicMapParmIndex >= 0 && metallicMapParmIndex < parmInfos.Length ) {
+ if ( metallicMapParmIndex > -1 && metallicMapParmIndex < parmInfos.Length ) {
string metallicTextureFileName =
GetTextureFileNameFromMaterialParam( session, materialInfo.nodeId,
parmInfos[ metallicMapParmIndex ] ) ;
@@ -255,11 +251,10 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
}
// Emission
- Color emission ;
- Color defaultEmission = new Color( 0, 0, 0, 0 ) ;
+ Color defaultEmission = new( 0, 0, 0, 0 ) ;
if ( !HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_OGL_EMISSIVE_ATTR, defaultEmission,
- out emission ) ) {
+ out Color emission ) ) {
HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_EMISSIVE_ATTR, defaultEmission,
out emission ) ;
@@ -289,11 +284,10 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
}
// Smoothness (need to invert roughness!)
- float roughness ;
float defaultRoughness = 0.5f ;
if ( !HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_OGL_ROUGH_ATTR, defaultRoughness,
- out roughness ) ) {
+ out float roughness ) ) {
HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_ROUGH_ATTR, defaultRoughness,
out roughness ) ;
@@ -313,7 +307,7 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
HEU_Defines.MAT_ROUGH_MAP_ATTR_ENABLED ) ;
}
- if ( roughMapParmIndex >= 0 && roughMapParmIndex < parmInfos.Length ) {
+ if ( roughMapParmIndex > -1 && roughMapParmIndex < parmInfos.Length ) {
string roughTextureFileName =
GetTextureFileNameFromMaterialParam( session, materialInfo.nodeId,
parmInfos[ roughMapParmIndex ] ) ;
@@ -345,9 +339,7 @@ public bool UpdateMaterialFromHoudini( HAPI_MaterialInfo materialInfo, string as
///
/// Returns true if this material was pre-existing in Unity and not generated from Houdini at cook time.
///
- public bool IsExistingMaterial( ) {
- return _materialSource == Source.UNITY || _materialSource == Source.SUBSTANCE ;
- }
+ public bool IsExistingMaterial( ) => _materialSource is Source.UNITY or Source.SUBSTANCE ;
// ===============================================================
@@ -367,8 +359,8 @@ public bool IsExistingMaterial( ) {
// the hash of the material path on project (eg. Assets/Materials/materialname.mat)
[SerializeField] internal int _materialKey = HEU_Defines.HEU_INVALID_MATERIAL ;
- bool UseLegacyShaders( HAPI_MaterialInfo materialInfo, string assetCacheFolderPath,
- HEU_SessionBase session, HAPI_NodeInfo nodeInfo, HAPI_ParmInfo[] parmInfos ) {
+ bool UseLegacyShaders( HAPI_MaterialInfo materialInfo, string assetCacheFolderPath,
+ HEU_SessionBase session, HAPI_NodeInfo nodeInfo, HAPI_ParmInfo[] parmInfos ) {
// Diffuse texture - render & extract
int diffuseMapParmIndex =
HEU_ParameterUtility.FindTextureParamByNameOrTag( session, nodeInfo.id, parmInfos,
@@ -426,27 +418,24 @@ bool UseLegacyShaders( HAPI_MaterialInfo materialInfo, string assetCacheF
// Clamp shininess to non-zero as results in very hard shadows. Unity's UI does not allow zero either.
- float shininess ;
if ( !HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
- HEU_Defines.MAT_OGL_ROUGH_ATTR, 0f, out shininess ) ) {
+ HEU_Defines.MAT_OGL_ROUGH_ATTR, 0f, out float shininess ) ) {
HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_ROUGH_ATTR, 0f, out shininess ) ;
}
_material.SetFloat( HEU_Defines.UNITY_SHADER_SHININESS, Mathf.Max( 0.03f, 1.0f - shininess ) ) ;
- Color diffuseColor ;
if ( !HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_OGL_DIFF_ATTR, Color.white,
- out diffuseColor ) ) {
+ out Color diffuseColor ) ) {
HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_DIFF_ATTR, Color.white,
out diffuseColor ) ;
}
- float alpha ;
if ( !HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
- HEU_Defines.MAT_OGL_ALPHA_ATTR, 1f, out alpha ) ) {
+ HEU_Defines.MAT_OGL_ALPHA_ATTR, 1f, out float alpha ) ) {
HEU_ParameterUtility.GetParameterFloatValue( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_ALPHA_ATTR, 1f, out alpha ) ;
}
@@ -454,10 +443,9 @@ bool UseLegacyShaders( HAPI_MaterialInfo materialInfo, string assetCacheF
diffuseColor.a = alpha ;
_material.SetColor( HEU_Defines.UNITY_SHADER_COLOR, diffuseColor ) ;
- Color specular ;
if ( !HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_OGL_SPEC_ATTR, Color.black,
- out specular ) ) {
+ out Color specular ) ) {
HEU_ParameterUtility.GetParameterColor3Value( session, materialInfo.nodeId, parmInfos,
HEU_Defines.MAT_SPEC_ATTR, Color.black, out specular ) ;
}
@@ -525,8 +513,7 @@ internal static string GetTextureFileNameFromMaterialParam( HEU_SessionBase sess
/// True if the material is transparent
internal static bool IsTransparentMaterial( HEU_SessionBase session, HAPI_NodeId nodeID,
HAPI_ParmInfo[ ] parameters ) {
- float alpha ;
- GetMaterialAlpha( session, nodeID, parameters, 1, out alpha ) ;
+ GetMaterialAlpha( session, nodeID, parameters, 1, out float alpha ) ;
return alpha < 0.95f ;
}
diff --git a/Plugins/HoudiniEngineUnity/Scripts/Utility/HEU_RenderingPipelineDefines.cs b/Plugins/HoudiniEngineUnity/Scripts/Utility/HEU_RenderingPipelineDefines.cs
index 98694088..9791de48 100644
--- a/Plugins/HoudiniEngineUnity/Scripts/Utility/HEU_RenderingPipelineDefines.cs
+++ b/Plugins/HoudiniEngineUnity/Scripts/Utility/HEU_RenderingPipelineDefines.cs
@@ -1,181 +1,181 @@
-/*
- * Copyright (c) <2020> Side Effects Software Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. The name of Side Effects Software may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using UnityEngine;
-using UnityEngine.Rendering;
-
-
-#if UNITY_EDITOR
-using UnityEditor;
-#endif
-
-namespace HoudiniEngineUnity
-{
-// Helper written by: https://gist.github.com/cjaube/944b0d5221808c2a761d616f29deaf49
-
-// To use:
-// #if UNITY_PIPELINE_URP
-// // code for URP
-// #elif UNITY_PIPELINE_HDRP
-// // code for HDRP
-// #else
-// // code for Stardard Pipeline
-// #endif
-
- public enum HEU_PipelineType
- {
- Unsupported,
- BiRP,
- URP,
- HDRP
- }
-
-#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED
- [InitializeOnLoad]
-#endif
- public class HEU_RenderingPipelineDefines
- {
- static HEU_RenderingPipelineDefines()
- {
- UpdateDefines();
- }
-
- ///
- /// Update the unity pipeline defines for URP
- ///
- private static void UpdateDefines()
- {
- var pipeline = GetPipeline();
-
- if (pipeline == HEU_PipelineType.URP)
- {
- AddDefine("UNITY_PIPELINE_URP");
- }
- else
- {
- RemoveDefine("UNITY_PIPELINE_URP");
- }
-
- if (pipeline == HEU_PipelineType.HDRP)
- {
- AddDefine("UNITY_PIPELINE_HDRP");
- }
- else
- {
- RemoveDefine("UNITY_PIPELINE_HDRP");
- }
- }
-
-
- ///
- /// Returns the type of renderpipeline that is currently running
- ///
- ///
- public static HEU_PipelineType GetPipeline()
- {
-#if UNITY_2019_1_OR_NEWER
- if (GraphicsSettings.renderPipelineAsset != null)
- {
- // SRP
- var srpType = GraphicsSettings.renderPipelineAsset.GetType().ToString();
- if (srpType.Contains("HDRenderPipelineAsset"))
- {
- return HEU_PipelineType.HDRP;
- }
- else if (srpType.Contains("UniversalRenderPipelineAsset") ||
- srpType.Contains("LightweightRenderPipelineAsset"))
- {
- return HEU_PipelineType.URP;
- }
- else return HEU_PipelineType.Unsupported;
- }
-#elif UNITY_2017_1_OR_NEWER
- if (GraphicsSettings.renderPipelineAsset != null) {
- // SRP not supported before 2019
- return HEU_PipelineType.Unsupported;
- }
-#endif
- // no SRP
- return HEU_PipelineType.BiRP;
- }
-
- ///
- /// Add a custom define
- ///
- ///
- ///
- private static void AddDefine(string define)
- {
- var definesList = GetDefines();
- if (!definesList.Contains(define))
- {
- definesList.Add(define);
- SetDefines(definesList);
- }
- }
-
- ///
- /// Remove a custom define
- ///
- ///
- ///
- public static void RemoveDefine(string define)
- {
- var definesList = GetDefines();
- if (definesList.Contains(define))
- {
- definesList.Remove(define);
- SetDefines(definesList);
- }
- }
-
- public static List GetDefines()
- {
-#if UNITY_EDITOR
- var target = EditorUserBuildSettings.activeBuildTarget;
- var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);
- var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);
- return defines.Split(';').ToList();
-#else
- return new List();
-#endif
- }
-
- public static void SetDefines(List definesList)
- {
-#if UNITY_EDITOR
- var target = EditorUserBuildSettings.activeBuildTarget;
- var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);
- var defines = string.Join(";", definesList.ToArray());
- PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines);
-#endif
- }
- }
+/*
+ * Copyright (c) <2020> Side Effects Software Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. The name of Side Effects Software may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+
+#if UNITY_EDITOR
+using UnityEditor;
+#endif
+
+namespace HoudiniEngineUnity
+{
+// Helper written by: https://gist.github.com/cjaube/944b0d5221808c2a761d616f29deaf49
+
+// To use:
+// #if UNITY_PIPELINE_URP
+// // code for URP
+// #elif UNITY_PIPELINE_HDRP
+// // code for HDRP
+// #else
+// // code for Stardard Pipeline
+// #endif
+
+ public enum HEU_PipelineType
+ {
+ Unsupported,
+ BiRP,
+ URP,
+ HDRP
+ }
+
+#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED
+ [InitializeOnLoad]
+#endif
+ public class HEU_RenderingPipelineDefines
+ {
+ static HEU_RenderingPipelineDefines()
+ {
+ UpdateDefines();
+ }
+
+ ///
+ /// Update the unity pipeline defines for URP
+ ///
+ private static void UpdateDefines()
+ {
+ var pipeline = GetPipeline();
+
+ if (pipeline == HEU_PipelineType.URP)
+ {
+ AddDefine("UNITY_PIPELINE_URP");
+ }
+ else
+ {
+ RemoveDefine("UNITY_PIPELINE_URP");
+ }
+
+ if (pipeline == HEU_PipelineType.HDRP)
+ {
+ AddDefine("UNITY_PIPELINE_HDRP");
+ }
+ else
+ {
+ RemoveDefine("UNITY_PIPELINE_HDRP");
+ }
+ }
+
+
+ ///
+ /// Returns the type of renderpipeline that is currently running
+ ///
+ ///
+ public static HEU_PipelineType GetPipeline()
+ {
+#if UNITY_2019_1_OR_NEWER
+ if (GraphicsSettings.renderPipelineAsset != null)
+ {
+ // SRP
+ var srpType = GraphicsSettings.renderPipelineAsset.GetType().ToString();
+ if (srpType.Contains("HDRenderPipelineAsset"))
+ {
+ return HEU_PipelineType.HDRP;
+ }
+ else if (srpType.Contains("UniversalRenderPipelineAsset") ||
+ srpType.Contains("LightweightRenderPipelineAsset"))
+ {
+ return HEU_PipelineType.URP;
+ }
+ else return HEU_PipelineType.Unsupported;
+ }
+#elif UNITY_2017_1_OR_NEWER
+ if (GraphicsSettings.renderPipelineAsset != null) {
+ // SRP not supported before 2019
+ return HEU_PipelineType.Unsupported;
+ }
+#endif
+ // no SRP
+ return HEU_PipelineType.BiRP;
+ }
+
+ ///
+ /// Add a custom define
+ ///
+ ///
+ ///
+ private static void AddDefine(string define)
+ {
+ var definesList = GetDefines();
+ if (!definesList.Contains(define))
+ {
+ definesList.Add(define);
+ SetDefines(definesList);
+ }
+ }
+
+ ///
+ /// Remove a custom define
+ ///
+ ///
+ ///
+ public static void RemoveDefine(string define)
+ {
+ var definesList = GetDefines();
+ if (definesList.Contains(define))
+ {
+ definesList.Remove(define);
+ SetDefines(definesList);
+ }
+ }
+
+ public static List GetDefines()
+ {
+#if UNITY_EDITOR
+ var target = EditorUserBuildSettings.activeBuildTarget;
+ var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);
+ var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);
+ return defines.Split(';').ToList();
+#else
+ return new List();
+#endif
+ }
+
+ public static void SetDefines(List definesList)
+ {
+#if UNITY_EDITOR
+ var target = EditorUserBuildSettings.activeBuildTarget;
+ var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);
+ var defines = string.Join(";", definesList.ToArray());
+ PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines);
+#endif
+ }
+ }
}
\ No newline at end of file