96 lines
2.8 KiB
C#
96 lines
2.8 KiB
C#
using BestHTTP.SecureProtocol.Org.BouncyCastle.Tsp;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 机器人对象
|
|
/// </summary>
|
|
public class RobotObject : MonoBehaviour
|
|
{
|
|
public RectTransform rect_transform;
|
|
/*
|
|
bmp_x = origin.x
|
|
*/
|
|
/// <summary>
|
|
/// 机器人信息
|
|
/// </summary>
|
|
public RobotClass RobotClass = null;
|
|
/// <summary>
|
|
/// 机器人地图数据
|
|
/// </summary>
|
|
public RobotMap RobotMap = null;
|
|
/// <summary>
|
|
/// 机器人位置状态信息
|
|
/// </summary>
|
|
public Queue<RobotPos> RobotPosQueue = new Queue<RobotPos>();
|
|
/// <summary>
|
|
/// 机器人任务队列
|
|
/// </summary>
|
|
public RobotTask RobotTask = null;
|
|
|
|
/// <summary>
|
|
/// 当前执行的机器人位置信息
|
|
/// </summary>
|
|
private RobotPos current_robot_pos = null;
|
|
|
|
//固定值
|
|
public int origin_x;//=info.origin.x
|
|
public int origin_y;//=info.origin.y
|
|
public int pixel_width;//info.width
|
|
public int pixel_height;//info.height
|
|
public double resolution;//=info.resolution
|
|
//public double bmp_x;//=origin.x/resolution
|
|
//public double bmp_y;//=info.height-(origin.y/resolution)
|
|
//public float bmp_h;//=info.height
|
|
//public float bmp_w;//=info.width
|
|
|
|
//实时值
|
|
//public double map_x;//=current_pos.x
|
|
//public double map_y;//=current_pos.y
|
|
public double display_x;//=(current_pos.x-origin.x)/resolution
|
|
public double display_y;//=(current_pos.y-origin.y)/resolution
|
|
|
|
private bool get;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
rect_transform = GetComponent<RectTransform>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (RobotClass == null || RobotMap == null) return;
|
|
if (!get)
|
|
{
|
|
get = true;
|
|
origin_x = RobotMap.info.origin.x;
|
|
origin_y = RobotMap.info.origin.y;
|
|
pixel_width = RobotMap.info.width;
|
|
pixel_height = RobotMap.info.height;
|
|
resolution = RobotMap.info.resolution;
|
|
}
|
|
|
|
if (RobotPosQueue.Count > 0 && current_robot_pos == null)
|
|
{
|
|
current_robot_pos = RobotPosQueue.Peek();
|
|
//Debug.Log(Newtonsoft.Json.JsonConvert.SerializeObject(current_robot_pos));
|
|
|
|
display_x = (current_robot_pos.current_pose.x - origin_x) / resolution;
|
|
display_y = (current_robot_pos.current_pose.x - origin_y) / resolution;
|
|
|
|
display_x *= (rect_transform.sizeDelta.x / pixel_width);
|
|
display_y *= (rect_transform.sizeDelta.y / pixel_height);
|
|
|
|
rect_transform.DOAnchorPos(new Vector2((float)display_x, (float)display_y), 0.5f).OnComplete(() =>
|
|
{
|
|
RobotPosQueue.Dequeue();
|
|
current_robot_pos = null;
|
|
});
|
|
}
|
|
}
|
|
}
|