Repository navigation
Expand file tree
/
Copy pathFlyModule.cs
More file actions
60 lines (53 loc) · 1.99 KB
/
Copy pathFlyModule.cs
File metadata and controls
60 lines (53 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.InputSystem;
namespace HTFToolkit
{
/// <summary>
/// 飞行:抵消重力并接管垂直速度,水平移动仍走游戏输入(WASD)。
/// 操作:开关后 —— 空格上升 / 左Ctrl 下降 / 松开悬停。
/// 玩家位置由游戏自身的网络同步(SendPosRot)上报,联机下其他玩家也能看到。
/// </summary>
internal static class FlyModule
{
public static bool Enabled;
private static ConfigEntry<float> _speed;
public static void BindConfig(ConfigFile cfg)
{
_speed = cfg.Bind("飞行", "升降速度", 8f, "上升/下降速度(米/秒)");
}
public static void Update()
{
if (!Enabled)
return;
try
{
Player p = Player.LocalPlayer;
if (p == null)
return;
Rigidbody rb = p.Rigidbody;
if (rb == null)
return;
float vertical = 0f;
// 游戏用新 Input System(旧 UnityEngine.Input 在本项目不可用)
Keyboard kb = Keyboard.current;
bool up = kb != null && kb.spaceKey.isPressed;
bool down = kb != null
&& (kb.leftCtrlKey.isPressed || kb.rightCtrlKey.isPressed || kb.cKey.isPressed);
if (up)
vertical += _speed?.Value ?? 8f;
if (down)
vertical -= _speed?.Value ?? 8f;
Vector3 v = rb.linearVelocity;
// 直接接管 y:抵消重力(悬停)或按升降键给速度;水平分量保持游戏输入的结果
v.y = vertical;
rb.linearVelocity = v;
}
catch (Exception e)
{
Plugin.Log?.LogWarning($"Fly update: {e.Message}");
}
}
}
}