new GUIStyle ( EditorStyles . foldout )
} ;
public readonly GUIContent materialLayer Text = new GUIContent ( "Material" ) ;
public readonly GUIContent syncButtonText = new GUIContent ( "Re-Synchronize Layers" , "Re-synchronize all layers's properties with the referenced Material " ) ;
public readonly GUIContent syncAllButton Text = new GUIContent ( "Re-Synchronize" , "Re-synchronize all layers material properties with the referenced Materials " ) ;
public readonly GUIContent syncAllButUV ButtonText = new GUIContent ( "Re-Synchronize Without UV Mapping" , "Re-synchronize all but UV Mapping properties with the referenced Materials " ) ;
public readonly GUIContent layersText = new GUIContent ( "Inputs" ) ;
public readonly GUIContent emissiveText = new GUIContent ( "Emissive" ) ;
public readonly GUIContent layerMapMaskText = new GUIContent ( "Layer Mask" , "Layer mask" ) ;
public readonly GUIContent inheritBaseColorText = new GUIContent ( "BaseColor influence" , "Inherit the base color from the base layer." ) ;
public readonly GUIContent heightOffset = new GUIContent ( "Height Offset" , "Offset applied to the height before layering." ) ;
public readonly GUIContent heightTransition = new GUIContent ( "Height Transition" , "Size in world units of the smooth transition between layers." ) ;
public readonly GUIContent materialReferencesText = new GUIContent ( "Material References" ) ;
public StylesLayer ( )
{
{
for ( int i = 0 ; i < layerCount ; + + i )
{
SynchronizeLayerProperties ( material , layers , i ) ;
SynchronizeLayerProperties ( material , layers , i , true ) ;
void SynchronizeAllLayersProperties ( )
void SynchronizeAllLayersProperties ( bool excludeUVMappingProperties )
SynchronizeLayerProperties ( m_MaterialEditor . target as Material , m_MaterialLayers , i ) ;
SynchronizeLayerProperties ( m_MaterialEditor . target as Material , m_MaterialLayers , i , excludeUVMappingProperties ) ;
}
}
static void SynchronizeLayerProperties ( Material material , Material [ ] layers , int layerIndex )
static void SynchronizeLayerProperties ( Material material , Material [ ] layers , int layerIndex , bool excludeUVMappingProperties )
string [ ] exclusionList = { kTexWorldScale , kUVBase , kUVMappingMask , kUVDetail , kUVDetailsMappingMask } ;
if ( layerMaterial ! = null )
{
{
string propertyName = ShaderUtil . GetPropertyName ( layerShader , i ) ;
string layerPropertyName = propertyName + layerIndex ;
if ( material . HasProperty ( layerPropertyName ) )
if ( ! exclusionList . Contains ( propertyName ) | | ! excludeUVMappingProperties )
ShaderUtil . ShaderPropertyType type = ShaderUtil . GetPropertyType ( layerShader , i ) ;
switch ( type )
if ( material . HasProperty ( layerPropertyName ) )
case ShaderUtil . ShaderPropertyType . Color :
{
material . SetColor ( layerPropertyName , layerMaterial . GetColor ( propertyName ) ) ;
break ;
}
case ShaderUtil . ShaderPropertyType . Float :
case ShaderUtil . ShaderPropertyType . Range :
{
material . SetFloat ( layerPropertyName , layerMaterial . GetFloat ( propertyName ) ) ;
break ;
}
case ShaderUtil . ShaderPropertyType . Vector :
{
material . SetVector ( layerPropertyName , layerMaterial . GetVector ( propertyName ) ) ;
break ;
}
case ShaderUtil . ShaderPropertyType . TexEnv :
ShaderUtil . ShaderPropertyType type = ShaderUtil . GetPropertyType ( layerShader , i ) ;
switch ( type )
material . SetTexture ( layerPropertyName , layerMaterial . GetTexture ( propertyName ) ) ;
material . SetTextureOffset ( layerPropertyName , layerMaterial . GetTextureOffset ( propertyName ) ) ;
material . SetTextureScale ( layerPropertyName , layerMaterial . GetTextureScale ( propertyName ) ) ;
break ;
case ShaderUtil . ShaderPropertyType . Color :
{
material . SetColor ( layerPropertyName , layerMaterial . GetColor ( propertyName ) ) ;
break ;
}
case ShaderUtil . ShaderPropertyType . Float :
case ShaderUtil . ShaderPropertyType . Range :
{
material . SetFloat ( layerPropertyName , layerMaterial . GetFloat ( propertyName ) ) ;
break ;
}
case ShaderUtil . ShaderPropertyType . Vector :
{
material . SetVector ( layerPropertyName , layerMaterial . GetVector ( propertyName ) ) ;
break ;
}
case ShaderUtil . ShaderPropertyType . TexEnv :
{
material . SetTexture ( layerPropertyName , layerMaterial . GetTexture ( propertyName ) ) ;
if ( ! excludeUVMappingProperties )
{
material . SetTextureOffset ( layerPropertyName , layerMaterial . GetTextureOffset ( propertyName ) ) ;
material . SetTextureScale ( layerPropertyName , layerMaterial . GetTextureScale ( propertyName ) ) ;
}
break ;
}
}
}
}
bool mainLayerInfluenceEnable = useMainLayerInfluence . floatValue > 0.0f ;
bool heightBasedBlend = useHeightBasedBlend . floatValue > 0.0f ;
EditorGUILayout . LabelField ( styles . layeringOptionText , EditorStyles . boldLabel ) ;
// Main layer does not have any options but height base blend.
if ( layerIndex > 0 | | heightBasedBlend )
EditorGUILayout . LabelField ( styles . layeringOptionText , EditorStyles . boldLabel ) ;
EditorGUI . BeginChangeCheck ( ) ;
m_MaterialLayers [ layerIndex ] = EditorGUILayout . ObjectField ( styles . materialLayerText , m_MaterialLayers [ layerIndex ] , typeof ( Material ) , true ) as Material ;
if ( EditorGUI . EndChangeCheck ( ) )
{
Undo . RecordObject ( materialImporter , "Change layer material" ) ;
SynchronizeLayerProperties ( material , m_MaterialLayers , layerIndex ) ;
result = true ;
}
// influence
if ( layerIndex > 0 )
{
}
}
if ( heightBasedBlend )
if ( heightBasedBlend )
{
m_MaterialEditor . ShaderProperty ( heightOffset [ layerIndex ] , styles . heightOffset ) ;
}
}
DoLayerGUI ( material , layerIndex ) ;
if ( layerIndex = = 0 )
}
bool DoLayersGUI ( AssetImporter materialImporter )
{
Material material = m_MaterialEditor . target as Material ;
bool layerChanged = false ;
GUI . changed = false ;
void DoLayeringInputGUI ( )
{
EditorGUI . indentLevel + + ;
GUILayout . Label ( styles . layersText , EditorStyles . boldLabel ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
Material material = m_MaterialEditor . target as Material ;
layerChanged = true ;
}
m_MaterialEditor . TexturePropertySingleLine ( styles . layerMapMaskText , layerMaskMap ) ;
}
m_MaterialEditor . ShaderProperty ( objectScaleAffectTile , mainLayerModeInfluenceEnable ? styles . objectScaleAffectTileText2 : styles . objectScaleAffectTileText ) ;
EditorGUI . indentLevel - - ;
}
EditorGUILayout . Space ( ) ;
bool DoMaterialReferencesGUI ( AssetImporter materialImporter )
{
EditorGUILayout . LabelField ( styles . materialReferencesText , EditorStyles . boldLabel ) ;
EditorGUI . indentLevel + + ;
bool layersChanged = false ;
Material material = m_MaterialEditor . target as Material ;
for ( int i = 0 ; i < numLayer ; i + + )
for ( int layerIndex = 0 ; layerIndex < numLayer ; + + layerIndex )
layerChanged | = DoLayerGUI ( materialImporter , i ) ;
EditorGUI . BeginChangeCheck ( ) ;
m_MaterialLayers [ layerIndex ] = EditorGUILayout . ObjectField ( styles . layerLabels [ layerIndex ] , m_MaterialLayers [ layerIndex ] , typeof ( Material ) , true ) as Material ;
if ( EditorGUI . EndChangeCheck ( ) )
{
Undo . RecordObject ( materialImporter , "Change layer material" ) ;
SynchronizeLayerProperties ( material , m_MaterialLayers , layerIndex , false ) ;
layersChanged = true ;
}
EditorGUILayout . Space ( ) ;
if ( GUILayout . Button ( styles . syncButtonText ) )
if ( GUILayout . Button ( styles . syncAllButUVButtonText ) )
SynchronizeAllLayersProperties ( ) ;
layerChanged = true ;
SynchronizeAllLayersProperties ( true ) ;
layersChanged = true ;
}
if ( GUILayout . Button ( styles . syncAllButtonText ) )
{
SynchronizeAllLayersProperties ( false ) ;
layersChanged = true ;
EditorGUI . indentLevel - - ;
EditorGUI . indentLevel - - ;
return layersChanged ;
}
bool DoLayersGUI ( AssetImporter materialImporter )
{
Material material = m_MaterialEditor . target as Material ;
bool layerChanged = false ;
GUI . changed = false ;
DoLayeringInputGUI ( ) ;
EditorGUILayout . Space ( ) ;
for ( int i = 0 ; i < numLayer ; i + + )
{
layerChanged | = DoLayerGUI ( materialImporter , i ) ;
}
EditorGUILayout . Space ( ) ;
layerChanged | = DoMaterialReferencesGUI ( materialImporter ) ;
layerChanged | = GUI . changed ;
GUI . changed = false ;