• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.Vector2类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UnityEngine.Vector2的典型用法代码示例。如果您正苦于以下问题:C# Vector2类的具体用法?C# Vector2怎么用?C# Vector2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Vector2类属于UnityEngine命名空间,在下文中一共展示了Vector2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Push

 public void Push(Vector2 value)
 {
     values.Add(new Value() {
     type  = "vector2",
     value = value.AsString()
     });
 }
开发者ID:jamiebell,项目名称:UWO,代码行数:7,代码来源:MultiValue.cs


示例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);
		}
开发者ID:Thaon,项目名称:IRNBRU,代码行数:27,代码来源:GaussianBlur.cs


示例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);
            }
        }
开发者ID:luisango,项目名称:TestStats,代码行数:30,代码来源:MinigameController.cs


示例4: Get2D

		public float Get2D(Vector2 position)
		{
			MathS.Lerp(x0, x1, position.x);

			MathS.Lerp(y0, y1, position.y);
			return 0f;
		}
开发者ID:mswf,项目名称:game-a-week,代码行数:7,代码来源:NoiseLib.cs


示例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);
        }
开发者ID:Ragzouken,项目名称:kooltool-rekindle,代码行数:30,代码来源:BorderRenderer.cs


示例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;
 }
开发者ID:MercilessMinions,项目名称:Gamejam_Ritual,代码行数:7,代码来源:FishMinigame.cs


示例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;
        }
开发者ID:tudela,项目名称:RealSolarSystem,代码行数:36,代码来源:ObjLib.cs


示例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);
 }
开发者ID:AhoyGames,项目名称:TouchScript,代码行数:7,代码来源:TwoD.cs


示例9: AddPoint

        public override void AddPoint(Vector2 touchPos)
        {
            lineRendererPoints.Add(ConvertPointPos(touchPos));

            lineRenderer.SetVertexCount(lineRendererPoints.Count);
            lineRenderer.SetPositions(lineRendererPoints.ToArray());
        }
开发者ID:Pavelko007,项目名称:Shape-Replica,代码行数:7,代码来源:LineDrawer.cs


示例10: Awake

        void Awake()
        {
            _resizedPanel = (ResizeParent ? transform.parent : transform) as RectTransform;

            var maximalSizeMargin = 10;
            _maximalSize = new Vector2(Screen.width - maximalSizeMargin, Screen.height - maximalSizeMargin);
        }
开发者ID:Youenn-Bouglouan,项目名称:Water,代码行数:7,代码来源:Resizer.cs


示例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;
 }
开发者ID:cuongngo90,项目名称:Unity-TrajectorySystem,代码行数:10,代码来源:PrincipalProjectile.cs


示例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;
        }
开发者ID:SebiH,项目名称:BachelorProject,代码行数:25,代码来源:RandomDataProvider.cs


示例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);
		}
开发者ID:coderespawn,项目名称:dungeon-architect-quick-start-unity,代码行数:34,代码来源:PlayerController.cs


示例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 ();
				
		}
开发者ID:local-minimum,项目名称:proc-pixels,代码行数:29,代码来源:NaiveIris.cs


示例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);

		}
开发者ID:zhaoluxyz,项目名称:Unity3d.UI.Windows,代码行数:34,代码来源:ProgressAnimationProcessing.cs


示例16: PointOnCircle

 public static Vector2 PointOnCircle(Vector2 midpoint, float radius, float angle)
 {
     return new Vector2(
         Mathf.Cos(angle),
         Mathf.Sin(angle)
     ) * radius + midpoint;
 }
开发者ID:KvanNes,项目名称:Contextproject-Group5,代码行数:7,代码来源:MathUtils.cs


示例17: ControlNode

            public ControlNode(Vector2i pos, float[,] map, Vector2 position, float size)
                : base(position)
            {
                Active = map[pos.x, pos.y];

                if (pos.x == map.GetLength(0))
                {
                    Right = new Node(position + Vector2.right * size * 0.5f);
                }
                else
                {
                    Right = new Node(position + Vector2.right * size * 0.5f);
                }

                if (pos.y == map.GetLength(1))
                {
                    Up = new Node(position + Vector2.up * size * 0.5f);
                }
                else
                {
                    Up = new Node(position + Vector2.up * size * 0.5f);
                }

                //float right = pos.x <  ? map[pos.x + 1, pos.y] : Active;
                //float up = map[pos.x, pos.y + 1];
            }
开发者ID:mfagerlund,项目名称:MC-Ubes,代码行数:26,代码来源:MeshGenerator.cs


示例18: DrawLine

        /// <summary>
        /// Implementation of Besenham's line algorithm:
        /// http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Simplification
        /// </summary>
        public void DrawLine(Vector2 p1, Vector2 p2, Color color)
        {
            int dx = Mathf.Abs((int) (p1.x - p2.x));
            int dy = Mathf.Abs((int) (p1.y - p2.y));
            int sx = (p1.x < p2.x) ? 1 : -1;
            int sy = (p1.y < p2.y) ? 1 : -1;
            int err = dx - dy;
            int err2;

            while (true)
            {
              content.SetPixel((int) p1.x, (int) p1.y, color);
              if (p1.x == p2.x && p1.y == p2.y) break;
              err2 = err << 1;
              if (err2 > -dy)
              {
            err -= dy;
            p1.x += sx;
              }

              if (err2 < dx)
              {
            err += dx;
            p1.y += sy;
              }
            }
        }
开发者ID:BrettGregson,项目名称:ProceduralBuildings,代码行数:31,代码来源:ProceduralTexture.cs


示例19: Tap

 public Tap(Vector2 position, float startTime)
     : base(GestureType.TAP)
 {
     this.position = position;
     this.startTime = startTime;
     EndTime = startTime;
 }
开发者ID:hydro-team,项目名称:hydro,代码行数:7,代码来源:Tap.cs


示例20: addVertex

 public Vertex addVertex(Vector3 vert, Vector3 norm, Vector2 uv)
 {
     Vertex vertex = new Vertex(vert, norm, uv, vertexNumber);
     vertexNumber++;
     vertices.Add(vertex);
     return vertex;
 }
开发者ID:SixDasher,项目名称:SSTULabs,代码行数:7,代码来源:MeshBuilder.cs



注:本文中的UnityEngine.Vector2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.Vector3类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.Transform类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap