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

C# UnityEngine.Vector3类代码示例

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

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



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

示例1: 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


示例2: RotateTo

        // Rotate this target towards a position
        public void RotateTo(Vector3 position)
        {
            if (pivot == null) return;

            if (pivot != lastPivot) {
                defaultLocalRotation = pivot.localRotation;
                lastPivot = pivot;
            }

            // Rotate to the default local rotation
            pivot.localRotation = defaultLocalRotation;

            // Twisting around the twist axis
            if (twistWeight > 0f) {
                Vector3 targetTangent = transform.position - pivot.position;
                Vector3 n = pivot.rotation * twistAxis;
                Vector3 normal = n;
                Vector3.OrthoNormalize(ref normal, ref targetTangent);

                normal = n;
                Vector3 direction = position - pivot.position;
                Vector3.OrthoNormalize(ref normal, ref direction);

                Quaternion q = QuaTools.FromToAroundAxis(targetTangent, direction, n);
                pivot.rotation = Quaternion.Lerp(Quaternion.identity, q, twistWeight) * pivot.rotation;
            }

            // Swinging freely
            if (swingWeight > 0f) {
                Quaternion s = Quaternion.FromToRotation(transform.position - pivot.position, position - pivot.position);
                pivot.rotation = Quaternion.Lerp(Quaternion.identity, s, swingWeight) * pivot.rotation;
            }
        }
开发者ID:nickgirardo,项目名称:KADAPT,代码行数:34,代码来源:InteractionTarget.cs


示例3: Start

        void Start()
        {
            m_Cam = GetComponent<Camera>();
            m_OriginalRotation = transform.localRotation;

            this.UpdateAsObservable()
                .Where(_ => GameState.Instance.GameStateReactiveProperty.Value == GameStateEnum.Countdown ||
                            GameState.Instance.GameStateReactiveProperty.Value == GameStateEnum.GameUpdate)
                .Select(_ =>
                {
                    var playerPos = PlayerManager.Instance.GetAlivePlayers()
                        .Select(x => x.transform.position);

                    var _x = playerPos.Average(x => x.x);
                    var _y = playerPos.Average(x => x.y);
                    var _z = playerPos.Average(x => x.z);

                    tergetPos = new Vector3(_x, _y, _z);
                    return tergetPos;

                }).DelayFrame(3)
                .Subscribe(target =>
                {
                    var campos = tergetPos + m_defaultPosition;
                    transform.position = Vector3.Lerp(this.transform.position, campos, Time.deltaTime * 5.0f);
             //       transform.LookAt(target - this.transform.position);
                });

        }
开发者ID:TORISOUP,项目名称:Born_to_Beans_src,代码行数:29,代码来源:StageCameraPotision.cs


示例4: FindHitPoint

 public static Vector3 FindHitPoint(Vector3 origin)
 {
     Ray ray = Camera.main.ScreenPointToRay(origin);
     RaycastHit hit;
     if (Physics.Raycast(ray, out hit)) return hit.point;
     return ResourseManager.InvalidPosition;
 }
开发者ID:amaximan,项目名称:educational,代码行数:7,代码来源:WorkManager.cs


示例5: OnUpdate

        public void OnUpdate()
        {
            _swipe = _down && Vector3.Distance(_startPosition, UnityEngine.Input.mousePosition) > 15;
            _tapUnknown = !_tap && _tapUnknown;
            _tap = _tapUnknown && Time.time - _tapUnknownTime > DoubleTapTimeout;
            _doubleTap = false;
            _longTap = false;

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                _tapStartTime = Time.time;
                _startPosition = UnityEngine.Input.mousePosition;
                _down = true;
            }
            if (UnityEngine.Input.GetMouseButtonUp(0))
            {
                _doubleTap = Time.time - _lastTapTime < DoubleTapTimeout;
                _longTap = !_swipe && Time.time - _tapStartTime >= LongTapTimeout;
                _tapUnknown = !(_swipe || _doubleTap || _longTap);
                _tapUnknownTime = _tapUnknown ? Time.time : 0;
                _lastTapTime = Time.time;
                _down = false;
            }
            if (_tap || _longTap || _doubleTap)
            {
                _result = new TouchResult(_startPosition);
            }
            if (_swipe)
            {
                _result = new TouchResult(UnityEngine.Input.mousePosition);
            }
        }
开发者ID:nikmarkovic,项目名称:mugd-module-input-touch,代码行数:32,代码来源:WindowsTouchGestureDetector.cs


示例6: RigidbodyRotateAround

 // Rotate a rigidbody around a point and axis by angle
 protected void RigidbodyRotateAround(Vector3 point, Vector3 axis, float angle)
 {
     Quaternion rotation = Quaternion.AngleAxis(angle, axis);
     Vector3 d = transform.position - point;
     r.MovePosition(point + rotation * d);
     r.MoveRotation(rotation * transform.rotation);
 }
开发者ID:nighzmarquls,项目名称:ParliamentPandamonium,代码行数:8,代码来源:CharacterBase.cs


示例7: Awake

		private Vector3 newPos;             // The position the camera is trying to reach.
		//private int check = 1;
	
		void Awake ()
		{
			// Setting up the reference.
			//player = GameObject.FindGameObjectWithTag ("Player");
			// Setting the relative position as the initial relative position of the camera in the scene.
			newPos = new Vector3 (9.39f, 12f, -2f);
		}
开发者ID:TomJasonHuang,项目名称:Game,代码行数:10,代码来源:Camera.cs


示例8: GetComposition

        public Dictionary<int, PhysSoundComposition> GetComposition(Vector3 contactPoint)
        {
            foreach (PhysSoundComposition c in compDic.Values)
                c.Reset();

            float[] mix = getTextureMix(contactPoint);

            for (int i = 0; i < mix.Length; i++)
            {
                if (i >= SoundMaterials.Count)
                    break;

                if (SoundMaterials[i] == null)
                    continue;

                PhysSoundComposition comp;

                if (compDic.TryGetValue(SoundMaterials[i].MaterialTypeKey, out comp))
                {
                    comp.Add(mix[i]);
                }
            }

            return compDic;
        }
开发者ID:scumbly,项目名称:Organ-Grinder,代码行数:25,代码来源:PhysSoundTerrain.cs


示例9: Vertex

 public Vertex(Vector3 pos, Vector3 normal)
 {
     //this.pos = (pos != Vector3.zero) ? pos : Vector3.zero;
     this.pos = pos;
     //this.normal = (normal != Vector3.zero) ? normal : Vector3.zero;
     this.normal = normal;
 }
开发者ID:icegbq,项目名称:csg.cs,代码行数:7,代码来源:Vertex.cs


示例10: SetWaypoint

 public virtual void SetWaypoint(Vector3 destination)
 {
     currentWaypoint = destination;
     isTurning = true;
     isMoving = false;
     targetEntityGameObject = null;
 }
开发者ID:Blkx-Darkreaper,项目名称:Unity,代码行数:7,代码来源:Entity.cs


示例11: GetPointAlongLine

 public Vector3 GetPointAlongLine(Vector3 point1, Vector3 point2, float magnitude)
 {
     Vector3 line = point2 - point1;
     line = line.normalized * magnitude;
     line = line + point1;
     return line;
 }
开发者ID:eiseneker,项目名称:ghost-game,代码行数:7,代码来源:TransformHelpers.cs


示例12: Add

 //        private int colMinCoordinate, rowMinCoordinate, colMaxCoordinate, rowMaxCoordinate;
 public void Add(Vector3 coordinates, HexField hex)
 {
     //			Vector2 offsetCoordinates;
     //			if (isEven) {
     //				offsetCoordinates = HexMath.ConvertCubeToEvenROffsetCoordinate ((int)coordinates.x, (int)coordinates.y, (int)coordinates.z);
     //			} else {
     //				offsetCoordinates = HexMath.ConvertCubeToOddROffsetCoordinate ((int)coordinates.x, (int)coordinates.y, (int)coordinates.z);
     //			}
     //			if (this.hexList.Count == 0) {
     //				colMinCoordinate = (int)offsetCoordinates.x;
     //				colMaxCoordinate = (int)offsetCoordinates.x;
     //				rowMinCoordinate = (int)offsetCoordinates.y;
     //				rowMaxCoordinate = (int)offsetCoordinates.y;
     //			}
     //			if (offsetCoordinates.x < colMinCoordinate) {
     //				colMinCoordinate = (int)offsetCoordinates.x;
     //			} else if (offsetCoordinates.x > colMaxCoordinate) {
     //				colMaxCoordinate = (int)offsetCoordinates.x;
     //			}
     //			if (offsetCoordinates.y < rowMinCoordinate) {
     //				rowMinCoordinate = (int)offsetCoordinates.y;
     //			} else if (offsetCoordinates.y > rowMaxCoordinate) {
     //				rowMaxCoordinate = (int)offsetCoordinates.y;
     //			}
     hex.SetCoordinates(coordinates);
     this.hexList.Add(coordinates , hex);
     hex.SetListenerList(this.listenerList);
 }
开发者ID:uhlryk,项目名称:unity-hexboard-generator,代码行数:29,代码来源:BoardHex.cs


示例13: GetAngleAxis

        public static void GetAngleAxis(this Quaternion q, out Vector3 axis, out float angle)
        {
            if (q.w > 1) q = QuaternionUtil.Normalize(q);

            //get as doubles for precision
            var qw = (double)q.w;
            var qx = (double)q.x;
            var qy = (double)q.y;
            var qz = (double)q.z;
            var ratio = System.Math.Sqrt(1.0d - qw * qw);

            angle = (float)(2.0d * System.Math.Acos(qw)) * Mathf.Rad2Deg;
            if (ratio < 0.001d)
            {
                axis = new Vector3(1f, 0f, 0f);
            }
            else
            {
                axis = new Vector3(
                    (float)(qx / ratio),
                    (float)(qy / ratio),
                    (float)(qz / ratio));
                axis.Normalize();
            }
        }
开发者ID:XianWorld,项目名称:spacepuppy-unity-framework,代码行数:25,代码来源:QuaternionUtil.cs


示例14: Update

        // Update is called once per frame
        void Update()
        {
            // Update water level
            Level = Mathf.Clamp01(Level);
            TopShape.localPosition = new Vector3(0, Level - 0.5f, 0);
            float newTopScale = Mathf.Sqrt(0.25f - Mathf.Pow (Level - 0.5f, 2))*2;
            TopShape.localScale = new Vector3(newTopScale, 0.0001f, newTopScale);
            r.material.SetTextureOffset("_MainTex", new Vector2(0, 0.25f-Mathf.Asin((Level-0.5f)/0.5f)/2f/Mathf.PI));

            // Tilt
            Vector3 accel = new Vector3();
            Vector3 pos;
            if (UseRootMotion) {
                pos = transform.position;
                Math3d.LinearAcceleration(out accel, pos, 2); // require Math 3D script
                accel.x *= axisAdjust.x;
                accel.y *= axisAdjust.y;
                accel.z *= axisAdjust.z;
            } else {
                pos = Root.transform.InverseTransformPoint(transform.position);
                Math3d.LinearAcceleration(out accel, pos, 2); // require Math 3D script
                accel.x *= axisAdjust.x;
                accel.y *= axisAdjust.y;
                accel.z *= axisAdjust.z;
                accel = Root.transform.TransformDirection(accel);
            }
            Vector3 gModified = new Vector3(-accel.x, Gravity-accel.y, -accel.z);

            Vector3 angularAccel = Vector3.Cross(-transform.up, gModified) * Acceleration; // (torque = F tangetial x r)
            AngularVelocity += angularAccel * Time.deltaTime;
            AngularVelocity *= Damp;
            transform.RotateAround(transform.position, AngularVelocity, AngularVelocity.magnitude * Time.deltaTime);

            Accel = accel;
        }
开发者ID:foundway,项目名称:EarlyBeeAR,代码行数:36,代码来源:LiquidBehavior.cs


示例15: Move

        public void Move(Vector3 move, bool crouch, bool jump)
        {
            // convert the world relative moveInput vector into a local-relative
            // turn amount and forward amount required to head in the desired
            // direction.
            if (move.magnitude > 1f) move.Normalize();
            move = transform.InverseTransformDirection(move);
            CheckGroundStatus();
            move = Vector3.ProjectOnPlane(move, m_GroundNormal);
            m_TurnAmount = Mathf.Atan2(move.x, move.z);
            m_ForwardAmount = move.z;

            ApplyExtraTurnRotation();

            // control and velocity handling is different when grounded and airborne:
            if (m_IsGrounded)
            {
                HandleGroundedMovement(crouch, jump);
            }
            else
            {
                HandleAirborneMovement();
            }

            ScaleCapsuleForCrouching(crouch);
            PreventStandingInLowHeadroom();

            // send input and other state parameters to the animator
            UpdateAnimator(move);
        }
开发者ID:ian-h-chamberlain,项目名称:rise-and-fall,代码行数:30,代码来源:ThirdPersonCharacter.cs


示例16: LateUpdate

        void LateUpdate()
        {
            /*
            if (target) {

                float x = IncrementTowards(transform.position.x, target.position.x, trackSpeed);
                float y = IncrementTowards(transform.position.y, target.position.y, trackSpeed);
                transform.position = new Vector3(x,y,transform.position.z);

            }
            */

            if (target)
            {
                Vector3 posNoZ = transform.position;
                posNoZ.z = target.position.z;

                Vector3 targetDirection = (target.position - posNoZ);

                interpVelocity = targetDirection.magnitude * 10f;

                targetPos = transform.position + (targetDirection.normalized * interpVelocity * Time.deltaTime);

                transform.position = Vector3.Lerp( transform.position, targetPos + offset, 0.25f);

            }
        }
开发者ID:robinsswei,项目名称:CSC631-831NewIdea2,代码行数:27,代码来源:GameCamera.cs


示例17: TakeDamage

        public void TakeDamage(int amount, Vector3 hitPoint)
        {
            // If the enemy is dead...
            if(isDead)
                // ... no need to take damage so exit the function.
                return;

            // Play the hurt sound effect.
            enemyAudio.Play ();

            // Reduce the current health by the amount of damage sustained.
            currentHealth -= amount;

            // Set the position of the particle system to where the hit was sustained.
            hitParticles.transform.position = hitPoint;

            // And play the particles.
            hitParticles.Play();

            // If the current health is less than or equal to zero...
            if(currentHealth <= 0)
            {
                // ... the enemy is dead.
                Death ();
            }
        }
开发者ID:bwallenaii,项目名称:gad307_wi2016_wed_survival,代码行数:26,代码来源:EnemyHealth.cs


示例18: Load

        public Unit Load(UnitPrefab a_prefab, Vector3 a_pos, Vector3 a_rot)
        {
            // Properties
            Unit.Properties properties = new Unit.Properties();
            properties.pos = a_pos;
            properties.rot = a_rot;
            properties.health = a_prefab.health;
            properties.buildTime = a_prefab.buildTime;
            properties.cost = a_prefab.cost;
            properties.miniSize = a_prefab.miniMapSize;
            properties.ID = a_prefab.ID;
            properties.turnSpeed = a_prefab.turnSpeed;
            properties.speed = a_prefab.speed;
            properties.accel = a_prefab.accel;

            // Type
            Unit unit = null;
            switch (a_prefab.type)
            {
                case Unit.Type.DOZER:
                    unit = new Dozer(properties, a_prefab.model, a_prefab.texture);
                    break;

                //case Unit.Type.INFANTRY:
                    //unit = new Infantry(properties, a_prefab.model, a_prefab.texture);
                    //break;

                default:
                    unit = new Unit(properties, a_prefab.model, a_prefab.texture);
                    break;
            }

            return unit;
        }
开发者ID:JJJohan,项目名称:RTS,代码行数:34,代码来源:UnitTemplate.cs


示例19: MoveTowards

        // Dir is world space direction.
        public void MoveTowards(Vector3 dir)
        {
            // We are not holding a button, so stop rotating.
            if (dir == Vector3.zero) {
            _rb.angularVelocity = dir;
            _rb.velocity = dir;
            return;
            }

            dir.y = 0.0f;
            dir.Normalize();

            Vector3 forward = transform.forward;
            Vector3 right = transform.right;

            forward.y = right.y = 0.0f;
            forward.Normalize();
            right.Normalize();

            float angle = Vector3.Angle(forward, dir);
            float direction = (Vector3.Dot(right, dir) > 0.0f) ? 1.0f : -1.0f;

            if (angle < snapAngle) {
            // If I use Mathf.Deg2Rad here, I get some stuttering, even though Vector3.Angle() returns degrees. :/
            _rb.angularVelocity = new Vector3(0.0f, angle * direction, 0.0f);
            } else {
            _rb.angularVelocity = new Vector3(0.0f, angularSpeed * direction * Mathf.Deg2Rad, 0.0f);
            }

            if (moveDirSeparateFromAngle) {
            _rb.velocity = dir * speed;
            } else {
            _rb.velocity = transform.forward * speed;
            }
        }
开发者ID:FreezeDriedGames,项目名称:Avocation,代码行数:36,代码来源:ThirdPersonMovementController.cs


示例20: OnDrawGizmos

        void OnDrawGizmos() {
            if (DebugManager.Instance.m_showDebug && cachedCollider != null) {

                //Matrix4x4 matrix = Matrix4x4.TRS(this.transform.localPosition, this.transform.rotation, this.transform.lossyScale);
                Matrix4x4 matrix =  preCalMatrix;
                //CalculateMatrix(ref matrix);
                Gizmos.matrix = preCalMatrix;

                Gizmos.color = Color.magenta;
                Vector3 adjusted = new Vector3(1/cachedCollider.size.x, 1/cachedCollider.size.y, 0) / 4f;

                Vector2 rCorner = Vector2.zero + Vector2.right * (.5f) + Vector2.up * (.5f); // Right Corner
                Vector2 lCorner = Vector2.zero - Vector2.right * (.5f) + Vector2.up * (.5f); // Left Corner

                Gizmos.DrawLine(lCorner, rCorner); // Draws line representing the platforms floor 

                // Reverts the matrix back to normal
                Gizmos.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);

                Vector3 adjLeftCorner = matrix.MultiplyPoint3x4(lCorner);
                Vector3 adjRightCorner = matrix.MultiplyPoint3x4(rCorner);

                Gizmos.color = Color.yellow;
                Gizmos.DrawRay(adjLeftCorner, this.transform.up);
                Gizmos.DrawRay(adjRightCorner, this.transform.up);

                Gizmos.color = Color.magenta;
                Gizmos.DrawWireSphere(adjLeftCorner, .15f);
                Gizmos.DrawWireSphere(adjRightCorner, .15f);

                // Find the bottom of the player ie feet/ farthest down point of the collider
                Gizmos.color = new Color(0f, 0f, 256f, .2f);
                Gizmos.DrawCube(testAgainstColliders[0].bounds.center, testAgainstColliders[0].bounds.size);    // Colors the bounding box area
            }
        }
开发者ID:Smoreley,项目名称:Unity-Revamped,代码行数:35,代码来源:OWPlatform.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.Vector3d类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.Vector2类代码示例发布时间: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