1.新建一个脚本,里面有static变量loadingPlayerList
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Assets.Scripts.Model
{internal class LoadData{public static List<PlayerModel> loadingPlayerList = new List<PlayerModel>();}
}
2.因为与MAP相关的函数实在太多,之前LOGIN USER那样写不合适,在handler文件夹下,新建一个脚本文件,MapHandler.cs
3.MessageManager中的MapHandlerFk部分如下:
public void MapHandlerFk(SocketModel model)
{Debug.Log("MapHandlerFk");switch (model.command){//这头应该是1 2 4 6 8case MapProtocol.ENTER_SRES://初始化所有玩家信息--一开始进好几个Debug.Log("MapHandler-ENTER_SRES");//没问题PlayerModel[] players= Coding<PlayerModel[]>.decode(model.message);//loadplayerlistDebug.Log(model.message);LoadData.loadingPlayerList.AddRange(players);//增加多个元素Debug.Log("当前玩家进入地图");Debug.Log(SelectMenu.nowPlayer.map);Loading(SelectMenu.nowPlayer.map);//这个是2号 没有问题,到现在 为止 还没有涉及到动画break;case MapProtocol.ENTER_BRO://其他玩家进入场景--每次进一个Debug.Log("MapHandler-ENTER_BRO");//没问题PlayerModel player = Coding<PlayerModel>.decode(model.message);LoadData.loadingPlayerList.Add(player);//增加多个元素//createplayerMapHandler.getInstance().createPlayer(player);//createPlayer(player);break;}}
4.在MapHandler.cs中所有的函数如下:
public void createPlayer(PlayerModel model){playerList.Add(model.id, model);//增加单个新角色-Assets.Model.Vector3 point = model.point;//见多自然就会了Assets.Model.Vector4 rotation = model.rotation;//下面大概率是要实例化了--通过预组件生成实例对象GameObject GO = (GameObject)GameObject.Instantiate(playerProfabs[model.job], new Vector3((float)point.X, (float)point.Y, (float)point.Z), new Quaternion((float)rotation.X, (float)rotation.Y, (float)rotation.Z, (float)rotation.W));GO.name = model.id;GO.tag = "Player";GO.transform.position = new Vector3(188f, 10f, 88f);//set position;playergoList.Add(model.id, GO);实例对象 数组 goGO.BroadcastMessage("InfoInit", model);//这个叫唤了也不一定收得到if (model.id == GameInfo.myModel.id){//make sure our camera wouln't look at other players.//GameObject tg= GameObject.Find ("Root");GO.BroadcastMessage("setTarget", GO);////BroadcastMessage ("setTarget",tg);//BroadcastMessage ("InfoInit",model);}}
到此为止没有错误了