部分代码重构,AR起步冲的问题和停车动画调整
This commit is contained in:
parent
71b6155946
commit
fb4da81ce2
@ -323,8 +323,8 @@ namespace Assets.AR
|
||||
//创建轨迹上的转向
|
||||
public void CreateTrajectoryOrientations()
|
||||
{
|
||||
Quaternion[] quaternionArray = new Quaternion[this.FilteredCameraPositions.Length];
|
||||
for (int index = 1; index < this.FilteredCameraPositions.Length - 1; ++index)
|
||||
var quaternionArray = new Quaternion[this.FilteredCameraPositions.Length];
|
||||
for (var index = 1; index < this.FilteredCameraPositions.Length - 1; ++index)
|
||||
quaternionArray[index] = Quaternion.LookRotation(this.FilteredCameraPositions[index + 1] - this.FilteredCameraPositions[index - 1], Vector3.up);
|
||||
quaternionArray[0] = quaternionArray[1];
|
||||
quaternionArray[this.FilteredCameraPositions.Length - 1] = quaternionArray[this.FilteredCameraPositions.Length - 2];
|
||||
@ -374,7 +374,7 @@ namespace Assets.AR
|
||||
}
|
||||
if (index1 + 1 == this.LightRotations.Length)
|
||||
return this.LightRotations[this.LightRotations.Length - 1];
|
||||
float t = Mathf.InverseLerp(this.LightRotationFrames[index1], this.LightRotationFrames[index1 + 1], distance);
|
||||
var t = Mathf.InverseLerp(this.LightRotationFrames[index1], this.LightRotationFrames[index1 + 1], distance);
|
||||
return Quaternion.Slerp(this.LightRotations[index1], this.LightRotations[index1 + 1], t);
|
||||
}
|
||||
|
||||
@ -433,7 +433,6 @@ namespace Assets.AR
|
||||
this.SlamSegments = data.SlamSegments;
|
||||
this.CameraHeight = data.CameraHeight;
|
||||
this.RiderScale = (double)data.RiderScale != 0.0 ? data.RiderScale : 1f;
|
||||
this.RiderScale *= 0.9f;
|
||||
this.CameraPositions = ((IEnumerable<VectorData>)data.CameraPositions).Select<VectorData, Vector3>((Func<VectorData, Vector3>)(x => x.ToUnityVector())).ToArray<Vector3>();
|
||||
this.ProjectionParameters = data.CameraProjectionParameters;
|
||||
this.CameraRotations = ((IEnumerable<VectorData>)data.CameraRotations).Select<VectorData, Quaternion>((Func<VectorData, Quaternion>)(x => Quaternion.Euler(x.ToUnityVector()))).ToArray<Quaternion>();
|
||||
|
||||
@ -18,8 +18,8 @@ namespace Assets.AR
|
||||
ARVideoPlayerControl VideoPlayerControl;
|
||||
ARLaneGameObject[] rides { get; set; }
|
||||
public ARLaneGameObject mainRiderObject { get; set; }
|
||||
private Light arLight;
|
||||
private Light arBackLight;
|
||||
public Light arLight;
|
||||
private Light arBackLight { get; set; }
|
||||
public CameraDistance RiderCameraDistance { get; set; }
|
||||
public VideoPlayMode VideoControlMode { get; private set; }
|
||||
private float autoCameraSwitchTimeCounter = 80f;
|
||||
@ -55,6 +55,7 @@ namespace Assets.AR
|
||||
//ar数据加载本地,本地没有就下载
|
||||
this.aRData = arData;
|
||||
this.detail = routeDetailData;
|
||||
|
||||
this.RiderCameraDistance = AR.CameraDistance.Middle;
|
||||
videoPointsSync = new VideoPointsSync(detail.VideoPoints.Select(c => new VideoPoint()
|
||||
{
|
||||
@ -62,14 +63,20 @@ namespace Assets.AR
|
||||
Time = (float)c.VideoTime
|
||||
}));
|
||||
videoSync = videoPointsSync;
|
||||
this.VideoPlayerControl = new ARVideoPlayerControl();
|
||||
this.VideoPlayerControl.VideoSyncSource = videoSync;
|
||||
this.VideoPlayerControl = new ARVideoPlayerControl
|
||||
{
|
||||
VideoSyncSource = videoSync
|
||||
};
|
||||
|
||||
this.videoPlayer = mediaPlayer.gameObject.AddComponent<AVProVideoPlayer>();
|
||||
this.videoPlayer.videoPlayer = mediaPlayer;
|
||||
|
||||
SetArRoute(new ARRoute(aRData.Route), videoSync, videoPlayer);
|
||||
|
||||
this.VideoPlayerControl.VideoFrameOffset = this.Route.VideoFrameOffset;
|
||||
this.VideoPlayerControl.Route = Route;
|
||||
this.VideoPlayerControl.SetVideoPlayer(videoPlayer);
|
||||
|
||||
rides = FindObjectsOfType<ARLaneGameObject>();
|
||||
SetUpLight();
|
||||
}
|
||||
@ -123,7 +130,7 @@ namespace Assets.AR
|
||||
}
|
||||
}
|
||||
|
||||
timers += 1f;
|
||||
timers += 0.2f;
|
||||
}
|
||||
|
||||
if (mainRiderObject == null || Route == null)
|
||||
@ -134,16 +141,15 @@ namespace Assets.AR
|
||||
var delta = Time.deltaTime;
|
||||
foreach (var obj in this.riderObjects.Values)
|
||||
{
|
||||
var offset = obj.DeltaDistance * delta;
|
||||
//Debug.Log($"offset:{offset}:{DateTime.Now}");
|
||||
obj.Distance += offset;
|
||||
obj.RouteDistance += offset;
|
||||
if(obj.DeltaDistance == 0 )continue;
|
||||
obj.Distance = Mathf.Lerp(obj.Distance, obj.Distance + obj.DeltaDistance, delta);
|
||||
obj.RouteDistance = Mathf.Lerp(obj.RouteDistance, obj.RouteDistance + obj.DeltaDistance, delta);
|
||||
}
|
||||
|
||||
VideoPlayerControl.UpdateVideoPlayRate(mainRiderObject.PreSpeed, mainRiderObject.Distance);
|
||||
|
||||
this.FrameIndexDistanceCorrection = this.VideoPlayerControl.FrameIndexDistanceCorrection;
|
||||
//this.FollowedRiderId = mainObject.Id;
|
||||
this.UpdateCameraFollowDistance();
|
||||
VideoPlayerControl.UpdateVideoPlayRate(mainRiderObject.PreSpeed, mainRiderObject.Distance);
|
||||
base.Update();
|
||||
this.UpdateRidersVisibility();
|
||||
this.UpdateRidersLean();
|
||||
@ -159,23 +165,11 @@ namespace Assets.AR
|
||||
//创建
|
||||
private void SetUpLight()
|
||||
{
|
||||
GameObject gameObject1 = new GameObject("ARLight");
|
||||
gameObject1.layer = this.gameObject.layer;
|
||||
gameObject1.transform.SetParent(this.transform);
|
||||
this.arLight = gameObject1.AddComponent<Light>();
|
||||
this.arLight.type = LightType.Directional;
|
||||
this.arLight.transform.rotation = Quaternion.Euler(90f, 0.0f, 0.0f);
|
||||
//if (this.BuildConfig.IsIOs || this.BuildConfig.IsTvOs)
|
||||
//{
|
||||
// this.arLight.shadows = LightShadows.Hard;
|
||||
// this.arLight.shadowStrength = 0.5f;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
this.arLight.shadows = LightShadows.Soft;
|
||||
this.arLight.shadowStrength = 1f;
|
||||
}
|
||||
this.arLight.cullingMask = 512;
|
||||
this.arLight.shadows = LightShadows.Soft;
|
||||
this.arLight.shadowStrength = 1f;
|
||||
|
||||
GameObject gameObject2 = new GameObject("ARBackLight");
|
||||
gameObject2.layer = this.gameObject.layer;
|
||||
gameObject2.transform.SetParent(this.transform);
|
||||
@ -184,7 +178,7 @@ namespace Assets.AR
|
||||
this.arBackLight.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
|
||||
this.arBackLight.shadows = LightShadows.None;
|
||||
this.arBackLight.intensity = 0.5f;
|
||||
this.arBackLight.cullingMask = 512;
|
||||
//this.arBackLight.cullingMask = 512;
|
||||
}
|
||||
//设置video显示模式
|
||||
public void SetVideoControlMode(VideoPlayMode mode)
|
||||
@ -202,15 +196,15 @@ namespace Assets.AR
|
||||
//更新摄像机的位置
|
||||
private void UpdateCameraFollowDistance()
|
||||
{
|
||||
this.NearViewMode = this.RiderCameraDistance == AR.CameraDistance.Near;
|
||||
float cameraFollowDistance = GetCameraFollowDistance(this.RiderCameraDistance);
|
||||
//this.NearViewMode = this.RiderCameraDistance == AR.CameraDistance.Near;
|
||||
var cameraFollowDistance = GetCameraFollowDistance(this.RiderCameraDistance);
|
||||
this.VideoPlayerControl.CameraFollowDistance = cameraFollowDistance;
|
||||
}
|
||||
//人物是否显示
|
||||
protected override bool IsObjectActive(ARGameObject arObject)
|
||||
{
|
||||
var flag = base.IsObjectActive(arObject);
|
||||
if ((UnityEngine.Object)arObject != (UnityEngine.Object)this.mainRiderObject)
|
||||
if (arObject != this.mainRiderObject)
|
||||
return flag;
|
||||
if ((double)this.VideoPlayerControl.CameraFollowDistance > 0.0 || this.AR360Version)
|
||||
return flag;
|
||||
@ -270,7 +264,7 @@ namespace Assets.AR
|
||||
}
|
||||
gameObject.transform.parent = this.transform;
|
||||
gameObject.transform.position = ARGameObjectsController.DefaultObjectPosition;
|
||||
gameObject.layer = 9;
|
||||
//gameObject.layer = 9;
|
||||
riderModel.Route = this.Route;
|
||||
riderModel.VideoSync = this.videoSync;
|
||||
//riderModel.VideoPlayer = this.videoPlayer;
|
||||
@ -297,7 +291,7 @@ namespace Assets.AR
|
||||
transform = {
|
||||
parent = this.transform
|
||||
},
|
||||
layer = 9
|
||||
//layer = 9
|
||||
}.AddComponent<ARLaneGameObject>();
|
||||
riderObject.Route = this.Route;
|
||||
riderObject.VideoSync = this.videoSync;
|
||||
@ -660,17 +654,9 @@ namespace Assets.AR
|
||||
}
|
||||
//更新后背的光线
|
||||
private void UpdateBackLight()
|
||||
{
|
||||
//if (this.SelectedPanorama != null)
|
||||
//{
|
||||
// this.arBackLight.transform.position = this.PanoramaCamera.transform.position;
|
||||
// this.arBackLight.transform.rotation = this.PanoramaCamera.transform.rotation;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
this.arBackLight.transform.position = this.UnityCamera.transform.position;
|
||||
this.arBackLight.transform.rotation = this.UnityCamera.transform.rotation;
|
||||
}
|
||||
{
|
||||
this.arBackLight.transform.position = this.UnityCamera.transform.position;
|
||||
this.arBackLight.transform.rotation = this.UnityCamera.transform.rotation;
|
||||
this.arLight.transform.rotation = this.Route.GetLightDirection(this.videoPlayer.CurrentFrame);
|
||||
this.arLight.shadowStrength = this.Route.GetShadowIntensity(this.videoPlayer.CurrentFrame);
|
||||
}
|
||||
|
||||
@ -82,6 +82,7 @@ namespace Assets.AR
|
||||
|
||||
private void SkipVideoToFrame(long frame) => this.VideoPlayer.Seek(frame);
|
||||
|
||||
private const float TimerInterval = 0.2f;
|
||||
public void UpdateVideoPlayRate(float speed, float routeDistance)
|
||||
{
|
||||
if (!this.AllowUpdate)
|
||||
@ -103,32 +104,32 @@ namespace Assets.AR
|
||||
}
|
||||
else
|
||||
{
|
||||
float videoFrameAtDistance1 = this.VideoSyncSource.GetVideoFrameAtDistance(routeDistance);
|
||||
float val2 = routeDistance - this.CameraFollowDistance;
|
||||
var videoFrameAtDistance1 = this.VideoSyncSource.GetVideoFrameAtDistance(routeDistance);
|
||||
var val2 = routeDistance - this.CameraFollowDistance;
|
||||
//if (this.IsMultilap && (double)this.RiderDistance.RouteDistance > (double)this.RiderDistance.LapDistance && (double)val2 < 0.0)
|
||||
// val2 += (float)this.lapLength;
|
||||
float distance = Math.Max(0.0f, val2);
|
||||
float frame = this.VideoSyncSource.GetVideoFrameAtDistance(distance) + (float)this.VideoFrameOffset;
|
||||
var distance = Math.Max(0.0f, val2);
|
||||
var frame = this.VideoSyncSource.GetVideoFrameAtDistance(distance) + (float)this.VideoFrameOffset;
|
||||
if (this.Route != null && (double)this.Route.GetVisibility(frame) > 10.0)
|
||||
frame = (float)this.Route.GetFrameAtDistance(Math.Max(0.0, this.Route.GetDistanceForFrame((double)videoFrameAtDistance1) - (double)this.CameraFollowDistance)) + (float)this.VideoFrameOffset;
|
||||
//if (this.VideoPlayer is RouvyLib.Video.RouvyVideoPlayer.RouvyVideoPlayer videoPlayer)
|
||||
// videoPlayer.TargetFrame = frame;
|
||||
this.VideoPlayer.UpdateCurrentFrame();
|
||||
float distanceForVideoFrame = this.VideoSyncSource.GetDistanceForVideoFrame(this.VideoPlayer.CurrentFrame - (float)this.VideoFrameOffset);
|
||||
var distanceForVideoFrame = this.VideoSyncSource.GetDistanceForVideoFrame(this.VideoPlayer.CurrentFrame - (float)this.VideoFrameOffset);
|
||||
float f;
|
||||
if (this.Route != null)
|
||||
{
|
||||
double frameAtDistance = this.Route.GetFrameAtDistance(this.Route.GetDistanceForFrame((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset) + (double)Mathf.Min(routeDistance, this.CameraFollowDistance));
|
||||
var frameAtDistance = this.Route.GetFrameAtDistance(this.Route.GetDistanceForFrame((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset) + (double)Mathf.Min(routeDistance, this.CameraFollowDistance));
|
||||
f = videoFrameAtDistance1 - (float)frameAtDistance;
|
||||
}
|
||||
else
|
||||
f = frame - (this.VideoPlayer.CurrentFrame - (float)this.VideoFrameOffset);
|
||||
float num1 = Mathf.Clamp01(PFMath.Lerp(0.0f, 1f, 100f, 0.0f, Mathf.Abs(f)));
|
||||
var num1 = Mathf.Clamp01(PFMath.Lerp(0.0f, 1f, 100f, 0.0f, Mathf.Abs(f)));
|
||||
this.FrameIndexDistanceCorrection = f * num1;
|
||||
this.CameraDistanceError = distance - distanceForVideoFrame;
|
||||
if (this.IsMultilap)
|
||||
{
|
||||
float num2 = distance - (distanceForVideoFrame + (float)this.lapLength);
|
||||
var num2 = distance - (distanceForVideoFrame + (float)this.lapLength);
|
||||
if ((double)Math.Abs(num2) < (double)Math.Abs(this.CameraDistanceError) && (double)Math.Abs(num2) < 200.0)
|
||||
return;
|
||||
}
|
||||
@ -139,7 +140,7 @@ namespace Assets.AR
|
||||
else
|
||||
{
|
||||
var totalSeconds = DateTime.UtcNow.Subtract(this.lastPlaybackSpeedChange).TotalSeconds;
|
||||
if (totalSeconds >= 0.0 && totalSeconds < 0.20000000298023224)
|
||||
if (totalSeconds >= 0.0 && totalSeconds < TimerInterval)
|
||||
return;
|
||||
var num3 = (float)totalSeconds;
|
||||
var num4 = num3 * speed;
|
||||
|
||||
8
Assets/Materials.meta
Normal file
8
Assets/Materials.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39e9f40939fde574ca2a293c619e95e9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
77
Assets/Materials/VideoMaterial.mat
Normal file
77
Assets/Materials/VideoMaterial.mat
Normal file
@ -0,0 +1,77 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: VideoMaterial
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 0
|
||||
- _SrcBlend: 1
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
8
Assets/Materials/VideoMaterial.mat.meta
Normal file
8
Assets/Materials/VideoMaterial.mat.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a7d739233991f94b80481005b079d7d
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@ -25,7 +25,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8629729479594509059}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 0, y: -100, z: -100}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 6918487040151656200}
|
||||
|
||||
@ -25,7 +25,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8629729479594509059}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 0, y: -100, z: -100}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 669762769015553617}
|
||||
|
||||
@ -3691,8 +3691,8 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1535700487792324436}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -1, z: 0}
|
||||
m_LocalScale: {x: 0.75, y: 0.75, z: 0.75}
|
||||
m_LocalPosition: {x: 0, y: -100, z: -100}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 5510178270068819320}
|
||||
- {fileID: 3524312104137692172}
|
||||
@ -4023,18 +4023,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
weight: 0
|
||||
speed: 0
|
||||
power: 0
|
||||
cadance: 0
|
||||
wkg: 0
|
||||
ticks: 0
|
||||
currentSlope: 0
|
||||
distance: 0
|
||||
totalClimb: 0
|
||||
currentIndex: 0
|
||||
bearing: 0
|
||||
target: {fileID: 0}
|
||||
diff: 0
|
||||
frames: 0
|
||||
power: 0
|
||||
--- !u!114 &6834098711345890891
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -4053,8 +4043,8 @@ MonoBehaviour:
|
||||
PositionOffset: {x: 0, y: 0, z: 0}
|
||||
RotationOffset: {x: 0, y: 0, z: 0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
StartPosition: 0
|
||||
TestPower: 500
|
||||
wheelFront: {fileID: 0}
|
||||
wheelRear: {fileID: 0}
|
||||
--- !u!1 &1540924146250517987
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -27,8 +27,8 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 26904646242573121}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -1, z: 0}
|
||||
m_LocalScale: {x: 0.75, y: 0.75, z: 0.75}
|
||||
m_LocalPosition: {x: 0, y: -100, z: -100}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 6442512681317347693}
|
||||
- {fileID: 2465416350492459823}
|
||||
@ -363,17 +363,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
weight: 0
|
||||
speed: 0
|
||||
power: 0
|
||||
cadance: 0
|
||||
wkg: 0
|
||||
ticks: 0
|
||||
currentSlope: 0
|
||||
distance: 0
|
||||
totalClimb: 0
|
||||
currentIndex: 0
|
||||
bearing: 0
|
||||
diff: 0
|
||||
frames: 0
|
||||
power: 0
|
||||
--- !u!114 &7778627600969797816
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -392,8 +383,8 @@ MonoBehaviour:
|
||||
PositionOffset: {x: 0, y: 0, z: 0}
|
||||
RotationOffset: {x: 0, y: 0, z: 0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
StartPosition: 0
|
||||
TestPower: 500
|
||||
wheelFront: {fileID: 0}
|
||||
wheelRear: {fileID: 0}
|
||||
--- !u!1 &32093163217517046
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -3691,8 +3691,8 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1535700487792324436}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -1, z: 3}
|
||||
m_LocalScale: {x: 0.65, y: 0.65, z: 0.65}
|
||||
m_LocalPosition: {x: 0, y: -100, z: -100}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 5510178270068819320}
|
||||
- {fileID: 3524312104137692172}
|
||||
@ -4023,16 +4023,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
weight: 0
|
||||
speed: 0
|
||||
power: 0
|
||||
cadance: 0
|
||||
wkg: 0
|
||||
ticks: 0
|
||||
currentSlope: 0
|
||||
distance: 0
|
||||
totalClimb: 0
|
||||
currentIndex: 0
|
||||
bearing: 0
|
||||
IsStart: 0
|
||||
power: 0
|
||||
--- !u!114 &3611148035918924976
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -27,8 +27,8 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 26904646242573121}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -1, z: 0}
|
||||
m_LocalScale: {x: 0.75, y: 0.75, z: 0.75}
|
||||
m_LocalPosition: {x: 0, y: -100, z: -100}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 6442512681317347693}
|
||||
- {fileID: 2465416350492459823}
|
||||
@ -363,15 +363,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
weight: 0
|
||||
speed: 0
|
||||
power: 0
|
||||
cadance: 0
|
||||
wkg: 0
|
||||
ticks: 0
|
||||
currentSlope: 0
|
||||
distance: 0
|
||||
totalClimb: 0
|
||||
currentIndex: 0
|
||||
bearing: 0
|
||||
power: 0
|
||||
--- !u!114 &5851000374308093711
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -390,8 +383,6 @@ MonoBehaviour:
|
||||
PositionOffset: {x: 0, y: 0, z: 0}
|
||||
RotationOffset: {x: 0, y: 0, z: 0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
StartPosition: 0
|
||||
TestPower: 500
|
||||
wheelFront: {fileID: 4724697995724873205}
|
||||
wheelRear: {fileID: 6597490539092503497}
|
||||
--- !u!1 &32093163217517046
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ using Assets.Scripts.Apis.Models;
|
||||
using DG.Tweening;
|
||||
using Mapbox.Utils;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
@ -58,6 +59,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
public double mockpower { get; set; }
|
||||
protected float ratio = 1;
|
||||
private static readonly int PreSpeed = Animator.StringToHash("preSpeed");
|
||||
private static readonly int AnimatorSpeed = Animator.StringToHash("speed");
|
||||
private static readonly int Grade = Animator.StringToHash("grade");
|
||||
private static readonly int Power = Animator.StringToHash("power");
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
@ -112,10 +117,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetFloat("preSpeed", (float)preSpeed);
|
||||
animator.SetFloat("speed", (float)Speed);
|
||||
animator.SetFloat("grade", (float)currentSlope);
|
||||
animator.SetFloat("power", (float)power);
|
||||
animator.SetFloat(PreSpeed, (float)preSpeed);
|
||||
animator.SetFloat(AnimatorSpeed, (float)speed);
|
||||
animator.SetFloat(Grade, (float)currentSlope);
|
||||
animator.SetFloat(Power, (float)power);
|
||||
}
|
||||
}
|
||||
//计算人物当前属性
|
||||
@ -148,21 +153,22 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
public virtual void ComputeAnimatorSpeed()
|
||||
{
|
||||
if (manager == null)
|
||||
return;
|
||||
Assert.IsNotNull(manager);
|
||||
|
||||
mapData = manager.GetMapData();
|
||||
int safeIndex = currentIndex + 1 < mapData.List.Count ? currentIndex + 1 : currentIndex;
|
||||
float num = speed == 0 ? 1f : (float)(speed / mapData.List[safeIndex].Distance);
|
||||
|
||||
var safeIndex = currentIndex + 1 < mapData.List.Count ? currentIndex + 1 : currentIndex;
|
||||
var num = speed == 0 ? 1f : (float)(speed / mapData.List[safeIndex].Distance);
|
||||
|
||||
ratio = Mathf.Clamp(num, 0.3f, 1.2f);
|
||||
|
||||
var info = animator.GetCurrentAnimatorClipInfo(0);
|
||||
if (info != null)
|
||||
if (info == null) return;
|
||||
|
||||
var currentClip = info.FirstOrDefault();
|
||||
if (currentClip.clip != null)
|
||||
{
|
||||
var currentClip = info.FirstOrDefault();
|
||||
if (currentClip.clip != null)
|
||||
{
|
||||
animator.speed = ratio;
|
||||
}
|
||||
animator.speed = ratio;
|
||||
}
|
||||
}
|
||||
public virtual void ComputeRecord() { }
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.SceneManagement;
|
||||
@ -14,58 +13,56 @@ using System.Linq;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.AR;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public class VideoLoading : MonoBehaviour, IProgress<float>
|
||||
{
|
||||
UnityWebRequest request { get; set; }
|
||||
VideoGameManager manager { get; set; }
|
||||
|
||||
protected Text mapName;
|
||||
protected RawImage mapRouteImage;
|
||||
protected CanvasGroup canvasGroup;
|
||||
protected Slider slider;
|
||||
protected Text processText;
|
||||
protected Text rideNowText;
|
||||
protected Button rideNow;
|
||||
protected Button cancel;
|
||||
protected Text mapDescText;
|
||||
protected Text distance;
|
||||
protected Text elevaction;
|
||||
protected Text slope;
|
||||
protected GameObject panel;
|
||||
protected GameObject download;
|
||||
protected GameObject watch;
|
||||
private Text mapName;
|
||||
private RawImage mapRouteImage;
|
||||
private CanvasGroup canvasGroup;
|
||||
private Slider slider;
|
||||
private Text processText;
|
||||
private Text rideNowText;
|
||||
private Button rideNow;
|
||||
private Button cancel;
|
||||
private Text mapDescText;
|
||||
private Text distance;
|
||||
private Text elevaction;
|
||||
private Text slope;
|
||||
private GameObject panel;
|
||||
private GameObject download;
|
||||
private GameObject watch;
|
||||
|
||||
protected GameObject loadingPanel { get; set; }
|
||||
|
||||
protected Text level;
|
||||
protected Text rideNum;
|
||||
protected Text uploadByUserName;
|
||||
protected RawImage head;
|
||||
protected RawImage country;
|
||||
protected RawImage mapCountry;
|
||||
protected RawImage altitudeGraph { get; set; }
|
||||
protected Transform mapRanking;
|
||||
protected Text mapId;
|
||||
|
||||
private Text level;
|
||||
private Text rideNum;
|
||||
private Text uploadByUserName;
|
||||
private RawImage head;
|
||||
private RawImage country;
|
||||
private RawImage mapCountry;
|
||||
private RawImage altitudeGraph { get; set; }
|
||||
private Transform mapRanking;
|
||||
private Text mapId;
|
||||
private Text downloadText { get; set; }
|
||||
private Transform ui;
|
||||
private MapRoute route;
|
||||
|
||||
protected float process = 0;//0-100 %
|
||||
public float targetAlpha = 0f;
|
||||
public float alphaSpeed = 2.0f;
|
||||
|
||||
protected Transform ui;
|
||||
|
||||
protected MapRoute route;
|
||||
|
||||
|
||||
private bool startBtnLock = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(App.gameRoomDetail != null)
|
||||
ShowGameRoomLoading();
|
||||
}
|
||||
void Start()
|
||||
|
||||
private void Start()
|
||||
{
|
||||
manager = FindObjectOfType<VideoGameManager>();
|
||||
ui = manager.GetCanvasTransform();
|
||||
@ -184,19 +181,18 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
downloadText = rideNow.GetComponentInChildren<Text>();//视频下载进度text
|
||||
}
|
||||
Text downloadText { get; set; }
|
||||
|
||||
protected void InitGameObjectData()
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
#region 绑定路书基本信息
|
||||
mapName.text = GetMaxString(route.Name, 40);
|
||||
mapName.text = route.Name.ToEllipsisString(40);
|
||||
level.text = route.Hard;
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2) + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2) + "%";
|
||||
rideNum.text = route.TheHeat.ToString();
|
||||
distance.text = route.Distance.ToString("f1") + "KM";
|
||||
mapDescText.text = GetMaxString(route.Dec, 255);
|
||||
mapDescText.text = route.Dec.ToEllipsisString(255);
|
||||
mapId.text = $"#{route.Id.ToString()}";
|
||||
var userList = ConfigHelper.mapApi.GetOnlineUserInfo(new int[] { route.UserId }).data;
|
||||
if (userList.Count > 0)
|
||||
@ -218,15 +214,18 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
CreateRankingList(list.data.list);
|
||||
}
|
||||
}
|
||||
bool startBtnLock = false;
|
||||
public void StartRide(BaseEventData baseEvent)
|
||||
|
||||
private void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
if (startBtnLock)
|
||||
return;
|
||||
if (startBtnLock) return;
|
||||
|
||||
startBtnLock = true;
|
||||
var ui = manager.GetCanvasTransform();
|
||||
|
||||
InitClientState(false);
|
||||
|
||||
InitAR();
|
||||
|
||||
canvasGroup.DOFade(0, 1).onComplete += () => {
|
||||
InitAR();
|
||||
gameObject.SetActive(false);
|
||||
manager.StartGame();
|
||||
manager.SetCyclingModel(Assets.Scenes.Ride.Scripts.Model.CyclingModel.Single);
|
||||
@ -234,9 +233,9 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
};
|
||||
}
|
||||
|
||||
public async void InitAR()
|
||||
private async void InitAR()
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
route = manager.mapRoute;
|
||||
var arDataPath = $"{PFConstants.ARFolder}/{route.Id}/{route.Id}.json";
|
||||
var videoRoute = $"{PFConstants.ARFolder}/{route.Id}/route-{route.Id}.json";
|
||||
|
||||
@ -245,13 +244,15 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
await Task.Run<ARData>((Func<ARData>)(() => aRData = ARData.LoadFromFile(arDataPath)));
|
||||
await Task.Run<RouteDetailData>((Func<RouteDetailData>)(() => routeDetailData = RouteDetailData.LoadFromFile(videoRoute)));
|
||||
|
||||
var arController = FindObjectOfType<ARTrainingController>();
|
||||
arController.Initialize(aRData, routeDetailData);
|
||||
}
|
||||
|
||||
|
||||
public void StartRide(int seconds)
|
||||
{
|
||||
InitClientState(false);
|
||||
|
||||
var ui = manager.GetCanvasTransform();
|
||||
canvasGroup.DOFade(0, 0).onComplete += () => {
|
||||
InitAR();
|
||||
@ -260,6 +261,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
manager.SetCurrentMode(VideoGameManager.ARMode.RIDE);
|
||||
ui.Find("Panel").gameObject.SetActive(true);
|
||||
};
|
||||
|
||||
UIManager.ShowGameRoomCountDownPanel(seconds,()=> {
|
||||
manager.StartGame();
|
||||
},false,true);
|
||||
@ -267,7 +269,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private bool downloading = false;
|
||||
private CancellationTokenSource cancelToken;
|
||||
protected async void DownloadAsync(BaseEventData baseEvent)
|
||||
private async void DownloadAsync(BaseEventData baseEvent)
|
||||
{
|
||||
if (downloading)
|
||||
return;
|
||||
@ -322,24 +324,35 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
return;
|
||||
|
||||
slider.value = value < 1 ? (float)Math.Round(value * 100, 0) : 100;
|
||||
downloadText.text = slider.value.ToString() + "%";
|
||||
downloadText.text = slider.value.ToString(CultureInfo.InvariantCulture) + "%";
|
||||
}
|
||||
//进入观察模式
|
||||
private void WatchHandler(BaseEventData data)
|
||||
{
|
||||
var canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
var ui = manager.GetCanvasTransform();
|
||||
InitAR();
|
||||
MapUDPService.IsWatch = true;
|
||||
MapUDPService.SendGizpModel();
|
||||
canvasGroup.DOFade(0, 1).onComplete += () => {
|
||||
InitClientState(true);
|
||||
|
||||
var canvas = transform.GetComponent<CanvasGroup>();
|
||||
var canvasTransform = manager.GetCanvasTransform();
|
||||
canvas.DOFade(0, 1).onComplete += () => {
|
||||
gameObject.SetActive(false);
|
||||
ui.gameObject.SetActive(true);
|
||||
canvasTransform.gameObject.SetActive(true);
|
||||
manager.SetCurrentMode(VideoGameManager.ARMode.INSPECT);
|
||||
manager.StartGame();
|
||||
};
|
||||
}
|
||||
protected void Cancel(BaseEventData baseEvent)
|
||||
|
||||
/// <summary>
|
||||
/// 告诉服务器是观察模式还是骑行模式
|
||||
/// </summary>
|
||||
/// <param name="isWatch"></param>
|
||||
private static void InitClientState(bool isWatch)
|
||||
{
|
||||
MapUDPService.IsWatch = isWatch;
|
||||
MapUDPService.SendGizpModel();
|
||||
}
|
||||
|
||||
private void Cancel(BaseEventData baseEvent)
|
||||
{
|
||||
if (cancelToken == null)
|
||||
{
|
||||
@ -361,7 +374,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
UIManager.CloseConfirm();
|
||||
});
|
||||
}
|
||||
protected async void DrawMapRouteAsync(int routeId, int type = 0)
|
||||
private async void DrawMapRouteAsync(int routeId, int type = 0)
|
||||
{
|
||||
var result = await ConfigHelper.mapApi.GetMapLoadingCoverageUrl(routeId, type);
|
||||
if (!result.result)
|
||||
@ -378,7 +391,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, DowloadCallBack);
|
||||
}
|
||||
}
|
||||
protected void DowloadCallBack(string url, RawImage rawImage)
|
||||
private void DowloadCallBack(string url, RawImage rawImage)
|
||||
{
|
||||
if (!App.TextureCache.ContainsKey(url))
|
||||
{
|
||||
@ -449,11 +462,5 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected string GetMaxString(string value, int length)
|
||||
{
|
||||
var s = Helper.SubStr(value, length);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Assets/Scripts/Utils/ObjectExtension.cs
Normal file
34
Assets/Scripts/Utils/ObjectExtension.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Text;
|
||||
|
||||
public static class ObjectExtension
|
||||
{
|
||||
public static string ToEllipsisString(this string message, int length)
|
||||
{
|
||||
var index = 0;
|
||||
var sb = new StringBuilder();
|
||||
foreach (var item in message)
|
||||
{
|
||||
if (IsChineseCharacter(item))
|
||||
{
|
||||
index += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
|
||||
sb.Append(item);
|
||||
if (length <= index)
|
||||
{
|
||||
return sb.Append("...").ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static bool IsChineseCharacter(char c)
|
||||
{
|
||||
return (19968 <= (int)c) && ((int)c <= 171941);
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Utils/ObjectExtension.cs.meta
Normal file
3
Assets/Scripts/Utils/ObjectExtension.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6474a1d1e1c3429dba1abc390b5e67e9
|
||||
timeCreated: 1678262635
|
||||
Loading…
x
Reference in New Issue
Block a user