powerfun-unity/Assets/AR/PlayerRenderer.cs
2023-01-31 18:22:15 +08:00

185 lines
6.7 KiB
C#

using System;
using UnityEngine;
namespace Assets.AR
{
public class PlayerRenderer : AbstractRenderer
{
private const int PowerWindowSize = 10;
private const float Circumference = 2.13097382f;
private const double SpeedLimitForWheelRotation = 10.0;
private const double MaxAngularSpeed = 1689.3684817282528;
private const double MaxAnglePerFrame = 6.5;
private const float AfterFinishRideInSec = 5f;
public const float MaxLeanAngle = 35f;
public const float MaxLeanAngleChange = 60f;
public const float MaxTurnAngle = 6f;
public const float MaxTurnAngleChange = 10f;
public const float LeanAngleSoftStageLength = 15f;
private float lastSpeed = 1f;
private bool lastPauseState;
private int lastDifficultyLevel;
private float lastVisibilitylevel = -1f;
private float afterFinishTime;
private float afterFinishFrame;
private float finishPassSpeed;
private float afterFinishOffsetZ;
private float lastDiffLevelChange = float.MinValue;
private float[] powerWindow = new float[10];
private float lastPowerWinWrite;
private int lastPowerWinIndex;
private float PowerWinSum;
private float lastPowerPeak = float.MinValue;
private int powerPeakSum;
public Transform wheelFront;
public Transform wheelRear;
private float lookTime;
private bool lockIdleAnimations;
public float Cadence { get; set; }
public int DifficultyLevel { get; set; }
public float Power { get; set; }
public float Weight { get; set; }
public float Slope { get; set; }
public Texture2D HelmTexture { get; set; }
public Texture2D BikeTexture { get; set; }
public bool WinAnimation { get; set; }
public bool TimeTrialBike { get; private set; }
public GameObject BasicShadowRenderer { get; set; }
public bool LockIdleAnimations
{
get => this.lockIdleAnimations;
set
{
if (value == this.lockIdleAnimations)
return;
this.lockIdleAnimations = value;
}
}
protected override void Awake()
{
base.Awake();
}
public void Initialize(bool male, bool timeTrialBike)
{
this.Initialize(male);
this.TimeTrialBike = timeTrialBike;
}
//人物再刚显示的时候计算当前人物的状态
private void OnEnable()
{
if ((UnityEngine.Object)this.animator != (UnityEngine.Object)null)
{
if (lastSpeed > 1)
{
animator.Play("rideLoop");
}
else
{
animator.Play("idle");
}
}
}
private string LastAnimatorState { get; set; }
protected override void Start()
{
base.Start();
}
protected override void Update()
{
if (this.route == null)
return;
base.Update();
float num = this.Speed;
this.Paused = this.Speed == 0;
bool flag = this.Paused;
if (this.IsAtFinish)
{
if ((double)this.afterFinishTime < 5.0)
{
this.ManualVisibility = 1000f;
float videoSpeedAtDistance = this.videoSync.GetVideoSpeedAtDistance(this.Distance - 5f);
if ((double)this.afterFinishFrame == 0.0 && (double)this.afterFinishOffsetZ == 0.0)
{
this.finishPassSpeed = (double)this.lastSpeed > 0.0 ? this.lastSpeed : 10f;
}
flag = false;
this.afterFinishTime += Time.deltaTime;
this.afterFinishTime = Math.Min(5f, this.afterFinishTime);
num = Mathf.Lerp(this.finishPassSpeed, 0.0f, this.afterFinishTime / 5f);
this.afterFinishFrame += num / videoSpeedAtDistance * Time.deltaTime * 29.97f;
this.frame = Math.Min((float)(this.route.CameraPositions.Length - 1), this.videoSync.GetVideoFrameAtDistance(this.Distance) + this.afterFinishFrame);
if ((double)this.frame == (double)(this.route.CameraPositions.Length - 1))
this.afterFinishOffsetZ += num * Time.deltaTime;
}
else
{
this.afterFinishTime += Time.deltaTime;
num = 0.0f;
if ((double)this.afterFinishTime > 15.0)
this.ManualVisibility = -1f;
else
this.ManualVisibility = 1000f;
}
this.PositionOffset.z = this.afterFinishOffsetZ;
this.transform.localScale = Vector3.one * this.route.RiderScale;
this.UpdateTransform();
}
else
{
this.transform.localScale = Vector3.one * this.route.RiderScale;
if (flag)
num = 0.0f;
this.ManualVisibility = 0.0f;
this.afterFinishTime = 0.0f;
this.afterFinishFrame = 0.0f;
this.afterFinishOffsetZ = 0.0f;
this.PositionOffset.z = 0.0f;
}
if (flag != this.lastPauseState)
{
this.lastPauseState = flag;
}
if ((double)this.lastSpeed != (double)num)
{
this.lastSpeed = num;
}
if ((double)this.lastSpeed > 0.0 && this.lastDifficultyLevel != this.DifficultyLevel && !this.lastPauseState && (double)Math.Abs(Time.time - this.lastDiffLevelChange) > 2.0)
{
this.lastDifficultyLevel = this.DifficultyLevel;
this.lastDiffLevelChange = Time.time;
}
if ((double)this.lastVisibilitylevel == (double)this.VisibilityLevel)
return;
this.lastVisibilitylevel = this.VisibilityLevel;
}
private void FixedUpdate()
{
////if (this.Paused || (double)this.Speed <= 0.0)
//if ((double)this.Speed <= 0.0)
// return;
//float angle = (float)VTMath.Clamp(VTMath.Lerp(0.0, 0.0, 1689.3684817282528, 6.5, 360.0 * ((double)this.Speed < 10.0 ? (double)this.Speed : 2.3463451135114624)), 0.0, 6.5);
//this.wheelFront.transform.Rotate(Vector3.right, angle);
//this.wheelRear.transform.Rotate(Vector3.right, angle);
}
}
}