From f258ad09aba147596ab20f37c2666ce63d7aa112 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Fri, 14 Feb 2025 13:20:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=843D=E8=A7=A3=E5=89=96=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Art/UIPrefab/UIBody3D.prefab | 280 +++++++++++++++++- Assets/Art/UIPrefab/UIBody3DInfo.prefab | 60 +++- Assets/Scripts/Controller/Body3DController.cs | 23 +- Assets/Scripts/Item/Body3DOjbItem.cs | 45 +++ Assets/Scripts/Item/ObjDrag.cs | 20 +- Assets/Scripts/Item/Show3DCamera.cs | 57 +++- Assets/Scripts/UI/UIBody3D.Designer.cs | 15 +- Assets/Scripts/UI/UIBody3D.cs | 21 +- Assets/Scripts/Xml/XmlParser.cs | 2 + 9 files changed, 477 insertions(+), 46 deletions(-) diff --git a/Assets/Art/UIPrefab/UIBody3D.prefab b/Assets/Art/UIPrefab/UIBody3D.prefab index 3860746f..34877244 100644 --- a/Assets/Art/UIPrefab/UIBody3D.prefab +++ b/Assets/Art/UIPrefab/UIBody3D.prefab @@ -1080,11 +1080,150 @@ MonoBehaviour: m_EditorClassIdentifier: BodyContent: {fileID: 5601864313735818432} LeftContent: {fileID: 3644811849542302248} - DragBtn: {fileID: 4284720363514511568} - DragBack: {fileID: 540967449707403434} + ResetBtn: {fileID: 1164260856681727312} ActiveBtn: {fileID: 6692543268377793545} ActiveBack: {fileID: 3554365675561402507} + DragBtn: {fileID: 4284720363514511568} + DragBack: {fileID: 540967449707403434} BodyItem: {fileID: 1682419669064365991} +--- !u!1 &4437185578165757201 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3959195348148526699} + - component: {fileID: 6893419802133694656} + - component: {fileID: 4072128863539031069} + - component: {fileID: 6573736067503725872} + - component: {fileID: 1164260856681727312} + m_Layer: 5 + m_Name: ResetBtn + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &3959195348148526699 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4437185578165757201} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 4205592421312639835} + m_Father: {fileID: 3644811849542302248} + 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: 102, y: 34} + m_Pivot: {x: 0.5, y: 1} +--- !u!222 &6893419802133694656 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4437185578165757201} + m_CullTransparentMesh: 1 +--- !u!114 &4072128863539031069 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4437185578165757201} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: 8c77a2052664d0d4e9be892444deddd1, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!114 &6573736067503725872 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4437185578165757201} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0d51f3a7c41ab0346b49ae50d456bece, type: 3} + m_Name: + m_EditorClassIdentifier: + MarkType: 0 + CustomComponentName: BtnPrefab + CustomComment: + mComponentName: UnityEngine.UI.Button +--- !u!114 &1164260856681727312 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4437185578165757201} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 4072128863539031069} + m_OnClick: + m_PersistentCalls: + m_Calls: [] --- !u!1 &5049956726037078213 GameObject: m_ObjectHideFlags: 0 @@ -1589,8 +1728,9 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 7134505307210740835} + - {fileID: 3959195348148526699} - {fileID: 165414428222451636} + - {fileID: 7134505307210740835} m_Father: {fileID: 1062102287437619772} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.5} @@ -1850,6 +1990,140 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 +--- !u!1 &7499310447612568881 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4205592421312639835} + - component: {fileID: 1855204455405537204} + - component: {fileID: 2739947805228490611} + m_Layer: 5 + m_Name: Label + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &4205592421312639835 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7499310447612568881} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 3959195348148526699} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &1855204455405537204 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7499310447612568881} + m_CullTransparentMesh: 1 +--- !u!114 &2739947805228490611 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7499310447612568881} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: "\u590D\u4F4D" + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 97936a7b3a86809479ac89371e95b079, type: 2} + m_sharedMaterial: {fileID: 168401102475399263, guid: 97936a7b3a86809479ac89371e95b079, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 16 + m_fontSizeBase: 16 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} --- !u!1 &8568279820254546874 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Art/UIPrefab/UIBody3DInfo.prefab b/Assets/Art/UIPrefab/UIBody3DInfo.prefab index 1a126814..92f01c3f 100644 --- a/Assets/Art/UIPrefab/UIBody3DInfo.prefab +++ b/Assets/Art/UIPrefab/UIBody3DInfo.prefab @@ -323,7 +323,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 51, y: -7.184} + m_AnchoredPosition: {x: 51, y: -7.1839905} m_SizeDelta: {x: 102, y: 34} m_Pivot: {x: 0.5, y: 1} --- !u!222 &4075577543603496310 @@ -1053,6 +1053,8 @@ GameObject: - component: {fileID: 6827284989092321893} - component: {fileID: 4497957665814808150} - component: {fileID: 5775295014847080228} + - component: {fileID: 3534695522984393869} + - component: {fileID: 2319114503345784786} m_Layer: 0 m_Name: bg m_TagString: Untagged @@ -1079,7 +1081,7 @@ RectTransform: m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 0} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 1010, y: 590} + m_SizeDelta: {x: 1010, y: 0} m_Pivot: {x: 0.99999994, y: -0.00000004284084} --- !u!222 &4497957665814808150 CanvasRenderer: @@ -1119,6 +1121,46 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 +--- !u!114 &3534695522984393869 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4630449187609202247} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 59f8146938fff824cb5fd77236b75775, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Padding: + m_Left: 0 + m_Right: 0 + m_Top: 0 + m_Bottom: 0 + m_ChildAlignment: 7 + m_Spacing: 0 + m_ChildForceExpandWidth: 0 + m_ChildForceExpandHeight: 0 + m_ChildControlWidth: 1 + m_ChildControlHeight: 1 + m_ChildScaleWidth: 0 + m_ChildScaleHeight: 0 + m_ReverseArrangement: 0 +--- !u!114 &2319114503345784786 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4630449187609202247} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3} + m_Name: + m_EditorClassIdentifier: + m_HorizontalFit: 0 + m_VerticalFit: 2 --- !u!1 &5243978266746649525 GameObject: m_ObjectHideFlags: 0 @@ -2019,10 +2061,10 @@ RectTransform: - {fileID: 8846071839557483914} m_Father: {fileID: 6827284989092321893} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -24.18396} - m_SizeDelta: {x: 0, y: 48.36798} + 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.5, y: 0.5} --- !u!114 &8897071683313985438 MonoBehaviour: @@ -2087,9 +2129,9 @@ RectTransform: m_Father: {fileID: 6827284989092321893} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 0} - m_AnchoredPosition: {x: 0, y: 24.183985} - m_SizeDelta: {x: 0, y: 48.368} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &6142069136662953391 MonoBehaviour: diff --git a/Assets/Scripts/Controller/Body3DController.cs b/Assets/Scripts/Controller/Body3DController.cs index 828f2d70..0b637870 100644 --- a/Assets/Scripts/Controller/Body3DController.cs +++ b/Assets/Scripts/Controller/Body3DController.cs @@ -30,6 +30,7 @@ public class Body3DController : MonoSingleton private Vector2 mouseDownPosition; // ¼갴ʱλ Stack activeObjs = new Stack(); + Stack moveObjs = new Stack(); public override void OnSingletonInit() { base.OnSingletonInit(); @@ -86,7 +87,8 @@ public class Body3DController : MonoSingleton } else { - this.status &= status; + // ɾ״̬ + this.status &= ~status; } } @@ -111,6 +113,25 @@ public class Body3DController : MonoSingleton } } + public void AddMoveObj(GameObject obj) + { + if (moveObjs.Contains(obj)==false) + { + moveObjs.Push(obj); + } + } + public GameObject PopMoveObj() + { + if (moveObjs.Count > 0) + { + return moveObjs.Pop(); + } + else + { + return null; + } + } + public void Active(bool isActive) { foreach (var item in objs) diff --git a/Assets/Scripts/Item/Body3DOjbItem.cs b/Assets/Scripts/Item/Body3DOjbItem.cs index 9827effe..8ecbf6f6 100644 --- a/Assets/Scripts/Item/Body3DOjbItem.cs +++ b/Assets/Scripts/Item/Body3DOjbItem.cs @@ -12,6 +12,10 @@ public class Body3DOjbItem : MonoBehaviour ObjectToggle objToggle; ObjDrag objDrag; + // ¼һ갴µʱ + private float lastClickTime; + // ˫ʱֵ + private const float doubleClickTimeThreshold = 0.3f; private void Awake() { } @@ -46,6 +50,10 @@ public class Body3DOjbItem : MonoBehaviour { colorToggle?.SetColor(isOn); objDrag = gameObject.GetOrAddComponent(); + objDrag.OnDragEnd.AddListener(obj => + { + Body3DController.Instance.AddMoveObj(gameObject); + }); RefreshDrag(); TypeEventSystem.Global.Send(new OnBody3DSelected() { isOn = isOn, obj = gameObject }); if (isOn) @@ -63,6 +71,43 @@ public class Body3DOjbItem : MonoBehaviour } } + private void OnMouseDown() + { + // 㵱ǰʱһεʱļ + float currentTime = Time.time; + if (currentTime - lastClickTime < doubleClickTimeThreshold) + { + // ˫¼ + OnDoubleClick(); + } + lastClickTime = currentTime; + + } + + + public void OnDoubleClick() + { + if (Body3DController.Instance.CheckStatus(Body3DController.Status.Drag)) + { + var drag = gameObject.GetComponent(); + if (drag != null) + { + drag.OnDoubleClick(); + } + } + else if (Body3DController.Instance.CheckStatus(Body3DController.Status.Active) == false) + { + float distance = 1; + if (float.TryParse(body.FocusDistance, out distance)) + { + Show3DCamera.instance.FocusObj(gameObject.transform.position, distance); + } + else + { + Show3DCamera.instance.FocusObj(gameObject.transform.position); + } + } + } private void OnBody3DDragHandler(OnBody3DDragChanged drag) { diff --git a/Assets/Scripts/Item/ObjDrag.cs b/Assets/Scripts/Item/ObjDrag.cs index 5e0500d5..26586930 100644 --- a/Assets/Scripts/Item/ObjDrag.cs +++ b/Assets/Scripts/Item/ObjDrag.cs @@ -1,6 +1,8 @@ using DG.Tweening; using QFramework; +using System; using UnityEngine; +using UnityEngine.Events; public class ObjDrag : MonoBehaviour { @@ -9,11 +11,7 @@ public class ObjDrag : MonoBehaviour Vector3 startPosition; - // ¼һ갴µʱ - private float lastClickTime; - // ˫ʱֵ - private const float doubleClickTimeThreshold = 0.3f; - + public UnityEvent OnDragEnd = new UnityEvent(); void Start() { startPosition = gameObject.transform.position; @@ -24,6 +22,7 @@ public class ObjDrag : MonoBehaviour if (isOn) { Show3DCamera.instance.lockMove = false; + OnDragEnd?.Invoke(gameObject); } } @@ -31,15 +30,6 @@ public class ObjDrag : MonoBehaviour { if (isOn) { - // 㵱ǰʱһεʱļ - float currentTime = Time.time; - if (currentTime - lastClickTime < doubleClickTimeThreshold) - { - // ˫¼ - OnDoubleClick(); - } - lastClickTime = currentTime; - // ȡӽƽϵ Vector3 mouseWorldPos = GetMouseWorldPositionOnPlane(); // λеƫ @@ -89,7 +79,7 @@ public class ObjDrag : MonoBehaviour } // ˫¼ - private void OnDoubleClick() + public void OnDoubleClick() { // Ҫִе˫߼ // 磬õʼλ diff --git a/Assets/Scripts/Item/Show3DCamera.cs b/Assets/Scripts/Item/Show3DCamera.cs index 1bffbf8a..1a4dda03 100644 --- a/Assets/Scripts/Item/Show3DCamera.cs +++ b/Assets/Scripts/Item/Show3DCamera.cs @@ -1,3 +1,4 @@ +using DG.Tweening; using GCSeries.Core; using System; using Unity.Burst.CompilerServices; @@ -29,6 +30,10 @@ public class Show3DCamera : MonoBehaviour public RenderTexture texture; public bool lockMove = false; + + + private Vector2 mouseDownPosition; // ¼갴ʱλ + private void Awake() { instance = this; @@ -38,7 +43,7 @@ public class Show3DCamera : MonoBehaviour } - 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) + 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) { if (target == null) { @@ -67,19 +72,30 @@ public class Show3DCamera : MonoBehaviour { self.targetTexture = null; } - UpdateCameraPosition(); + UpdateCameraPosition(moveTime); } void Update() { - if (targetPos != null && lockMove == false) + if (targetPos != null && lockMove == false && EventSystem.current.IsPointerOverGameObject() == false) { + if (Input.GetMouseButtonDown(0)) + { + // ¼갴ʱλ + mouseDownPosition = Input.mousePosition; + } + // סʱת if (Input.GetMouseButton(0)) { - RotateCamera(); + // 갴º̧λ֮ľ + float distance = Vector2.Distance(mouseDownPosition, Input.mousePosition); + if (distance > 1f) + { + RotateCamera(); + } } // @@ -147,6 +163,21 @@ public class Show3DCamera : MonoBehaviour } + /// + /// ۽ij + /// + public void FocusObj(Vector3 target, float distance = 1f) + { + // ǰһλãΪCubeĿλ + // ԸҪ + Vector3 cameraPos = target - transform.forward * distance; + + targetPos = target; + this.distance = distance; + offset = new Vector3(0, 0, -distance); + transform.position = cameraPos; + } + public void OnMouseEnterObj(GameObject obj) { TipItem tip = obj.GetComponent(); @@ -200,17 +231,25 @@ public class Show3DCamera : MonoBehaviour } // λúͳ - private void UpdateCameraPosition() + private void UpdateCameraPosition(float moveTime = -1) { // תƫ Quaternion rotation = Quaternion.Euler(pitch, yaw, 0); Vector3 rotatedOffset = rotation * offset; - // λ - transform.position = targetPos + rotatedOffset; + if (moveTime != -1) + { + transform.DOMove(targetPos + rotatedOffset, moveTime).onUpdate = () => + // ʼճĿ + transform.LookAt(targetPos); + } + else + { + transform.position = targetPos + rotatedOffset; + // ʼճĿ + transform.LookAt(targetPos); + } - // ʼճĿ - transform.LookAt(targetPos); } } diff --git a/Assets/Scripts/UI/UIBody3D.Designer.cs b/Assets/Scripts/UI/UIBody3D.Designer.cs index 1a76abab..32bf1efc 100644 --- a/Assets/Scripts/UI/UIBody3D.Designer.cs +++ b/Assets/Scripts/UI/UIBody3D.Designer.cs @@ -5,7 +5,7 @@ using QFramework; namespace QFramework.Example { - // Generate Id:54cc185d-5dba-4a35-a35c-f7ccce574623 + // Generate Id:517b031d-7fb8-4418-aa63-70787d47d5ff public partial class UIBody3D { public const string Name = "UIBody3D"; @@ -15,14 +15,16 @@ namespace QFramework.Example [SerializeField] public RectTransform LeftContent; [SerializeField] - public UnityEngine.UI.Toggle DragBtn; - [SerializeField] - public UnityEngine.UI.Button DragBack; + public UnityEngine.UI.Button ResetBtn; [SerializeField] public UnityEngine.UI.Toggle ActiveBtn; [SerializeField] public UnityEngine.UI.Button ActiveBack; [SerializeField] + public UnityEngine.UI.Toggle DragBtn; + [SerializeField] + public UnityEngine.UI.Button DragBack; + [SerializeField] public UnityEngine.UI.Toggle BodyItem; private UIBody3DData mPrivateData = null; @@ -31,10 +33,11 @@ namespace QFramework.Example { BodyContent = null; LeftContent = null; - DragBtn = null; - DragBack = null; + ResetBtn = null; ActiveBtn = null; ActiveBack = null; + DragBtn = null; + DragBack = null; BodyItem = null; mData = null; diff --git a/Assets/Scripts/UI/UIBody3D.cs b/Assets/Scripts/UI/UIBody3D.cs index 72c351ad..8a9ca2f3 100644 --- a/Assets/Scripts/UI/UIBody3D.cs +++ b/Assets/Scripts/UI/UIBody3D.cs @@ -11,6 +11,7 @@ namespace QFramework.Example } public partial class UIBody3D : UIPanel { + GameObject root; protected override void OnInit(IUIData uiData = null) { DragBtn.onValueChanged.AddListener(isOn => @@ -22,7 +23,11 @@ namespace QFramework.Example }); DragBack.onClick.AddListener(() => { - DragBtn.isOn = false; + GameObject obj = Body3DController.Instance.PopMoveObj(); + if (obj != null) + { + obj.GetComponent().OnDoubleClick(); + } }); ActiveBtn.onValueChanged.AddListener(isOn => @@ -35,13 +40,18 @@ namespace QFramework.Example { Body3DController.Instance.PopActiveObj()?.gameObject.SetActive(true); }); + ResetBtn.onClick.AddListener(() => + { + ResetCamera(0.5f); + }); + } protected override void OnOpen(IUIData uiData = null) { mData = uiData as UIBody3DData ?? new UIBody3DData(); BodyContent.RemoveAllChildren(); - GameObject root = Utility.FindObj(mData.body.Path); + root = Utility.FindObj(mData.body.Path); root.SetActive(true); foreach (var bodyData in mData.body.subBody) { @@ -59,11 +69,16 @@ namespace QFramework.Example } FreeCameraController.instance.gameObject.SetActive(false); Show3DCamera.instance.gameObject.SetActive(true); - Show3DCamera.instance.Set(root.transform, distance: 5, isRenderTexture: false); + ResetCamera(-1); } + public void ResetCamera(float moveTime) + { + Show3DCamera.instance.Set(root.transform, distance: 5, isRenderTexture: false, moveTime: moveTime); + } + protected override void OnShow() { } diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index b92d0606..8cdd6c76 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -173,6 +173,8 @@ namespace XMLTool public string Audio { get; set; } + public string FocusDistance { get; set; } + public bool isShow = false; public ObjectToggle toggle;