private static int AddPoint(Curve curve, Vector2 addPos) /// Returns the number of added point. AddPos is in curve-relative coordinates { //finding segemnt int addSegment = 0; if (addPos.x < curve.points[0].pos.x) { addSegment = 0; } else if (addPos.x > curve.points[curve.points.Length - 1].pos.x) { addSegment = curve.points.Length; } else { for (int p = 0; p < curve.points.Length - 1; p++) { if (addPos.x > curve.points[p].pos.x && addPos.x < curve.points[p + 1].pos.x) { addSegment = p + 1; } } } UI.current.MarkChanged(); ArrayTools.Insert(ref curve.points, addSegment, new Curve.Node(addPos)); return(addSegment); }
private static void AddLockLayer (MapMagicObject mapMagic, int num) { Lock newLock = new Lock(); newLock.guiName = "Location " + mapMagic.locks.Length; newLock.worldPos = new Vector3(mapMagic.tileSize.x/2, 0, mapMagic.tileSize.z/2); //placing at the center of the tile 0 ArrayTools.Insert(ref mapMagic.locks, mapMagic.locks.Length, newLock); //mapMagic.ClearAll(); //don't jenerate on adding lock (we might have a custom location prepared) //mapMagic.StartGenerate(); //mapMagic.GenerateAll(); SceneView.RepaintAll(); }
private void DrawRewiredActionProperty(SerializedProperty serializedProperty) { if (serializedProperty == null) { return; } DrawPopupProperty( ArrayTools.Insert(userData.GetActionIds(), 0, -1), ArrayTools.Insert(userData.GetActionNames(), 0, "[None]"), serializedProperty ); }
public static void DragCurve(Curve curve) /// Backup curve to return the removed nodes when dragging cursor returned to curve field { if (UI.current.layout) { return; } if (UI.current.optimizeElements && !UI.current.IsInWindow()) { return; } //moving bool isDragging = false; bool isReleased = false; int dragNum = -1; Curve.Node[] originalPoints = null; for (int i = 0; i < curve.points.Length; i++) { bool newDragging = false; bool newReleased = false; Vector2 newPos = DragPoint(curve, i, ref newDragging, ref newReleased); if (newDragging) { originalPoints = new Curve.Node[curve.points.Length]; //curve.GetPositions(); for (int p = 0; p < originalPoints.Length; p++) { originalPoints[p] = new Curve.Node(curve.points[p]); } curve.points[i].pos = newPos; } if (newDragging || newReleased) { dragNum = i; } isDragging = isDragging || newDragging; isReleased = isReleased || newReleased; } //adding if (ClickedNearCurve(curve)) { Vector2 addPos = ToCurve(UI.current.mousePos); int addedNum = AddPoint(curve, addPos); //starting drag DragPoint(curve, addedNum, ref isDragging, ref isReleased); //just to start drag } //removing if (isDragging) { //calc if node should be removed bool isRemoved = false; if (dragNum != 0 && dragNum != curve.points.Length - 1) //ignoring first and last { Vector2 pos = ToCell(curve.points[dragNum].pos); if (!Cell.current.InternalRect.Extended(10).Contains(pos)) { isRemoved = true; } } //removing if (isRemoved) { UI.current.MarkChanged(completeUndo: true); ArrayTools.RemoveAt(ref curve.points, dragNum); } //clamping if cursor is too close to the field to remove else { ClampPoint(curve, dragNum); } } //if returned dragging to field else if (DragDrop.obj != null && DragDrop.obj.GetType() == typeof((Curve, Curve.Node, int))) { (Curve curve, Curve.Node node, int num)dragObj = ((Curve, Curve.Node, int))DragDrop.obj; if (dragObj.curve == curve && !curve.points.Contains(dragObj.node)) { DragDrop.TryDrag(dragObj, UI.current.mousePos); //to make it repaint if (Cell.current.InternalRect.Extended(10).Contains(UI.current.mousePos)) { ArrayTools.Insert(ref curve.points, dragObj.num, dragObj.node); dragObj.node.pos = ToCurve(UI.current.mousePos); ClampPoint(dragObj.curve, dragObj.num); //this will place it between prev and next points } DragDrop.TryRelease(dragObj, UI.current.mousePos); //otherwise it will not be released forever } } if (Cell.current.valChanged) { curve.Refresh(); } }
public void Split(int n, float p) { Vector3 point = GetPoint(n, p); ArrayTools.Insert(ref nodes, n + 1, point); //new node position will be n+1 }
public void InsertSegment(int index, Segment segment) { ArrayTools.Insert(ref segments, index, segment); }
public void Split(int s, float p) { (Segment prev, Segment next) = segments[s].GetSplitted(p); segments[s] = prev; ArrayTools.Insert(ref segments, s + 1, next); }