127 lines
3.2 KiB
C#
127 lines
3.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
|
||
/// <summary>
|
||
/// 机器人保存坐标
|
||
/// </summary>
|
||
[AddComponentMenu("SaveCoordinateRobot/机器人保存坐标")]
|
||
public class SaveCoordinateRobot : MonoBehaviour
|
||
{
|
||
public static SaveCoordinateRobot Inst;
|
||
public Root myroot = new Root();
|
||
public RectTransform bg_img;
|
||
public RectTransform start_img;
|
||
public RectTransform end_img;
|
||
|
||
/// <summary>
|
||
/// X输入范围最小
|
||
/// </summary>
|
||
[SerializeField] float inputMin_x => 0;
|
||
/// <summary>
|
||
/// X输入范围最大
|
||
/// </summary>
|
||
[SerializeField] float inputMax_x => 320;
|
||
/// <summary>
|
||
/// X输出范围最小
|
||
/// </summary>
|
||
[SerializeField] float outputMin_x;
|
||
/// <summary>
|
||
/// X输出范围最大
|
||
/// </summary>
|
||
[SerializeField] float outputMax_x;
|
||
|
||
/// <summary>
|
||
/// Y输入范围最小
|
||
/// </summary>
|
||
[SerializeField] float inputMin_y => 0;
|
||
/// <summary>
|
||
/// Y输入范围最大
|
||
/// </summary>
|
||
[SerializeField] float inputMax_y => 800;
|
||
/// <summary>
|
||
/// Y输出范围最小
|
||
/// </summary>
|
||
[SerializeField] float outputMin_y;
|
||
/// <summary>
|
||
/// Y输出范围最大
|
||
/// </summary>
|
||
[SerializeField] float outputMax_y;
|
||
|
||
|
||
private void Awake()
|
||
{
|
||
Inst = this;
|
||
}
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
/*Debug.Log("X初:" +*/
|
||
outputMin_x = (bg_img.anchoredPosition3D.x + start_img.anchoredPosition3D.x);
|
||
/*Debug.Log("Y初:" + */
|
||
outputMin_y = (/*Screen.height*/ +(bg_img.anchoredPosition3D.y + start_img.anchoredPosition3D.y));
|
||
|
||
/*Debug.Log("X止:" + */
|
||
outputMax_x = (bg_img.anchoredPosition3D.x + end_img.anchoredPosition3D.x);
|
||
/*Debug.Log("Y止:" + */
|
||
outputMax_y = (/*Screen.height*/ +(bg_img.anchoredPosition3D.y + end_img.anchoredPosition3D.y));
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
/// <param name="inputMin">输入范围最小</param>
|
||
/// <param name="inputMax">输入范围最大</param>
|
||
/// <param name="outputMin">输出范围最小</param>
|
||
/// <param name="outputMax">输出范围最大</param>
|
||
/// <returns></returns>
|
||
float Map(float value, float inputMin, float inputMax, float outputMin, float outputMax)
|
||
{
|
||
return (value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin;
|
||
}
|
||
|
||
public Vector3 MapCoordinates(Vector2 coordinates)
|
||
{
|
||
float x = coordinates.x;
|
||
float y = coordinates.y;
|
||
|
||
float mappedX = Map(x, inputMin_x, inputMax_x, outputMin_x, outputMax_x);
|
||
float mappedY = Map(y, inputMin_y, inputMax_y, outputMin_y, outputMax_y);
|
||
|
||
//映射后的三维坐标
|
||
return new Vector3(mappedX, mappedY, 0);
|
||
}
|
||
|
||
|
||
[System.Serializable]
|
||
public class Root
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string code;
|
||
/// <summary>
|
||
/// 操作成功
|
||
/// </summary>
|
||
public string message;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public int data;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string serverTime;
|
||
}
|
||
|
||
}
|