结构大修改,改成朴实无华的结构,不过度架构。能跑就行
This commit is contained in:
98
Assets/Scripts/Fishing2~/Common/CameraComponent.cs
Normal file
98
Assets/Scripts/Fishing2~/Common/CameraComponent.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using Fantasy.Async;
|
||||
using NBC;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using Fantasy.Event;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public enum CameraShowMode
|
||||
{
|
||||
None = 0,
|
||||
FPP,
|
||||
TPP,
|
||||
}
|
||||
|
||||
public class CameraComponent : Entity
|
||||
{
|
||||
public CameraShowMode Mode = CameraShowMode.None;
|
||||
|
||||
private CameraAsset _cameraAsset;
|
||||
private CameraShowMode _lastMode = CameraShowMode.None;
|
||||
|
||||
public class CameraComponentAwakeSystem : AwakeSystem<CameraComponent>
|
||||
{
|
||||
protected override void Awake(CameraComponent self)
|
||||
{
|
||||
self._cameraAsset = Game.Instance.gameObject.GetComponentInChildren<CameraAsset>();
|
||||
}
|
||||
}
|
||||
|
||||
public class CameraComponentUpdateSystem : UpdateSystem<CameraComponent>
|
||||
{
|
||||
protected override void Update(CameraComponent self)
|
||||
{
|
||||
self.UpdateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
public class CameraComponentDestroySystem : DestroySystem<CameraComponent>
|
||||
{
|
||||
protected override void Destroy(CameraComponent self)
|
||||
{
|
||||
self._cameraAsset = null;
|
||||
self._lastMode = CameraShowMode.None;
|
||||
self.Mode = CameraShowMode.None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateCamera()
|
||||
{
|
||||
if (_lastMode == Mode) return;
|
||||
if (Mode == CameraShowMode.TPP)
|
||||
{
|
||||
//第三人称视角
|
||||
SetTPPCam();
|
||||
}
|
||||
else if (Mode == CameraShowMode.FPP)
|
||||
{
|
||||
//第一人称视角
|
||||
SetFPPCam();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetTPPCam()
|
||||
{
|
||||
_cameraAsset.fppVCam.Priority = 0;
|
||||
_cameraAsset.tppVCam.Priority = 10;
|
||||
}
|
||||
|
||||
private void SetFPPCam()
|
||||
{
|
||||
var map = App.Main.GetComponent<Map>();
|
||||
var unityComponent = map.SelfMapUnit.GetComponent<UnitUnityComponent>();
|
||||
if (unityComponent != null)
|
||||
{
|
||||
_cameraAsset.fppVCam.LookAt = unityComponent.RootAsset.FppLook;
|
||||
_cameraAsset.fppVCam.Follow = unityComponent.ModelAsset.NeckTransform;
|
||||
unityComponent.ModelAsset.LookIk.solver.target = unityComponent.RootAsset.FppLook;
|
||||
}
|
||||
|
||||
_cameraAsset.fppVCam.Priority = 10;
|
||||
_cameraAsset.tppVCam.Priority = 0;
|
||||
}
|
||||
|
||||
public void SetFppLook(Transform fppCamLook)
|
||||
{
|
||||
_cameraAsset.fppVCam.LookAt = fppCamLook;
|
||||
}
|
||||
|
||||
public void SetFppFollow(Transform fppCamFollow)
|
||||
{
|
||||
_cameraAsset.fppVCam.Follow = fppCamFollow;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing2~/Common/CameraComponent.cs.meta
Normal file
3
Assets/Scripts/Fishing2~/Common/CameraComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aee3947bbf944ecb9e955d2ac1d9e3a5
|
||||
timeCreated: 1756822741
|
||||
104
Assets/Scripts/Fishing2~/Common/CursorComponent.cs
Normal file
104
Assets/Scripts/Fishing2~/Common/CursorComponent.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
// using Fantasy.Async;
|
||||
// using Fantasy.Entitas;
|
||||
// using Fantasy.Entitas.Interface;
|
||||
// using Fantasy.Event;
|
||||
// using NBC;
|
||||
// using UnityEngine;
|
||||
//
|
||||
// namespace NBF.Fishing2
|
||||
// {
|
||||
// public class CursorUIShowEvent : AsyncEventSystem<UIShowEvent>
|
||||
// {
|
||||
// protected override async FTask Handler(UIShowEvent self)
|
||||
// {
|
||||
// var cursorComponent = App.Main.GetComponent<CursorComponent>();
|
||||
// cursorComponent.UpdateCursor();
|
||||
// }
|
||||
// // protected override FTask Handler(UIShowEvent self)
|
||||
// // {
|
||||
// // throw new System.NotImplementedException();
|
||||
// // }
|
||||
// }
|
||||
//
|
||||
// public class CursorUIHideEvent : AsyncEventSystem<UIHideEvent>
|
||||
// {
|
||||
// protected override async FTask Handler(UIHideEvent self)
|
||||
// {
|
||||
// var cursorComponent = App.Main.GetComponent<CursorComponent>();
|
||||
// cursorComponent.UpdateCursor();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class CursorComponent : Entity
|
||||
// {
|
||||
// #region System
|
||||
//
|
||||
//
|
||||
//
|
||||
// // public class CursorComponentAwakeSystem : AwakeSystem<CursorComponent>
|
||||
// // {
|
||||
// // protected override void Awake(CursorComponent self)
|
||||
// // {
|
||||
// //
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // public class CursorComponentUpdateSystem : UpdateSystem<CursorComponent>
|
||||
// // {
|
||||
// // protected override void Update(CursorComponent self)
|
||||
// // {
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // public class CursorComponentDestroySystem : DestroySystem<CursorComponent>
|
||||
// // {
|
||||
// // protected override void Destroy(CursorComponent self)
|
||||
// // {
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// #endregion
|
||||
//
|
||||
// public void UpdateCursor()
|
||||
// {
|
||||
// bool showCursor = false;
|
||||
// var uis = App.UI.GetAllUI();
|
||||
// foreach (var ui in uis)
|
||||
// {
|
||||
// if (ui.IsShowing && ui.IsShowCursor)
|
||||
// {
|
||||
// showCursor = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// SetMouseCursor(showCursor);
|
||||
// }
|
||||
//
|
||||
// public ControllerType controllerType = ControllerType.GamePad;
|
||||
//
|
||||
// public void SetMouseCursor(bool val)
|
||||
// {
|
||||
// Log.Info($"设置鼠标光标==={val}");
|
||||
// if (val)
|
||||
// {
|
||||
// if (controllerType == ControllerType.KeyboardMouse)
|
||||
// {
|
||||
// Cursor.visible = true;
|
||||
// }
|
||||
//
|
||||
// Cursor.lockState = CursorLockMode.None;
|
||||
// }
|
||||
// else if (controllerType == ControllerType.KeyboardMouse)
|
||||
// {
|
||||
// Cursor.visible = false;
|
||||
// }
|
||||
//
|
||||
// Cursor.visible = val;
|
||||
// if (!val)
|
||||
// {
|
||||
// Cursor.lockState = CursorLockMode.Confined;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
3
Assets/Scripts/Fishing2~/Common/CursorComponent.cs.meta
Normal file
3
Assets/Scripts/Fishing2~/Common/CursorComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a04f3272f2604244b8cd9d9923bb35b0
|
||||
timeCreated: 1765374579
|
||||
222
Assets/Scripts/Fishing2~/Common/InputComponent.cs
Normal file
222
Assets/Scripts/Fishing2~/Common/InputComponent.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public enum ControllerType
|
||||
{
|
||||
KeyboardMouse = 0,
|
||||
GamePad = 1
|
||||
}
|
||||
|
||||
public class InputComponent : Entity
|
||||
{
|
||||
public PlayerInputControl PlayerInputControl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件
|
||||
/// </summary>
|
||||
public event Action<string> OnUIPerformed;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件完毕
|
||||
/// </summary>
|
||||
public event Action<string> OnUICanceled;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件
|
||||
/// </summary>
|
||||
public event Action<string> OnPlayerPerformed;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件完毕
|
||||
/// </summary>
|
||||
public event Action<string> OnPlayerCanceled;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件
|
||||
/// </summary>
|
||||
public event Action<InputAction.CallbackContext> OnPlayerValuePerformed;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件完毕
|
||||
/// </summary>
|
||||
public event Action<InputAction.CallbackContext> OnPlayerValueCanceled;
|
||||
|
||||
/// <summary>
|
||||
/// 触发交互游戏对象
|
||||
/// </summary>
|
||||
public event Action<InteractiveObject> OnInteractiveObjectAction;
|
||||
|
||||
/// <summary>
|
||||
/// 手柄输入
|
||||
/// </summary>
|
||||
public static bool IsControllerInput;
|
||||
|
||||
/// <summary>
|
||||
/// ui阻止游戏输入
|
||||
/// </summary>
|
||||
public static bool IsUIStopInput;
|
||||
|
||||
|
||||
#region Event
|
||||
|
||||
public class InputComponentAwakeSystem : AwakeSystem<InputComponent>
|
||||
{
|
||||
protected override void Awake(InputComponent self)
|
||||
{
|
||||
self.PlayerInputControl = new PlayerInputControl();
|
||||
self.PlayerInputControl.Enable();
|
||||
|
||||
foreach (var actionMap in self.PlayerInputControl.asset.actionMaps)
|
||||
{
|
||||
actionMap.Enable();
|
||||
if (actionMap.name == "UI")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed += self.OnUIButtonPerformed;
|
||||
action.canceled += self.OnUIButtonCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (actionMap.name == "Player")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed += self.OnPlayerButtonPerformed;
|
||||
action.canceled += self.OnPlayerButtonCanceled;
|
||||
}
|
||||
else if (action.type == InputActionType.Value)
|
||||
{
|
||||
action.performed += self.OnInputPlayerValuePerformed;
|
||||
action.canceled += self.OnInputPlayerValueCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class InputComponentDestroySystem : DestroySystem<InputComponent>
|
||||
{
|
||||
protected override void Destroy(InputComponent self)
|
||||
{
|
||||
foreach (var actionMap in self.PlayerInputControl.asset.actionMaps)
|
||||
{
|
||||
actionMap.Enable();
|
||||
if (actionMap.name == "UI")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed -= self.OnUIButtonPerformed;
|
||||
action.canceled -= self.OnUIButtonCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (actionMap.name == "Player")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed -= self.OnPlayerButtonPerformed;
|
||||
action.canceled -= self.OnPlayerButtonCanceled;
|
||||
}
|
||||
else if (action.type == InputActionType.Value)
|
||||
{
|
||||
action.performed -= self.OnInputPlayerValuePerformed;
|
||||
action.canceled -= self.OnInputPlayerValueCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnUIButtonPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
OnUIPerformed?.Invoke(context.action.name);
|
||||
}
|
||||
|
||||
private void OnUIButtonCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
OnUICanceled?.Invoke(context.action.name);
|
||||
}
|
||||
|
||||
private void OnPlayerButtonPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
var actionName = context.action.name;
|
||||
// if (actionName == "Op1")
|
||||
// {
|
||||
// OnOp1Action?.Invoke(true);
|
||||
// }
|
||||
// else if (actionName == "Op2")
|
||||
// {
|
||||
// OnOp2Action?.Invoke(true);
|
||||
// }
|
||||
|
||||
OnPlayerPerformed?.Invoke(actionName);
|
||||
}
|
||||
|
||||
private void OnPlayerButtonCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
var actionName = context.action.name;
|
||||
// if (actionName == "Op1")
|
||||
// {
|
||||
// OnOp1Action?.Invoke(false);
|
||||
// }
|
||||
// else if (actionName == "Op2")
|
||||
// {
|
||||
// OnOp2Action?.Invoke(false);
|
||||
// }
|
||||
//
|
||||
OnPlayerCanceled?.Invoke(actionName);
|
||||
}
|
||||
|
||||
private void OnInputPlayerValuePerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
OnPlayerValuePerformed?.Invoke(context);
|
||||
}
|
||||
|
||||
private void OnInputPlayerValueCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
OnPlayerValueCanceled?.Invoke(context);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public Vector2 GetMovementInput()
|
||||
{
|
||||
if (IsUIStopInput) return Vector2.zero;
|
||||
return PlayerInputControl.Player.Move?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
public Vector2 GetLookInput()
|
||||
{
|
||||
if (IsUIStopInput) return Vector2.zero;
|
||||
return PlayerInputControl.Player.Look?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
public void SendUIInput(string actionName)
|
||||
{
|
||||
OnUIPerformed?.Invoke(actionName);
|
||||
OnUICanceled?.Invoke(actionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing2~/Common/InputComponent.cs.meta
Normal file
3
Assets/Scripts/Fishing2~/Common/InputComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09132878c89a444a88421b7434394235
|
||||
timeCreated: 1756826439
|
||||
9
Assets/Scripts/Fishing2~/Common/SettingComponent.cs
Normal file
9
Assets/Scripts/Fishing2~/Common/SettingComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Fantasy.Entitas;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public class SettingComponent : Entity
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing2~/Common/SettingComponent.cs.meta
Normal file
3
Assets/Scripts/Fishing2~/Common/SettingComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c6adcf67ef545f99c590d1078a76eea
|
||||
timeCreated: 1756826460
|
||||
Reference in New Issue
Block a user