From 1af887a27520d18358b89484482336f2747c8ab2 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 25 Mar 2025 11:43:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/Main.unity | 205 --------------------------------------- 1 file changed, 205 deletions(-) diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index ad85add9..8f27026f 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -123,108 +123,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1001 &513830674 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 1269024859} - m_Modifications: - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_Pivot.x - value: 0.5 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_Pivot.y - value: 0.5 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_AnchorMax.x - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_AnchorMax.y - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_AnchorMin.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_AnchorMin.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_SizeDelta.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_SizeDelta.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_AnchoredPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_AnchoredPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 2554052722243120825, guid: 36d96953b023420408466d801b10c7b7, type: 3} - propertyPath: m_Name - value: UILoading - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 36d96953b023420408466d801b10c7b7, type: 3} ---- !u!224 &513830675 stripped -RectTransform: - m_CorrespondingSourceObject: {fileID: 1462941856791656077, guid: 36d96953b023420408466d801b10c7b7, type: 3} - m_PrefabInstance: {fileID: 513830674} - m_PrefabAsset: {fileID: 0} --- !u!1 &547432235 GameObject: m_ObjectHideFlags: 0 @@ -891,108 +789,6 @@ MonoBehaviour: - {fileID: 21300000, guid: 9a698dc39d2b4f843b2a75867e181acb, type: 3} - {fileID: 21300000, guid: 39d627f6b66e2d34fb070358f8a0a1c5, type: 3} bg: {fileID: 1271049686} ---- !u!1 &1269024855 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1269024859} - - component: {fileID: 1269024858} - - component: {fileID: 1269024857} - - component: {fileID: 1269024856} - m_Layer: 5 - m_Name: Canvas - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1269024856 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1269024855} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} - m_Name: - m_EditorClassIdentifier: - m_IgnoreReversedGraphics: 1 - m_BlockingObjects: 0 - m_BlockingMask: - serializedVersion: 2 - m_Bits: 4294967295 ---- !u!114 &1269024857 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1269024855} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} - m_Name: - m_EditorClassIdentifier: - m_UiScaleMode: 0 - m_ReferencePixelsPerUnit: 100 - m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} - m_ScreenMatchMode: 0 - m_MatchWidthOrHeight: 0 - m_PhysicalUnit: 3 - m_FallbackScreenDPI: 96 - m_DefaultSpriteDPI: 96 - m_DynamicPixelsPerUnit: 1 - m_PresetInfoIsWorld: 0 ---- !u!223 &1269024858 -Canvas: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1269024855} - m_Enabled: 1 - serializedVersion: 3 - m_RenderMode: 0 - m_Camera: {fileID: 0} - m_PlaneDistance: 100 - m_PixelPerfect: 0 - m_ReceivesEvents: 1 - m_OverrideSorting: 0 - m_OverridePixelPerfect: 0 - m_SortingBucketNormalizedSize: 0 - m_VertexColorAlwaysGammaSpace: 0 - m_AdditionalShaderChannelsFlag: 25 - m_UpdateRectTransformForStandalone: 0 - m_SortingLayerID: 0 - m_SortingOrder: 0 - m_TargetDisplay: 0 ---- !u!224 &1269024859 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1269024855} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0, y: 0, z: 0} - m_ConstrainProportionsScale: 0 - m_Children: - - {fileID: 513830675} - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} - m_Pivot: {x: 0, y: 0} --- !u!1 &1271049684 GameObject: m_ObjectHideFlags: 0 @@ -1547,7 +1343,6 @@ SceneRoots: - {fileID: 1655025501} - {fileID: 547432243} - {fileID: 1089184134} - - {fileID: 1269024859} - {fileID: 2114935606} - {fileID: 555070719} - {fileID: 2028686194} From be625fe73a63fcaa2992d1064c588dc6c2917247 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 25 Mar 2025 11:44:39 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Data/Xml/3DJiePao.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data/Xml/3DJiePao.xml b/Data/Xml/3DJiePao.xml index 0c23a4bc..4f732078 100644 --- a/Data/Xml/3DJiePao.xml +++ b/Data/Xml/3DJiePao.xml @@ -2,7 +2,7 @@ Test All - 3D解刨 + 头面颈部解剖虚拟仿真训练系统 From 0179fcff00004bc49e87e6fbd21482e9d75d68e2 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 25 Mar 2025 11:51:14 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Art/UIPrefab/UIBody3D.prefab | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/Art/UIPrefab/UIBody3D.prefab b/Assets/Art/UIPrefab/UIBody3D.prefab index 0c00caab..6f39b780 100644 --- a/Assets/Art/UIPrefab/UIBody3D.prefab +++ b/Assets/Art/UIPrefab/UIBody3D.prefab @@ -5102,7 +5102,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: MarkType: 0 - CustomComponentName: + CustomComponentName: TitleName CustomComment: mComponentName: TMPro.TextMeshProUGUI --- !u!1 &3757304191228791456 @@ -9077,7 +9077,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} m_AnchoredPosition: {x: 30, y: -30} - m_SizeDelta: {x: 225, y: 0} + m_SizeDelta: {x: 0, y: 54} m_Pivot: {x: 0.000000026077032, y: 1} --- !u!222 &7766581516026923184 CanvasRenderer: @@ -9191,7 +9191,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Padding: m_Left: 0 - m_Right: 0 + m_Right: 20 m_Top: 0 m_Bottom: 0 m_ChildAlignment: 3 @@ -9215,8 +9215,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3} m_Name: m_EditorClassIdentifier: - m_HorizontalFit: 0 - m_VerticalFit: 2 + m_HorizontalFit: 2 + m_VerticalFit: 0 --- !u!114 &4911184181535695060 MonoBehaviour: m_ObjectHideFlags: 0 From 292e1f0a3d33eca542c78404b3aa6759159a1fdc Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 25 Mar 2025 13:23:47 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=81=E5=B1=8F?= =?UTF-8?q?=E5=8F=8A=E5=8F=91=E5=8C=85=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/Main.unity | 2 +- Assets/Scripts/Event/EventEx.cs | 4 ++++ Assets/Scripts/Item/ObjectToggle.cs | 17 +++++++++++++++++ Assets/Scripts/Item/Show3DCamera.cs | 7 +++++++ Assets/Scripts/UI/UIBody3D.cs | 2 +- ProjectSettings/GraphicsSettings.asset | 1 + 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 8f27026f..89bfe170 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -1329,7 +1329,7 @@ MonoBehaviour: rotateSpeed: 10 moveSpeed: 0.1 distance: 2 - distanceMin: 1 + distanceMin: 0.5 distanceMax: 15 pitchMinMax: {x: -80, y: 80} texture: {fileID: 8400000, guid: 187fba8368491cb428c8cbd324fa9bb4, type: 2} diff --git a/Assets/Scripts/Event/EventEx.cs b/Assets/Scripts/Event/EventEx.cs index 6c77c517..dae3ce7d 100644 --- a/Assets/Scripts/Event/EventEx.cs +++ b/Assets/Scripts/Event/EventEx.cs @@ -15,3 +15,7 @@ struct EndScreenShot { } +struct OnLock +{ + public bool isLock; +} \ No newline at end of file diff --git a/Assets/Scripts/Item/ObjectToggle.cs b/Assets/Scripts/Item/ObjectToggle.cs index 856b5e8e..f7374a6b 100644 --- a/Assets/Scripts/Item/ObjectToggle.cs +++ b/Assets/Scripts/Item/ObjectToggle.cs @@ -1,3 +1,4 @@ +using QFramework; using System; using System.Collections; using System.Collections.Generic; @@ -11,8 +12,23 @@ public class ObjectToggle : MonoBehaviour public UnityEvent OnValueChanged = new UnityEvent(); private float mouseDownTime; private bool isMouseDown; + bool isLock = false; + private void Awake() + { + TypeEventSystem.Global.Register(OnLockEvent).UnRegisterWhenDisabled(this); + } + + private void OnLockEvent(OnLock islock) + { + this.isLock = islock.isLock; + } + private void OnMouseDown() { + if (isLock == true) + { + return; + } // ¼갴µʱ mouseDownTime = Time.time; isMouseDown = true; @@ -44,4 +60,5 @@ public class ObjectToggle : MonoBehaviour this.isOn = isOn; OnValueChanged?.Invoke(isOn); } + } diff --git a/Assets/Scripts/Item/Show3DCamera.cs b/Assets/Scripts/Item/Show3DCamera.cs index f18b4a03..b2a5cafd 100644 --- a/Assets/Scripts/Item/Show3DCamera.cs +++ b/Assets/Scripts/Item/Show3DCamera.cs @@ -1,4 +1,6 @@ using DG.Tweening; +using QFramework; +using System; using UnityEngine; using UnityEngine.EventSystems; @@ -47,8 +49,13 @@ public class Show3DCamera : MonoBehaviour self = transform.GetComponent(); DontDestroyOnLoad(this); gameObject.SetActive(false); + TypeEventSystem.Global.Register(OnLockEvent).UnRegisterWhenDisabled(this); } + private void OnLockEvent(OnLock islock) + { + this.lockMove = islock.isLock; + } public void Set(Transform target, float rotateSpeed = 10, float moveSpeed = 0.1f, float distance = 0.1f, float pitchMin = -20, float pitchMax = 80, float distanceMin = 0.2f, float distanceMax = 20f, RectTransform inputRect = null, bool isRenderTexture = true, float moveTime = -1) { diff --git a/Assets/Scripts/UI/UIBody3D.cs b/Assets/Scripts/UI/UIBody3D.cs index 57b70533..e37a221f 100644 --- a/Assets/Scripts/UI/UIBody3D.cs +++ b/Assets/Scripts/UI/UIBody3D.cs @@ -233,7 +233,7 @@ namespace QFramework.Example LockMode.transform.Find("Label").GetComponent().text = "Ļ"; LockMode.transform.Find("Label").GetComponent().color = new Color(74f / 255f, 91f / 255f, 116f / 255f); } - Show3DCamera.instance.lockMove = isOn; + TypeEventSystem.Global.Send(new OnLock() { isLock = isOn }); }); diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index f72acb40..d4505c0a 100644 --- a/ProjectSettings/GraphicsSettings.asset +++ b/ProjectSettings/GraphicsSettings.asset @@ -37,6 +37,7 @@ GraphicsSettings: - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 4800000, guid: c8b5bc66eaa9c574cb2bfefd127c88b9, type: 3} m_PreloadedShaders: [] m_PreloadShadersBatchTimeLimit: -1 m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} From 08fc6b4b02f881f5a00e177f805ac34f40bc02fb Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 25 Mar 2025 15:22:32 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E6=8C=87?= =?UTF-8?q?=E8=A7=A6=E6=8E=A7=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Item/Show3DCamera.cs | 179 +++++++++++++++++++++++----- 1 file changed, 148 insertions(+), 31 deletions(-) diff --git a/Assets/Scripts/Item/Show3DCamera.cs b/Assets/Scripts/Item/Show3DCamera.cs index b2a5cafd..9239937b 100644 --- a/Assets/Scripts/Item/Show3DCamera.cs +++ b/Assets/Scripts/Item/Show3DCamera.cs @@ -43,6 +43,7 @@ public class Show3DCamera : MonoBehaviour Transform target; Vector3 targetPosition; Vector3 targetRotate; + private float prevTouchDistance; // 洢һ֡˫ָ private void Awake() { instance = this; @@ -124,27 +125,42 @@ public class Show3DCamera : MonoBehaviour UpdateCameraPosition(-1); } + void Update() { if (targetPos != null && lockMove == false && EventSystem.current.IsPointerOverGameObject() == false) { + // ȴָ + if (HandleThreeFingerDrag()) return; + bool isTouching = Input.touchCount > 0; - - if (Input.GetMouseButtonDown(0)) + // תǰȴ˫ָ + bool isZooming = false; + if (isTouching && Input.touchCount == 2) + { + HandleTouchZoom(); + isZooming = true; // + } + + // ʼų˫ָ + if (isTouching && Input.touchCount == 1) + { + if (Input.GetTouch(0).phase == TouchPhase.Began) + { + mouseDownPosition = Input.GetTouch(0).position; + } + } + // 갴 + else if (Input.GetMouseButtonDown(0)) { - // ¼갴ʱλ mouseDownPosition = Input.mousePosition; } - // סʱת - if (Input.GetMouseButton(0)) + // ޸ĺתų״̬ + if (!isZooming && (isTouching ? (Input.GetTouch(0).phase == TouchPhase.Moved) : Input.GetMouseButton(0))) { - // 갴º̧λ֮ľ - float distance = Vector2.Distance(mouseDownPosition, Input.mousePosition); - if (distance > 1f) - { - RotateCamera(); - } + // ƳжֱӦ + RotateCamera(); } // @@ -154,7 +170,6 @@ public class Show3DCamera : MonoBehaviour ZoomCamera(scroll); } - // סҼʱƶĿ if (Input.GetMouseButton(1)) { @@ -163,6 +178,91 @@ public class Show3DCamera : MonoBehaviour DetectHoveredObject(); } } + // Ψһָbool + private bool HandleThreeFingerDrag() + { + if (Input.touchCount == 5) + { + // ƽƶ + Vector2 totalDelta = Vector2.zero; + foreach (Touch t in Input.touches) + { + totalDelta += t.deltaPosition; + } + Vector2 delta = totalDelta / 3f; + + // DPIӦ + float dpiScale = Screen.dpi == 0 ? 1 : Screen.dpi / 160f; + float sensitivity = moveSpeed * 0.1f / dpiScale; + + // Ӧƶֵ2أ + if (delta.magnitude > 2f) + { + // ޸ĺƶ + MoveTarget(delta.x * sensitivity, delta.y * sensitivity); + } + + // + return true; + } + return false; + } + + + // ˫ָŴ + // + private float zoomSmoothVelocity; // ƽٶȻ + [SerializeField] private float zoomSmoothTime = 0.1f; // ƽʱ + private void HandleTouchZoom() + { + if (Input.touchCount == 2) + { + Touch touch0 = Input.GetTouch(0); + Touch touch1 = Input.GetTouch(1); + // ˫ָʱתر + if (touch0.phase == TouchPhase.Began || touch1.phase == TouchPhase.Began) + { + yaw = transform.eulerAngles.y; // ֵǰתǶ + pitch = transform.eulerAngles.x; + mouseDownPosition = Vector2.zero; + } + + Vector2 touch0Pos = touch0.position; + Vector2 touch1Pos = touch1.position; + float currentDistance = Vector2.Distance(touch0Pos, touch1Pos); + + // DPIӦ + float dpi = Screen.dpi == 0 ? 200 : Screen.dpi; + float zoomFactor = 0.01f * (200 / dpi); // ׼DPIΪ200 + + if (touch0.phase == TouchPhase.Began || touch1.phase == TouchPhase.Began) + { + prevTouchDistance = currentDistance; + zoomSmoothVelocity = 0; // ƽٶ + } + else if (touch0.phase == TouchPhase.Moved || touch1.phase == TouchPhase.Moved) + { + float deltaDistance = currentDistance - prevTouchDistance; + + // ʹƽ + float targetDistance = distance - deltaDistance * zoomFactor; + targetDistance = Mathf.Clamp(targetDistance, distanceMin, distanceMax); + + distance = Mathf.SmoothDamp( + distance, + targetDistance, + ref zoomSmoothVelocity, + zoomSmoothTime + ); + + offset = new Vector3(0, 0, -distance); + UpdateCameraPosition(); + + prevTouchDistance = currentDistance; + } + } + } + // ͣ public void DetectHoveredObject() @@ -252,11 +352,15 @@ public class Show3DCamera : MonoBehaviour } - // ƶĿ - private void MoveTarget() + // ޸ĺƶͳһԴ + private void MoveTarget(float mouseX = 0, float mouseY = 0) { - float mouseX = Input.GetAxis("Mouse X") * moveSpeed; - float mouseY = Input.GetAxis("Mouse Y") * moveSpeed; + // ԶжԴ + if (Mathf.Approximately(mouseX, 0) && Mathf.Approximately(mouseY, 0)) + { + mouseX = Input.GetAxis("Mouse X") * moveSpeed; + mouseY = Input.GetAxis("Mouse Y") * moveSpeed; + } transform.Translate(new Vector3(-mouseX, -mouseY, 0)); targetPos += new Vector3(-mouseX, -mouseY, 0); @@ -270,31 +374,44 @@ public class Show3DCamera : MonoBehaviour UpdateCameraPosition(); } - // ת + // ޸RotateCamera private void RotateCamera() { - // ȡƶ - float mouseX = Input.GetAxis("Mouse X") * rotateSpeed; - float mouseY = Input.GetAxis("Mouse Y") * rotateSpeed; + // ʹô + float deltaX = 0, deltaY = 0; + + // + if (Input.touchCount == 1) + { + Touch touch = Input.GetTouch(0); + deltaX = touch.deltaPosition.x; + deltaY = touch.deltaPosition.y; + } + // 괦 + else + { + deltaX = Input.GetAxis("Mouse X") * 10; // ԭ + deltaY = Input.GetAxis("Mouse Y") * 10; + } + + // ӦDPIţؼ + float dpiScale = Screen.dpi == 0 ? 1 : Screen.dpi / 160f; + deltaX *= rotateSpeed * Time.deltaTime / dpiScale; + deltaY *= rotateSpeed * Time.deltaTime / dpiScale; + switch (type) { case RotationType.Orbit: - - // ƫǺ͸ - yaw += mouseX; - pitch -= mouseY; // ע⣺ Y ƶ븩෴ - pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y); // ƸǷΧ - - // λ + yaw += deltaX; + pitch -= deltaY; + pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y); UpdateCameraPosition(); break; case RotationType.Spherical: - // ȫɵתX/Y/Z - target.Rotate(Vector3.up, mouseX, Space.World); // ˮƽYת - target.Rotate(Vector3.right, -mouseY, Space.Self); // ֱ򱾵Xת + target.Rotate(Vector3.up, deltaX, Space.World); + target.Rotate(Vector3.right, -deltaY, Space.Self); break; } - } public void ChangeMode(RotationType type)