Skip to content

Commit 78fc180

Browse files
committed
优化:自由视角的旋转、平移控制按键,支持在检视器面板修改。
1 parent 0ef0822 commit 78fc180

File tree

5 files changed

+68
-4
lines changed

5 files changed

+68
-4
lines changed

Editor/Controller/CameraControl/MousePositionInspector.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,34 @@ protected override void OnInspectorDefaultGUI()
1818

1919
PropertyField(nameof(MousePosition.IsCanOnUGUI), "Can Control On UGUI");
2020
PropertyField(nameof(MousePosition.IsCanByKey), "Can Control By Key");
21-
21+
22+
GUILayout.BeginHorizontal();
23+
EditorGUILayout.LabelField("Translate Key", GUILayout.Width(LabelWidth));
24+
if (GUILayout.Button(Target.TranslateKey, EditorStyles.popup, GUILayout.Width(EditorGUIUtility.currentViewWidth - LabelWidth - 25)))
25+
{
26+
GenericMenu gm = new GenericMenu();
27+
gm.AddItem(new GUIContent("Mouse Left"), Target.TranslateKey == "MouseLeft", () =>
28+
{
29+
Undo.RecordObject(target, "Change Translate Key");
30+
Target.TranslateKey = "MouseLeft";
31+
HasChanged();
32+
});
33+
gm.AddItem(new GUIContent("Mouse Right"), Target.TranslateKey == "MouseRight", () =>
34+
{
35+
Undo.RecordObject(target, "Change Translate Key");
36+
Target.TranslateKey = "MouseRight";
37+
HasChanged();
38+
});
39+
gm.AddItem(new GUIContent("Mouse Middle"), Target.TranslateKey == "MouseMiddle", () =>
40+
{
41+
Undo.RecordObject(target, "Change Translate Key");
42+
Target.TranslateKey = "MouseMiddle";
43+
HasChanged();
44+
});
45+
gm.ShowAsContext();
46+
}
47+
GUILayout.EndHorizontal();
48+
2249
GUILayout.BeginHorizontal();
2350
EditorGUILayout.LabelField("Speed", EditorStyles.boldLabel);
2451
GUILayout.EndHorizontal();

Editor/Controller/CameraControl/MouseRotationInspector.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,34 @@ protected override void OnInspectorDefaultGUI()
1818

1919
PropertyField(nameof(MouseRotation.IsCanOnUGUI), "Can Control On UGUI");
2020
PropertyField(nameof(MouseRotation.AllowOverstepDistance), "Allow Overstep Distance");
21-
21+
22+
GUILayout.BeginHorizontal();
23+
EditorGUILayout.LabelField("Rotate Key", GUILayout.Width(LabelWidth));
24+
if (GUILayout.Button(Target.RotateKey, EditorStyles.popup, GUILayout.Width(EditorGUIUtility.currentViewWidth - LabelWidth - 25)))
25+
{
26+
GenericMenu gm = new GenericMenu();
27+
gm.AddItem(new GUIContent("Mouse Left"), Target.RotateKey == "MouseLeft", () =>
28+
{
29+
Undo.RecordObject(target, "Change Rotate Key");
30+
Target.RotateKey = "MouseLeft";
31+
HasChanged();
32+
});
33+
gm.AddItem(new GUIContent("Mouse Right"), Target.RotateKey == "MouseRight", () =>
34+
{
35+
Undo.RecordObject(target, "Change Rotate Key");
36+
Target.RotateKey = "MouseRight";
37+
HasChanged();
38+
});
39+
gm.AddItem(new GUIContent("Mouse Middle"), Target.RotateKey == "MouseMiddle", () =>
40+
{
41+
Undo.RecordObject(target, "Change Rotate Key");
42+
Target.RotateKey = "MouseMiddle";
43+
HasChanged();
44+
});
45+
gm.ShowAsContext();
46+
}
47+
GUILayout.EndHorizontal();
48+
2249
GUILayout.BeginHorizontal();
2350
EditorGUILayout.LabelField("Speed", EditorStyles.boldLabel);
2451
GUILayout.EndHorizontal();

HTFramework.prefab

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ MonoBehaviour:
820820
CanControl: 1
821821
IsCanOnUGUI: 0
822822
AllowOverstepDistance: 1
823+
RotateKey: MouseRight
823824
XSpeed: 150
824825
YSpeed: 150
825826
MSpeed: 50
@@ -847,6 +848,7 @@ MonoBehaviour:
847848
CanControl: 1
848849
IsCanOnUGUI: 0
849850
IsCanByKey: 1
851+
TranslateKey: MouseMiddle
850852
XSpeed: 0.1
851853
YSpeed: 0.1
852854
ZSpeed: 0.1

RunTime/Controller/CameraControl/MousePosition.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ internal sealed class MousePosition : HTBehaviour
2222
/// </summary>
2323
public bool IsCanByKey = true;
2424
/// <summary>
25+
/// 控制移动的按键
26+
/// </summary>
27+
public string TranslateKey = "MouseMiddle";
28+
/// <summary>
2529
/// x轴移动速度,y轴移动速度,z轴移动速度
2630
/// </summary>
2731
public float XSpeed = 0.1f, YSpeed = 0.1f, ZSpeed = 0.1f;
@@ -131,7 +135,7 @@ private void Control()
131135
if (!IsCanOnUGUI && UIToolkit.IsStayUINotWorld)
132136
return;
133137

134-
if (Main.m_Input.GetButton(InputButtonType.MouseMiddle))
138+
if (Main.m_Input.GetButton(TranslateKey))
135139
{
136140
if (_moveTweener != null)
137141
{

RunTime/Controller/CameraControl/MouseRotation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ internal sealed class MouseRotation : HTBehaviour
2121
/// </summary>
2222
public bool AllowOverstepDistance = true;
2323
/// <summary>
24+
/// 控制旋转的按键
25+
/// </summary>
26+
public string RotateKey = "MouseRight";
27+
/// <summary>
2428
/// x轴旋转速度,y轴旋转速度,滚轮缩放速度
2529
/// </summary>
2630
public float XSpeed = 150, YSpeed = 150, MSpeed = 30;
@@ -111,7 +115,7 @@ private void Control()
111115
if (!IsCanOnUGUI && UIToolkit.IsStayUINotWorld)
112116
return;
113117

114-
if (Main.m_Input.GetButton(InputButtonType.MouseRight))
118+
if (Main.m_Input.GetButton(RotateKey))
115119
{
116120
X += Main.m_Input.GetAxis(InputAxisType.MouseX) * XSpeed * Time.deltaTime;
117121
Y -= Main.m_Input.GetAxis(InputAxisType.MouseY) * YSpeed * Time.deltaTime;

0 commit comments

Comments
 (0)