private void DrawSelectedPointInspector() { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Selected Point N°" + selectedIndex); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } GUILayout.Space(10); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); }
// Allow the points to be dragged individually. private Vector3 ShowPoint(int index) { Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(index)); float size = HandleUtility.GetHandleSize(point); // Keep the handle size constant regardless of view. if (index == 0) { size *= 2f; // Make the first point larger than the rest. } Handles.color = modeColors[(int)spline.GetControlPointMode(index)]; // Show Button Handles for each point. if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotCap)) { selectedIndex = index; Repaint(); // Force the Inspector GUI to refresh. } // Show the Transform Handle for the selected point. if (selectedIndex == index) { EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, handleRotation); if (EditorGUI.EndChangeCheck()) { // Enable Undo for this action. Undo.RecordObject(spline, "Move Point"); // Let Unity know that a change was made. EditorUtility.SetDirty(spline); // Update the spline's point position in localspace. spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point)); } } return(point); }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } if (GUILayout.Button("Remove point")) { spline.RemovePoint(selectedIndex); EditorUtility.SetDirty(spline); } }
/// <summary> /// 改变控制点 /// </summary> private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); //在Inspector面板上显示已选择点的信息 EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectIndex, point); } //改变已选择的点的模式 EditorGUI.BeginChangeCheck(); //inspector面板上显示Mode属性,可以弹出枚举选择菜单 //这里可以实时获取当前选择的点的模式(传入点的索引,找出对应的模式索引下的模式) BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectIndex, mode); EditorUtility.SetDirty(spline); } }
private void DrawSelectedPointInspector() { string displayText = "Selected Point (index " + selectedIndex; if ((selectedIndex % 3) != 0) { displayText += " cp"; } displayText += ")"; GUILayout.Label(displayText); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } }
private Vector3 ShowPoint(int index) { Vector3 point = _handleTransform.TransformPoint(_spline.GetControlPoint(index)); float size = HandleUtility.GetHandleSize(point); if (index == 0) { size *= 2f; } Handles.color = MODE_COLORS[(int)_spline.GetControlPointMode(index)]; if (Handles.Button(point, _handleRotation, size * HANDLE_SIZE, size * PICK_SIZE, Handles.DotCap)) { _selectedIndex = index; Repaint(); } if (_selectedIndex == index) { EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, _handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Move Point"); EditorUtility.SetDirty(_spline); _spline.SetControlPoint(index, _handleTransform.InverseTransformPoint(point)); } } return(point); }
private Vector3 ShowPoint(int index) { Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(index)); float size = HandleUtility.GetHandleSize(point); if (index == 0) { size *= 2f; } Handles.color = modeColors[(int)spline.GetControlPointMode(index)]; if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotHandleCap)) { selectedIndex = index; Repaint(); } if (selectedIndex == index) { EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point)); } } return(point); }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); GUI.enabled = false; EditorGUILayout.TextField("Index", selectedIndex.ToString()); GUI.enabled = true; EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } }
/// <summary> /// Given each sub-spline from one node to the next in our path, stitch them all together to form one large bezier spline. /// </summary> public void CalculatePathSpline() { // Quick way to remove all previous curves and points. // One curve is created during Reset(), so we have to clear that out too selectedPathSpline.Reset(); selectedPathSpline.RemoveCurve(); for (int currentNodeIndex = 0; currentNodeIndex < selectedPath.Count - 1; currentNodeIndex++) { selectedPathSpline.AddCurve(); // -- Set the control point mode. // Due to the way that I set up the node positions, free mode is the only one that looks good. I could use Aligned or Mirrored if I added more inbetween nodes, but my setup for creating nodes was kinda garbage // Free mode only is fine for now selectedPathSpline.SetControlPointMode(3 * currentNodeIndex, controlPointMode); selectedPathSpline.SetControlPointMode(3 * currentNodeIndex + 3, controlPointMode); // Find the index of the sub-spline we want, in the node. // We have to do this search, since we store multiple sub-splines in each node int index = selectedPath[currentNodeIndex].connectedNodes.IndexOf(selectedPath[currentNodeIndex + 1]); BezierSpline subSpline = selectedPath[currentNodeIndex].connectedNodePaths[index]; Vector3 toNode = selectedPath[currentNodeIndex].transform.position - transform.position; // -- Copy over each control point of the spline // Need to do this in this weird order, because we have to set the control points after the pivot points. // BezierSpline.SetControlPoints should probably get refactored to include an overload method to avoid this, but oh well selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 0, toNode + subSpline.GetControlPoint(0)); selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 1, toNode + subSpline.GetControlPoint(1)); selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 3, toNode + subSpline.GetControlPoint(3)); selectedPathSpline.SetControlPoint(3 * currentNodeIndex + 2, toNode + subSpline.GetControlPoint(2)); } }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } GUILayout.Label("Constraint"); EditorGUI.BeginChangeCheck(); Transform constraint = EditorGUILayout.ObjectField("Constraint", spline.GetConstraint(selectedIndex), typeof(Transform), true) as Transform; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Constraint"); spline.SetConstraint(selectedIndex, constraint); EditorUtility.SetDirty(spline); } }
// --------- // Functions // --------- // Used to draw a new inspector based on the selected spline control point private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); // Draw our spline control points if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } // Draw the mode per point EditorGUI.BeginChangeCheck(); // This probably should be its own class. BezierSpline.BezierControlPointMode mode = (BezierSpline.BezierControlPointMode) EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } }
private Vector3 ShowPoint(int p) { Vector3 point = t.TransformPoint(spline.GetControlPoint(p)); float zoom = 1f; /* If the handle is active, mark the index as currently selected for then, draw the Handle */ Handles.color = modeColor[(int)spline.GetControlPointMode(p)]; if (p == 0) { zoom *= 2f; } if (Handles.Button(point, q, handleSize * zoom, pickSize, Handles.DotCap)) { selectedIndex = p; } // refresh point in inspector - such that it is updated on the GUI upon selection Repaint(); if (selectedIndex == p) { EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, q); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Cubic Curve Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(p, t.InverseTransformPoint(point)); } } return(point); }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); isFlat = GUILayout.Toggle(isFlat, new GUIContent("Make Flat")); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { if (isFlat) { point.y = 0; } Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = ( BezierControlPointMode ) EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } /* Now BezierSplineInspector can allow us to change the mode of the selected point. * You will notice that changing the mode of one point also appears to change the mode of the points that are linked to it. */ EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode) EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); spline.RecalculateSplineDistance(); spline.SetControlPoint(selectedIndex, point); EditorUtility.SetDirty(spline); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode) EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } if (selectedIndex % 3 == 0 && spline.points.Length > 4) { if (GUILayout.Button("Delete Curve Point")) { Undo.RecordObject(spline, "Delete Curve Point"); spline.DeleteCurve(selectedIndex); spline.RecalculateSplineDistance(); selectedIndex = -1; EditorUtility.SetDirty(spline); } } }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } }
static void RenderCustomGizmo(Transform objectTransform_, GizmoType gizmoType_) { //If our list of splines to render is null, we initialize a new one if (splinesToAlwaysRender == null) { splinesToAlwaysRender = new List <BezierSpline>(); return; } //If we have at least 1 spline in our list, we render them if (splinesToAlwaysRender.Count > 0) { //Looping through all of the splines in our list for (int b = 0; b < splinesToAlwaysRender.Count; ++b) { BezierSpline bs = splinesToAlwaysRender[b]; //If the current spline is null, we remove it from the list of splines to render if (bs == null) { splinesToAlwaysRender.RemoveAt(b); b -= 1; } //If the current spline isn't the one we have selected, we render it else { //Getting the spline object's transform Transform bsTransformPoint = bs.gameObject.transform; //Getting each point's handle position to display Vector3 p0 = bsTransformPoint.TransformPoint(bs.GetControlPoint(0)); //Looping through every curve in our spline to draw them for (int i = 1; i < bs.ControlPointCount; i += 3) { Vector3 p1 = bsTransformPoint.TransformPoint(bs.GetControlPoint(i)); Vector3 p2 = bsTransformPoint.TransformPoint(bs.GetControlPoint(i + 1)); Vector3 p3 = bsTransformPoint.TransformPoint(bs.GetControlPoint(i + 2)); //Drawing the bezier curve Handles.DrawBezier(p0, p3, p1, p2, bs.splineColor, null, bs.splineWidth); //Setting it so that the last point on this drawn curve is the starting point for the next curve p0 = p3; } } } } }
private void SpawnSplines() { BezierSpline[] deleteSplines = GameObject.FindObjectsOfType <BezierSpline>(); foreach (BezierSpline spline in deleteSplines) { spline.SetDestroy(true); } int splineCount = StatManager.instance.GetWaveNumber(); splineCount = Mathf.Clamp(splineCount, 1, 5); for (int i = 0; i < splineCount; i++) { BezierSpline spline = droneSplines[Random.Range(0, droneSplines.Count)]; Vector3 approxPlayerPosition = GameManager.instance.GetPlayer().position; approxPlayerPosition += new Vector3(Random.Range(-2.0f, 2.0f), Random.Range(-2.0f, 2.0f), 0); Vector3 splineCenterPosition = spline.GetControlPoint((int)spline.GetControlPointCount() / 2); Vector3 splinePosition = approxPlayerPosition - splineCenterPosition; Instantiate(spline.gameObject, splinePosition, Quaternion.identity); Swarmspawner swarmSpawner = spline.GetComponent <Swarmspawner>(); if (swarmSpawner != null) { swarmSpawner.SetPool(dronePool); } } }
// Draw the line, and record any changes performed via the GUI private Vector3 ShowPoint(int i) { Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(i)); // Scale the points' cube size with screen size float screenSize = HandleUtility.GetHandleSize(point); Handles.color = modeColors[(int)spline.GetControlPointMode(i)]; // Draw cube buttons on each point if (Handles.Button(point, handleRotation, screenSize * handleSize, screenSize * pickSize, Handles.DotHandleCap)) { selectedIndex = i; } // If we've selected the current point, then draw a Position Handle if (selectedIndex == i) { EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(i, handleTransform.InverseTransformPoint(point)); } } return point; }
public void Generate() { var previousAnchor = spline.GetControlPoint(spline.ControlPointCount - 1); var previousControl = spline.GetControlPoint(spline.ControlPointCount - 2); // Random random anchors with control points automatically smoothed var anchors = GenerateAnchors(anchorGenerationCount, previousAnchor, ref forward); splinePoints = SmoothBezierFromAnchors(anchors); for (var i = 1; i < splinePoints.Length; i += 3) { spline.AddCurve(splinePoints[i], splinePoints[i + 1], splinePoints[i + 2]); spline.SetControlPointMode(spline.ControlPointCount - 1, BezierControlPointMode.Mirrored); } mesh.UpdateMesh(); }
/// <summary> /// Call after generating the stitched spline /// </summary> /// <param name="position"></param> public void AdjustFinalPosition(Vector3 position) { // Cache the n-1'th control point, since that'll get altered when we change the final position Vector3 tempControlPoint = selectedPathSpline.GetControlPoint(selectedPathSpline.numControlPoints - 2); selectedPathSpline.SetControlPoint(selectedPathSpline.numControlPoints - 1, position); selectedPathSpline.SetControlPoint(selectedPathSpline.numControlPoints - 2, tempControlPoint); }
protected virtual void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", _spline.GetControlPoint(_selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Move Point"); EditorUtility.SetDirty(_spline); _spline.SetControlPoint(_selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", _spline.GetControlPointMode(_selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Change Point Mode"); _spline.SetControlPointMode(_selectedIndex, mode); EditorUtility.SetDirty(_spline); } // Draw Node Data if ADV SPLINE // Would be in AdvSplineInspector, except AdvSpline is generic meaning // we can't use the CustomEditor attribute and force child types to use its inspector // which means either this is here or every AdvSpline child needs an associated TypeInspector script if (_selectedIndex % 3 == 0) { int advNodeIndex = _selectedIndex / 3; SerializedObject so = serializedObject; SerializedProperty nodeDataProp = so.FindProperty(string.Format("{0}.Array.data[{1}]", "_nodeData", advNodeIndex)); if (nodeDataProp != null) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(nodeDataProp, new GUIContent("Node Data"), true); if (EditorGUI.EndChangeCheck()) { so.ApplyModifiedProperties(); } } } }
void Start() { curve = Mathf.Clamp(curve, 0, spline.CurveCount - 1); points = new Vector3[4]; for (int i = 0; i < 4; i++) { points[i] = spline.GetControlPoint(3 * curve + i); } }
public bool checkIsComplete() { bool isComplete = false; float checkUntilIndex = m_splinePointCount - (m_bezierSpline.getDimension() * 4); if (m_splinePointCount > checkUntilIndex) { for (int i = 0; i < checkUntilIndex; ++i) { if (Vector3.Distance(m_raycastedPosition, m_bezierSpline.GetControlPoint(i)) < m_completionDistanceCheck) { isComplete = true; m_closedLoopStartPoint = (float)i / (float)m_splinePointCount; } } } return(isComplete); }
private void ManageDrag(int dragPointIndex) { Vector3 pointNewPositionSplineSpace = new Vector3(); Vector3 originalPoint = mySpline.GetControlPoint(dragPointIndex); switch (m_dragType) { case DragType.LeftMouse: pointNewPositionSplineSpace = MousePosInSplinePlane(originalPoint.y); break; case DragType.RightMouse: pointNewPositionSplineSpace = MousePosInSplineVertical(originalPoint.x, originalPoint.z); break; } Undo.RecordObject(mySpline, "Moved Point"); mySpline.SetControlPoint(dragPointIndex, pointNewPositionSplineSpace); SceneView.RepaintAll(); }
void OnDrawGizmos() { BezierSpline spline = this; Transform handleTransform = spline.transform; Vector3 p0 = handleTransform.TransformPoint(spline.GetControlPoint(0)); for (int i = 1; i < spline.ControlPointCount; i += 3) { Vector3 p1 = handleTransform.TransformPoint(spline.GetControlPoint((i))); Vector3 p2 = handleTransform.TransformPoint(spline.GetControlPoint((i + 1))); Vector3 p3 = handleTransform.TransformPoint(spline.GetControlPoint((i + 2))); UnityEditor.Handles.color = Color.gray; UnityEditor.Handles.DrawLine(p0, p1); UnityEditor.Handles.DrawLine(p2, p3); UnityEditor.Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f); p0 = p3; } }
public void AdaptSplineToTerrain() { int splineNodes = spline.ControlPointCount; Debug.Log(splineNodes); for (int i = 0; i < splineNodes; i += 3) { Vector3 nodePos = spline.GetControlPoint(i); float terrainHeight = tCE.WorldToTerrainHeight(new Vector2(nodePos.x, nodePos.z)); nodePos.y = terrainHeight; spline.SetControlPoint(i, nodePos); } }
Vector3 ShowPoint(int idx) { // convert to world space since handles are in local space Vector3 point = _splineT.TransformPoint(_spline.GetControlPoint(idx)); Handles.color = Color.white; float size = HandleUtility.GetHandleSize(point); if (idx == 0) { size *= 2f; } Handles.color = modeColors[(int)_spline.GetControlPointMode(idx)]; // If this point is selected if (Handles.Button(point, _splineR, size * HANDLE_SIZE, size * PICK_SIZE, Handles.DotCap)) { _selectedIndex = idx; Repaint(); } // If point is selected and position is changed if (_selectedIndex == idx) { EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, _splineR); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Move Point"); EditorUtility.SetDirty(_spline); // convert back to local space _spline.SetControlPoint(idx, _splineT.InverseTransformPoint(point)); } } return(point); }
public void DrawSelectedPointInspector(int index) { GUILayout.Label("Selected Point: " + index.ToString()); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(index)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(index, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(index)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(index, mode); EditorUtility.SetDirty(spline); } }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); var point = EditorGUILayout.Vector3Field("Position", _spline.GetControlPoint(SelectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Move Point"); EditorUtility.SetDirty(_spline); _spline.SetControlPoint(SelectedIndex, point); } EditorGUI.BeginChangeCheck(); var mode = (BezierSpline.BezierControlPointMode) EditorGUILayout.EnumPopup("Mode", _spline.GetControlPointMode(SelectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Change Point Mode"); _spline.SetControlPointMode(SelectedIndex, mode); EditorUtility.SetDirty(_spline); } }