202 lines
7.4 KiB
C#
202 lines
7.4 KiB
C#
using CG.UTility;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using ZXK.GYJQR;
|
|
/// <summary>
|
|
/// 调整方向菜单枚举类型
|
|
/// </summary>
|
|
namespace ZXK.GYJQR
|
|
{
|
|
public enum AdjustAngleType
|
|
{
|
|
clockwise = -1,//顺时针
|
|
anticlockwise = 1,//逆时针
|
|
none
|
|
}
|
|
/// <summary>
|
|
/// 保存安装部署流程接头的物体集合
|
|
/// </summary>
|
|
[System.Serializable]
|
|
public class AZBSStateJoints
|
|
{
|
|
public string aZBSState;//安装部署流程枚举
|
|
public string aZBSPartName;//安装部署流程接头路径
|
|
}
|
|
/// <summary>
|
|
/// 方向调整UI菜单//机器人接线-信号电缆旋转失灵//TODO:
|
|
/// </summary>
|
|
public class AdjustAngleMenu : MonoBehaviour
|
|
{
|
|
public List<ClockWiseControl> clockWiseControls;//菜单列表
|
|
//public List<AZBSStateJoints> aZBSStateJoints;//安装部署接头列表
|
|
public GameObject azbstateJoint;//需要操作的安装部署接头
|
|
private float excutetime = 0.0f;//实际执行时间
|
|
private float rotateSpeed = 0.5f;//旋转速度
|
|
[Header("允许拼接的最小旋转数值")]
|
|
public float allowedJointMinValue;
|
|
[Header("允许拼接的最大旋转数值")]
|
|
public float allowedJointMaxValue;
|
|
[Header("偏移量")]
|
|
public float offset;//偏移量
|
|
[Header("当前步骤类的唯一标识符")]
|
|
[ReadOnly]
|
|
public string identityID;//唯一标识符
|
|
public void Start()
|
|
{
|
|
foreach (var item in clockWiseControls)
|
|
{
|
|
item.onMouseDown.AddListener(OnClockWiseMouseDown);
|
|
item.onMouseUp.AddListener(OnClockWiseMouseUp);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 鼠标按下绑定事件
|
|
/// </summary>
|
|
/// <param name="state"></param>
|
|
public void OnClockWiseMouseDown(AdjustAngleType angleType, string state)
|
|
{
|
|
if (!CG.UTility.PopUpMng._TriAble) return;
|
|
if (azbstateJoint == null) return;
|
|
//if (aZBSStateJoints.Count == 0)
|
|
//{
|
|
// return;
|
|
//}
|
|
//azbstateJoint = ModelManager.Instance.SeekPathModeWithName(aZBSStateJoints[0].aZBSPartName);
|
|
excutetime += Time.deltaTime;
|
|
var v = (int)angleType;
|
|
PathManager pm = azbstateJoint.GetComponent<PathManager>();
|
|
switch (pm.lockRoateType)
|
|
{
|
|
case LockRoateType.LockX:
|
|
azbstateJoint.transform.localEulerAngles -= new Vector3(excutetime * rotateSpeed * v, 0.0f, 0.0f);
|
|
break;
|
|
case LockRoateType.LockY:
|
|
azbstateJoint.transform.eulerAngles -= new Vector3(0.0f, excutetime * rotateSpeed * v, 0.0f);
|
|
break;
|
|
case LockRoateType.LockZ:
|
|
azbstateJoint.transform.eulerAngles -= new Vector3(0.0f, 0.0f, excutetime * rotateSpeed * v);
|
|
break;
|
|
case LockRoateType.None:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 鼠标抬起绑定事件
|
|
/// <param name="state"></param>
|
|
/// </summary>
|
|
public void OnClockWiseMouseUp(AdjustAngleType angleType, string state)
|
|
{
|
|
if (!CG.UTility.PopUpMng._TriAble|| azbstateJoint==null) return;
|
|
//azbstateJoint = ModelManager.Instance.SeekPathModeWithName(aZBSStateJoints[0].aZBSPartName);
|
|
//if (azbstateJoint == null)
|
|
//{
|
|
// return;
|
|
//}
|
|
excutetime = 0.0f;
|
|
PathManager pm_azbstateJoint = azbstateJoint.GetComponent<PathManager>() ? azbstateJoint.GetComponent<PathManager>() : azbstateJoint.AddComponent<PathManager>();
|
|
pm_azbstateJoint.onMouseDown = new UnityEngine.Events.UnityEvent();
|
|
pm_azbstateJoint.onMouseDown.AddListener(() =>
|
|
{
|
|
pm_azbstateJoint.onMouseDown.RemoveAllListeners();
|
|
pm_azbstateJoint.GetComponent<BoxCollider>().enabled = false;
|
|
CanJoint(pm_azbstateJoint, azbstateJoint, () =>
|
|
{
|
|
AZBS curAzbs = GameManager.Instance._DataAZBSHandler.CurAZBShandler.Value;
|
|
//TODO 加分系统
|
|
//GameManager.Instance._DataAZBSHandler.AddScore(curAzbs.stepName, StepManager.Instance.GetIdentityStep(identityID).stepName, StepManager.Instance.GetIdentityStep(identityID).score);
|
|
AzbsStateJointStep(azbstateJoint, pm_azbstateJoint);
|
|
}, () =>
|
|
{
|
|
PopUpMng.PopToast("方向错误,需将两者调至水平对齐", 0.0f);
|
|
StartCoroutine(OnDelay(3.0f, () =>
|
|
{
|
|
AzbsStateJointStep(azbstateJoint, pm_azbstateJoint);
|
|
}));
|
|
});
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 拼接步骤
|
|
/// </summary>
|
|
public void AzbsStateJointStep(GameObject o, PathManager pm)
|
|
{
|
|
Sequence sequence = DOTween.Sequence();
|
|
sequence.SetId("correct");
|
|
sequence.Append(pm.transform.DORotate(pm._JieTouFinishTran.rotation.eulerAngles, 2.0f));
|
|
sequence.Insert(0, pm.transform.DOMove(pm._JieTouFinishTran.position, 2.0f));
|
|
sequence.onComplete += () =>
|
|
{
|
|
pm.GetComponent<BoxCollider>().enabled = false;
|
|
if (pm.transform.GetComponent<OutLineRender>() != null)
|
|
{
|
|
pm.transform.GetComponent<OutLineRender>().enabled = false;
|
|
}
|
|
StepManager.Instance.SwitchIdentityStep(StepManager.Instance.GetIdentityStep(identityID));
|
|
StopAllCoroutines();
|
|
gameObject.SetActive(false);
|
|
};
|
|
}
|
|
/// <summary>
|
|
/// 判断是否可以进行拼接组装
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void CanJoint(PathManager pm, GameObject o, Action correct, Action error)
|
|
{
|
|
Vector3 v = o.transform.eulerAngles;
|
|
float _v = 0.0f;//旋转数值
|
|
switch (pm.lockRoateType)
|
|
{
|
|
case LockRoateType.LockX:
|
|
break;
|
|
case LockRoateType.LockY:
|
|
_v = v.y;
|
|
break;
|
|
case LockRoateType.LockZ:
|
|
_v = v.z;
|
|
break;
|
|
case LockRoateType.None:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (allowedJointMinValue > allowedJointMaxValue)
|
|
{
|
|
if (_v >= allowedJointMinValue || _v <= allowedJointMaxValue)
|
|
{
|
|
correct?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
error?.Invoke();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_v >= allowedJointMinValue && _v <= allowedJointMaxValue)
|
|
{
|
|
correct?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
error?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 延迟函数
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IEnumerator OnDelay(float t, Action action)
|
|
{
|
|
yield return new WaitForSeconds(t);
|
|
action?.Invoke();
|
|
}
|
|
}
|
|
}
|