/// <summary> /// 处理鼠标行为事件 /// </summary> void OnMouseAction() { if (bLock) { return; } // #region 平移 视角 // if (Input.GetMouseButtonDown(2)) // { // bCameraOffset = true; // } // if (Input.GetMouseButtonUp(2)) // { // bCameraOffset = false; // } // // if (bCameraOffset) // { // vTargetOffset = new Vector3( // vTargetOffset.x + ((Input.GetAxis("Mouse X") * fMoveSpeed)), // vTargetOffset.y + ((Input.GetAxis("Mouse Y") * fMoveSpeed)), // 0 // ); // // //Vector3 vOffset = new Vector3(Input.GetAxis("Mouse X") * fMoveSpeed, 0, Input.GetAxis("Mouse Y") * fMoveSpeed); // //this.transform.Translate(this.transform.position + Vector3.left); // //Debug.Log(this.transform.position); // // return; // } // #endregion #region 移动视角 if (mSelectElement == null) { //!EventSystem.current.IsPointerOverGameObject()是否点在UI上 // // // if (Input.GetMouseButtonDown(1) && GUIUtility.hotControl == 0 && !EventSystem.current.IsPointerOverGameObject()) // { // bRightPress = true; // } if (Input.GetMouseButtonDown(1)) { bRightPress = true; Screen.lockCursor = false; } if (Input.GetMouseButtonUp(1)) { bRightPress = false; } if (bRightPress) { float fCamRotaY; if (bCanRotatDown) { //Mathf.Clamp 钳制.限制value的值在min和max之间, 如果value小于min,返回min。 如果value大于max,返回max,否则返回value fCamRotaY = Mathf.Clamp(vCamRotation.x + (Input.GetAxis("Mouse Y") * fRotatSpeed), 90f, 180); } else { fCamRotaY = vCamRotation.x + (Input.GetAxis("Mouse Y") * fRotatSpeed); } vCamRotation = new Vector3( fCamRotaY, vCamRotation.y + (Input.GetAxis("Mouse X") * fRotatSpeed), 180 ); } } #endregion /// if (Input.GetMouseButtonUp(0)) { bLeftPress = false; } if (Input.GetMouseButtonDown(0)) { if (GUIUtility.hotControl == 0) { ray = mCamera.ScreenPointToRay(Input.mousePosition); // 基本选择物体 if (Physics.Raycast(ray, out hit)) { CElement mElement = hit.collider.gameObject.GetComponent <CElement>(); if (mElement != null) { // 选中 ClearSelectElement(); mSelectElement = mElement; mSelectElement.ShowHighLight(); if (objArrayAll) { objArrayAll.transform.position = mSelectElement.transform.position; float fScale = mCamera.fieldOfView * 0.01f; objArrayAll.transform.localScale = new Vector3(fScale, fScale, fScale); objArrayAll.gameObject.SetActive(true); } else { //分解 , 结合操作 } } } else { ClearSelectElement(); //没有选择 return; } } } }