// Clone constructor public LBGroupZone(LBGroupZone lbGroupZone) { if (lbGroupZone == null) { SetClassDefaults(); } else { zoneType = lbGroupZone.zoneType; zoneMode = lbGroupZone.zoneMode; zoneName = lbGroupZone.zoneName; GUID = lbGroupZone.GUID; centrePointX = lbGroupZone.centrePointX; centrePointZ = lbGroupZone.centrePointZ; width = lbGroupZone.width; length = lbGroupZone.length; isScaledPointX = lbGroupZone.isScaledPointX; isScaledPointZ = lbGroupZone.isScaledPointZ; isScaledWidth = lbGroupZone.isScaledWidth; isScaledLength = lbGroupZone.isScaledLength; showInScene = lbGroupZone.showInScene; showInEditor = lbGroupZone.showInEditor; useBiome = lbGroupZone.useBiome; lbBiome = lbGroupZone.lbBiome; } }
/// <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)); } }
// Draw gizmos whenever the designer is being shown in the scene private void OnDrawGizmos() { if (isInitialised && lbGroup != null) { // Show the clearing location as a 2D circle UnityEditor.Handles.color = Color.blue; Vector3 locPos = transform.position; UnityEditor.Handles.DrawWireDisc(locPos, Vector3.up, lbGroup.maxClearingRadius); //Vector3 arcPosition = this.transform.position; //UnityEditor.Handles.DrawWireArc(arcPosition, Vector3.up, this.transform.forward, 360, lbGroup.maxClearingRadius); // Show the zones using (new UnityEditor.Handles.DrawingScope(Color.cyan)) { Vector3 areaPos = new Vector3(0f, locPos.y, 0f); if (zoneLabelStyle == null) { zoneLabelStyle = new GUIStyle("Box"); zoneLabelStyle.fontSize = 14; zoneLabelStyle.border = new RectOffset(2, 2, 2, 2); GUI.skin.box.normal.textColor = zoneLabelColour; zoneLabelStyle.onFocused.textColor = zoneLabelColour; } // Show zones in scene for the current manual clearing location for (int zoneIdx = 0; zoneIdx < numZones; zoneIdx++) { LBGroupZone lbGroupZone = lbGroup.zoneList[zoneIdx]; if (lbGroupZone.showInScene) { areaPos.x = (lbGroupZone.centrePointX * lbGroup.maxClearingRadius) + locPos.x; areaPos.z = (lbGroupZone.centrePointZ * lbGroup.maxClearingRadius) + locPos.z; LBGroupDesigner.DrawZone(lbGroupZone, areaPos, locPos, lbGroup.maxClearingRadius, areaPos.y, rotationY, false, zoneLabelStyle); } } } } }