powerfun-unity/Assets/AR/ARLaneObject.cs

73 lines
2.6 KiB
C#
Raw Normal View History

2022-11-25 19:18:21 +08:00
using UnityEngine;
using DG.Tweening;
namespace Assets.AR
{
public class ARLaneObject : ARObject
{
public Vector3 Lean { get; set; }//偏移量
public int StartPosition;
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 Curvature { get; set; }//转向
public float LaneChangingDirection { get; set; }//方向
public float LaneCamera { get; set; }//车道上摄像机的位置
public float DistanceSort { get; set; }//距离排序
public float FrameIndexDistanceCorrection { get; set; }//位置纠正
public double TestPower = 500;
//重置碰撞检测参数
public void ResetCollisionDetectionParameters()
{
this.StartPosition = 0;//开始位置
this.Lane = 0.0f;//轨迹上的距离
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);
Quaternion cameraRotation = this.GetCameraRotation(this.frame - this.FrameIndexDistanceCorrection);
Vector3 filteredCameraPosition = this.GetFilteredCameraPosition(this.frame + this.FrameIndexDistanceCorrection);
Debug.Log($"{filteredCameraPosition}={this.CameraPositionOffset}:{this.Route.GetFilteredCameraPosition(this.frame )}");
Vector3 vector3 = Vector3.left * (this.route.LeftHanded ? -1f : 1f) * (this.LaneWidth * (this.Lane + this.LaneCamera) - this.BaseOffset);
this.transform.position = filteredCameraPosition + cameraRotation * (vector3 + this.PositionOffset);
this.transform.rotation = cameraRotation * Quaternion.Euler(this.RotationOffset) * Quaternion.Euler(this.Lean);
this.transform.localScale = this.Scale;
var animator = GetComponent<Animator>();
animator.SetFloat("speed", 30);
animator.SetFloat("power", (float)TestPower);
}
}
}