本文整理汇总了C#中UnityEngine.Vector2类的典型用法代码示例。如果您正苦于以下问题:C# Vector2类的具体用法?C# Vector2怎么用?C# Vector2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector2类属于UnityEngine命名空间,在下文中一共展示了Vector2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Push
public void Push(Vector2 value)
{
values.Add(new Value() {
type = "vector2",
value = value.AsString()
});
}
示例2: MultiPassBlur
protected virtual void MultiPassBlur(RenderTexture source, RenderTexture destination)
{
int w = Mathf.FloorToInt((float)source.width / Downscaling);
int h = Mathf.FloorToInt((float)source.height / Downscaling);
Vector2 horizontal = new Vector2(1f / w, 0f);
Vector2 vertical = new Vector2(0f, 1f / h);
RenderTexture rt1 = RenderTexture.GetTemporary(w, h, 0, source.format);
RenderTexture rt2 = RenderTexture.GetTemporary(w, h, 0, source.format);
Material.SetVector("_Direction", horizontal);
Graphics.Blit(source, rt1, Material);
Material.SetVector("_Direction", vertical);
Graphics.Blit(rt1, rt2, Material);
for (int i = 1; i < Passes; i++)
{
Material.SetVector("_Direction", horizontal);
Graphics.Blit(rt2, rt1, Material);
Material.SetVector("_Direction", vertical);
Graphics.Blit(rt1, rt2, Material);
}
Graphics.Blit(rt2, destination);
RenderTexture.ReleaseTemporary(rt1);
RenderTexture.ReleaseTemporary(rt2);
}
示例3: InstantiatePlayers
protected override void InstantiatePlayers()
{
// Hardcoded spawn metrics
Vector2 spawnRange = new Vector2(-11, 9);
float spawnLength = spawnRange.y - spawnRange.x;
float spawnStep = spawnLength / (Manager.Player.Instance.Get().Count * 2);
float lastSpawn = spawnRange.x;
foreach (Player.Wrapper p in Manager.Player.Instance.Get())
{
lastSpawn += spawnStep;
int id = p.GetPuppet().GetIdentifier();
// Instantiate player
GameObject newPlayer = ( GameObject )Instantiate( m_puppetPrefabs[ id ] );
newPlayer.AddComponent<SweetRain.PlayerController>();
m_playerInstances.Add( newPlayer );
// Set positoin
newPlayer.transform.position = new Vector3(lastSpawn, 0, 0);
// Add player as a child
newPlayer.transform.parent = this.transform;
// Subscribe to each player
newPlayer.GetComponent<PlayerController>().Subscribe(this);
}
}
示例4: Get2D
public float Get2D(Vector2 position)
{
MathS.Lerp(x0, x1, position.x);
MathS.Lerp(y0, y1, position.y);
return 0f;
}
示例5: Render
public void Render()
{
Sprite sprite = sourceSprite;
Rect rect = sprite.textureRect;
float iw = 1f / sprite.texture.width;
float ih = 1f / sprite.texture.height;
var srcPixel = new Vector2(iw, ih);
var dstPixel = new Vector2(1f / texture.width, 1f / texture.height);
material.SetVector("_SpriteUV",
new Vector4(rect.xMin * iw,
rect.yMin * ih,
rect.xMax * iw,
rect.yMax * ih));
material.SetVector("_DstPixel", dstPixel);
material.SetVector("_SrcPixel", srcPixel);
material.SetVector("_Scale", new Vector2(texture.width / rect.width,
texture.height / rect.height));
image.uvRect = Rect.MinMaxRect(0,
0,
(rect.width + size * 2) / texture.width,
(rect.height + size * 2) / texture.height);
image.SetNativeSize();
Graphics.Blit(sprite.texture, texture, material);
}
示例6: SpawnFish
private void SpawnFish(RepetitionTimer t)
{
Bounds b = GameManager.instance.field.GetComponent<Collider2D>().bounds;
Vector2 pos = new Vector2(Random.Range(b.min.x, b.max.x), Random.Range(b.min.y, b.max.y));
GameObject fish = (GameObject)Instantiate(fishPrefab, pos, Quaternion.identity);
fish.GetComponent<Fish>().Game = this;
}
示例7: FileToMesh
// Use this for initialization
public static Mesh FileToMesh(string filePath)
{
meshStruct newMesh = createMeshStruct(filePath);
populateMeshStruct(ref newMesh);
Vector3[] newVerts = new Vector3[newMesh.faceData.Length];
Vector2[] newUVs = new Vector2[newMesh.faceData.Length];
Vector3[] newNormals = new Vector3[newMesh.faceData.Length];
int i = 0;
/* The following foreach loops through the facedata and assigns the appropriate vertex, uv, or normal
* for the appropriate Unity mesh array.
*/
foreach (Vector3 v in newMesh.faceData)
{
newVerts[i] = newMesh.vertices[(int)v.x - 1];
if (v.y >= 1)
newUVs[i] = newMesh.uv[(int)v.y - 1];
if (v.z >= 1)
newNormals[i] = newMesh.normals[(int)v.z - 1];
i++;
}
Mesh mesh = new Mesh();
mesh.vertices = newVerts;
mesh.uv = newUVs;
mesh.normals = newNormals;
mesh.triangles = newMesh.triangles;
mesh.RecalculateBounds();
mesh.Optimize();
return mesh;
}
示例8: Rotate
public static Vector2 Rotate(Vector2 point, float angle)
{
var rad = angle*Mathf.Deg2Rad;
var cos = Mathf.Cos(rad);
var sin = Mathf.Sin(rad);
return new Vector2(point.x * cos - point.y * sin, point.x * sin + point.y * cos);
}
示例9: AddPoint
public override void AddPoint(Vector2 touchPos)
{
lineRendererPoints.Add(ConvertPointPos(touchPos));
lineRenderer.SetVertexCount(lineRendererPoints.Count);
lineRenderer.SetPositions(lineRendererPoints.ToArray());
}
示例10: Awake
void Awake()
{
_resizedPanel = (ResizeParent ? transform.parent : transform) as RectTransform;
var maximalSizeMargin = 10;
_maximalSize = new Vector2(Screen.width - maximalSizeMargin, Screen.height - maximalSizeMargin);
}
示例11: GetInitialVelocityGivenRelativeTargetAndTime
// Calculate the initial velocity for this PrincipalProjectile that results in
// hitting the given target position (in principal space) at the given time.
// Implements Equation 21 and 22 from the paper.
public Vector2 GetInitialVelocityGivenRelativeTargetAndTime(
Vector2 relativeTargetPosition, float timeToTarget)
{
Vector2 v0 = relativeTargetPosition * (k + 1 / timeToTarget);
v0.y += k * vInfinity * timeToTarget;
return v0;
}
示例12: GetDimData
public override Vector2[] GetDimData(string dimX, string dimY)
{
if (!_dimensions.ContainsKey(dimX))
{
GenerateDimension(dimX);
}
if (!_dimensions.ContainsKey(dimY))
{
GenerateDimension(dimY);
}
var x = _dimensions[dimX];
var y = _dimensions[dimY];
Debug.Assert(x.Length == y.Length);
var dimData = new Vector2[x.Length];
for (int i = 0; i < dimData.Length; i++)
{
dimData[i].x = x[i];
dimData[i].y = y[i];
}
return dimData;
}
示例13: FixedUpdate
void FixedUpdate () {
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
attacking = Input.GetButton("Fire1");
animator.SetBool("Attack", attacking);
var sprintPressed = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
var targetSpeed = maxSpeed;
if (attacking) {
targetSpeed *= attackMoveSpeedMultiplier;
}
else if (sprintPressed) {
targetSpeed *= sprintMultiplier;
}
var direction = new Vector2(moveX, moveY);
var directionLength = direction.magnitude;
if (directionLength > 1) {
direction /= directionLength;
}
var currentSpeed = rigidBody2D.velocity.magnitude;
var desiredSpeed = Mathf.Lerp(currentSpeed, targetSpeed, movementSensitivity);
rigidBody2D.velocity = direction * desiredSpeed;
if (moveX > 0 && !facingRight) {
Flip();
} else if (moveX < 0 && facingRight) {
Flip ();
}
animator.SetFloat("Speed", rigidBody2D.velocity.magnitude);
}
示例14: SetPolygon
protected override void SetPolygon ()
{
if (eyeShape == null)
throw new System.ArgumentNullException ("The irises needs its eyes");
Vector2 centerLeft = (eyeShape [1] + eyeShape [4]) * 0.5f;
float widthLeft = Mathf.Min (Mathf.Min (eyeShape [0].x - eyeShape [2].x, eyeShape [5].x - eyeShape [3].x) * maxEyeHalfWidthIris,
(eyeShape [4].y - eyeShape [1].y) * sougthAspectRatio);
Vector2 centerRight = (eyeShape [11] + eyeShape [8]) * 0.5f;
float widthRight = Mathf.Min (Mathf.Min (eyeShape [10].x - eyeShape [6].x, eyeShape[9].x - eyeShape [7].x) * maxEyeHalfWidthIris,
(eyeShape [8].y - eyeShape [11].y) * sougthAspectRatio);
polygon = new Vector2[8] {
eyeShape [1],
centerLeft + Vector2.left * widthLeft / 2f,
eyeShape [4],
centerLeft + Vector2.right * widthLeft / 2f,
eyeShape [11],
centerRight + Vector2.left * widthRight /2f,
eyeShape [8],
centerRight + Vector2.right * widthRight /2f
};
if (noise > 0)
ApplyNoise ();
}
示例15: LateUpdate
public void LateUpdate() {
if (this.duration <= 0f) return;
var step = Vector2.zero;
if (this.direction == Slider.Direction.BottomToTop) {
step = Vector2.up;
} else if (this.direction == Slider.Direction.TopToBottom) {
step = -Vector2.up;
} else if (this.direction == Slider.Direction.LeftToRight) {
step = Vector2.right;
} else if (this.direction == Slider.Direction.RightToLeft) {
step = -Vector2.right;
}
this.offset += step * Time.deltaTime / this.duration;
if (this.offset.x < 0f) this.offset.x += 1f;
if (this.offset.x > 1f) this.offset.x -= 1f;
if (this.offset.y < 0f) this.offset.y += 1f;
if (this.offset.y > 1f) this.offset.y -= 1f;
this.rectTransform.sizeDelta = new Vector2(this.size.x * Mathf.Abs(step.x) * 2f, this.size.y * Mathf.Abs(step.y) * 2f);
this.rectTransform.anchoredPosition = new Vector2(this.offset.x * this.size.x, this.offset.y * this.size.y);
}