private void CreateMasks(Bounds bounds) { #if RAM_2019 RiverSettings riverSettings = editor.extension.riverSettings; for (int i = 0; i < riverSettings.count; i++) { // just some offset so that we don't start at an edge float offsetX = bounds.size.x / 10f; float offsetZ = bounds.size.z / 10f; float x = Random.Range(bounds.min.x + offsetX, bounds.max.x - offsetX); float y = 0; float z = Random.Range(bounds.min.z + offsetZ, bounds.max.z - offsetZ); // get y position on terrain by raycasting float?terrainHeight = TerrainUtils.GetTerrainHeight(x, z); if (terrainHeight != null) { y = (float)terrainHeight; } Vector3 position = new Vector3(x, y, z); int maskId = editor.GetNextMaskId(); CreateRiver("River " + maskId, position); } #endif }
public void CreateRiver(string gameObjectName, Vector3 position) { #if RAM_2019 RiverSettings riverSettings = editor.extension.riverSettings; GameObject parentGameObject = editor.extension.transform.gameObject; // create new gameobject RamSpline spline = RamSpline.CreateSpline(AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat")); // ensure gameobject gets reparented if this was a context click (otherwise does nothing) GameObjectUtility.SetParentAndAlign(spline.gameObject, parentGameObject); // set position spline.transform.position = Vector3.zero; // keeping it unique for the gameobject; using the point position we'd have to adjust the river points // apply river settings spline.width = 100; spline.currentProfile = riverSettings.splineProfile; spline.width = Random.Range(riverSettings.widthMin, riverSettings.widthMax); // apply simulation settings spline.AddPoint(position); spline.simulatedRiverLength = Random.Range(riverSettings.simulatedRiverLengthMin, riverSettings.simulatedRiverLengthMax); spline.simulatedRiverPoints = Random.Range(riverSettings.simulatedRiverPointsMin, riverSettings.simulatedRiverPointsMax); spline.simulatedMinStepSize = Random.Range(riverSettings.simulatedMinStepSizeMin, riverSettings.simulatedMinStepSizeMax); spline.simulatedNoUp = riverSettings.simulatedNoUp; spline.simulatedBreakOnUp = riverSettings.simulatedBreakOnUp; spline.noiseWidth = riverSettings.noiseWidth; spline.simulatedMinStepSize = Random.Range(riverSettings.simulatedMinStepSizeMin, riverSettings.simulatedMinStepSizeMax); spline.simulatedMinStepSize = Random.Range(riverSettings.simulatedMinStepSizeMin, riverSettings.simulatedMinStepSizeMax); spline.noiseMultiplierWidth = Random.Range(riverSettings.noiseMultiplierWidthMin, riverSettings.noiseMultiplierWidthMax); spline.noiseSizeWidth = Random.Range(riverSettings.noiseSizeWidthMin, riverSettings.noiseSizeWidthMax); // simulate bool generate = riverSettings.automation == RiverSettings.Automation.Generate; spline.SimulateRiver(generate); // register the creation in the undo system Undo.RegisterCreatedObjectUndo(spline.gameObject, "Create " + spline.gameObject.name); #endif }