You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
337 lines
18 KiB
337 lines
18 KiB
using UnityEngine; |
|
using System.Collections; |
|
using AX.TrackRecord; |
|
using AX.MessageSystem; |
|
using UnityEngine.EventSystems; |
|
using System; |
|
[RequireComponent(typeof(LineamentEvent))] |
|
[RequireComponent(typeof(BoxCollider))] |
|
public class DragMove : MonoBehaviour |
|
{ |
|
private OtherArrribute_Fire fireAttri; |
|
public GameObject messageBox; |
|
float TIMESTAMP = 1.0f; |
|
float timer = 0f; |
|
float THRESHOLD = 1.0f; |
|
Vector3 lastFrame; |
|
Vector3 currentFrame; |
|
|
|
LineamentEvent lineamentEvent; |
|
void Start() |
|
{ |
|
messageBox = GameObject.Find("Canvas").transform.Find("MessageBox").gameObject; |
|
timer = TIMESTAMP; |
|
lastFrame = this.gameObject.transform.position; |
|
lineamentEvent = GetComponent<LineamentEvent>(); |
|
} |
|
|
|
//IEnumerator OnMouseDown() |
|
//{ |
|
// Debug.Log("drag!!!!!!!!!!!!!!!"); |
|
// var screenSpace = Camera.main.WorldToScreenPoint(transform.position);//三维物体坐标转屏幕坐标 |
|
// //将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离 |
|
// var offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z)); |
|
// while (Input.GetMouseButton(0)) |
|
// { |
|
// var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
// var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; |
|
// //transform.position = curPosition; |
|
// //transform.position.x = curPosition.x; |
|
// //transform.position.z = curPosition.z; |
|
// transform.position = new Vector3(curPosition.x, transform.position.y, curPosition.z); |
|
// //world.y=transform.position.y; |
|
// if (RecordManager.Instance.IsRecording) |
|
// { |
|
// GetComponent<RecordFineTuningEvent>().ResetData(); |
|
// } |
|
// yield return 1;//这个很重要,循环执行 |
|
// } |
|
//} |
|
|
|
void Update() |
|
{ |
|
ProcessRecordFineTuning(); |
|
if (timer > 0) |
|
{ |
|
timer -= Time.deltaTime; |
|
} |
|
else |
|
{ |
|
currentFrame = this.gameObject.transform.position; |
|
if (Vector3.Distance(currentFrame, lastFrame) > THRESHOLD) |
|
{ |
|
if (RecordManager.Instance.IsRecording) |
|
{ |
|
//if (ExamInfoHelpClass.applicationMode == ExamInfoHelpClass.ApplicationMode.PATHFINDING && |
|
// GetComponent<NavMeshAgent>().velocity.magnitude > 0)//寻路过程中不记录旋转 |
|
//{ |
|
// lastFrame = currentFrame; |
|
// timer = TIMESTAMP; |
|
// return; |
|
//} |
|
MessageDispatcher.SendMessage("RecordFineTuningEvent", (object)this.name); |
|
Debug.Log("position move: -------" + Vector3.Distance(currentFrame, lastFrame)); |
|
} |
|
} |
|
lastFrame = currentFrame; |
|
timer = TIMESTAMP; |
|
} |
|
} |
|
|
|
private void ProcessRecordFineTuning() |
|
{ |
|
if (RecordManager.Instance.IsRecording) |
|
{ |
|
if (ExamInfoHelpClass.applicationMode == ExamInfoHelpClass.ApplicationMode.PATHFINDING) |
|
{ |
|
if (GetComponent<UnityEngine.AI.NavMeshAgent>()) |
|
{ |
|
if (GetComponent<UnityEngine.AI.NavMeshAgent>().velocity.magnitude > 0) |
|
{ |
|
lastFrame = this.gameObject.transform.position; |
|
return; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
IEnumerator OnMouseDown() |
|
{ |
|
if (this.GetComponent<UnityEngine.AI.NavMeshObstacle>()) |
|
{//拖动时,NavmeshObstacle不能激活,否则会使其它消防车产生位移 |
|
GetComponent<UnityEngine.AI.NavMeshObstacle>().enabled = false; |
|
} |
|
|
|
yield return new WaitForEndOfFrame(); |
|
// Debug.Log("drag!!!!!!!!!!!!!!!" + "isConnectCar=" + GetComponent<AgentControl>().isConnectCar); |
|
if (TrackRecordHelpClass.CheckIfCanControl()) |
|
{ |
|
#region 火 |
|
if (this.name.Contains("fire")) |
|
{ |
|
fireAttri = this.GetComponent<ShowFireSetWin>().fireAttri; |
|
|
|
//创建考题,备课中新建课件,自学 |
|
if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.CreatQuestion |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditQuestion |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.CopyQuestion |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareMode |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.SelfStudyMode) |
|
{ |
|
//新建节点,既没有新建节点也没有加载节点两种情况下允许拖动(加载节点不允许拖动) |
|
if (RecordManager.Instance.IsRecording |
|
|| (!RecordManager.Instance.IsRecording && !LoadManager.Instance.IsPlayBacking)) |
|
{ |
|
if (fireAttri.PathPointList.Count == 0) |
|
{ |
|
var screenSpace = Camera.main.WorldToScreenPoint(transform.position);//三维物体坐标转屏幕坐标 |
|
//将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离 |
|
var offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z)); |
|
while (Input.GetMouseButton(0)) |
|
{ |
|
var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; |
|
//transform.position = curPosition; |
|
//transform.position.x = curPosition.x; |
|
//transform.position.z = curPosition.z; |
|
if (Vector3.Distance(new Vector3(curPosition.x,transform.position.y,curPosition.z),transform.position)>0.3f) |
|
{//防止发生小范围位移 |
|
transform.position = new Vector3(curPosition.x, transform.position.y, curPosition.z); |
|
} |
|
//world.y=transform.position.y; |
|
yield return 1;//这个很重要,循环执行 |
|
} |
|
} |
|
//else |
|
//{ |
|
// messageBox.GetComponent<MessageTool>().showMessage(ShowMessageType.prompt, "提示信息", "设置蔓延路径后不能拖动"); |
|
//} |
|
} |
|
} |
|
} |
|
|
|
#endregion |
|
|
|
else |
|
{ |
|
if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.TeachMode && DrawLinePlate.instance.CanDrawing) |
|
{ |
|
//授课画板打开不可拖动 |
|
} |
|
#region 消防车和消防员 |
|
else if (name.Contains("xiaofang")) |
|
{ |
|
|
|
//if (this.name.Contains("gpc") || this.name.Contains("dgc") || |
|
// this.name.Contains("ytc") || name.Contains("sgc") || name.Contains("pmc")) |
|
//{ |
|
// if (lineamentEvent.isConnectCar || lineamentEvent.ControlJuBi) |
|
// {//不管是管线连接还是举臂控制,只要有一个为真就不能移动 |
|
// } |
|
// else |
|
// { |
|
// var screenSpace = Camera.main.WorldToScreenPoint(transform.position);//三维物体坐标转屏幕坐标 |
|
// //将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离 |
|
// var offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z)); |
|
// while (Input.GetMouseButton(0)) |
|
// { |
|
// var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
// var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; |
|
|
|
// if (Vector3.Distance(new Vector3(curPosition.x, transform.position.y, curPosition.z), transform.position) > 2f) |
|
// {//防止发生小范围位移 |
|
// transform.position = new Vector3(curPosition.x, transform.position.y, curPosition.z); |
|
// if (GetComponent<NavMeshAgent>()) |
|
// { |
|
// GetComponent<NavMeshAgent>().enabled = false; |
|
// } |
|
// } |
|
// //world.y=transform.position.y; |
|
// yield return 1;//这个很重要,循环执行 |
|
// } |
|
|
|
// } |
|
|
|
//} |
|
//else |
|
//{ |
|
// if (lineamentEvent.isConnectCar) |
|
// {//不管是管线连接还是举臂控制,只要有一个为真就不能移动 |
|
// } |
|
// else |
|
// { |
|
// var screenSpace = Camera.main.WorldToScreenPoint(transform.position);//三维物体坐标转屏幕坐标 |
|
// //将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离 |
|
// var offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z)); |
|
// while (Input.GetMouseButton(0)) |
|
// { |
|
// var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
// var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; |
|
|
|
// if (Vector3.Distance(new Vector3(curPosition.x, transform.position.y, curPosition.z), transform.position) > 0.3f) |
|
// {//防止发生小范围位移 |
|
// transform.position = new Vector3(curPosition.x, transform.position.y, curPosition.z); |
|
// if (GetComponent<NavMeshAgent>()) |
|
// { |
|
// GetComponent<NavMeshAgent>().enabled = false; |
|
// } |
|
// } |
|
// //world.y=transform.position.y; |
|
// yield return 1;//这个很重要,循环执行 |
|
// } |
|
|
|
|
|
// } |
|
//} |
|
|
|
if (lineamentEvent.isConnectCar || lineamentEvent.ControlJuBi) |
|
{//不管是管线连接还是举臂控制,只要有一个为真就不能移动 |
|
} |
|
else |
|
{ |
|
var screenSpace = Camera.main.WorldToScreenPoint(transform.position);//三维物体坐标转屏幕坐标 |
|
//将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离 |
|
var offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z)); |
|
while (Input.GetMouseButton(0)) |
|
{ |
|
var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; |
|
|
|
if (Vector3.Distance(new Vector3(curPosition.x, transform.position.y, curPosition.z), transform.position) > 2f) |
|
{//防止发生小范围位移 |
|
transform.position = new Vector3(curPosition.x, transform.position.y, curPosition.z); |
|
if (GetComponent<UnityEngine.AI.NavMeshAgent>()) |
|
{ |
|
GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false; |
|
} |
|
} |
|
//world.y=transform.position.y; |
|
yield return 1;//这个很重要,循环执行 |
|
} |
|
|
|
} |
|
if (GetComponent<UnityEngine.AI.NavMeshAgent>()) |
|
{ |
|
GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = true; |
|
} |
|
} |
|
|
|
#endregion |
|
|
|
else if (this.name.Contains("shangyuan") || this.name.Contains("zhiqingren") || this.name.Contains("weixianpin") || this.name.Contains("zwd")) |
|
{ |
|
if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.CreatQuestion |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditQuestion |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.CopyQuestion |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareMode |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware |
|
|| ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.SelfStudyMode) |
|
{ |
|
//新建节点,既没有新建节点也没有加载节点两种情况下允许拖动(加载节点不允许拖动) |
|
if (RecordManager.Instance.IsRecording |
|
|| (!RecordManager.Instance.IsRecording && !LoadManager.Instance.IsPlayBacking)) |
|
{ |
|
var screenSpace = Camera.main.WorldToScreenPoint(transform.position);//三维物体坐标转屏幕坐标 |
|
//将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离 |
|
var offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z)); |
|
while (Input.GetMouseButton(0)) |
|
{ |
|
var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; |
|
|
|
if (Vector3.Distance(new Vector3(curPosition.x, transform.position.y, curPosition.z), transform.position) > 0.3f) |
|
{//防止发生小范围位移 |
|
transform.position = new Vector3(curPosition.x, transform.position.y, curPosition.z); |
|
if(GetComponent<AgentRecord>()) GetComponent<AgentRecord>().timer = RecordManager.Instance.RecordTimer; |
|
} |
|
//world.y=transform.position.y; |
|
yield return 1;//这个很重要,循环执行 |
|
} |
|
} |
|
} |
|
|
|
} |
|
else |
|
{ |
|
var screenSpace = Camera.main.WorldToScreenPoint(transform.position);//三维物体坐标转屏幕坐标 |
|
//将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离 |
|
var offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z)); |
|
while (Input.GetMouseButton(0)) |
|
{ |
|
var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; |
|
//transform.position = curPosition; |
|
//transform.position.x = curPosition.x; |
|
//transform.position.z = curPosition.z; |
|
if (Vector3.Distance(new Vector3(curPosition.x, transform.position.y, curPosition.z), transform.position) > 0.3f) |
|
{//防止发生小范围位移 |
|
transform.position = new Vector3(curPosition.x, transform.position.y, curPosition.z); |
|
} //world.y=transform.position.y; |
|
yield return 1;//这个很重要,循环执行 |
|
} |
|
} |
|
|
|
} |
|
|
|
} |
|
} |
|
void OnMouseUp() |
|
{ |
|
if (ExamInfoHelpClass.applicationMode == ExamInfoHelpClass.ApplicationMode.PATHFINDING) |
|
{ |
|
if (GetComponent<UnityEngine.AI.NavMeshAgent>()) |
|
{ |
|
if (GetComponent<UnityEngine.AI.NavMeshAgent>().enabled) |
|
{ |
|
return; |
|
} |
|
if (GetComponent<UnityEngine.AI.NavMeshObstacle>() && !GetComponent<UnityEngine.AI.NavMeshObstacle>().enabled) |
|
{ |
|
GetComponent<UnityEngine.AI.NavMeshObstacle>().enabled = true; |
|
} |
|
} |
|
} |
|
} |
|
}
|
|
|