364 lines
12 KiB
C#
364 lines
12 KiB
C#
using DefaultNamespace;
|
|
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Runtime.Remoting.Messaging;
|
|
using UnityEngine;
|
|
|
|
public class Machine : MonoBehaviour
|
|
{
|
|
[Header("机械手臂ID")]
|
|
public string Id;
|
|
[Header("机械手臂动画")]
|
|
public Animation animations;
|
|
[Header("机械手臂箱子生成位置")]
|
|
public Transform points;
|
|
[Header("箱子")]
|
|
public GameObject Box;
|
|
[Header("箱子2")]
|
|
public GameObject Box2;
|
|
[Header("位移的速度")]
|
|
public float speed = 3.5f;
|
|
/// <summary>
|
|
/// 接收执行的动画
|
|
/// </summary>
|
|
private GameObject boxdata;
|
|
private void Awake()
|
|
{
|
|
|
|
}
|
|
void Update()
|
|
{
|
|
//if (Input.GetKeyDown(KeyCode.A))
|
|
//{
|
|
// //GameObject ga = Instantiate(Box2);
|
|
// //GameObject game = ga.transform.GetChild(0).gameObject;
|
|
// //Destroy(game);
|
|
// //ga.transform.position = points.transform.position;
|
|
// //ga.transform.localEulerAngles = new Vector3(0, 0, 0);
|
|
// //ga.transform.SetParent(points);
|
|
// //animations["take"].time = 5f;
|
|
// animations.Play("take");
|
|
//}
|
|
//if (Input.GetKeyDown(KeyCode.S))
|
|
//{
|
|
// animations.Play("take");
|
|
//}
|
|
//if (Input.GetKeyDown(KeyCode.D))
|
|
//{
|
|
// animations.Play("To");
|
|
//}
|
|
//if (Input.GetKeyDown(KeyCode.F))
|
|
//{
|
|
// animations.Play("hello");
|
|
//}
|
|
//if (Input.GetKeyDown(KeyCode.G))
|
|
//{
|
|
// animations.Play("qing");
|
|
//}
|
|
//if (Input.GetKeyDown(KeyCode.H))
|
|
//{
|
|
// animations.Play("qinghou");
|
|
//}
|
|
//if (Input.GetKeyDown(KeyCode.J))
|
|
//{
|
|
// animations.Play("add");
|
|
//}
|
|
//if (Input.GetKeyDown(KeyCode.K))
|
|
//{
|
|
// animations.Play("put");
|
|
//}
|
|
}
|
|
public void Getarm(Roboticarm roboticarm)
|
|
{
|
|
if (roboticarm.Jobcontent.Length > 0 && roboticarm.Workingsmokeboxnumber != "0")
|
|
{
|
|
Motionexecution(roboticarm.Jobcontent, roboticarm);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 先判断步骤运动到指定位置再执行动画
|
|
/// </summary>
|
|
/// <param name="procedurem"></param>
|
|
/// <param name="roboticarm"></param>
|
|
public void Motionexecution(string procedurem, Roboticarm roboticarm)
|
|
{
|
|
Debug.Log("调用步骤");
|
|
switch (procedurem)
|
|
{
|
|
case "1":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Debug.Log("取箱子");
|
|
Transform point = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(point.position, (Vector3.Distance(transform.position, point.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
animations.Play("take");
|
|
StartCoroutine(Judgmentbox(roboticarm.Workstation));
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case "2":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
Debug.Log("读箱子信息");
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Transform box = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(box.position, (Vector3.Distance(transform.position, box.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
animations.Play("read");
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case "3":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
Debug.Log("去盖");
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Transform box = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(box.position, (Vector3.Distance(transform.position, box.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
animations.Play("To");
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case "4":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
Debug.Log("喂料");
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Transform box = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(box.position, (Vector3.Distance(transform.position, box.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
animations.Play("hello");
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case "5":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
Debug.Log("清扫");
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Transform box = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(box.position, (Vector3.Distance(transform.position, box.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
animations.Play("qing");
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case "6":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
Debug.Log("拍照");
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Transform box = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(box.position, (Vector3.Distance(transform.position, box.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case "7":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
Debug.Log("加盖");
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Transform box = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(box.position, (Vector3.Distance(transform.position, box.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
animations.Play("qinghou");
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case "8":
|
|
if (roboticarm.Workstation.Length > 0)
|
|
{
|
|
Debug.Log("放箱子");
|
|
if (MqttManager.Instance.Mechanicalarm(roboticarm.Workstation))
|
|
{
|
|
Transform point = MqttManager.Instance.Mechanicalarm(roboticarm.Workstation);
|
|
transform.DOMove(point.position, (Vector3.Distance(transform.position, point.position) / speed)).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
animations.Play("put");
|
|
Invoke("Laydown", 1f);
|
|
StartCoroutine(Judgmentbox2(roboticarm.Workstation));
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 查找箱子点位
|
|
/// </summary>
|
|
/// <param name="point"></param>
|
|
IEnumerator Judgmentbox(string box)
|
|
{
|
|
yield return new WaitForSeconds(0.95f);
|
|
switch (box)
|
|
{
|
|
case "11":
|
|
Deletebox("5402");
|
|
break;
|
|
case "12":
|
|
Deletebox("5402");
|
|
break;
|
|
case "21":
|
|
Deletebox("5406");
|
|
break;
|
|
case "22":
|
|
Deletebox("5406");
|
|
break;
|
|
case "31":
|
|
Deletebox("5408");
|
|
break;
|
|
case "32":
|
|
Deletebox("5408");
|
|
break;
|
|
case "41":
|
|
Deletebox("5410");
|
|
break;
|
|
case "42":
|
|
Deletebox("5410");
|
|
break;
|
|
case "51":
|
|
Deletebox("5414");
|
|
break;
|
|
case "52":
|
|
Deletebox("5414");
|
|
break;
|
|
case "61":
|
|
Deletebox("5416");
|
|
break;
|
|
case "62":
|
|
Deletebox("5416");
|
|
break;
|
|
case "71":
|
|
Deletebox("5418");
|
|
break;
|
|
case "72":
|
|
Deletebox("5418");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 放下箱子
|
|
/// </summary>
|
|
/// <param name="box"></param>
|
|
IEnumerator Judgmentbox2(string box)
|
|
{
|
|
yield return new WaitForSeconds(1.03f);
|
|
switch (box)
|
|
{
|
|
case "111":
|
|
Addbox("5404");
|
|
break;
|
|
case "112":
|
|
Addbox("5404");
|
|
break;
|
|
case "121":
|
|
Addbox("5410");
|
|
break;
|
|
case "122":
|
|
Addbox("5410");
|
|
break;
|
|
case "131":
|
|
Addbox("5412");
|
|
break;
|
|
case "132":
|
|
Addbox("5412");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 删除对应点位箱子
|
|
/// </summary>
|
|
public void Deletebox(string point)
|
|
{
|
|
if (MqttManager.Instance.GetTransformByName(point))
|
|
{
|
|
Transform points = MqttManager.Instance.GetTransformByName(point);
|
|
if (points.GetChild(0).transform.childCount == 1)
|
|
{
|
|
GameObject box = points.transform.GetChild(0).GetChild(0).gameObject;
|
|
box.transform.SetParent(null);
|
|
box.transform.position = this.points.transform.position;
|
|
box.transform.localEulerAngles = new Vector3(0, 0, 0);
|
|
box.transform.SetParent(this.points);
|
|
|
|
Debug.Log("删除第一个对应箱子");
|
|
}
|
|
else if (points.childCount == 1)
|
|
{
|
|
GameObject box = points.transform.GetChild(0).gameObject;
|
|
box.transform.SetParent(null);
|
|
box.transform.position = this.points.transform.position;
|
|
box.transform.localEulerAngles = new Vector3(0, 0, 0);
|
|
box.transform.SetParent(this.points);
|
|
Debug.Log("删除第二个对应箱子");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("找不到删除对象");
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 增加对应箱子
|
|
/// </summary>
|
|
public void Addbox(string point)
|
|
{
|
|
if (MqttManager.Instance.GetTransformByName(point))
|
|
{
|
|
Transform points = MqttManager.Instance.GetTransformByName(point);
|
|
if (points.childCount == 0)
|
|
{
|
|
Debug.Log("添加第一个箱子");
|
|
boxdata = Instantiate(Box, points.transform);
|
|
}
|
|
else if (points.childCount == 1)
|
|
{
|
|
Debug.Log("添加第二个箱子");
|
|
if (boxdata)
|
|
{
|
|
Destroy(boxdata);
|
|
}
|
|
GameObject game = Instantiate(Box2, points.transform);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 删除手臂的箱子
|
|
/// </summary>
|
|
public void Laydown()
|
|
{
|
|
if (points.transform.childCount > 0)
|
|
{
|
|
GameObject game = points.transform.GetChild(0).gameObject;
|
|
Destroy(game);
|
|
}
|
|
}
|
|
}
|