Exemplo n.º 1
0
		private void DrawTerrainSection(HEU_HoudiniAsset asset, SerializedObject assetObject)
		{
			int numVolumes = asset.GetVolumeCacheCount();
			if(numVolumes <= 0)
			{
				return;
			}

			HEU_EditorUI.BeginSection();
			{
				SerializedProperty showTerrainProperty = HEU_EditorUtility.GetSerializedProperty(assetObject, "_showTerrainSection");
				if (showTerrainProperty != null)
				{
					showTerrainProperty.boolValue = HEU_EditorUI.DrawFoldOut(showTerrainProperty.boolValue, "TERRAIN");
					if (showTerrainProperty.boolValue)
					{
						// Draw each volume layer
						List<HEU_VolumeCache> volumeCaches = asset.GetVolumeCaches();
						int numCaches = volumeCaches.Count;
						for (int i = 0; i < numCaches; ++i)
						{
							SerializedObject cacheObjectSerialized = new SerializedObject(volumeCaches[i]);
							bool bChanged = false;

							SerializedProperty layersProperty = cacheObjectSerialized.FindProperty("_layers");
							if (layersProperty == null || layersProperty.arraySize == 0)
							{
								continue;
							}

							string heading = string.Format("{0}-{1}:", volumeCaches[i].ObjectName, volumeCaches[i].GeoName);

							if (HEU_EditorUI.DrawFoldOutSerializedProperty(HEU_EditorUtility.GetSerializedProperty(cacheObjectSerialized, "_uiExpanded"), heading, ref bChanged))
							{
								EditorGUI.indentLevel++;

								int numlayers = layersProperty.arraySize;
								for (int j = 0; j < numlayers; ++j)
								{
									SerializedProperty layerProperty = layersProperty.GetArrayElementAtIndex(j);
									if (layerProperty == null)
									{
										continue;
									}

									string layerName = string.Format("Layer: {0}", layerProperty.FindPropertyRelative("_layerName").stringValue);

									SerializedProperty uiExpandedProperty = layerProperty.FindPropertyRelative("_uiExpanded");
									bool bExpanded = uiExpandedProperty != null ? uiExpandedProperty.boolValue : true;
									bool bNewExpanded = HEU_EditorUI.DrawFoldOut(bExpanded, layerName);
									if (uiExpandedProperty != null && bExpanded != bNewExpanded)
									{
										bChanged = true;
										uiExpandedProperty.boolValue = bNewExpanded;
									}

									if (!bNewExpanded)
									{
										continue;
									}

									if (HEU_EditorUtility.EditorDrawFloatSliderProperty(layerProperty, "_strength", "Strength", "Amount to multiply the layer values by on import."))
									{
										bChanged = true;
									}

									SerializedProperty overrideProperty = layerProperty.FindPropertyRelative("_overrides");

									SerializedProperty textureProperty = layerProperty.FindPropertyRelative("_diffuseTexture");
									if (textureProperty != null)
									{
										Object textureObject = textureProperty.objectReferenceValue;
										EditorGUILayout.PropertyField(textureProperty, new GUIContent("Diffuse Texture", "Difuse texture used by terrain layer."));
										if (textureObject != textureProperty.objectReferenceValue)
										{
											SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.Diffuse);
											bChanged = true;
										}

										HEU_EditorUI.DrawSeparator();
									}

#if UNITY_2018_3_OR_NEWER
									SerializedProperty maskTextureProperty = layerProperty.FindPropertyRelative("_maskTexture");
									if (maskTextureProperty != null)
									{
										Object textureObject = maskTextureProperty.objectReferenceValue;
										EditorGUILayout.PropertyField(maskTextureProperty, new GUIContent("Mask Texture", "The mask map texture used by the terrain layer."));
										if (textureObject != maskTextureProperty.objectReferenceValue)
										{
											SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.Mask);
											bChanged = true;
										}

										HEU_EditorUI.DrawSeparator();
									}
#endif

									SerializedProperty normalProperty = layerProperty.FindPropertyRelative("_normalTexture");
									if (normalProperty != null)
									{
										Object normalObject = normalProperty.objectReferenceValue;
										EditorGUILayout.PropertyField(normalProperty, new GUIContent("NormalMap", "Normal map of the splat applied to the Terrain."));
										if (normalObject != normalProperty.objectReferenceValue)
										{
											SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.Normal);
											bChanged = true;
										}

										HEU_EditorUI.DrawSeparator();
									}

#if UNITY_2018_3_OR_NEWER
									if (HEU_EditorUtility.EditorDrawFloatSliderProperty(layerProperty, "_normalScale", "Normal Scale", "The normal scale value of the splat layer."))
									{
										SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.NormalScale);
										bChanged = true;
									}
#endif

									if (HEU_EditorUtility.EditorDrawFloatSliderProperty(layerProperty, "_metallic", "Metallic", "The metallic value of the splat layer."))
									{
										SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.Metallic);
										bChanged = true;
									}

									if (HEU_EditorUtility.EditorDrawFloatSliderProperty(layerProperty, "_smoothness", "Smoothness", "The smoothness value of the splat layer when the main texture has no alpha channel."))
									{
										SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.Smoothness);
										bChanged = true;
									}

#if UNITY_2018_3_OR_NEWER
									SerializedProperty specularProperty = layerProperty.FindPropertyRelative("_specularColor");
									if (specularProperty != null)
									{
										Color specColor = specularProperty.colorValue;
										EditorGUILayout.PropertyField(specularProperty, new GUIContent("Specular", "Specular color"));
										if (specularProperty.colorValue != specColor)
										{
											SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.Specular);

											bChanged = true;
										}
									}
#endif

									if (HEU_EditorUtility.EditorDrawVector2RelativeProperty(layerProperty, "_tileSize", "Tile Size (W, H)", "Size of the tile used in the texture of the SplatPrototype."))
									{
										SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.TileSize);
										bChanged = true;
									}

									if (HEU_EditorUtility.EditorDrawVector2RelativeProperty(layerProperty, "_tileOffset", "Tile Offset (X, Y)", "Offset of the tile texture of the SplatPrototype."))
									{
										SetVolumeLayerPropertyOverride(overrideProperty, HEU_VolumeLayer.Overrides.TileOffset);
										bChanged = true;
									}

									HEU_EditorUI.DrawSeparator();
								}

								EditorGUI.indentLevel--;
							}

							if(bChanged)
							{
								SerializedProperty dirtyProperty = cacheObjectSerialized.FindProperty("_isDirty");
								if (dirtyProperty != null)
								{
									dirtyProperty.boolValue = true;
								}

								cacheObjectSerialized.ApplyModifiedProperties();
							}
						}
					}
				}
			}
			HEU_EditorUI.EndSection();

			HEU_EditorUI.DrawSeparator();
		}
		private void DrawTerrainSection(HEU_HoudiniAsset asset, SerializedObject assetObject)
		{
			int numVolumes = asset.GetVolumeCacheCount();
			if(numVolumes <= 0)
			{
				return;
			}

			HEU_EditorUI.BeginSection();
			{
				SerializedProperty showTerrainProperty = HEU_EditorUtility.GetSerializedProperty(assetObject, "_showTerrainSection");
				if (showTerrainProperty != null)
				{
					showTerrainProperty.boolValue = HEU_EditorUI.DrawFoldOut(showTerrainProperty.boolValue, "TERRAIN");
					if (showTerrainProperty.boolValue)
					{
						// Draw each volume layer
						List<HEU_VolumeCache> volumeCaches = asset.GetVolumeCaches();
						int numCaches = volumeCaches.Count;
						for (int i = 0; i < numCaches; ++i)
						{
							SerializedObject cacheObjectSerialized = new SerializedObject(volumeCaches[i]);
							bool bChanged = false;
							bool bStrengthChanged = false;

							SerializedProperty layersProperty = cacheObjectSerialized.FindProperty("_layers");
							if (layersProperty == null || layersProperty.arraySize == 0)
							{
								continue;
							}

							string heading = string.Format("{0}-{1}:", volumeCaches[i].ObjectName, volumeCaches[i].GeoName);

							if (HEU_EditorUI.DrawFoldOutSerializedProperty(HEU_EditorUtility.GetSerializedProperty(cacheObjectSerialized, "_uiExpanded"), heading, ref bChanged))
							{
								EditorGUI.indentLevel++;

								int numlayers = layersProperty.arraySize;
								for (int j = 0; j < numlayers; ++j)
								{
									SerializedProperty layerProperty = layersProperty.GetArrayElementAtIndex(j);
									if (layerProperty == null)
									{
										continue;
									}

									// Skipping "height" layer on UI since its treated as Houdini-specific layer
									string layerName = layerProperty.FindPropertyRelative("_layerName").stringValue;
									if (layerName.Equals(HEU_Defines.HAPI_HEIGHTFIELD_LAYERNAME_HEIGHT))
									{
										continue;
									}
									layerName = string.Format("Layer: {0}", layerName);

									SerializedProperty uiExpandedProperty = layerProperty.FindPropertyRelative("_uiExpanded");
									bool bExpanded = uiExpandedProperty != null ? uiExpandedProperty.boolValue : true;
									bool bNewExpanded = HEU_EditorUI.DrawFoldOut(bExpanded, layerName);
									if (uiExpandedProperty != null && bExpanded != bNewExpanded)
									{
										bChanged = true;
										uiExpandedProperty.boolValue = bNewExpanded;
									}

									if (!bNewExpanded)
									{
										continue;
									}

									if (HEU_EditorUtility.EditorDrawFloatSliderProperty(layerProperty, "_strength", "Strength", "Amount to multiply the layer values by on import."))
									{
										bStrengthChanged = true;
									}

									HEU_EditorUI.DrawSeparator();
								}

								EditorGUI.indentLevel--;
							}

							if (bStrengthChanged)
							{
								SerializedProperty dirtyProperty = cacheObjectSerialized.FindProperty("_isDirty");
								if (dirtyProperty != null)
								{
									dirtyProperty.boolValue = true;
									bChanged = true;
								}
							}

							if(bChanged)
							{
								cacheObjectSerialized.ApplyModifiedProperties();
							}
						}
					}
				}
			}
			HEU_EditorUI.EndSection();

			HEU_EditorUI.DrawSeparator();
		}