public void AddNewPrefab(PrefabSettings prefabSettings, Vector3 newPosition, Quaternion newRotation, Vector3 newLocalScale) { #if VEGETATION_STUDIO_PRO // ensure the prefab has a VegetationItemID updateVSProSettings(prefabSettings, true); if (!string.IsNullOrEmpty(prefabSettings.vspro_VegetationItemID)) { string vegetationItemID = prefabSettings.vspro_VegetationItemID; Vector3 worldPosition = newPosition; Vector3 scale = newLocalScale; // TODO local or world? Quaternion rotation = newRotation; bool applyMeshRotation = true; // TODO ??? float distanceFalloff = 1f; // TODO ??? bool clearCellCache = true; // TODO ??? byte vegetationSourceID = Constants.VegetationStudioPro_SourceId; VegetationStudioManager.AddVegetationItemInstance(vegetationItemID, worldPosition, scale, rotation, applyMeshRotation, vegetationSourceID, distanceFalloff, clearCellCache); } #endif }
private void AddNewPrefab(Vector3 position, Vector3 normal) { GameObject container = gizmo.container as GameObject; PrefabSettings prefabSettings = this.gizmo.GetPrefabSettings(); GameObject prefab = prefabSettings.prefab; /// /// Calculate position / rotation / scale /// // get new position Vector3 newPosition = position; // add offset newPosition += prefabSettings.positionOffset; Vector3 newLocalScale = prefabSettings.prefab.transform.localScale; // size if (prefabSettings.changeScale) { newLocalScale = Vector3.one * Random.Range(prefabSettings.scaleMin, prefabSettings.scaleMax); } // rotation Quaternion newRotation; if (prefabSettings.randomRotation) { float rotationX = Random.Range(prefabSettings.rotationMinX, prefabSettings.rotationMaxX); float rotationY = Random.Range(prefabSettings.rotationMinY, prefabSettings.rotationMaxY); float rotationZ = Random.Range(prefabSettings.rotationMinZ, prefabSettings.rotationMaxZ); newRotation = Quaternion.Euler(rotationX, rotationY, rotationZ); } else if (this.gizmo.brushSettings.alignToTerrain) { newRotation = Quaternion.FromToRotation(Vector3.up, normal); } else { newRotation = Quaternion.Euler(prefabSettings.rotationOffset); //rotation = Quaternion.identity; } /// /// create instance and apply position / rotation / scale /// // spawn item to vs pro if (gizmo.brushSettings.spawnToVSPro) { #if VEGETATION_STUDIO_PRO // ensure the prefab has a VegetationItemID updateVSProSettings(prefabSettings, true); if (!string.IsNullOrEmpty(prefabSettings.vspro_VegetationItemID)) { string vegetationItemID = prefabSettings.vspro_VegetationItemID; Vector3 worldPosition = position; Vector3 scale = newLocalScale; // TODO local or world? Quaternion rotation = newRotation; bool applyMeshRotation = true; // TODO ??? byte vegetationSourceID = 5; // TODO see PersistentVegetationStorageTools for constants. 5 = "Vegetation Studio - Painted" float distanceFalloff = 1f; // TODO ??? bool clearCellCache = true; // TODO ??? VegetationStudioManager.AddVegetationItemInstance(vegetationItemID, worldPosition, scale, rotation, applyMeshRotation, vegetationSourceID, distanceFalloff, clearCellCache); } #endif } // spawn item to scene else { // new prefab GameObject instance = PrefabUtility.InstantiatePrefab(prefab) as GameObject; instance.transform.position = newPosition; instance.transform.rotation = newRotation; instance.transform.localScale = newLocalScale; // attach as child of container instance.transform.parent = container.transform; Undo.RegisterCreatedObjectUndo(instance, "Instantiate Prefab"); } }