当前位置: 首页 > article >正文

unity学习(60)——选择角色界面--MapHandler2-MapHandler.cs

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 8
        case MapProtocol.ENTER_SRES://初始化所有玩家信息--一开始进好几个
            Debug.Log("MapHandler-ENTER_SRES");//没问题
            PlayerModel[] players= Coding<PlayerModel[]>.decode(model.message);
            //loadplayerlist
            Debug.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);//增加多个元素
            //createplayer
            MapHandler.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);实例对象 数组 go
     GO.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);
     }
 }

到此为止没有错误了


http://www.kler.cn/a/271229.html

相关文章:

  • spring boot集成redis实现共享存储session
  • C语言 内存函数
  • 【C语言】整型提升与算术转换
  • vue3新功能-Teleport
  • cool 中的Midway ----node.js的TypeORM的使用
  • 算法中出现的一些报错及其处理办法
  • 贪心算法(两个实例)
  • 纽约时报起诉OpenAI和微软将决定未来LLM的发展
  • HTML
  • 统一异常处理ControllerAdvice
  • Jmeter+Ant 接口自动化环境配置指南
  • RK3568平台开发系列讲解(基础篇)内核是如何发送事件到用户空间
  • git pull 报错: 在签出前,请清理存储库工作树
  • ChatGPT 遇到对手:Anthropic Claude 语言模型的崛起
  • EXCEL+PYTHON学习3
  • 【2024-03-12】设计模式之模板模式的理解
  • 剑指offer面试题36 数组中的逆序对
  • rust学习笔记(1-7)
  • 【类脑智能】脑网络通信模型分类及量化指标(附思维导图)
  • springboot基于spring boot的在线答题微信小程序