本文整理汇总了C#中NetInfo.GetMinNodeDistance方法的典型用法代码示例。如果您正苦于以下问题:C# NetInfo.GetMinNodeDistance方法的具体用法?C# NetInfo.GetMinNodeDistance怎么用?C# NetInfo.GetMinNodeDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetInfo
的用法示例。
在下文中一共展示了NetInfo.GetMinNodeDistance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SnapDirectionOverride
public static NetTool.ControlPoint SnapDirectionOverride(NetTool.ControlPoint newPoint,
NetTool.ControlPoint oldPoint,
NetInfo info, out bool success, out float minDistanceSq)
{
if (Debug.Enabled)
{
DebugPrint = string.Format("oldPoint: {0}\nnewPoint:{1}", StringUtil.ToString(oldPoint),
StringUtil.ToString(newPoint));
}
GuideLines.Clear();
SnappedGuideLine = null;
minDistanceSq = info.GetMinNodeDistance();
minDistanceSq = minDistanceSq*minDistanceSq;
var controlPoint = newPoint;
success = false;
if (EnableSnapping)
{
// If dragging from a node
if (oldPoint.m_node != 0 && !newPoint.m_outside)
{
// Node the road build operation is starting from
var sourceNodeId = oldPoint.m_node;
var sourceNode = NetManager.instance.m_nodes.m_buffer[sourceNodeId];
// Direction and length of the line from the node to the users control point
var userLineDirection = (newPoint.m_position - sourceNode.m_position).Flatten();
var userLineLength = userLineDirection.magnitude;
userLineDirection.Normalize();
var closestSegmentId = NetNodeUtility.GetClosestSegmentId(sourceNodeId, userLineDirection);
if (closestSegmentId > 0)
{
// Snap to angle increments originating from this closest segment
var closestSegmentDirection = NetNodeUtility.GetSegmentExitDirection(sourceNodeId,
closestSegmentId);
var currentAngle = Vector3Extensions.Angle(closestSegmentDirection, userLineDirection,
Vector3.up);
var snappedAngle = Mathf.Round(currentAngle/Settings.SnapAngle)*Settings.SnapAngle;
var snappedDirection = Quaternion.AngleAxis(snappedAngle, Vector3.up)*closestSegmentDirection;
controlPoint.m_direction = snappedDirection.normalized;
controlPoint.m_position = sourceNode.m_position + userLineLength*controlPoint.m_direction;
controlPoint.m_position.y = newPoint.m_position.y;
minDistanceSq = (newPoint.m_position - controlPoint.m_position).sqrMagnitude;
success = true;
//minDistanceSq = olpo;
}
}
else if (oldPoint.m_segment != 0 && !newPoint.m_outside)
{
// Else if dragging from a segment
// Segment the road build operation is starting from
var sourceSegmentId = oldPoint.m_segment;
var sourceSegment = NetManager.instance.m_segments.m_buffer[sourceSegmentId];
Vector3 segmentDirection;
Vector3 segmentPosition;
// Direction and length of the line between control points
var userLineDirection = (newPoint.m_position - oldPoint.m_position).Flatten();
var userLineLength = userLineDirection.magnitude;
userLineDirection.Normalize();
// Get direction of the segment at the branch position
sourceSegment.GetClosestPositionAndDirection(oldPoint.m_position, out segmentPosition,
out segmentDirection);
var currentAngle = Vector3Extensions.Angle(segmentDirection, userLineDirection, Vector3.up);
segmentDirection = segmentDirection.Flatten().normalized;
var snappedAngle = Mathf.Round(currentAngle/Settings.SnapAngle)*Settings.SnapAngle;
var snappedDirection = Quaternion.AngleAxis(snappedAngle, Vector3.up)*segmentDirection;
controlPoint.m_direction = snappedDirection.normalized;
controlPoint.m_position = oldPoint.m_position + userLineLength*controlPoint.m_direction;
controlPoint.m_position.y = newPoint.m_position.y;
minDistanceSq = (newPoint.m_position - controlPoint.m_position).sqrMagnitude;
success = true;
}
else if (oldPoint.m_direction.sqrMagnitude > 0.5f)
{
if (newPoint.m_node == 0 && !newPoint.m_outside)
{
// Let's do some snapping between control point directions
var currentAngle = Vector3Extensions.Angle(oldPoint.m_direction, newPoint.m_direction,
Vector3.up);
//.........这里部分代码省略.........