本文整理汇总了C#中UnityEngine.Vector2.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.Scale方法的具体用法?C# Vector2.Scale怎么用?C# Vector2.Scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Vector2
的用法示例。
在下文中一共展示了Vector2.Scale方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateLine
private void UpdateLine()
{
_size = size;
float totalDistance = 0;
Vector3 lastPosition = Vector3.zero;
List<Vector3> vertices = new List<Vector3>();
List<Vector2> uvs = new List<Vector2>();
List<Vector3> normals = new List<Vector3>();
List<int> triangles = new List<int>();
List<Vector3> positions = new List<Vector3>();
for (int i = 0; i < coords.Length; i++)
{
// Get world position by coordinates
Vector3 position = OnlineMapsTileSetControl.instance.GetWorldPosition(coords[i]);
positions.Add(position);
if (i != 0)
{
// Calculate angle between coordinates.
float a = OnlineMapsUtils.Angle2DRad(lastPosition, position, 90);
// Calculate offset
Vector3 off = new Vector3(Mathf.Cos(a) * size, 0, Mathf.Sin(a) * size);
// Init verticles, normals and triangles.
int vCount = vertices.Count;
vertices.Add(lastPosition + off);
vertices.Add(lastPosition - off);
vertices.Add(position + off);
vertices.Add(position - off);
normals.Add(Vector3.up);
normals.Add(Vector3.up);
normals.Add(Vector3.up);
normals.Add(Vector3.up);
triangles.Add(vCount);
triangles.Add(vCount + 3);
triangles.Add(vCount + 1);
triangles.Add(vCount);
triangles.Add(vCount + 2);
triangles.Add(vCount + 3);
totalDistance += (lastPosition - position).magnitude;
}
lastPosition = position;
}
float tDistance = 0;
for (int i = 1; i < positions.Count; i++)
{
float distance = (positions[i - 1] - positions[i]).magnitude;
// Updates UV
uvs.Add(new Vector2(tDistance / totalDistance, 0));
uvs.Add(new Vector2(tDistance / totalDistance, 1));
tDistance += distance;
uvs.Add(new Vector2(tDistance / totalDistance, 0));
uvs.Add(new Vector2(tDistance / totalDistance, 1));
}
// Update mesh
mesh.vertices = vertices.ToArray();
mesh.normals = normals.ToArray();
mesh.uv = uvs.ToArray();
mesh.triangles = triangles.ToArray();
// Scale texture
Vector2 scale = new Vector2(totalDistance / size, 1);
scale.Scale(uvScale);
meshRenderer.material.mainTextureScale = scale;
}
示例2: PopulateLineSegment
/**
* The coordinate point set must be length 4
* <p>
* Notice that C# uses pass by value; use; x.v = PopulateLineSegment(x.v);
*/
public static void PopulateLineSegment(Vector3[] points, Vector2 start, Vector2 end, float startWidth, float endWidth)
{
var q = end - start;
var x = new Vector3(q [1], -q [0], 0);
var w1 = startWidth;
var w2 = endWidth;
/* Some kind of weird issue prevents unity from rendering tiny width meshes.
* This is minimum size of a half-strip-width that seems to render ok. */
var minStripWidth = 0.01;
/* Start point */
x.Normalize();
var y = new Vector2(x[0], x[1]);
y.Scale(new Vector3(w1 / 2.0f, w1 / 2.0f, 0f));
if (y.magnitude < minStripWidth) {
y = new Vector2(x[0], x[1]);
y[0] = (float) ((double) y[0] * minStripWidth);
y[1] = (float) ((double) y[1] * minStripWidth);
}
points[0] = new Vector3(start [0] + y[0], start [1] + y[1], 0);
points[1] = new Vector3(start [0] - y[0], start [1] - y[1], 0);
/* End point */
y = new Vector2(x[0], x[1]);
y.Scale(new Vector3(w2 / 2.0f, w2 / 2.0f, 0f));
if (y.magnitude < minStripWidth) {
y = new Vector2(x[0], x[1]);
y[0] = (float) ((double) y[0] * minStripWidth);
y[1] = (float) ((double) y[1] * minStripWidth);
}
points[2] = new Vector3(end [0] + y[0], end[1] + y[1], 0);
points[3] = new Vector3(end [0] - y[0], end[1] - y[1], 0);
}
示例3: TestScaleBy
public static void TestScaleBy()
{
const float floatScale = 4.8f;
const float floatStart = 1.2f;
float floatVal = floatStart;
Ref<float> floatRef = new Ref<float>(
() => floatVal,
t => floatVal = t
);
const double doubleScale = 3.2;
const double doubleStart = 9.2;
double doubleVal = doubleStart;
Ref<double> doubleRef = new Ref<double>(
() => doubleVal,
t => doubleVal = t
);
Vector2 vec2Scale = new Vector2(9.5f, 2.0f);
Vector2 vec2Start = new Vector2(4.0f, 5.0f);
Vector2 vec2Val = vec2Start;
Ref<Vector2> vec2Ref = new Ref<Vector2>(
() => vec2Val,
t => vec2Val = t
);
Vector3 vec3Scale = new Vector3(4.0f, 19.0f, 2.0f);
Vector3 vec3Start = new Vector3(92.0f, 0.5f, 34.0f);
Vector3 vec3Val = vec3Start;
Ref<Vector3> vec3Ref = new Ref<Vector3>(
() => vec3Val,
t => vec3Val = t
);
Vector4 vec4Scale = new Vector4(92.0f, 0.5f, 14.0f, 7.0f);
Vector4 vec4Start = new Vector4(0.4f, 10.0f, 3.0f, 82.0f);
Vector4 vec4Val = vec4Start;
Ref<Vector4> vec4Ref = new Ref<Vector4>(
() => vec4Val,
t => vec4Val = t
);
CommandQueue queue = new CommandQueue();
queue.Enqueue(
Commands.Repeat(2,
Commands.Sequence(
Commands.Parallel(
Commands.ScaleBy(floatRef, floatScale, 1.0),
Commands.ScaleBy(doubleRef, doubleScale, 1.0),
Commands.ScaleBy(vec2Ref, vec2Scale, 1.0),
Commands.ScaleBy(vec3Ref, vec3Scale, 1.0),
Commands.ScaleBy(vec4Ref, vec4Scale, 1.0)
),
Commands.WaitForFrames(1)
)
)
);
queue.Update(0.2f);
Vector2 vec2ExpectedScale = vec2Scale;
Vector3 vec3ExpectedScale = vec3Scale;
Vector4 vec4ExpectedScale = vec4Scale;
vec2ExpectedScale.Scale(new Vector2(0.2f, 0.2f));
vec3ExpectedScale.Scale(new Vector3(0.2f, 0.2f, 0.2f));
vec4ExpectedScale.Scale(new Vector4(0.2f, 0.2f, 0.2f, 0.2f));
vec2ExpectedScale += new Vector2(0.8f, 0.8f);
vec3ExpectedScale += new Vector3(0.8f, 0.8f, 0.8f);
vec4ExpectedScale += new Vector4(0.8f, 0.8f, 0.8f, 0.8f);
vec2ExpectedScale.Scale(vec2Start);
vec3ExpectedScale.Scale(vec3Start);
vec4ExpectedScale.Scale(vec4Start);
AreEqual(floatVal, floatStart * (0.8f + floatScale * 0.2f), 0.001f);
AreEqual(doubleVal, doubleStart * (0.8 + doubleScale * 0.2), 0.001f);
AreEqual(vec2Val, vec2ExpectedScale, 0.001f);
AreEqual(vec3Val, vec3ExpectedScale, 0.001f);
AreEqual(vec4Val, vec4ExpectedScale, 0.001f);
queue.Update(0.8);
vec2ExpectedScale = vec2Scale;
vec3ExpectedScale = vec3Scale;
vec4ExpectedScale = vec4Scale;
vec2ExpectedScale.Scale(vec2Start);
vec3ExpectedScale.Scale(vec3Start);
vec4ExpectedScale.Scale(vec4Start);
AreEqual(floatVal, floatStart * floatScale, 0.001f);
AreEqual(doubleVal, doubleStart * doubleScale, 0.001f);
AreEqual(vec2Val, vec2ExpectedScale, 0.001f);
AreEqual(vec3Val, vec3ExpectedScale, 0.001f);
AreEqual(vec4Val, vec4ExpectedScale, 0.001f);
floatVal = floatStart;
doubleVal = doubleStart;
vec2Val = vec2Start;
vec3Val = vec3Start;
vec4Val = vec4Start;
queue.Update(0.0);
queue.Update(0.5);
vec2ExpectedScale = vec2Scale;
vec3ExpectedScale = vec3Scale;
//.........这里部分代码省略.........