首次提交
This commit is contained in:
67
Assets/Scripts/Fishing/Helper/LoginHelper.cs
Normal file
67
Assets/Scripts/Fishing/Helper/LoginHelper.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Helper/LoginHelper.cs.meta
Normal file
3
Assets/Scripts/Fishing/Helper/LoginHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 031ed023449844cdb9d6c4eb5d7fee90
|
||||
timeCreated: 1755698636
|
||||
115
Assets/Scripts/Fishing/Helper/MapHelper.cs
Normal file
115
Assets/Scripts/Fishing/Helper/MapHelper.cs
Normal 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
|
||||
// }
|
||||
// }
|
||||
3
Assets/Scripts/Fishing/Helper/MapHelper.cs.meta
Normal file
3
Assets/Scripts/Fishing/Helper/MapHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfc04c7d83084b7784cb7cf69dde1be6
|
||||
timeCreated: 1756132207
|
||||
48
Assets/Scripts/Fishing/Helper/PrefabsHelper.cs
Normal file
48
Assets/Scripts/Fishing/Helper/PrefabsHelper.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Fantasy;
|
||||
using NBC;
|
||||
using NBC.Asset;
|
||||
using NBF.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public static class PrefabsHelper
|
||||
{
|
||||
public static GameObject LoadPrefab(string path, Transform parent = null)
|
||||
{
|
||||
var prefab = Assets.Load<GameObject>(path);
|
||||
if (prefab == null)
|
||||
{
|
||||
|
||||
}
|
||||
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($"Assets/ResRaw/Prefabs/Player/{modelName}.prefab", parent);
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建物品预制体
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="isPreview">是否预览模式</param>
|
||||
/// <returns></returns>
|
||||
public static GameObject CreateItem(cfg.Item config, bool isPreview = false)
|
||||
{
|
||||
//创建主物体
|
||||
var mainObject = LoadPrefab(config.GetFullModelPath());
|
||||
//创建配件
|
||||
|
||||
return mainObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Helper/PrefabsHelper.cs.meta
Normal file
3
Assets/Scripts/Fishing/Helper/PrefabsHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18ffcf16981040b2a88990281adcb4ac
|
||||
timeCreated: 1756451102
|
||||
39
Assets/Scripts/Fishing/Helper/SceneHelper.cs
Normal file
39
Assets/Scripts/Fishing/Helper/SceneHelper.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Helper/SceneHelper.cs.meta
Normal file
3
Assets/Scripts/Fishing/Helper/SceneHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4a2e9c0ac6d4faabbec4bccdb7a2917
|
||||
timeCreated: 1756367987
|
||||
Reference in New Issue
Block a user