private static CurvedLinePoint InsertControlPoint(CurvedLinePoint linePoint, bool before) { CurvedLineRenderer curvedLine = linePoint.GetComponentInParent <CurvedLineRenderer>(); CurvedLinePoint newLinePoint = AddControlPoint(curvedLine); List <CurvedLinePoint> linePointList = new List <CurvedLinePoint>(curvedLine.LinePoints); int idx = linePointList.IndexOf(linePoint); int siblingIndex = linePoint.transform.GetSiblingIndex(); if (before) { CurvedLinePoint prevLinePoint = curvedLine.LinePoints[idx - 1]; newLinePoint.transform.SetSiblingIndex(siblingIndex); linePoint.transform.SetSiblingIndex(siblingIndex + 1); // set the new point in the middle between the current and the prervious point newLinePoint.transform.position = (prevLinePoint.transform.position + linePoint.transform.position) * 0.5f; } else { if (curvedLine.LinePoints.Length > idx + 1) { CurvedLinePoint nextLinePoint = curvedLine.LinePoints[idx + 1]; newLinePoint.transform.SetSiblingIndex(siblingIndex + 1); // set the new point in the middle between the current and the next point newLinePoint.transform.position = (nextLinePoint.transform.position + linePoint.transform.position) * 0.5f; } } curvedLine.Update(); RenameControlPoints(curvedLine.LinePoints); return(newLinePoint); }
private static bool ValidateInsertControlPointCommand(MenuCommand menuCommand) { CurvedLinePoint linePoint = menuCommand.context as CurvedLinePoint; CurvedLineRenderer curvedLine = linePoint.GetComponentInParent <CurvedLineRenderer>(); return(curvedLine.LinePoints.Length > 1); }
private static void NewCurvedLineCommand(MenuCommand menuCommand) { GameObject newObj = new GameObject("CurvedLine"); Undo.RegisterCreatedObjectUndo(newObj, "New curved line"); GameObject selectedObject = Selection.activeGameObject; Material parentLineMaterial = null; if (selectedObject != null && selectedObject.GetComponent <CurvedLineRenderer>() == null) { newObj.transform.SetParent(selectedObject.transform, false); CurvedLinePoint parentLinePoint = selectedObject.GetComponent <CurvedLinePoint>(); if (parentLinePoint != null) { CurvedLineRenderer parentCurvedLine = parentLinePoint.GetComponentInParent <CurvedLineRenderer>(); if (parentCurvedLine != null) { parentLineMaterial = parentCurvedLine.GetComponent <LineRenderer>().sharedMaterial; } } } CurvedLineRenderer curvedLine = newObj.AddComponent <CurvedLineRenderer>(); Selection.activeGameObject = newObj; UnityEditorInternal.ComponentUtility.MoveComponentUp(curvedLine); AddControlPoint(curvedLine); AddControlPoint(curvedLine); if (parentLineMaterial != null) { newObj.GetComponent <LineRenderer>().sharedMaterial = parentLineMaterial; } curvedLine.Update(); }