导入资源
This commit is contained in:
@@ -8,6 +8,8 @@ namespace NBF
|
||||
{
|
||||
public class InputManager : MonoBehaviour
|
||||
{
|
||||
public static InputManager Instance { get; private set; }
|
||||
|
||||
public static bool IsOp1;
|
||||
public static bool IsOp2;
|
||||
|
||||
@@ -100,8 +102,19 @@ namespace NBF
|
||||
/// </summary>
|
||||
public static event Action<bool> OnRunAction;
|
||||
|
||||
/// <summary>
|
||||
/// 触发交互游戏对象
|
||||
/// </summary>
|
||||
public static event Action<InteractiveObject> OnInteractiveObjectAction;
|
||||
|
||||
public static PlayerInputControl PlayerInputControl { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public static Vector2 GetMovementInput()
|
||||
{
|
||||
return PlayerInputControl.Normal.Move?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
@@ -271,6 +284,12 @@ namespace NBF
|
||||
PlayerInputControl.Normal.Quick9.performed -= OnQuick9;
|
||||
}
|
||||
|
||||
public void OnInteractiveObject(InteractiveObject interactiveObject)
|
||||
{
|
||||
Debug.LogError($"OnInteractiveObject {interactiveObject != null}");
|
||||
OnInteractiveObjectAction?.Invoke(interactiveObject);
|
||||
}
|
||||
|
||||
private void OnRun(InputAction.CallbackContext context)
|
||||
{
|
||||
OnRunAction?.Invoke(context.performed);
|
||||
|
||||
8
Assets/Scripts/Fishing/InteractiveObject.cs
Normal file
8
Assets/Scripts/Fishing/InteractiveObject.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class InteractiveObject : MonoBehaviour
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/InteractiveObject.cs.meta
Normal file
3
Assets/Scripts/Fishing/InteractiveObject.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa29ad8321da4a29a6fb475e9e97f87e
|
||||
timeCreated: 1747577976
|
||||
@@ -9,7 +9,6 @@ namespace NBF
|
||||
{
|
||||
private float _cameraPitch;
|
||||
private FPlayer _player;
|
||||
private float _defBackSpineZ;
|
||||
|
||||
|
||||
[Space(10.0f)] public float maxSprintSpeed = 10.0f;
|
||||
@@ -25,8 +24,6 @@ namespace NBF
|
||||
[HideInInspector] public int nextShowSlotIndex = -1;
|
||||
public bool IsSelf;
|
||||
|
||||
private Quaternion spineInitialLocalRotation;
|
||||
|
||||
|
||||
public LookAtIK lookAtIK; // 挂在背部上的 LookAtIK 脚本
|
||||
public float aimDistance = 1.5f; // 目标点离相机多远
|
||||
@@ -35,6 +32,8 @@ namespace NBF
|
||||
[Header("限制角度(单位:度)")] public float maxUpAngle = 20f; // 相机抬头最多20°
|
||||
public float maxDownAngle = 40f; // 相机低头最多40°
|
||||
|
||||
public LayerMask interactableLayer;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
@@ -53,8 +52,6 @@ namespace NBF
|
||||
lookTarget = new GameObject("SpineLookTarget").transform;
|
||||
lookTarget.SetParent(_player.transform);
|
||||
|
||||
spineInitialLocalRotation = _player.BackSpine.localRotation;
|
||||
_defBackSpineZ = -AnglesChange(_player.BackSpine.localEulerAngles.z);
|
||||
transform.position = _player.Data.position;
|
||||
transform.rotation = _player.Data.rotation;
|
||||
|
||||
@@ -63,10 +60,13 @@ namespace NBF
|
||||
InputManager.OnQuickIndexAction += OnQuickIndexAction;
|
||||
InputManager.OnUseTorchAction += OnUseTorchAction;
|
||||
InputManager.OnUseTelescopeAction += OnUseTelescopeAction;
|
||||
|
||||
interactableLayer = LayerMask.GetMask("Interactive");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
InteractiveCheck();
|
||||
UpdatePlayerPositionAndRotation();
|
||||
UpdateGear();
|
||||
}
|
||||
@@ -98,6 +98,48 @@ namespace NBF
|
||||
InputManager.OnUseTelescopeAction -= OnUseTelescopeAction;
|
||||
}
|
||||
|
||||
#region 交互检测
|
||||
|
||||
private RaycastHit hitInfo;
|
||||
private bool isHit;
|
||||
private readonly float _interactionDistance = 8f;
|
||||
private InteractiveObject _lastInteractiveObject;
|
||||
|
||||
private void InteractiveCheck()
|
||||
{
|
||||
if (IsSelf && _player && _player.Fsm.CurrentStateId == States.Player.Idle)
|
||||
{
|
||||
// 从屏幕中心发射射线
|
||||
Ray ray = BaseCamera.Main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
|
||||
isHit = Physics.Raycast(ray, out hitInfo, _interactionDistance, interactableLayer);
|
||||
|
||||
// 检测到可交互物体时
|
||||
if (isHit)
|
||||
{
|
||||
var interactiveObject = hitInfo.transform.gameObject.GetComponent<InteractiveObject>();
|
||||
if (interactiveObject != null)
|
||||
{
|
||||
SetInteractiveObject(interactiveObject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SetInteractiveObject(null);
|
||||
}
|
||||
|
||||
private void SetInteractiveObject(InteractiveObject interactiveObject)
|
||||
{
|
||||
if (_lastInteractiveObject != interactiveObject)
|
||||
{
|
||||
_lastInteractiveObject = interactiveObject;
|
||||
InputManager.Instance.OnInteractiveObject(_lastInteractiveObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 肩膀控制
|
||||
|
||||
private void UpdatePlayerHandView()
|
||||
@@ -270,23 +312,5 @@ namespace NBF
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 工具方法
|
||||
|
||||
float GetCameraPitch()
|
||||
{
|
||||
Vector3 camForward = cameraParent.transform.forward;
|
||||
camForward.y = 0;
|
||||
camForward.Normalize();
|
||||
float pitch = Vector3.SignedAngle(camForward, cameraParent.transform.forward, cameraParent.transform.right);
|
||||
return pitch;
|
||||
}
|
||||
|
||||
private float AnglesChange(float angle)
|
||||
{
|
||||
return (angle > 180f) ? angle - 360f : angle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class RodPoint : MonoBehaviour
|
||||
{
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawSphere(transform.position, 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e81b3bcbba6645c687b0e4bc0aa7ece0
|
||||
timeCreated: 1744512805
|
||||
@@ -1,44 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SkyCapture : MonoBehaviour
|
||||
{
|
||||
public Camera mainCamera;
|
||||
public Material reflectionSkyboxMaterial;
|
||||
public RenderTexture skyRenderTexture;
|
||||
|
||||
private Camera skyCaptureCamera;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// 创建一个隐藏的截图相机
|
||||
GameObject camObj = new GameObject("SkyCaptureCam");
|
||||
skyCaptureCamera = camObj.AddComponent<Camera>();
|
||||
skyCaptureCamera.enabled = false;
|
||||
|
||||
// 配置截图用的 RenderTexture
|
||||
skyRenderTexture = new RenderTexture(1024, 1024, 16, RenderTextureFormat.ARGB32);
|
||||
skyRenderTexture.Create();
|
||||
|
||||
// 配置 skybox 材质(你需要一个简单的 Skybox/6 Sided Shader 材质)
|
||||
reflectionSkyboxMaterial.SetTexture("_FrontTex", skyRenderTexture);
|
||||
reflectionSkyboxMaterial.SetTexture("_BackTex", skyRenderTexture);
|
||||
reflectionSkyboxMaterial.SetTexture("_LeftTex", skyRenderTexture);
|
||||
reflectionSkyboxMaterial.SetTexture("_RightTex", skyRenderTexture);
|
||||
reflectionSkyboxMaterial.SetTexture("_UpTex", skyRenderTexture);
|
||||
reflectionSkyboxMaterial.SetTexture("_DownTex", skyRenderTexture);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
// 将截图相机位置同步到主相机
|
||||
skyCaptureCamera.transform.position = mainCamera.transform.position;
|
||||
skyCaptureCamera.transform.rotation = mainCamera.transform.rotation;
|
||||
|
||||
skyCaptureCamera.CopyFrom(mainCamera);
|
||||
skyCaptureCamera.cullingMask = LayerMask.GetMask("Sky", "Clouds"); // 只渲染天空和云层
|
||||
skyCaptureCamera.targetTexture = skyRenderTexture;
|
||||
skyCaptureCamera.clearFlags = CameraClearFlags.Skybox;
|
||||
|
||||
skyCaptureCamera.Render();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35651a70914145729b397cf364ccd3b9
|
||||
timeCreated: 1746195772
|
||||
@@ -49,7 +49,7 @@ namespace NBF
|
||||
}
|
||||
|
||||
QualitySettings.vSyncCount = 0;
|
||||
Application.targetFrameRate = 120;
|
||||
// Application.targetFrameRate = 120;
|
||||
// NBC.Asset.Const.Offline = true;
|
||||
// yield return NBC.Asset.Assets.Initialize();
|
||||
Init();
|
||||
|
||||
Reference in New Issue
Block a user