void DrawLineOutline(Vector3[] worldPoints, List <Node> nodeList, float width, float additionalWidth, Color color) { Vector3 cameraPosition = SceneView.currentDrawingSceneView.camera.transform.position; for (int i = 0; i <= worldPoints.Length - 2; i++) { if (!nodeList[i].Active) { continue; } float lineWidth = width + additionalWidth; if (nodeList[i].OverrideWidth) { lineWidth = nodeList[i].CustomWidth / 2f + additionalWidth; } float distance = Vector3.Distance(worldPoints[i], cameraPosition); if (distance < 200) { List <Vector3> pointList = new List <Vector3> { worldPoints[i], worldPoints[i + 1] }; List <Vector3> newInflatedList = PolygonUtility.InflatePolygon(pointList, lineWidth, false); PolygonUtility.AlignPointsWithTerrain(newInflatedList, true, VegetationMaskLine.GroundLayerMask); Handles.color = color; Handles.DrawAAPolyLine(3, newInflatedList.ToArray()); } } }
// ReSharper disable once InconsistentNaming public virtual void OnSceneGUI() { _biomeMaskArea = (BiomeMaskArea)target; if (_biomeMaskArea.ShowHandles && _biomeMaskArea.enabled) { Event currentEvent = Event.current; if (currentEvent.shift || currentEvent.control) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } if (currentEvent.shift && currentEvent.control) { for (int i = 0; i <= _biomeMaskArea.Nodes.Count - 1; i++) { Vector3 cameraPosition = SceneView.currentDrawingSceneView.camera.transform.position; Vector3 worldSpaceNode = _biomeMaskArea.transform.TransformPoint(_biomeMaskArea.Nodes[i].Position); float distance = Vector3.Distance(cameraPosition, worldSpaceNode); Handles.color = Color.red; if (Handles.Button(worldSpaceNode, Quaternion.LookRotation(worldSpaceNode - cameraPosition, Vector3.up), 0.030f * distance, 0.015f * distance, Handles.CircleHandleCap)) { _biomeMaskArea.DeleteNode(_biomeMaskArea.Nodes[i]); SetMaskDirty(); } } } if (currentEvent.alt && currentEvent.control) { for (int i = 0; i <= _biomeMaskArea.Nodes.Count - 1; i++) { Vector3 cameraPosition = SceneView.currentDrawingSceneView.camera.transform.position; Vector3 worldSpaceNode = _biomeMaskArea.transform.TransformPoint(_biomeMaskArea.Nodes[i].Position); float distance = Vector3.Distance(cameraPosition, worldSpaceNode); Handles.color = Color.yellow; if (Handles.Button(worldSpaceNode, Quaternion.LookRotation(worldSpaceNode - cameraPosition, Vector3.up), 0.030f * distance, 0.015f * distance, Handles.CircleHandleCap)) { _biomeMaskArea.Nodes[i].DisableEdge = !_biomeMaskArea.Nodes[i].DisableEdge; SetMaskDirty(); } } } if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0 && currentEvent.control && !currentEvent.shift && !currentEvent.alt) { Ray ray = HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition); var hits = Physics.RaycastAll(ray, 10000f); for (int i = 0; i <= hits.Length - 1; i++) { if (hits[i].collider is TerrainCollider || _biomeMaskArea.GroundLayerMask.Contains(hits[i].collider.gameObject.layer)) { _biomeMaskArea.AddNode(hits[i].point); currentEvent.Use(); SetMaskDirty(); break; } } } if (!currentEvent.shift && !currentEvent.alt) { bool nodeChange = false; Vector3 cameraPosition = SceneView.currentDrawingSceneView.camera.transform.position; for (int i = 0; i <= _biomeMaskArea.Nodes.Count - 1; i++) { Vector3 worldSpaceNode = _biomeMaskArea.transform.TransformPoint(_biomeMaskArea.Nodes[i].Position); float distance = Vector3.Distance(cameraPosition, worldSpaceNode); if (distance > 200 && _biomeMaskArea.Nodes.Count > 50) { continue; } Vector3 newWorldSpaceNode = Handles.PositionHandle(worldSpaceNode, Quaternion.identity); _biomeMaskArea.Nodes[i].Position = _biomeMaskArea.transform.InverseTransformPoint(newWorldSpaceNode); if (worldSpaceNode != newWorldSpaceNode) { nodeChange = true; } } if (nodeChange) { _biomeMaskArea.PositionNodes(); SetMaskDirty(); } } } if (_biomeMaskArea.ShowArea) { Vector3[] worldPoints = new Vector3[_biomeMaskArea.Nodes.Count]; for (int i = 0; i <= _biomeMaskArea.Nodes.Count - 1; i++) { worldPoints[i] = _biomeMaskArea.transform.TransformPoint(_biomeMaskArea.Nodes[i].Position); } List <Vector3> worldPointsClosedList = new List <Vector3>(worldPoints); worldPointsClosedList.Add(worldPointsClosedList[0]); Handles.color = new Color(1, 1, 1, 0.8f); Handles.DrawAAPolyLine(3, worldPointsClosedList.ToArray()); if (_biomeMaskArea.BlendDistance > 0.01f) { List <Vector3> inflatedTreeListMax = PolygonUtility.InflatePolygon(worldPointsClosedList, -_biomeMaskArea.BlendDistance, true); PolygonUtility.AlignPointsWithTerrain(inflatedTreeListMax, true, _biomeMaskArea.GroundLayerMask); Handles.color = new Color(1, 0, 0, 0.8f); Handles.DrawAAPolyLine(3, inflatedTreeListMax.ToArray()); } } }
public override void OnSceneGUI() { base.OnSceneGUI(); if (VegetationMaskArea.ShowArea) { Vector3[] worldPoints = new Vector3[VegetationMask.Nodes.Count]; for (int i = 0; i <= VegetationMask.Nodes.Count - 1; i++) { worldPoints[i] = VegetationMask.transform.TransformPoint(VegetationMask.Nodes[i].Position); } List <Vector3> worldPointsClosedList = new List <Vector3>(worldPoints); worldPointsClosedList.Add(worldPointsClosedList[0]); Handles.color = new Color(1, 1, 1, 0.8f); Handles.DrawAAPolyLine(3, worldPointsClosedList.ToArray()); List <Vector3> worldPointsList = new List <Vector3>(worldPoints); GUIStyle stLabel = new GUIStyle(EditorStyles.boldLabel); if ((VegetationMask.AdditionalGrassPerimiter > 0.1f || VegetationMask.AdditionalGrassPerimiterMax > 0.1f) && VegetationMask.RemoveGrass) { List <Vector3> inflatedGrassList = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalGrassPerimiter, true); PolygonUtility.AlignPointsWithTerrain(inflatedGrassList, true, VegetationMaskArea.GroundLayerMask); Handles.Label(GetLabelPosition(inflatedGrassList, 0), "Grass", stLabel); Handles.color = new Color(0, 1, 0, 0.8f); Handles.DrawAAPolyLine(3, inflatedGrassList.ToArray()); if (VegetationMask.AdditionalGrassPerimiterMax > VegetationMask.AdditionalGrassPerimiter) { List <Vector3> inflatedGrassListMax = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalGrassPerimiterMax, true); PolygonUtility.AlignPointsWithTerrain(inflatedGrassListMax, true, VegetationMaskArea.GroundLayerMask); Handles.DrawAAPolyLine(3, inflatedGrassListMax.ToArray()); } } if ((VegetationMask.AdditionalPlantPerimiter > 0.1f || VegetationMask.AdditionalPlantPerimiterMax > 0.1f) && VegetationMask.RemovePlants) { List <Vector3> inflatedPlantList = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalPlantPerimiter, true); PolygonUtility.AlignPointsWithTerrain(inflatedPlantList, true, VegetationMaskArea.GroundLayerMask); Handles.Label(GetLabelPosition(inflatedPlantList, 1), "Plants", stLabel); Handles.color = new Color(0, 0, 1, 0.8f); Handles.DrawAAPolyLine(3, inflatedPlantList.ToArray()); if (VegetationMask.AdditionalPlantPerimiterMax > VegetationMask.AdditionalPlantPerimiter) { List <Vector3> inflatedPlantListMax = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalPlantPerimiterMax, true); PolygonUtility.AlignPointsWithTerrain(inflatedPlantListMax, true, VegetationMaskArea.GroundLayerMask); Handles.DrawAAPolyLine(3, inflatedPlantListMax.ToArray()); } } if ((VegetationMask.AdditionalTreePerimiter > 0.1f || VegetationMask.AdditionalTreePerimiterMax > 0.1f) && VegetationMask.RemoveTrees) { List <Vector3> inflatedTreeList = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalTreePerimiter, true); PolygonUtility.AlignPointsWithTerrain(inflatedTreeList, true, VegetationMaskArea.GroundLayerMask); Handles.Label(GetLabelPosition(inflatedTreeList, 2), "Trees", stLabel); Handles.color = new Color(1, 0, 0, 0.8f); Handles.DrawAAPolyLine(3, inflatedTreeList.ToArray()); if (VegetationMask.AdditionalTreePerimiterMax > VegetationMask.AdditionalTreePerimiter) { List <Vector3> inflatedTreeListMax = PolygonUtility.InflatePolygon(worldPointsList, -VegetationMask.AdditionalTreePerimiterMax, true); PolygonUtility.AlignPointsWithTerrain(inflatedTreeListMax, true, VegetationMaskArea.GroundLayerMask); Handles.DrawAAPolyLine(3, inflatedTreeListMax.ToArray()); } } if ((VegetationMask.AdditionalObjectPerimiter > 0.1f || VegetationMask.AdditionalObjectPerimiterMax > 0.1f) && VegetationMask.RemoveObjects) { List <Vector3> inflatedObjectList = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalObjectPerimiter, true); PolygonUtility.AlignPointsWithTerrain(inflatedObjectList, true, VegetationMaskArea.GroundLayerMask); Handles.Label(GetLabelPosition(inflatedObjectList, 3), "Objects", stLabel); Handles.color = new Color(1, 1, 0, 0.8f); Handles.DrawAAPolyLine(3, inflatedObjectList.ToArray()); if (VegetationMask.AdditionalObjectPerimiterMax > VegetationMask.AdditionalObjectPerimiter) { List <Vector3> inflatedObjectListMax = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalObjectPerimiterMax, true); PolygonUtility.AlignPointsWithTerrain(inflatedObjectListMax, true, VegetationMaskArea.GroundLayerMask); Handles.DrawAAPolyLine(3, inflatedObjectListMax.ToArray()); } } if ((VegetationMask.AdditionalLargeObjectPerimiter > 0.1f || VegetationMask.AdditionalLargeObjectPerimiterMax > 0.1f) && VegetationMask.RemoveLargeObjects) { List <Vector3> inflatedLargeObjectList = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalLargeObjectPerimiter, true); PolygonUtility.AlignPointsWithTerrain(inflatedLargeObjectList, true, VegetationMaskArea.GroundLayerMask); Handles.Label(GetLabelPosition(inflatedLargeObjectList, 4), "Large Objects", stLabel); Handles.color = new Color(1, 1, 1, 0.8f); Handles.DrawAAPolyLine(3, inflatedLargeObjectList.ToArray()); if (VegetationMask.AdditionalLargeObjectPerimiterMax > VegetationMask.AdditionalLargeObjectPerimiter) { List <Vector3> inflatedLargeObjectListMax = PolygonUtility.InflatePolygon(worldPointsList, VegetationMask.AdditionalLargeObjectPerimiterMax, true); PolygonUtility.AlignPointsWithTerrain(inflatedLargeObjectListMax, true, VegetationMaskArea.GroundLayerMask); Handles.DrawAAPolyLine(3, inflatedLargeObjectListMax.ToArray()); } } //List<Vector3> _inflatedList2 = PolygonUtility.InflatePolygon(_worldPointsList, 4d, true); //PolygonUtility.AlignPointsWithTerrain(_inflatedList, true); //PolygonUtility.AlignPointsWithTerrain(_inflatedList2, true); //Handles.color = new Color(1, 0, 0, 0.8f); //Handles.DrawAAPolyLine(2, _inflatedList.ToArray()); //Handles.color = new Color(0, 1, 0, 0.8f); //Handles.DrawAAPolyLine(2, _inflatedList2.ToArray()); } }