结构大修改,改成朴实无华的结构,不过度架构。能跑就行

This commit is contained in:
2025-12-23 00:09:39 +08:00
parent 384f11f620
commit 3d14085920
2837 changed files with 149714 additions and 1100 deletions

View File

@@ -0,0 +1,107 @@
using System.Collections.Generic;
using Fantasy;
using Fantasy.Async;
using NBF.Fishing2;
using RootMotion.FinalIK;
using Log = NBC.Log;
namespace NBF
{
public class Fishing
{
private List<MapUnitInfo> _units;
private List<FPlayer> _players = new List<FPlayer>();
private static Fishing _instance;
public static Fishing Instance
{
get
{
_instance ??= new Fishing();
return _instance;
}
}
public async FTask<bool> Go(int mapId, string roomCode = "")
{
if (mapId == 0)
{
Log.Warning("账号没有进入过地图,进入新手引导地图");
mapId = 99;
}
var root = Game.Main;
var response = (G2C_EnterMapResponse)await Net.Call(new C2G_EnterMapRequest()
{
MapId = mapId,
RoomCode = roomCode
});
Log.Info($"进入地图请求返回={response.ErrorCode}");
LoadingPanel.Show();
await ChangeMap(response.MapId, response.RoomCode, response.Units);
LoadingPanel.Hide();
return true;
}
public async FTask ChangeMap(int mapId, string roomCode, List<MapUnitInfo> units)
{
_units = units;
var sceneName = "Map1";
//加载场景==
await SceneHelper.LoadScene(sceneName);
LoadAllUnit();
// var oldMap = Game.Main.GetComponent<GenericPoser.Map>();
// await oldMap.UnLoadMap();
//
// var map = Game.Main.AddComponent<GenericPoser.Map>();
// map.MapId = mapId;
// map.RoomCode = roomCode;
// map.SelfId = Game.SelfId;
// foreach (var mapUnitInfo in units)
// {
// map.CreateMapUnit(mapUnitInfo);
// }
//
// await map.LoadMap();
}
/// <summary>
/// 加载所有unit单位
/// </summary>
public void LoadAllUnit()
{
foreach (var unit in _units)
{
CreateUnit(unit);
}
//
// var cameraComponent = self.Scene.GetComponent<CameraComponent>();
// if (cameraComponent != null)
// {
// cameraComponent.Mode = CameraShowMode.FPP;
// }
}
private void CreateUnit(MapUnitInfo unit)
{
var gameObject = PrefabsHelper.CreatePlayer(SceneSettings.Instance.Node);
var player = gameObject.GetComponent<FPlayer>();
player.InitData(unit);
_players.Add(player);
}
/// <summary>
/// 卸载旧场景
/// </summary>
public async FTask UnLoadMap()
{
await FTask.CompletedTask;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0afcee9eb5f848e08b2fae2cc673b6d8
timeCreated: 1766414593

View File

@@ -0,0 +1,7 @@
namespace NBF
{
public class FishingMap
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c361da1bcda647eb96fa27af894d2a7a
timeCreated: 1766417823

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b4177c0c4cf94787b06ec92973ba4722
timeCreated: 1766412118

View File

@@ -0,0 +1,69 @@
using Assets.Scripts.Entity;
using Assets.Scripts.Hotfix;
using Fantasy;
using Fantasy.Async;
using Fantasy.Network;
using NBC;
using NBF.Fishing2;
using Newtonsoft.Json;
using Log = NBC.Log;
namespace NBF
{
public static class LoginHelper
{
private static Session _session;
public static async FTask Login(string account)
{
_session = Net.CreateSession("127.0.0.1:20001");
// _session.Scene.AddComponent<UnitUnityComponent>();
var acc = account;
// 发送登录的请求给服务器
var response = (A2C_LoginResponse)await Net.Call(new C2A_LoginRequest()
{
Username = acc,
Password = acc,
LoginType = 1
});
if (response.ErrorCode != 0)
{
Log.Error($"登录发生错误{response.ErrorCode}");
return;
}
if (!Game.Main.GetComponent<JWTParseComponent>().Parse(response.ToKen, out var payload))
{
return;
}
// 根据ToKen返回的Address登录到Gate服务器
_session = Net.CreateSession(payload.Address);
// 发送登录请求到Gate服务器
var loginResponse = (G2C_LoginResponse)await Net.Call(new C2G_LoginRequest()
{
ToKen = response.ToKen
});
if (loginResponse.ErrorCode != 0)
{
Log.Error($"登录发生错误{loginResponse.ErrorCode}");
return;
}
// var role = Game.Main.AddComponent<Role>(loginResponse.RoleId);
RoleModel.Instance.Id = loginResponse.RoleId;
Log.Info($"登录到Gate服务器成功ErrorCode:{loginResponse.ErrorCode}");
await RoleModel.Instance.GetRoleInfo();
Log.Info(
$"获取角色信息成功roleId={RoleModel.Instance.Id} Room={RoleModel.Instance.RoomCode} RoleInfo={JsonConvert.SerializeObject(RoleModel.Instance.Info)}");
//获取背包数据
await RoleModel.Instance.GetBagInfo();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 031ed023449844cdb9d6c4eb5d7fee90
timeCreated: 1755698636

View File

@@ -0,0 +1,115 @@
// using System;
// using System.Collections.Generic;
// using Fantasy;
// using Fantasy.Async;
// using NBC;
// using Fantasy.Entitas;
// using UnityEngine;
// using Log = NBC.Log;
// using Object = System.Object;
//
// namespace NBF.Fishing2
// {
// public static class MapHelper
// {
// #region Map
//
// /// <summary>
// /// 开始进入地图
// /// </summary>
// public static async FTask<int> EnterMap(int mapId, string roomCode = "")
// {
// try
// {
// var root = Game.Main;
//
// var response = (G2C_EnterMapResponse)await Net.Call(new C2G_EnterMapRequest()
// {
// MapId = mapId,
// RoomCode = roomCode
// });
// Log.Info($"进入地图请求返回={response.ErrorCode}");
//
// await ChangeMap(response.MapId, response.RoomCode, response.Units);
// // 等待场景切换完成
// // await root.GetComponent<ObjectWait>().Wait<Wait_SceneChangeFinish>();
// Log.Info($"等待场景切换结束");
// await root.EventComponent.PublishAsync(new EnterMapFinish());
// LoadingPanel.Hide();
// }
// catch (Exception e)
// {
// Log.Error(e);
// return ErrorCode.Error;
// }
//
// return ErrorCode.Success;
// }
//
//
// public static async FTask ChangeMap(int mapId, string roomCode, List<MapUnitInfo> units)
// {
// LoadingPanel.Show();
//
// var oldMap = App.Main.GetComponent<Map>();
// await oldMap.UnLoadMap();
//
// var map = App.Main.AddComponent<Map>();
// map.MapId = mapId;
// map.RoomCode = roomCode;
// map.SelfId = Game.SelfId;
// foreach (var mapUnitInfo in units)
// {
// map.CreateMapUnit(mapUnitInfo);
// }
//
// await map.LoadMap();
// }
//
//
// /// <summary>
// /// 卸载旧场景
// /// </summary>
// /// <param name="self"></param>
// public static async FTask UnLoadMap(this Map self)
// {
// await FTask.CompletedTask;
// }
//
// public static async FTask LoadMap(this Map self)
// {
// var sceneName = "Map1";
// //加载场景==
// await SceneHelper.LoadScene(sceneName);
// await self.LoadAllUnit();
// FishingPanel.Show();
//
// // 通知等待场景切换的协程
// App.Main.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());
// }
//
// #endregion
//
// #region Unit
//
// /// <summary>
// /// 加载所有unit单位
// /// </summary>
// /// <param name="self"></param>
// public static async FTask LoadAllUnit(this Map self)
// {
// foreach (var (_, unit) in self.Units)
// {
// await unit.CreateView();
// }
//
// var cameraComponent = self.Scene.GetComponent<CameraComponent>();
// if (cameraComponent != null)
// {
// cameraComponent.Mode = CameraShowMode.FPP;
// }
// }
//
// #endregion
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dfc04c7d83084b7784cb7cf69dde1be6
timeCreated: 1756132207

View File

@@ -0,0 +1,43 @@
using Fantasy;
using NBC;
using NBF.Utils;
using UnityEngine;
namespace NBF.Fishing2
{
public static class PrefabsHelper
{
public static GameObject LoadPrefab(string path, Transform parent = null)
{
var prefab = Resources.Load<GameObject>(path);
return parent == null ? Object.Instantiate(prefab) : Object.Instantiate(prefab, parent);
}
/// <summary>
/// 创建角色预制体
/// </summary>
/// <param name="parent"></param>
/// <param name="modelName"></param>
/// <returns></returns>
public static GameObject CreatePlayer(Transform parent, string modelName = "Player")
{
var model = LoadPrefab($"Prefabs/Player/{modelName}", parent);
return model;
}
/// <summary>
/// 创建物品预制体
/// </summary>
/// <param name="config"></param>
/// <param name="isPreview">是否预览模式</param>
/// <returns></returns>
public static GameObject CreateItem(ItemConfig config, bool isPreview = false)
{
//创建主物体
var mainObject = LoadPrefab(config.GetFullModelPath());
//创建配件
return mainObject;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 18ffcf16981040b2a88990281adcb4ac
timeCreated: 1756451102

View File

@@ -0,0 +1,39 @@
using System;
using Fantasy.Async;
using NBC;
using UnityEngine.SceneManagement;
namespace NBF
{
public static class SceneHelper
{
public static async FTask LoadScene(string sceneName)
{
try
{
Game.Main.EventComponent.Publish(new SceneChangeStart());
LoadingPanel.Show();
var asyncOperation = SceneManager.LoadSceneAsync(sceneName);
if (asyncOperation == null) throw new Exception($"Scene not found,name={sceneName}");
while (true)
{
await Game.Main.EventComponent.PublishAsync(new LoadingProgress()
{
Progress = asyncOperation.progress
});
LoadingPanel.SetProgress(asyncOperation.progress);
// 等待0.5秒后执行下面的逻辑。
await Game.Main.TimerComponent.Net.WaitAsync(500);
if (asyncOperation.isDone)
{
break;
}
}
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d4a2e9c0ac6d4faabbec4bccdb7a2917
timeCreated: 1756367987

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1228e92e0b3744cdb44cd5144a12b241
timeCreated: 1765283747

View File

@@ -0,0 +1,153 @@
using RootMotion.FinalIK;
using UnityEngine;
namespace NBF
{
public class PlayerIK : MonoBehaviour
{
public enum UpdateType
{
Update = 0,
FixedUpdate = 1,
LateUpdate = 2,
Default = 3
}
public UpdateType UpdateSelected;
[SerializeField] private Transform _LeftHandTransform;
private LookAtIK _LookAtIK;
private AimIK _AimIK;
private FullBodyBipedIK _FullBodyIK;
private ArmIK _ArmIK;
private bool _isLeftHandEnabled;
private bool _isRightHandEnabled;
public bool isAimEnabled;
private bool _isFishingLeftArmEnabled;
[SerializeField] private float transitionWeightTimeScale = 1f;
public Transform CurrentTarget => _FullBodyIK.solver.leftHandEffector.target;
public Transform LeftHandTransform => _LeftHandTransform;
private void Awake()
{
_LookAtIK = GetComponent<LookAtIK>();
_AimIK = GetComponent<AimIK>();
_FullBodyIK = GetComponent<FullBodyBipedIK>();
_ArmIK = GetComponent<ArmIK>();
SetAimIK(enabled: false);
}
public void SetBipedIK(bool enabled)
{
}
public void SetFishingLeftArm(bool enabled)
{
_isFishingLeftArmEnabled = enabled;
}
public void SetFishingLeftArm(bool enabled, Transform target)
{
_isFishingLeftArmEnabled = enabled;
_ArmIK.solver.arm.target = target;
}
public void SetBipedLeftHandIK(bool enabled, bool instant = false)
{
_isLeftHandEnabled = enabled;
if (instant)
{
_FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
}
}
public void SetBipedRightHandIK(bool enabled, bool instant = false)
{
_isRightHandEnabled = enabled;
if (instant)
{
_FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
}
}
public void SetBipedLeftHandIK(bool enabled, Transform target, bool instant = false)
{
_isLeftHandEnabled = enabled;
_FullBodyIK.solver.leftHandEffector.target = target;
if (instant)
{
_FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
}
}
public void SetBipedRightHandIK(bool enabled, Transform target, bool instant = false)
{
_isRightHandEnabled = enabled;
_FullBodyIK.solver.rightHandEffector.target = target;
if (instant)
{
_FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
}
}
public void SetAimIK(bool enabled)
{
isAimEnabled = enabled;
}
private void Update()
{
if (UpdateSelected == UpdateType.Update)
{
IKUpdateHandler();
}
}
private void FixedUpdate()
{
if (UpdateSelected == UpdateType.FixedUpdate)
{
IKUpdateHandler();
}
}
private void LateUpdate()
{
if (UpdateSelected == UpdateType.LateUpdate)
{
IKUpdateHandler();
}
}
private void IKUpdateHandler()
{
_AimIK.UpdateSolverExternal();
_LookAtIK.UpdateSolverExternal();
_FullBodyIK.UpdateSolverExternal();
_FullBodyIK.solver.Update();
_AimIK.solver.IKPositionWeight = Mathf.MoveTowards(_AimIK.solver.IKPositionWeight, isAimEnabled ? 1f : 0f,
Time.deltaTime * transitionWeightTimeScale);
_FullBodyIK.solver.leftArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.leftArmMapping.weight,
_isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_FullBodyIK.solver.rightArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.rightArmMapping.weight,
_isRightHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_FullBodyIK.solver.IKPositionWeight = Mathf.MoveTowards(_FullBodyIK.solver.IKPositionWeight,
_isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_ArmIK.solver.IKPositionWeight = Mathf.MoveTowards(_ArmIK.solver.IKPositionWeight,
_isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_ArmIK.solver.IKRotationWeight = Mathf.MoveTowards(_ArmIK.solver.IKRotationWeight,
_isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cb36ecc5b1784d948837600cf18808cd
timeCreated: 1765121426

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4f89752d44de4cf798a163bf6a554e8e
timeCreated: 1766419447

View File

@@ -0,0 +1,19 @@
using Fantasy;
using UnityEngine;
namespace NBF
{
public class FPlayer : MonoBehaviour
{
public MapUnitInfo Unit { get; private set; }
public Transform Root;
public Transform Eye;
public Transform FppLook;
public Transform IK;
public void InitData(MapUnitInfo unit)
{
Unit = unit;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 625346c970c542bab9f3a36f78720a77
timeCreated: 1766419452