using AX.InputSystem; using AX.MessageSystem; using System; using System.Collections; using UnityEngine; using UnityEngine.AI; using UnityEngine.EventSystems; /// /// 处理输入的类 /// public class InputManager : MonoBehaviour { private const long gameObjID = 0; private RaycastHit hit; public static int frameCount = 0;//进入场景后累加的帧数 public static SceneType sceneType;//记录进入场景的类型(这里测试暂时在Start里初始化,做项目时进入场景时赋值) public static CloneObjType cloneObjType;//克隆对象的类型 public static bool skill; private float mouseScroll = 0.0f;//鼠标中键滚动值 //控制鼠标中键没有滚动时及mouseScroll为0时只分发一次命令,避免中键没有滚动情况下战斗回放历史记录一直记录没有改变的信息 private bool mouseScrollIsZero = true; private float mouseX = 0.0f;//鼠标在屏幕坐标系下X方向的变化值 private float mouseY = 0.0f;//鼠标在屏幕坐标系下Y方向的变化值 private bool rotateStart = false;//旋转是否开始 private bool flag;//控制 鼠标右键按下状态时,如果鼠标停止移动,只发一次旋转中命令,避免鼠标停止后,还会有旋转效果 public static GameObject pointerObj; private bool dragStart = false;//物体拖拽是否开始 private bool CamdragStart = false;//相机拖拽是否开始 private bool notDragUI = false;//拖拽的不是UI面板(ScrollRect)----为了处理拖拽ScrollRect时,当鼠标处于ScrollRect范围之外,摄像机跟着移动 private CameraManager cameraManager; private Transform target; private float yMax; private float initialTargetPosY; private Vector3 preMousePos; private Vector3 curMousePos; private GameObject gameObjectCloneable; private bool cloneable; private bool LeftShift; private bool drawRectStart;//框选画框是否开始 public static bool isRectSelect;//是否处于框选状态 public static bool isCameraDrag;//是否处于相机(场景)拖动状态 public static bool OccupyKeyboard;//是否占用键盘输入(比如正在输入字符) public static bool isDargUI = false;//是否正在拖拽UI public static bool PathFindingEnable = true; private GameObject hitObjToDrag; private GameObject hitObjToDragCamera; public static bool IsControl = true; public static bool MutiSelectFind;//是否是多选寻路 void Start() { //sceneType = SceneType.地下建筑; if (!pointerObj) { var pointer = Resources.Load("Particle"); pointerObj = Instantiate(pointer); // pointhit = transform.position; } cameraManager = GameObject.Find("Main Camera").GetComponent(); if (cameraManager) { target = cameraManager.target; yMax = cameraManager.yMax; initialTargetPosY = cameraManager.initialTargetPosY; } gameObjectCloneable = GameObject.Find("GameObjectCloneable"); if (gameObjectCloneable == null) { gameObjectCloneable = new GameObject("GameObjectCloneable"); gameObjectCloneable.AddComponent(); } } void Update() { InputHandle(); KeyboardHandle(); } void FixedUpdate() { ++frameCount; } private void KeyboardHandle() { if (RecordEvent.IsReplay()) return; if (OccupyKeyboard) return; long gameObjID = 0; if (SelectedObjs.selectedObj != null) { gameObjID = SelectedObjs.selectedObj.GetComponent().GameObjID; var cmdargs = new WeightCmdArgs(); cmdargs.Weight += Time.deltaTime * 10f; if (Input.GetButtonDown("LeftShift")) { LeftShift = true; } if (Input.GetButtonUp("LeftShift")) { LeftShift = false; } if (SelectedObjs.selectedObj.GetComponent()) { cmdargs.Weight += GlobalVariable.TruckArmSpeed; cmdargs.Weight *= 0.1f; if (Input.GetButton("W")) { if (LeftShift) { LeftShiftWCommand.Instance.Execute(gameObjID, cmdargs); } else { WCommand.Instance.Execute(gameObjID, cmdargs); } } else if (Input.GetButton("S")) { if (LeftShift) { LeftShiftSCommand.Instance.Execute(gameObjID, cmdargs); } else { SCommand.Instance.Execute(gameObjID, cmdargs); } } else if (Input.GetButton("A")) { ACommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("D")) { DCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("U")) { if (LeftShift) { LeftShiftUCommand.Instance.Execute(gameObjID, cmdargs); } } else if (Input.GetButton("J")) { if (LeftShift) { LeftShiftJCommand.Instance.Execute(gameObjID, cmdargs); } } } if (SelectedObjs.selectedObj.GetComponent() || SelectedObjs.selectedObj.GetComponent()) { if (Input.GetButton("U")) { if (LeftShift == false) UCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("J")) { if (LeftShift == false) JCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("H")) { HCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("K")) { KCommand.Instance.Execute(gameObjID, cmdargs); } if (Input.GetButton("Equals")) { EqualsCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("Minus")) { MinusCommand.Instance.Execute(gameObjID, cmdargs); } } //场景中自带的自动水炮 if (SelectedObjs.selectedObj.GetComponent()) { if (Input.GetButton("U")) { //if (LeftShift == false) UCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("J")) { //if (LeftShift == false) JCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("H")) { HCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("K")) { KCommand.Instance.Execute(gameObjID, cmdargs); } if (Input.GetButton("Equals")) { EqualsCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("Minus")) { MinusCommand.Instance.Execute(gameObjID, cmdargs); } } //拉梯 if (SelectedObjs.selectedObj.GetComponent()) { if (Input.GetButton("W")) { if (LeftShift) { LeftShiftWCommand.Instance.Execute(gameObjID, cmdargs); } else { WCommand.Instance.Execute(gameObjID, cmdargs); } } else if (Input.GetButton("S")) { if (LeftShift) { LeftShiftSCommand.Instance.Execute(gameObjID, cmdargs); } else { SCommand.Instance.Execute(gameObjID, cmdargs); } } } //水炮、暴风雪炮、灭火机器人 if (SelectedObjs.selectedObj.GetComponent()) { if (Input.GetButton("U")) { //if (LeftShift == false) UCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("J")) { //if (LeftShift == false) JCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("H")) { ACommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("K")) { DCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("Equals")) { EqualsCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("Minus")) { MinusCommand.Instance.Execute(gameObjID, cmdargs); } else if(Input.GetButtonDown("A")) { MessageDispatcher.SendMessage("AutoSwing", gameObjID); } } //泡沫钩管、二分水器 可以Y方向拖动 if(SelectedObjs.selectedObj.GetComponent()|| SelectedObjs.selectedObj.GetComponent()) { if (Input.GetButton("W")) { WCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("S")) { SCommand.Instance.Execute(gameObjID, cmdargs); } if (SelectedObjs.selectedObj.GetComponent()) { if (Input.GetButton("U")) { //if (LeftShift == false) UCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("J")) { //if (LeftShift == false) JCommand.Instance.Execute(gameObjID, cmdargs); } } } } if (SelectedObjs.selectedCharacters.Count != 0) { var cmdargs = new WeightCmdArgs(); cmdargs.Weight += Time.deltaTime * 10f; if (SelectedObjs.selectedCharacters.Count < 1 || SelectedObjs.selectedCharacters[0] == null) { return; } gameObjID = SelectedObjs.selectedCharacters[0].GetComponent().GameObjID; if (Input.GetButton("Equals")) { EqualsCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("Minus")) { MinusCommand.Instance.Execute(gameObjID, cmdargs); } if (Input.GetButton("U")) { //if (LeftShift == false) UCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("J")) { //if (LeftShift == false) JCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("H")) { HCommand.Instance.Execute(gameObjID, cmdargs); } else if (Input.GetButton("K")) { KCommand.Instance.Execute(gameObjID, cmdargs); } } if (RecordEvent.IsRecord()) if (Input.GetButtonUp("J") | Input.GetButtonUp("U") | Input.GetButtonUp("Minus") | Input.GetButtonUp("Equals") | Input.GetButtonUp("K") | Input.GetButtonUp("H") | Input.GetButtonUp("W") | Input.GetButtonUp("A") | Input.GetButtonUp("S") | Input.GetButtonUp("D") | Input.GetButtonUp("LeftShift")) { MessageDispatcher.SendMessage(gameObjID, "GetButtonUp"); } } private bool getRayCastAll(Ray ray) { bool rayCast = false; //Ray ray = Camera.main.ScreenPointToRay(point); RaycastHit[] hits; //int notRendering = LayerMask.NameToLayer("NotRendering"); int ignoreRaycast = LayerMask.NameToLayer("Ignore Raycast"); hits = Physics.RaycastAll(ray, Mathf.Infinity, ~(1 << ignoreRaycast)); //List hitList= hits. Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance)); for (var i = 0; i < hits.Length; i++) { var hitpoint = hits[i]; var renderer = hitpoint.collider.GetComponent(); if (renderer) { if (renderer.enabled) { rayCast = true; hit = hitpoint; //Debug.Log("----->"+hit.collider.name); break; } } else { var renderers = hitpoint.transform.GetComponentsInChildren(); for (int k = 0; k < renderers.Length; k++) { if (renderers[k].enabled) { rayCast = true; hit = hitpoint; //Debug.Log("----->"+hit.collider.name); break; } } if (rayCast) { break; } } } /* string a = ""; for (var i = 0; i < hits.Length; i++) { a += "|" + hits[i].collider.name; } Debug.Log(a); */ return rayCast; } private void InputHandle() { if (!IsControl) return; if (RecordEvent.IsReplay() && !RecordEvent.IsReplayPause())//回放时暂定操作相机 return; if (RecordEvent.IsReplay()) { if (!EventSystem.current.IsPointerOverGameObject()) { CameraScaleInputHandle(); } } //相机横向移动的输入操作处理 CameraHorizontalMoveInputHandle(); //相机竖向移动的输入操作处理 CameraVerticalMoveInputHandle(); //相机旋转的输入操作处理 CameraRotationInputHandle(); if (RecordEvent.IsReplay()) return; //框选画框输入处理 DrawSelectionRectangle(); //对象拖动输入处理 ObjDrag(); //取消克隆按钮选中的输入处理 CancelCloneBtnSelected(); //取消游戏对象的选中的输入处理 CancelObjSelected(); //对象删除输入处理 ObjDelete(); //对象旋转输入处理 ObjRotate(); if (!EventSystem.current.IsPointerOverGameObject()) { //相机缩放的输入操作处理 CameraScaleInputHandle(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); var rayCast = getRayCastAll(ray); //Debug.Log("------>"+ rayCast); if (rayCast) { if (skill) { //寻路输入处理 PathFinding(); } //克隆按钮没有被选中 else if (cloneObjType == CloneObjType.None) { //单选输入处理 RadioSelect(); //寻路输入处理 PathFinding(); } else {//克隆按钮被选中 cloneable = gameObjectCloneable.GetComponent().GetCloneAble(hit.transform.gameObject, cloneObjType); //克隆状态下,如果点击到能被选中或者既不能被选中也不能在其上面克隆对象时,不分发克隆指令 //(即只有点击到能克隆的对象上才发生克隆行为) if (!cloneable) { return; } //克隆的输入处理 CloneObj(); } } } else//如果鼠标在UI上 相关操作没有结束 { } } /// /// 相机缩放的输入操作处理 /// private void CameraScaleInputHandle() { //控制摄像头以Target为参照物缩放 mouseScroll = Input.GetAxis("Mouse ScrollWheel"); if (mouseScroll != 0) { if (!mouseScrollIsZero) { var arg = new CameraCmdArgs(); arg.mouseScroll = mouseScroll; MiddleMouseScrollCommand.Instance.Execute(gameObjID, arg); mouseScrollIsZero = true; } } else { if (mouseScrollIsZero) { var arg = new CameraCmdArgs(); arg.mouseScroll = mouseScroll; arg.distance = cameraManager.distance; MiddleMouseScrollCommand.Instance.Execute(gameObjID, arg); mouseScrollIsZero = false; } } } /// /// 相机旋转的输入操作处理 /// private void CameraRotationInputHandle() { if (!EventSystem.current.IsPointerOverGameObject() && Input.GetButtonDown("Fire2")) { //preMousePos = Input.mousePosition; rotateStart = true; var arg = new CameraCmdArgs(); arg.mouseX = mouseX; arg.mouseY = mouseY; arg.rotateStart = rotateStart; //旋转开始 RotateEnterCommand.Instance.Execute(gameObjID, arg); } if (Input.GetButton("Fire2")) { //curMousePos = Input.mousePosition; mouseX = Input.GetAxis("Mouse X"); mouseY = Input.GetAxis("Mouse Y"); //var thresholdValue = Vector3.Distance(preMousePos, curMousePos);//旋转开始阈值为2两个像素单位长度 if (rotateStart) { var arg = new CameraCmdArgs(); arg.mouseX = mouseX; arg.mouseY = mouseY; arg.rotateStart = rotateStart; if (mouseX == 0 && mouseY == 0) {//控制右键按下状态但没有移动鼠标,不分发指令,避免历史记录记录很多无用指令 if (!flag) { RotatingCommand.Instance.Execute(gameObjID, arg); flag = true; } return; } else { flag = false; } //旋转中 RotatingCommand.Instance.Execute(gameObjID, arg); } } if (Input.GetButtonUp("Fire2")) { if (rotateStart) { mouseX = Input.GetAxis("Mouse X"); mouseY = Input.GetAxis("Mouse Y"); rotateStart = false; var arg = new CameraCmdArgs(); arg.mouseX = mouseX; arg.mouseY = mouseY; arg.rotateStart = rotateStart; arg.x = cameraManager.x; arg.y = cameraManager.y; //旋转结束 RotateExitCommand.Instance.Execute(gameObjID, arg); } } } /// /// 相机横向移动的输入操作处理 /// private void CameraHorizontalMoveInputHandle() { if (isDargUI) return;//防止跟UI拖拽冲突 //区分相机(场景)横向拖动与游戏对象的拖动 //if (isDragEditorMode) //{ // return; //} //区分相机(场景)横向拖动与框选操作 if (isRectSelect) { return; } if (!EventSystem.current.IsPointerOverGameObject() && Input.GetButtonDown("Fire1")) { //preMousePos = Input.mousePosition; notDragUI = true; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); var rayCast = getRayCastAll(ray); if (rayCast) { hitObjToDragCamera = hit.transform.gameObject; } else { hitObjToDragCamera = null; } if (hitObjToDragCamera != null && hitObjToDragCamera == SelectedObjs.selectedObj) { return; } //if (hitObjToDragCamera) //{ //var thresholdValue = Vector3.Distance(preMousePos, curMousePos);//拖动开始阈值为2个像素单位长度 if (!CamdragStart) { CamdragStart = true; var arg = new CameraCmdArgs(); arg.mousePosition = Input.mousePosition; //拖拽开始 CameraDragEnterCommand.Instance.Execute(gameObjID, arg); isCameraDrag = true; //Debug.Log("相机拖动开始"); } // } } if (Input.GetButton("Fire1") && notDragUI) { curMousePos = Input.mousePosition; mouseX = Input.GetAxis("Mouse X"); mouseY = Input.GetAxis("Mouse Y"); //if (hitObjToDragCamera) //{ if (CamdragStart) { var arg = new CameraCmdArgs(); arg.mousePosition = Input.mousePosition; arg.dragStart = CamdragStart; if (mouseX == 0 && mouseY == 0) {//控制中键按下状态但没有移动鼠标,不分发指令 return; } //Debug.Log("相机拖动中..."); //拖拽中 CameraDragingCommand.Instance.Execute(gameObjID, arg); } // } } if (Input.GetButtonUp("Fire1")) { // if (hitObjToDragCamera) // { if (CamdragStart) { CamdragStart = false; notDragUI = false; var arg = new CameraCmdArgs(); arg.mousePosition = Vector3.zero; arg.dragStart = CamdragStart; //Debug.Log("相机拖动结束"); //拖拽结束 CameraDragExitCommand.Instance.Execute(gameObjID, arg); isCameraDrag = false; } // } } } /// /// 相机竖向移动的输入处理 /// private void CameraVerticalMoveInputHandle() { if (isDargUI) return;//防止跟UI拖拽冲突 if (Input.GetButtonDown("VerticalDU")) { notDragUI = true; } if (Input.GetButton("VerticalDU") && notDragUI) { var arg = new CameraCmdArgs(); arg.keyX = Input.GetAxis("VerticalDU"); arg.targetMoveing = true; if (arg.keyX < 0) { if (target.position.y > initialTargetPosY) { //控制摄像头跟随Target垂直移动 CameraVerticalMoveCommand.Instance.Execute(gameObjID, arg); } } if (arg.keyX > 0) { if (target.position.y < yMax) { //控制摄像头跟随Target垂直移动 CameraVerticalMoveCommand.Instance.Execute(gameObjID, arg); } } } if (Input.GetButtonUp("VerticalDU")) { notDragUI = false; var arg = new CameraCmdArgs(); arg.keyX = Input.GetAxis("VerticalDU"); arg.targetMoveing = false; if (arg.keyX < 0) { if (target.position.y >= initialTargetPosY) { //控制摄像头跟随Target垂直移动 CameraVerticalMoveCommand.Instance.Execute(gameObjID, arg); } } if (arg.keyX > 0) { if (target.position.y <= yMax) { //控制摄像头跟随Target垂直移动 CameraVerticalMoveCommand.Instance.Execute(gameObjID, arg); } } } } /// /// 取消克隆按钮选中的输入处理 /// private void CancelCloneBtnSelected() { if (Input.GetButtonDown("Fire2")) { preMousePos = Input.mousePosition; } if (Input.GetButtonUp("Fire2")) { curMousePos = Input.mousePosition; if (Vector3.Distance(preMousePos, curMousePos) < 2)//解决:右键单击取消克隆按钮的选中操作与右键旋转的冲突 { var arg = new CloneCmdArgs(); arg.selected = false; if (cloneObjType != CloneObjType.None) { CancelCloneBtnSelectedCommand.Instance.Execute(gameObjID, arg); } } } } /// /// 取消游戏对象的选中 的输入处理 /// private void CancelObjSelected() { if (Input.GetButtonUp("Cancel")) { if (SelectedObjs.selectedObj || SelectedObjs.selectedCharacters.Count != 0) { CancelSelectedCommand.Instance.Execute(gameObjID, (CmdArgs)null); } } } /// /// 单选输入处理 /// private void RadioSelect() { if (Input.GetButtonDown("Fire1")) { preMousePos = Input.mousePosition; } if (Input.GetButtonUp("Fire1")) { curMousePos = Input.mousePosition; if (Vector3.Distance(preMousePos, curMousePos) < 2)//解决:左键单击选中操作与左键框选的冲突 { if (SelectedObjs.gameObjs.Contains(hit.transform.gameObject)) { if (SelectedObjs.selectedObj != hit.transform.gameObject) { //除消防员外,其他可单选物体的单选处理 RadioSelectedCommand.Instance.Execute(hit.transform.GetComponent().GameObjID, (CmdArgs)null); } } if (SelectedObjs.characters.Contains(hit.transform.gameObject)) { if (!SelectedObjs.selectedCharacters.Contains(hit.transform.gameObject)) { //消防员的单选处理 RadioSelectedCommand.Instance.Execute(hit.transform.GetComponent().GameObjID, (CmdArgs)null); } } } } } /// /// 框选画框输入处理 /// private void DrawSelectionRectangle() { //区分框选与游戏对象的拖动 //if (isDragEditorMode) //{ // return; //} //区分框选与相机的拖动 if (isCameraDrag) { return; } if (!isRectSelect && Input.GetButton("LeftShift")) { isRectSelect = true; } if (isRectSelect && Input.GetButtonUp("LeftShift")) { isRectSelect = false; if (drawRectStart) { drawRectStart = false; var arg = new DrawRectSelectRangeCmdArgs(); arg.mousePosition = Vector3.zero; arg.drawRectStart = drawRectStart; //拖拽结束 RectDrawExitCommand.Instance.Execute(gameObjID, arg); } } if (isRectSelect) { if (!EventSystem.current.IsPointerOverGameObject() && Input.GetButtonDown("Fire1")) { //preMousePos = Input.mousePosition; drawRectStart = true; var arg = new DrawRectSelectRangeCmdArgs(); arg.mousePosition = Input.mousePosition; //框选画框开始 RectDrawEnterCommand.Instance.Execute(gameObjID, arg); } if (Input.GetButton("Fire1")) { curMousePos = Input.mousePosition; mouseX = Input.GetAxis("Mouse X"); mouseY = Input.GetAxis("Mouse Y"); var arg = new DrawRectSelectRangeCmdArgs(); //var thresholdValue = Vector3.Distance(preMousePos, curMousePos);//框选画框开始阈值为2个像素单位长度 if (drawRectStart) { arg.mousePosition = Input.mousePosition; arg.drawRectStart = drawRectStart; if (mouseX == 0 && mouseY == 0) {//控制左键按下状态但没有移动鼠标,不分发指令 return; } //框选画框中 RectDrawingCommand.Instance.Execute(gameObjID, arg); } } if (Input.GetButtonUp("Fire1")) { if (drawRectStart) { drawRectStart = false; var arg = new DrawRectSelectRangeCmdArgs(); arg.mousePosition = Vector3.zero; arg.drawRectStart = drawRectStart; //拖拽结束 RectDrawExitCommand.Instance.Execute(gameObjID, arg); isRectSelect = false; } } } } /// /// 克隆的输入处理 /// private void CloneObj() { if (Input.GetButtonDown("Fire1")) { preMousePos = Input.mousePosition; } if (Input.GetButtonUp("Fire1")) { curMousePos = Input.mousePosition; if (Vector3.Distance(preMousePos, curMousePos) < 2)//解决:左键单击克隆操作与左键框选的冲突 { var arg = new CloneCmdArgs(); arg.cloneObjType = cloneObjType; arg.hitPos = hit.point; arg.mousePosition = Input.mousePosition; if (hit.transform.GetComponent()) { arg.gameObjID = hit.transform.GetComponent().GameObjID; } CloneCommand.Instance.Execute(EntitiesManager.Instance.CreateObjID(), arg); } } } /// /// 寻路输入处理 /// private void PathFinding() { if (Input.GetButtonDown("Fire1")) { preMousePos = Input.mousePosition; } if (Input.GetButtonUp("Fire1")) { curMousePos = Input.mousePosition; if (Vector3.Distance(preMousePos, curMousePos) < 2)//解决:左键单击寻路操作与左键框选的冲突 { if (PathFindingEnable) { if (hit.transform.GetComponent() && hit.transform.GetComponent()) { if ((SelectedObjs.selectedObj != null && SelectedObjs.selectedObj.GetComponent()) || SelectedObjs.selectedCharacters.Count > 0) { var arg = new PathFindingCmdArgs(); arg.hitPoint = hit.point; arg.gameObjID = hit.transform.GetComponent().GameObjID; PathFindingCommand.Instance.Execute(gameObjID, arg); pointerObj.transform.position = hit.point; } else if (MutiSelectFind) { var arg = new PathFindingCmdArgs(); arg.hitPoint = hit.point; arg.gameObjID = hit.transform.GetComponent().GameObjID; PathFindingCommand.Instance.Execute(gameObjID, arg); pointerObj.transform.position = hit.point; } } } } } } /// /// 对象删除输入处理 /// private void ObjDelete() { if (Input.GetButtonUp("Delete")) { if (SelectedObjs.selectedObj && SelectedObjs.selectedObj.GetComponent()) { DeleteCommand.Instance.Execute(gameObjID, (CmdArgs)null); } if (SelectedObjs.selectedCharacters.Count > 0) { DeleteCommand.Instance.Execute(gameObjID, (CmdArgs)null); } } } /// /// 对象旋转输入处理 /// private void ObjRotate() { //if (isRotateEditorMode) //{ if ((SelectedObjs.selectedObj && SelectedObjs.selectedObj.GetComponent()) || SelectedObjs.selectedCharacters.Count != 0 || (SelectedObjs.selectedObj && SelectedObjs.selectedObj.GetComponent())) { if (Input.GetButton("Q")) { LeftRotateCommand.Instance.Execute(gameObjID, (CmdArgs)null); } if (Input.GetButton("E")) { RightRotateCommand.Instance.Execute(gameObjID, (CmdArgs)null); } if (Input.GetButton("W")) { UpRotateCommand.Instance.Execute(gameObjID, (CmdArgs)null); } if (Input.GetButton("S")) { DownRotateCommand.Instance.Execute(gameObjID, (CmdArgs)null); } } //} } /// /// 对象拖动输入处理 /// private void ObjDrag() { //if (!isDragEditorMode) //{ // return; //} if (isRectSelect) { return; } if (!EventSystem.current.IsPointerOverGameObject() && Input.GetButtonDown("Fire1")) { //preMousePos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); var rayCast = getRayCastAll(ray); if (rayCast) { hitObjToDrag = hit.transform.gameObject; } else { hitObjToDrag = null; } //var msg = hitObjToDrag.GetComponent(); //var gameObjID = SelectedObjs.selectedObj.GetComponent().GameObjID; if (hitObjToDrag != SelectedObjs.selectedObj) { return; } if (hitObjToDrag && hitObjToDrag.GetComponent()) { //var thresholdValue = Vector3.Distance(preMousePos, curMousePos);//拖动开始阈值为2个像素单位长度 if (!dragStart) { dragStart = true; var arg = new ObjDragCmdArgs(); arg.mousePosition = Input.mousePosition; //Debug.Log("物体拖动开始"); //拖拽开始 ObjDragEnterCommand.Instance.Execute(hitObjToDrag.GetComponent().GameObjID, arg); } } } if (Input.GetButton("Fire1")) { curMousePos = Input.mousePosition; mouseX = Input.GetAxis("Mouse X"); mouseY = Input.GetAxis("Mouse Y"); if (hitObjToDrag && hitObjToDrag.GetComponent()) { if (dragStart) { var arg = new ObjDragCmdArgs(); arg.mousePosition = Input.mousePosition; arg.dragStart = dragStart; if (mouseX == 0 && mouseY == 0) {//控制中键按下状态但没有移动鼠标,不分发指令 return; } //Debug.Log("物体拖动中..."); //拖拽中 ObjDragingCommand.Instance.Execute(hitObjToDrag.GetComponent().GameObjID, arg); } } } if (Input.GetButtonUp("Fire1")) { if (hitObjToDrag && hitObjToDrag.GetComponent()) { if (dragStart) { dragStart = false; var arg = new ObjDragCmdArgs(); arg.mousePosition = Vector3.zero; arg.dragStart = dragStart; //Debug.Log("物体拖动结束"); //拖拽结束 ObjDragExitcommand.Instance.Execute(hitObjToDrag.GetComponent().GameObjID, arg); } } } } }