public static void DrawPolygonCollider( bool snapToGrid, EditorShapeProperty shape, EditorShapeColor color, List <Vector2> vertices, Vector3[] polygonBuffer, Vector3[] faceBuffer) { var zPos = shape.Position.z; var baseHeight = zPos * Constants.ZConstant; var roofHeight = (zPos + shape.Height) * Constants.ZConstant; var floorPos = (Vector2)shape.Position; var basePos = floorPos + new Vector2(0, baseHeight); var roofPos = floorPos + new Vector2(0, roofHeight); var offset2 = (Vector2)shape.Offset; var floorPivot = floorPos + offset2; var roofPivot = roofPos + offset2; var basePivot = basePos + offset2; DrawFilledPolygon(floorPivot, shape.Rotation, vertices, polygonBuffer, color.Shadow); DrawPolygon3DFeatures(floorPivot, baseHeight, roofHeight, shape.Rotation, vertices, faceBuffer, color.Face); DrawFilledPolygon(roofPivot, shape.Rotation, vertices, polygonBuffer, color.Roof); DrawFilledPolygon(basePivot, shape.Rotation, vertices, polygonBuffer, color.Base); DrawVertexHandles(snapToGrid, basePivot, shape.Rotation, vertices, shape.HandleSize, color.Line); }
public void OnSceneGUI() { var collider = (ColliderAuthoring)target; var transform = collider.GetComponent <Transform>(); var rotation = transform.eulerAngles.z; var offset2 = (Vector2)collider.PivotOffset; var position2 = (Vector2)transform.position; var isConvex = EditorUtils.IsConvex(collider.Vertices); var handleSize = EditorUtils.FixHandleSize(HandleSize); EditorUtils.DrawPivot(ref position2, ref offset2, handleSize, PositionColor, PivotColor); var shape = new EditorShapeProperty { Height = collider.Height, Offset = collider.PivotOffset, Position = transform.position, Rotation = rotation, HandleSize = handleSize, }; var color = new EditorShapeColor { Line = isConvex ? ValidLineColor : InvalidLineColor, Base = isConvex ? ValidBaseColor : InvalidBaseColor, Roof = isConvex ? ValidRoofColor : InvalidRoofColor, Face = isConvex ? ValidFaceColor : InvalidFaceColor, Shadow = ShadowColor, }; var isBiggerThanCellSize = false; switch (collider.Shape) { case ColliderShapeType.Polygon: var bounds = EditorUtils.GetBounds(offset2 + position2, rotation, collider.Vertices); isBiggerThanCellSize = bounds.IsBiggerThanCellSize; var boundsColor = isBiggerThanCellSize ? InvalidBoundsColor : ValidBoundsColor; EditorUtils.DrawBounds(bounds, boundsColor); EditorUtils.DrawPolygonCollider(SnapToGrid, shape, color, collider.Vertices, ConvexPolygonBuffer, FaceBuffer); break; case ColliderShapeType.Circle: EditorUtils.DrawCircleCollider(shape, color, ref collider.CenterOffset, ref collider.Radius); break; case ColliderShapeType.Cone: break; } collider.IsBiggerThanCellSize = isBiggerThanCellSize; collider.PivotOffset = new Vector3(offset2.x, offset2.y, transform.position.z); transform.position = new Vector3(position2.x, position2.y, transform.position.z); }
public static void DrawCircleCollider( EditorShapeProperty shape, EditorShapeColor color, ref Vector2 centerOffset, ref float radius) { var zPos = shape.Position.z; var baseHeight = zPos * Constants.ZConstant; var roofHeight = (zPos + shape.Height) * Constants.ZConstant; var floorPos = (Vector2)shape.Position; var basePos = floorPos + new Vector2(0, baseHeight); var roofPos = floorPos + new Vector2(0, roofHeight); var offset2 = (Vector2)shape.Offset; var floorPivot = floorPos + offset2; var roofPivot = roofPos + offset2; var basePivot = basePos + offset2; var rot = MathUtil.GetRotationMatrix(shape.Rotation); var unrot = math.transpose(rot); centerOffset = math.mul(rot, centerOffset); var floorCenter = floorPivot + centerOffset; var roofCenter = roofPivot + centerOffset; var baseCenter = basePivot + centerOffset; Handles.color = color.Shadow; Handles.DrawSolidDisc(floorCenter, Vector3.forward, radius); Handles.color = color.Roof; Handles.DrawSolidDisc(roofCenter, Vector3.forward, radius); Handles.color = color.Base; Handles.DrawWireDisc(baseCenter, Vector3.forward, radius); Handles.DrawLine(baseCenter + new Vector2(radius, 0), roofCenter + new Vector2(radius, 0)); Handles.DrawLine(baseCenter - new Vector2(radius, 0), roofCenter - new Vector2(radius, 0)); Handles.DrawLine(baseCenter - new Vector2(0, radius), roofCenter - new Vector2(0, radius)); Handles.DrawLine(baseCenter - new Vector2(radius, radius).normalized *radius, roofCenter - new Vector2(radius, radius).normalized *radius); Handles.DrawLine(baseCenter - new Vector2(-radius, radius).normalized *radius, roofCenter - new Vector2(-radius, radius).normalized *radius); Handles.DrawDottedLine(floorCenter + new Vector2(radius, 0), baseCenter + new Vector2(radius, 0), 5); Handles.DrawDottedLine(floorCenter - new Vector2(radius, 0), baseCenter - new Vector2(radius, 0), 5); Handles.DrawDottedLine(floorCenter - new Vector2(0, radius), baseCenter - new Vector2(0, radius), 5); centerOffset = math.mul(unrot, MoveHandle(centerOffset + floorPivot, shape.HandleSize) - floorPivot); }