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

unity学习(57)——选择角色界面--删除角色2

1.客户端添加点击按钮所触发的事件,在selectMenu界面中增加myDelete函数,当点击“删除角色”按钮时触发该函数的内容。

public void myDelete()
{string message = nowPlayer.id;//string m = Coding<StringDTO>.encode(message);NetWorkScript.getInstance().sendMessage(Protocol.USER, 0, 6, message);Debug.Log(message);
}

2.服务器也成功接受到来自客户端的内容,这里有瑕疵,此时是明文通信。

3.完善remove函数中的内容,这个大改了,从最终的测试结果来看是成功的:

public PlayerModel[] remove(string accId, string playerId)
{//确实到这里的,但是逻辑需要大改Console.WriteLine("remove:");Console.WriteLine(accId);Console.WriteLine(playerId);if (this.userPlayerIds.ContainsKey(accId))//当前账号是否注册{List<string> stringList1;this.userPlayerIds.TryGetValue(accId, out stringList1);//得到当前账号下所有的角色信息if (stringList1 != null && stringList1.Contains(playerId)){stringList1.Remove(playerId);//删除或者怎加以后还要写入,类似的操作不久前刚做过的//借鉴之前put中的相关操作,其实可以很快完成的//写userPlayerIds.txt//List<string> stringList;List<string> stringList_out;this.userPlayerIds.TryRemove(accId, out stringList_out);//删旧的bool ur=this.userPlayerIds.TryAdd(accId, stringList1);//写新的--//原来账号下三个角色,此时应该就剩下2个了if (ur)//这次应该没问题了{StreamWriter file = new StreamWriter("userPlayerIds.txt");string json = JsonConvert.SerializeObject(this.userPlayerIds);Console.WriteLine("userPlayerIds.TryAdd:" + json);file.Write(json);file.Close();Console.WriteLine("userPlayerIds删除完成");}//到此位置删除 并 文件写入 userPlayerIds//下面删除players.txt中的内容bool ur1=this.players.TryRemove(playerId, out PlayerModel _);//这里直接删就行,不用删完再加了if (ur1)//这次应该没问题了{StreamWriter file = new StreamWriter("players.txt");string json = JsonConvert.SerializeObject(this.players);Console.WriteLine("userPlayerIds.TryAdd:" + json);file.Write(json);file.Close();Console.WriteLine("players删除完成");}}}//返回playermodel数组--自己改的List<string> stringList;this.userPlayerIds.TryGetValue(accId, out stringList);//创建第一个角色,这里是空的--之前注册角色的id(PlayerIds)--专属名词调试几遍就会了if (stringList == null)return (PlayerModel[])null;PlayerModel[] playerModelArray = new PlayerModel[stringList.Count];for (int index = 0; index < stringList.Count; ++index)this.players.TryGetValue(stringList[index], out playerModelArray[index]);return playerModelArray;}

4.返回值的部分也需要做对应的修改:command用1,直接更新列表

 5.最后成功删除角色:

6.补充

http://www.lryc.cn/news/319739.html

相关文章:

  • Flutter:构建美观应用的跨平台方案
  • 【深度学习模型移植】用torch普通算子组合替代torch.einsum方法
  • 鸿蒙 Harmony 初体验
  • Jmeter+ant,ant安装与配置
  • 【MySQL基础】MySQL基础操作三
  • 【K8s】肿么办??Kubernetes Secrets并不是Secret哟!!
  • 数星星 刷题笔记 (树状数组)
  • Windows→Linux,本地同步到服务器
  • Pycharm连接远程服务器Anoconda中的虚拟环境
  • 无人机自动返航算法实现与优化
  • 切面条-蓝桥杯?-Lua 中文代码解题第1题
  • WebRTC:真正了解 RTP 和 RTCP
  • vue实现双向绑定原理深度解析
  • C语言 —— memeove函数的模拟实现
  • <el-tab>样式自定义——一个可以触类旁通的小例子
  • XDP学习笔记
  • JavaScript进阶:js的一些学习笔记-4
  • 【可能是全网最丝滑的LangChain教程】三、快速入门LLMChain
  • Oracle Primavera Analytics 是什么,与P6的关系?
  • 在 Amazon Bedrock 上使用 Anthropic Claude 系统 Prompt
  • 【LeetCode】动态规划--题目练习
  • 【LeetCode热题100】101. 对称二叉树(二叉树)
  • VLC抓取m3u8视频
  • 聊聊Python都能做些什么
  • JavaWeb06-MVC和三层架构
  • MySQL数据库实现增删改查基础操作
  • PCM和I2S区别
  • 大模型笔记:吴恩达 ChatGPT Prompt Engineering for Developers(1) prompt的基本原则和策略
  • 设计模式 — — 单例模式
  • C++:菱形继承与虚继承