|
|
|
|
|
|
}; |
|
|
|
public readonly GUIContent syncButton = new GUIContent("Sync", "Re-synchronize this layer's properties with the referenced Material"); |
|
|
|
public readonly GUIContent layers = new GUIContent("Layers"); |
|
|
|
public readonly GUIContent layerMapMask = new GUIContent("LayerMask", "Layer mask (multiplied by vertex color)"); |
|
|
|
public readonly GUIContent layerMapMask = new GUIContent("Layer Mask", "Layer mask (multiplied by vertex color)"); |
|
|
|
public readonly GUIContent layerCount = new GUIContent("Layer Count", "Number of layers."); |
|
|
|
} |
|
|
|
|
|
|
|
static Styles s_Styles = null; |
|
|
|
|
|
|
public string[] GUIDArray; |
|
|
|
} |
|
|
|
|
|
|
|
private int kSyncButtonWidth = 58; |
|
|
|
private const int kMaxLayerCount = 4; |
|
|
|
private const int kSyncButtonWidth = 58; |
|
|
|
private string kLayerCount = "_LayerCount"; |
|
|
|
private Material[] m_MaterialLayers = new Material[4]; |
|
|
|
MaterialProperty layerMaskMap = null; |
|
|
|
private Material[] m_MaterialLayers = new Material[kMaxLayerCount]; |
|
|
|
|
|
|
|
MaterialProperty layerCountProperty = null; |
|
|
|
MaterialProperty layerMaskMapProperty = null; |
|
|
|
|
|
|
|
int layerCount |
|
|
|
{ |
|
|
|
set { layerCountProperty.floatValue = (float)value; } |
|
|
|
get { return (int)layerCountProperty.floatValue; } |
|
|
|
} |
|
|
|
|
|
|
|
void SynchronizeLayerProperties(int layerIndex) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
bool result = true; |
|
|
|
outValueNames = ""; |
|
|
|
for(int i = 0 ; i < m_MaterialLayers.Length ; ++i) |
|
|
|
for(int i = 0 ; i < layerCount ; ++i) |
|
|
|
{ |
|
|
|
Material layer = m_MaterialLayers[i]; |
|
|
|
if (layer != null) |
|
|
|
|
|
|
outValueNames += shortNames[currentValue] + " "; |
|
|
|
|
|
|
|
for(int j = i + 1 ; j < m_MaterialLayers.Length ; ++j) |
|
|
|
for (int j = i + 1; j < layerCount; ++j) |
|
|
|
{ |
|
|
|
Material otherLayer = m_MaterialLayers[j]; |
|
|
|
if(otherLayer != null) |
|
|
|
|
|
|
{ |
|
|
|
bool result = true; |
|
|
|
outValueNames = ""; |
|
|
|
for (int i = 0; i < m_MaterialLayers.Length; ++i) |
|
|
|
for (int i = 0; i < layerCount; ++i) |
|
|
|
{ |
|
|
|
Material layer = m_MaterialLayers[i]; |
|
|
|
if (layer != null) |
|
|
|
|
|
|
|
|
|
|
for (int j = i + 1; j < m_MaterialLayers.Length; ++j) |
|
|
|
for (int j = i + 1; j < layerCount; ++j) |
|
|
|
{ |
|
|
|
Material otherLayer = m_MaterialLayers[j]; |
|
|
|
if (otherLayer != null) |
|
|
|
|
|
|
// We synchronize input options with the firsts non null Layer (all layers should have consistent options)
|
|
|
|
Material firstLayer = null; |
|
|
|
int i = 0; |
|
|
|
while (i < m_MaterialLayers.Length && !(firstLayer = m_MaterialLayers[i])) ++i; |
|
|
|
while (i < layerCount && !(firstLayer = m_MaterialLayers[i])) ++i; |
|
|
|
|
|
|
|
if(firstLayer != null) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
bool LayersGUI(AssetImporter materialImporter) |
|
|
|
{ |
|
|
|
Material material = m_MaterialEditor.target as Material; |
|
|
|
|
|
|
|
m_MaterialEditor.TexturePropertySingleLine(styles.layerMapMask, layerMaskMap); |
|
|
|
EditorGUI.BeginChangeCheck(); |
|
|
|
int newLayerCount = EditorGUILayout.IntSlider(styles.layerCount, (int)layerCountProperty.floatValue, 2, 4 ); |
|
|
|
if (EditorGUI.EndChangeCheck()) |
|
|
|
{ |
|
|
|
Undo.RecordObject(material, "Change layer count"); |
|
|
|
layerCountProperty.floatValue = (float)newLayerCount; |
|
|
|
layerChanged = true; |
|
|
|
} |
|
|
|
|
|
|
|
m_MaterialEditor.TexturePropertySingleLine(styles.layerMapMask, layerMaskMapProperty); |
|
|
|
for (int i = 0; i < m_MaterialLayers.Length; i++) |
|
|
|
for (int i = 0; i < layerCount; i++) |
|
|
|
{ |
|
|
|
EditorGUILayout.BeginHorizontal(); |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
// Find first non null layer
|
|
|
|
int i = 0; |
|
|
|
while (i < m_MaterialLayers.Length && (m_MaterialLayers[i] == null)) ++i; |
|
|
|
while (i < layerCount && (m_MaterialLayers[i] == null)) ++i; |
|
|
|
if(i < m_MaterialLayers.Length) |
|
|
|
if (i < layerCount) |
|
|
|
{ |
|
|
|
SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap + i)); |
|
|
|
SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap + i)); |
|
|
|
|
|
|
SetKeyword(material, "_LAYERMASKMAP", material.GetTexture(kLayerMaskMap)); |
|
|
|
} |
|
|
|
|
|
|
|
void SetupMaterialForLayers(Material material) |
|
|
|
{ |
|
|
|
if(layerCount == 4) |
|
|
|
{ |
|
|
|
SetKeyword(material, "_LAYEREDLIT_4_LAYERS", true); |
|
|
|
SetKeyword(material, "_LAYEREDLIT_3_LAYERS", false); |
|
|
|
} |
|
|
|
else if (layerCount == 3) |
|
|
|
{ |
|
|
|
SetKeyword(material, "_LAYEREDLIT_4_LAYERS", false); |
|
|
|
SetKeyword(material, "_LAYEREDLIT_3_LAYERS", true); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
SetKeyword(material, "_LAYEREDLIT_4_LAYERS", false); |
|
|
|
SetKeyword(material, "_LAYEREDLIT_3_LAYERS", false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
layerMaskMap = FindProperty(kLayerMaskMap, props); |
|
|
|
layerMaskMapProperty = FindProperty(kLayerMaskMap, props); |
|
|
|
layerCountProperty = FindProperty(kLayerCount, props); |
|
|
|
|
|
|
|
m_MaterialEditor = materialEditor; |
|
|
|
|
|
|
|
|
|
|
SynchronizeInputOptions(); |
|
|
|
|
|
|
|
foreach (var obj in m_MaterialEditor.targets) |
|
|
|
{ |
|
|
|
SetupMaterialForLayers((Material)obj); |
|
|
|
} |
|
|
|
|
|
|
|
SaveMaterialLayers(materialImporter); |
|
|
|
} |
|
|
|