cfclient/Managers/Battle.cs
2024-05-23 08:55:13 +08:00

90 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Protobuf;
using UnityEngine;
using LuaFramework;
class Battle
{
private JoinInfo joinInfo;
private Net.ClientNet conn;
private int netMapId = 0;
private int netMyselfUniId = 0;
private string netRoomUuid;
private Mt.Map mapMeta;
public Battle(JoinInfo joinInfo)
{
var rootObj = new GameObject();
rootObj.AddComponent(typeof(Net.ClientNet));
this.conn = rootObj.GetComponent<Net.ClientNet>();
this.conn.Init("ws://192.168.100.21:7601/websocket?server_id=2");
this.conn.OnOpen += (Net.ClientNet conn) =>
{
var joinMsg = new battle.cs.CMJoin();
joinMsg.AccountId = joinInfo.account_id;
joinMsg.SessionId = joinInfo.session_id;
joinMsg.TeamUuid = joinInfo.team_uuid;
joinMsg.PayloadData = joinInfo.payload_data;
this.conn.SendMsg(joinMsg);
};
this.conn.Open();
this.conn.msgHandler.RegisterHandler((battle.cs.SMJoinedNotify msg) =>
{
});
this.conn.msgHandler.RegisterHandler((battle.cs.SMMapInfo msg) =>
{
this.SMMapInfo(msg);
});
this.conn.msgHandler.RegisterHandler((battle.cs.SMUpdate msg) =>
{
this.SMUpdate(msg);
});
}
private void SMMapInfo(battle.cs.SMMapInfo msg)
{
this.netMapId = msg.MapId;
this.netMyselfUniId = msg.PlayerId;
this.netRoomUuid = msg.RoomUuid;
this.mapMeta = Mt.Table.Map.GetById(this.netMapId);
GameObject fightRootObject = new GameObject("fight");
{
fightRootObject.transform.parent = LuaHelper.GetGameManager().m_pGameMap.transform;
fightRootObject.layer = CUtil.WorldMapLayer_0_31;
}
GameObject mapObj = new GameObject("map");
{
mapObj.transform.parent = fightRootObject.transform;
mapObj.layer = CUtil.WorldMapLayer_0_31;
TransformExtension.localPosition(mapObj.transform, 0, 0, 0);
TransformExtension.localScale(mapObj.transform, 1, 1, 1);
}
var mapBase = LuaHelper.GetResManager().LoadPrefab<GameObject>(this.mapMeta.asset_name, "Data/model/mapterrain/", "model/mapterrain");
var t = CUtil.AddChild(mapObj, mapBase, true);
{
TransformExtension.localEulerAngles(t.transform, 0, 0, 0);
TransformExtension.localPosition(t.transform, 0, 0, 0);
}
{
var terrainName = "l_" + this.mapMeta.asset_name;
var terrainObj = LuaHelper.GetResManager().LoadPrefab<GameObject>(
terrainName, "Data/model/mapterrain/", "model/mapterrain");
CUtil.AddChild(t, terrainObj, true);
TransformExtension.localEulerAngles(terrainObj.transform, 0, 0, 0);
TransformExtension.localPosition(terrainObj.transform, 0, 0, 0);
}
}
private void SMUpdate(battle.cs.SMUpdate msg)
{
}
}