/// <summary> /// If the prefab is instantiated from LBLandscapeTerrain.PopulateLandscapeWithGroups(..) /// it doesn't know about editor-only classes like LBGroupDesigner. That's because it can be /// called at runtime. This method can be called to add the GroupDesigner reference to itself. /// </summary> public void FindGroupDesigner() { // Get the parent of this object which should be gameobject beginning with [DESIGNER] Transform tfm = this.transform.parent; if (tfm != null && tfm.name.StartsWith("[DESIGNER]")) { Transform landscapeTfrm = tfm.parent; if (landscapeTfrm != null) { // Get the first (and hopefully only) LBGroupDesigner lbGroupDesigner = landscapeTfrm.GetComponentInChildren <LBGroupDesigner>(); } } // SubGroup "items" appear directly below the lanscape. else if (this.name.StartsWith("[DESIGNER]")) { Transform landscapeTfrm = this.transform.parent; if (landscapeTfrm != null) { // Get the first (and hopefully only) LBGroupDesigner lbGroupDesigner = landscapeTfrm.GetComponentInChildren <LBGroupDesigner>(); } } }
// 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); } } } } }
private void CloseGroupDesigner() { LBLandscape landscape = lbGroupDesignerItem.lbGroupDesigner.transform.GetComponentInParent <LBLandscape>(); if (landscape != null && lbGroupDesignerItem != null && lbGroupDesignerItem.lbGroupDesigner != null) { lbGroupDesignerItem.lbGroupDesigner.lbGroup.showGroupDesigner = !LBGroupDesigner.ShowGroupDesigner(landscape, ref lbGroupDesignerItem.lbGroupDesigner, lbGroupDesignerItem.lbGroupDesigner.lbGroup, false); // Save the scene after attempting to close the Designer if (!EditorApplication.isPlayingOrWillChangePlaymode) { if (lbGroupDesignerItem.lbGroupDesigner.autoSaveEnabled) { EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); } else { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } } }