本文整理汇总了C#中Rect.GetValueOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.GetValueOrDefault方法的具体用法?C# Rect.GetValueOrDefault怎么用?C# Rect.GetValueOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rect
的用法示例。
在下文中一共展示了Rect.GetValueOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObjectDetection
/// <summary>
///
/// </summary>
/// <param name="rect"></param>
/// <param name="score"></param>
/// <param name="classId"></param>
public ObjectDetection(Rect? rect = null, float score = 0, int classId = -1)
{
Rect = rect.GetValueOrDefault(new Rect());
Score = score;
ClassId = classId;
}
示例2: InternalInitFromImage
private void InternalInitFromImage(Texture2D texture, float pixelsPerMeter, string shaderType, RegistrationPoint regPoint, Rect? rect = null)
{
_texture = texture;
_textureRect = rect.GetValueOrDefault(new Rect(0f, 0f, (float)_texture.width, (float)_texture.height));
if (pixelsPerMeter == 0)
pixelsPerMeter = CinchOptions.DefaultPixelsPerMeter;
this._pixelsPerMeter = pixelsPerMeter;
_regPoint = regPoint;
//flip the y-axis
if (CinchOptions.UseTopLeftSpriteSheetCoordinates)
{
var h = _textureRect.height;
_textureRect.yMin = _texture.height - (_textureRect.yMin + _textureRect.height);
_textureRect.height = h;
}
var scaledRect = new Rect(_textureRect.x/_texture.width, _textureRect.y/_texture.height, _textureRect.width/_texture.width, _textureRect.height/_texture.height);
_originalMesh = new Mesh();
_originalMesh.name = "Scripted_Plane_New_Mesh";
var fullWidth = _textureRect.width / pixelsPerMeter;
var fullHeight = _textureRect.height / pixelsPerMeter;
var left = fullWidth * (0f-regPoint.X);
var right = fullWidth * (1f-regPoint.X);
var top = fullHeight * (0f-regPoint.Y);
var bottom = fullHeight * (1f-regPoint.Y);
var front = -.1f;
var flt = new Vector3(left, top, front);
var frt = new Vector3(right, top, front);
var frb = new Vector3(right, bottom, front);
var flb = new Vector3(left, bottom, front);
_originalMesh.vertices = new Vector3[] {
flt, frt, frb, flb
};
_originalMesh.uv = new Vector2[] {
new Vector2 (scaledRect.xMin, scaledRect.yMin),
new Vector2 (scaledRect.xMax, scaledRect.yMin),
new Vector2 (scaledRect.xMax, scaledRect.yMax),
new Vector2 (scaledRect.xMin, scaledRect.yMax)
};
_originalMesh.triangles = new int[] {
3 , 2 , 1 , 0 , 3 , 1
};
_originalMesh.RecalculateNormals();
_meshFilter = gameObject.AddComponent<MeshFilter>();
_meshFilter.sharedMesh = _transformedMesh;
var shader = ShaderCache.GetShader(shaderType);
_meshRenderer = gameObject.AddComponent<MeshRenderer>();
_meshRenderer.castShadows = false;
_meshRenderer.receiveShadows = false;
_material = _meshRenderer.material;
_material.shader = shader;
_material.mainTexture = _texture;
_material.color = new Color( 1f, 1f, 1f, 1f );
_material.mainTexture.wrapMode = TextureWrapMode.Clamp;
if (Parent == null)
_meshRenderer.enabled = false; //default it to false until it gets added
__UpdateMesh();
}