static void create3DGround() { GameObject ground = new GameObject("3DCurvedGround"); CurvedGround3D curve = ground.AddComponent <CurvedGround3D>(); ground.AddComponent <MeshFilter>(); ground.AddComponent <MeshRenderer>(); ground.AddComponent <MeshCollider>(); curve.addPointAtPosition(new Vector3(1, 30, 0)); curve.addPointAtPosition(new Vector3(10, 40, 0)); curve.addPointAtPosition(new Vector3(20, 30, 0)); setDefaulMaterial(ground); curve.renderCurveMesh(); Undo.RegisterCreatedObjectUndo(ground, "created 3DCurvedGround"); }
public override void OnInspectorGUI() { bool render = false; int selection = EditorGUILayout.Popup("type", selectedType, types); if (selection != selectedType) { selectedType = selection; render = true; if (selectedType == 0) { curve.type = CurvedGround.curveType.Bezier; } else { curve.type = CurvedGround.curveType.Lagrange; } } curve.precision = 1 / EditorGUILayout.FloatField("precision", 1 / curve.precision); curve.yheight = EditorGUILayout.FloatField("y-height", curve.yheight); if (curve.GetType() == typeof(CurvedGround3D)) { CurvedGround3D c = (CurvedGround3D)curve; c.zdepth = EditorGUILayout.FloatField("z-depth", c.zdepth); } CurvedGroundPoint toDelete = null; foreach (CurvedGroundPoint point in curve.anchorPoints) { if (drawPointInInspector(point)) { toDelete = point; } } if (toDelete != null) { curve.anchorPoints.Remove(toDelete); DestroyImmediate(toDelete.gameObject); } if (GUILayout.Button("add point")) { Vector3 point = new Vector3(0, 0, 0); if (curve.anchorPoints.Count > 0) { Vector3 lastPoint = curve.anchorPoints[curve.anchorPoints.Count - 1].position; point.x = lastPoint.x + 5; point.y = lastPoint.y; point.z = 0; } curve.addPointAtPosition(point); } if (GUILayout.Button("update")) { render = true; } if (render) { curve.renderCurveMesh(); } }