unity学习(29)——GameInfo角色信息

1.把GameInfo.cs PlayerModel.cs Vector3.cs Vector4.cs PlayerStateConstans.cs GameState.cs依次粘到model文件夹中,此时项目没有错误,如下图所示;

对应处所修改的代码如下:

cs 复制代码
case LoginProtocol.LOGIN_SRES://1
{
     Debug.Log("成功登录,要进行场景跳转了");
        //继承一些信息,来自loginhadler里面的,有原代码很省事的--把message对住就没问题了
        StringDTO dto = Coding<StringDTO>.decode(model.message);//基本就完全等于是我自己写的
        Debug.Log("dto.value:"+ dto.value);
        if (dto.value == null || dto.value == string.Empty)//登录如果失败啥都不做就可以了
        {
            Debug.Log("登陆失败!");
            //顺便修改一下对应文字即可
            TMP_Text c = GameObject.FindWithTag("logText").GetComponent<TMP_Text>(); ;//得到两个Text对象
            c.text = "登录失败";
        }
        else
        {
            TMP_Text d = GameObject.FindWithTag("logText").GetComponent<TMP_Text>(); ;//得到两个Text对象
            d.text = "登录成功";
            Debug.Log("成功登录,要进行场景跳转了");
            GameInfo.ACC_ID = dto.value;//静态类起到全局效果
            GameInfo.GAME_STATE = GameState.LOADING;
            BroadcastMessage("Loading", 1);
            Debug.Log("等待下一次挑战");
        }    
        break;
}
cs 复制代码
public class GameInfo
{
	public static int GAME_STATE=0;
	public static string ACC_ID="";
	public static float LOAD_PRORESS=0f;
	public static int LAST_STATE=0;
	public static PlayerModel selectModel;
	public static PlayerModel myModel;
	public static int PLAYER_STATE=PlayerStateConstans.IDLE;
}

类中static静态变量,可以直接起到全局对象(变量)的作用(不用再实例化对象了,此时类更像是一个全局结构体),敌人和玩家是不同的模型,这点我之前写panda3d时也经历过,很清楚。

实测,可以有区别的进入"成功"和"失败"状态。

这个逆向出来的服务器处理"重复登陆","错误登录"时做的很好,而且现就可以做到"多开"。

相关推荐
西岸行者2 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
悠哉悠哉愿意2 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
别催小唐敲代码2 天前
嵌入式学习路线
学习
毛小茛2 天前
计算机系统概论——校验码
学习
babe小鑫2 天前
大专经济信息管理专业学习数据分析的必要性
学习·数据挖掘·数据分析
winfreedoms2 天前
ROS2知识大白话
笔记·学习·ros2
在这habit之下2 天前
Linux Virtual Server(LVS)学习总结
linux·学习·lvs
我想我不够好。2 天前
2026.2.25监控学习
学习
im_AMBER2 天前
Leetcode 127 删除有序数组中的重复项 | 删除有序数组中的重复项 II
数据结构·学习·算法·leetcode
CodeJourney_J2 天前
从“Hello World“ 开始 C++
c语言·c++·学习