void DoAddPersistentStorage(VegetationSystem _vegetationSystem) { _vegetationSystem.AutomaticWakeup = true; // NB seems redundant to recurse into parent object - but this is needed to get the terrain name GameObject parentTerrainGo = _vegetationSystem.gameObject.transform.parent.gameObject; PersistentVegetationStorage _persistentVegetationStorage = parentTerrainGo.GetComponentInChildren <PersistentVegetationStorage>(); PersistentVegetationStoragePackage newPersistentVegetationStoragePackage = ScriptableObject.CreateInstance <PersistentVegetationStoragePackage>(); AssetDatabase.CreateAsset(newPersistentVegetationStoragePackage, _assetsPath + "/" + parentTerrainGo.name + _DEFAULT_SUFFIX + ".asset"); _persistentVegetationStorage.PersistentVegetationStoragePackage = newPersistentVegetationStoragePackage; // initialize _persistentVegetationStorage.InitializePersistentStorage(); if (_debugToLog) { Debug.Log("Added storage asset for " + parentTerrainGo.name); } if (_autoBake) { if (_debugToLog) { Debug.Log("Auto Baking " + parentTerrainGo.name); } //if (_vegetationSystem.GetSleepMode()) //{ _vegetationSystem.SetSleepMode(false); // wake up VegetationSystem, needed for prefab //} // now bake List <string> vegetationItemIdList = VegetationPackageEditorTools.CreateVegetationInfoIdList(_persistentVegetationStorage.VegetationSystem.CurrentVegetationPackage); for (int i = 0; i <= vegetationItemIdList.Count - 1; i++) { _persistentVegetationStorage.BakeVegetationItem(vegetationItemIdList[i]); } _persistentVegetationStorage.VegetationSystem.DelayedClearVegetationCellCache(); EditorUtility.SetDirty(_persistentVegetationStorage.PersistentVegetationStoragePackage); EditorUtility.SetDirty(_persistentVegetationStorage.VegetationSystem.CurrentVegetationPackage); if (_debugToLog) { Debug.Log("Finished Baking for " + parentTerrainGo.name); } } }
public override void OnInspectorGUI() { _vegetationPackagePro = (VegetationPackagePro)target; base.OnInspectorGUI(); //EditorUtility.SetDirty(target); for (int i = 0; i <= _vegetationPackagePro.VegetationInfoList.Count - 1; i++) { bool changed = false; VegetationItemInfoPro vegetationItemInfo = _vegetationPackagePro.VegetationInfoList[i]; if (vegetationItemInfo.VegetationItemID == "") { vegetationItemInfo.VegetationItemID = System.Guid.NewGuid().ToString(); changed = true; } if (changed) { EditorUtility.SetDirty(_vegetationPackagePro); } } GUILayout.BeginVertical("box"); EditorGUILayout.HelpBox( "To edit an vegetation package add it to a vegetation system pro component", MessageType.Info); GUILayout.EndVertical(); GUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Biome", LabelStyle); EditorGUI.BeginDisabledGroup(true); _vegetationPackagePro.BiomeType = (BiomeType)EditorGUILayout.EnumPopup("Select biome", _vegetationPackagePro.BiomeType); EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); if (_vegetationPackagePro.VegetationInfoList.Count > 0) { List <string> vegetationItemIdList = VegetationPackageEditorTools.CreateVegetationInfoIdList(_vegetationPackagePro); VegetationPackageEditorTools.DrawVegetationItemSelector(_vegetationPackagePro, vegetationItemIdList, 60, ref _selectedVegetationItem); VegetationItemInfoPro vegetationItemInfoPro = _vegetationPackagePro.GetVegetationInfo(_selectedVegetationItem); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("VegetationItemID", LabelStyle); EditorGUILayout.SelectableLabel(vegetationItemInfoPro.VegetationItemID); GUILayout.EndHorizontal(); } else { GUILayout.BeginVertical("box"); EditorGUILayout.HelpBox( "Vegetation package has no vegetation items configured", MessageType.Info); GUILayout.EndVertical(); } if (_vegetationPackagePro.TerrainTextureCount > 0) { EditorGUILayout.LabelField("Terrain textures", LabelStyle); GUIContent[] textureImageButtons = new GUIContent[_vegetationPackagePro.TerrainTextureList.Count]; for (int i = 0; i <= _vegetationPackagePro.TerrainTextureList.Count - 1; i++) { var textureItemTexture = AssetPreview.GetAssetPreview(_vegetationPackagePro.TerrainTextureList[i].Texture); Texture2D convertedTexture = new Texture2D(2, 2, TextureFormat.ARGB32, true, true); if (textureItemTexture) { convertedTexture.LoadImage(textureItemTexture.EncodeToPNG()); } textureImageButtons[i] = new GUIContent { image = convertedTexture }; } int imageWidth = 60; int columns = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - imageWidth / 2f) / imageWidth); int rows = Mathf.CeilToInt((float)textureImageButtons.Length / columns); int gridHeight = (rows) * imageWidth; _currentTextureItem = GUILayout.SelectionGrid(_currentTextureItem, textureImageButtons, columns, GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight)); GUIStyle variantStyle = new GUIStyle(EditorStyles.helpBox); GUILayout.BeginVertical("box"); EditorGUILayout.LabelField("Terrain layer: " + (_currentTextureItem + 1).ToString(), LabelStyle); EditorGUI.BeginDisabledGroup(true); _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].Enabled = EditorGUILayout.Toggle("Enable", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].Enabled); EditorGUILayout.BeginHorizontal(variantStyle); EditorGUILayout.LabelField("Texture " + (_currentTextureItem + 1).ToString() + " Height", LabelStyle, GUILayout.Width(150)); _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureHeightCurve = EditorGUILayout.CurveField(_vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureHeightCurve, Color.green, new Rect(0, 0, 1, 1), GUILayout.Height(75)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(variantStyle); EditorGUILayout.LabelField("Texture " + (_currentTextureItem + 1).ToString() + " Steepness", LabelStyle, GUILayout.Width(150)); _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureSteepnessCurve = EditorGUILayout.CurveField(_vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureSteepnessCurve, Color.green, new Rect(0, 0, 1, 1), GUILayout.Height(75)); EditorGUILayout.EndHorizontal(); _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].UseNoise = EditorGUILayout.Toggle("Use perlin noise", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].UseNoise); if (_vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].UseNoise) { _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].InverseNoise = EditorGUILayout.Toggle("Inverse noise", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].InverseNoise); _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseScale = EditorGUILayout.Slider("Noise scale", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseScale, 1, 50f); _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseOffset = EditorGUILayout.Vector2Field("Noise offset", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].NoiseOffset); } _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureWeight = EditorGUILayout.Slider("Texture weight", _vegetationPackagePro.TerrainTextureSettingsList[_currentTextureItem].TextureWeight, 0, 5f); EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); } else { GUILayout.BeginVertical("box"); EditorGUILayout.HelpBox( "Vegetation package has no textures configured", MessageType.Info); GUILayout.EndVertical(); } }