动态海拔图,全路线小地图,骑行记录上传增加截图
This commit is contained in:
1 parent
65fc5b5c50
commit
725b510748
11 files changed
+4294
-4675
No files matched your search
@@ -21,11 +21,13 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
GameObject character;
|
||||
[SerializeField]
|
||||
Animator characterAnimator;
|
||||
[SerializeField]
|
||||
AbstractMap map;
|
||||
//AbstractMap map;
|
||||
|
||||
#region 动画控制参数
|
||||
Vector3 nextPos;
|
||||
Vector3 prePos;
|
||||
Vector3 prePos = Vector3.zero;
|
||||
float timer = 1.0f;//计时器
|
||||
#endregion
|
||||
|
||||
@@ -104,11 +106,11 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
Excute();
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Excute();
|
||||
|
||||
}
|
||||
#region 骑行逻辑
|
||||
//初始化骑行数据
|
||||
@@ -118,7 +120,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
characterAnimator = GetComponentInChildren<Animator>();
|
||||
mainController = transform.parent.GetComponent<CyclingController>();
|
||||
map = FindObjectOfType<AbstractMap>();
|
||||
//map = FindObjectOfType<AbstractMap>();
|
||||
mapData = mainController.GetMapData();//获取路书信息
|
||||
nextlatlong = new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);//初始化人物位置 TODO加上之前骑行距离
|
||||
cyclingExcutor = mainController.cyclingController;
|
||||
@@ -126,6 +128,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
protected virtual void Excute()
|
||||
{
|
||||
//CamControl();
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)//定时器 一秒执行一次
|
||||
{
|
||||
@@ -147,7 +150,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//数据处理
|
||||
nextlatlong = Along(totalDistance);//下一个坐标
|
||||
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
|
||||
nextPos.y += 0.3f;//提高y轴让人物站在地图上面
|
||||
nextPos.y += 0.5f;//提高y轴让人物站在地图上面
|
||||
prePos = transform.localPosition;//当前点
|
||||
thisRotation = transform.localRotation;
|
||||
//动画控制
|
||||
@@ -181,11 +184,42 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//当前用户调用来上传骑行记录
|
||||
protected virtual void Upload()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 工具类
|
||||
|
||||
protected string CaptureCamera(Camera camera, Rect rect)
|
||||
{
|
||||
// 创建一个RenderTexture对象
|
||||
RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
|
||||
// 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
|
||||
camera.targetTexture = rt;
|
||||
camera.Render();
|
||||
//ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
|
||||
//ps: camera2.targetTexture = rt;
|
||||
//ps: camera2.Render();
|
||||
//ps: -------------------------------------------------------------------
|
||||
|
||||
// 激活这个rt, 并从中中读取像素。
|
||||
RenderTexture.active = rt;
|
||||
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
|
||||
screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
|
||||
screenShot.Apply();
|
||||
|
||||
// 重置相关参数,以使用camera继续在屏幕上显示
|
||||
camera.targetTexture = null;
|
||||
//ps: camera2.targetTexture = null;
|
||||
RenderTexture.active = null; // JC: added to avoid errors
|
||||
GameObject.Destroy(rt);
|
||||
// 最后将这些纹理数据,成一个图片文件
|
||||
byte[] bytes = screenShot.EncodeToJPG();
|
||||
string filename = Application.dataPath + "/"+Guid.NewGuid().ToString() +".jpg";
|
||||
System.IO.File.WriteAllBytes(filename, bytes);
|
||||
//Debug.Log(string.Format("截屏了一张照片: {0}", filename));
|
||||
return filename;
|
||||
}
|
||||
|
||||
public int CurrentIndex;
|
||||
//当前距离所在的海拔/坡度/距离 下一个点的坡度以及剩余距离
|
||||
void ComputeNextSlope()
|
||||
@@ -244,7 +278,15 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 deltaPos = Vector3.zero;
|
||||
Vector3 previousPos = Vector3.zero;
|
||||
void CamControl()
|
||||
{
|
||||
deltaPos = transform.position - previousPos;
|
||||
deltaPos.y = 0;
|
||||
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, Camera.main.transform.position + deltaPos, Time.time);
|
||||
previousPos = transform.position;
|
||||
}
|
||||
//人物移动控制
|
||||
IEnumerator MoveTo()
|
||||
{
|
||||
@@ -255,8 +297,13 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
Vector3 v = Vector3.Lerp(prePos, nextPos, t);
|
||||
Vector3 nextPosition = new Vector3((float)Math.Round(v.x, 2), (float)Math.Round(v.y, 2), (float)Math.Round(v.z, 2));
|
||||
if (!nextPosition.Equals(transform.localPosition))
|
||||
{
|
||||
transform.localPosition = nextPosition;
|
||||
//Camera.main.transform.localPosition = nextPosition;
|
||||
}
|
||||
|
||||
transform.localPosition = new Vector3((float)Math.Round(v.x,4), (float)Math.Round(v.y, 4), (float)Math.Round(v.z, 4));
|
||||
//控制海拔图的位置
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user