using System; using UnityEngine; namespace Assets.AR { public class ARLaneGameObject : ARGameObject { public Vector3 Lean { get; set; }//偏移量 public int StartPosition { get; set; } public int StartRouteDistance { get; set; } public bool IsAtFinish { get; set; }//是否到达终点 public float RouteDistance { get; set; }//线路上的距离 public float Lane { get; set; } //车道上的位置 public float BaseOffset { get; set; }//基准偏移量 public float DeltaLane { get; set; }// public float LaneWidth { get; set; }//车道宽度 public float Speed { get; set; }//速度 public float PreSpeed { get; set; }//速度 public float Curvature { get; set; }//转向 public float LaneChangingDirection { get; set; }//方向 public float LaneCamera { get; set; }//车道上摄像机的位置 public float DistanceSort { get; set; }//距离排序 public float FrameIndexDistanceCorrection { get; set; }//位置纠正 public int TestPower { get; set; } protected void Start() { this.Lane = route.Lane;//轨迹上的距离 } //重置碰撞检测参数 public void ResetCollisionDetectionParameters() { this.StartPosition = 0;//开始位置 this.Lane = route.Lane;//轨迹上的距离 this.DeltaLane = 0.0f;//差距 this.LaneWidth = 0.0f;//轨迹宽度 this.LaneCamera = 0.0f;//轨迹上摄像头的位置 this.DistanceSort = 0.0f;//距离上的远近 this.Curvature = 0.0f;//角度 this.LaneChangingDirection = 0.0f;//偏转方向 } //更新人物的位置和转向 public override void UpdateTransform() { PositionOffset = Vector3.up * route.CameraHeight * (-1); var cameraRotation = this.GetCameraRotation(this.frame - this.FrameIndexDistanceCorrection); var normalizeCameraRotation = Quaternion.Euler(new Vector3(cameraRotation.eulerAngles.x+route.CameraRotationsOffset.x, cameraRotation.eulerAngles.y+route.CameraRotationsOffset.y, cameraRotation.eulerAngles.z+route.CameraRotationsOffset.z)); var filteredCameraPosition = this.GetFilteredCameraPosition(this.frame - this.FrameIndexDistanceCorrection); var vector3 = Vector3.left * (this.route.LeftHanded ? -1f : 1f) * (this.LaneWidth * (this.Lane + this.LaneCamera + this.route.Lane) - this.BaseOffset); var targetPos = filteredCameraPosition + normalizeCameraRotation * (vector3 + this.PositionOffset); this.transform.position = targetPos; this.transform.rotation = normalizeCameraRotation * Quaternion.Euler(this.RotationOffset) * Quaternion.Euler(this.Lean); this.transform.localScale = this.Scale; } } }