当前位置: 首页>>代码示例>>C#>>正文


C# UnityEngine.Vector3类代码示例

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


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


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