/// <summary> /// Snap the prefab to ground (y-axis). Sets the prefab position to 0 on y-axis. /// If isConsiderPrefabExtents is true, set ground to be the bottom of the prefab /// rather than its pivot point. /// NOTE: Currently doesn't consider scaling. /// </summary> /// <param name="isConsiderPrefabExtents"></param> private void SnapToGround(bool isConsiderPrefabExtents = false) { if (lbGroupMember != null && lbGroupDesignerItem != null) { // Default lbGroupMember.minOffsetY = 0f; lbGroupMember.maxOffsetY = 0f; if (isConsiderPrefabExtents && lbGroupMember.prefab != null && lbGroupMember.lbMemberType == LBGroupMember.LBMemberType.Prefab) { // Need to reset y value for GetBounds to work correctly Vector3 tempPos = lbGroupMember.prefab.transform.position; tempPos.y = 0f; lbGroupMember.prefab.transform.position = tempPos; Bounds bounds = LBMeshOperations.GetBounds(lbGroupMember.prefab.transform, false, true); if (bounds.extents.y != 0f) { // bounds.extents.y is half the height of the prefab. lbGroupMember.minOffsetY = bounds.extents.y - bounds.center.y; lbGroupMember.maxOffsetY = lbGroupMember.minOffsetY; } } lbGroupDesignerItem.lbGroupDesigner.UpdateGroupMember(lbGroupMember); LBEditorHelper.RepaintEditorWindow(typeof(LandscapeBuilderWindow)); } }
/// <summary> /// Add a zone at the same location as an object/prefab using its extents. /// NOTE: Rectangular zones cannot be rotated, so only width and length can be switched /// </summary> private void AddZoneToObject() { if (lbGroup != null && lbGroupMember != null && lbGroupDesignerItem != null && lbGroupMember.prefab != null && lbGroupMember.lbMemberType == LBGroupMember.LBMemberType.Prefab) { // Need to reset postion for GetBounds to work correctly Vector3 tempPos = lbGroupMember.prefab.transform.position; lbGroupMember.prefab.transform.position = Vector3.zero; Bounds bounds = LBMeshOperations.GetBounds(lbGroupMember.prefab.transform, false, true); lbGroupMember.prefab.transform.position = tempPos; if (bounds.extents.x != 0f && bounds.extents.z != 0f && lbGroup.maxClearingRadius > 0f) { LBGroupZone lbGroupZone = new LBGroupZone(); if (lbGroupZone != null) { if (bounds.extents.x == bounds.extents.z) { lbGroupZone.zoneType = LBGroupZone.LBGroupZoneType.circle; lbGroupZone.centrePointX = lbGroupMember.minOffsetX / lbGroup.maxClearingRadius; lbGroupZone.centrePointZ = lbGroupMember.minOffsetZ / lbGroup.maxClearingRadius; lbGroupZone.width = (bounds.extents.x - bounds.center.x) / lbGroup.maxClearingRadius; lbGroupZone.length = lbGroupZone.width; } else { lbGroupZone.zoneType = LBGroupZone.LBGroupZoneType.rectangle; lbGroupZone.centrePointX = lbGroupMember.minOffsetX / lbGroup.maxClearingRadius; lbGroupZone.centrePointZ = lbGroupMember.minOffsetZ / lbGroup.maxClearingRadius; lbGroupZone.width = (bounds.extents.x - bounds.center.x) * 2f / lbGroup.maxClearingRadius; lbGroupZone.length = (bounds.extents.z - bounds.center.z) * 2f / lbGroup.maxClearingRadius; float rotationY = lbGroupDesignerItem.transform.rotation.eulerAngles.y; // Get the absolute rotation on y-axis if (rotationY < 0) { rotationY = -rotationY; } // cater for rotation by switching width and length if ((rotationY > 45f && rotationY < 135f) || (rotationY > 225f && rotationY < 315f)) { float width = lbGroupZone.width; lbGroupZone.width = lbGroupZone.length; lbGroupZone.length = width; } } lbGroupZone.zoneName = lbGroupMember.prefab.name + " zone"; lbGroup.zoneList.Add(lbGroupZone); } } LBEditorHelper.RepaintEditorWindow(typeof(LandscapeBuilderWindow)); } }