Unity3D仿星露谷物语开发57之保存库存信息到文件

1、目标

保存下面库存栏中信息到文件中。

2、修改SceneSave.cs脚本

添加2行代码:

3、修改InventoryManager对象

添加Generate GUID组件。

4、修改InventoryManager.cs脚本

添加继承自ISaveable

添加属性信息:

    private string _iSaveableUniqueID;public string ISaveableUniqueID { get { return _iSaveableUniqueID; } set { _iSaveableUniqueID = value; } }private GameObjectSave _gameObjectSave;public GameObjectSave GameObjectSave { get { return _gameObjectSave; } set { _gameObjectSave = value; } }private UIInventoryBar inventoryBar;

在Awake()方法中添加2行代码:

添加如下几个方法:

 private void OnDisable(){ISaveableDeregister();}private void OnEnable(){ISaveableRegister();}private void Start()
{inventoryBar = FindObjectOfType<UIInventoryBar>();
}public void ISaveableRegister(){SaveLoadManager.Instance.iSaveableObjectList.Add(this);}public void ISaveableDeregister(){SaveLoadManager.Instance.iSaveableObjectList.Remove(this);}public GameObjectSave ISaveableSave(){// Create new scene saveSceneSave sceneSave = new SceneSave();// Remove any existing scene save for persistent scene for this gameobjectGameObjectSave.sceneData.Remove(Settings.PersistentScene);// Add inventory lists array to persistent scene savesceneSave.listInvItemArray = inventoryLists;// Add inventory list capacity array to persistent scene savesceneSave.intArrayDictionary = new Dictionary<string, int[]>();sceneSave.intArrayDictionary.Add("inventoryListCapacityArray", inventoryListCapacityIntArray);// Add scene save for gameobjectGameObjectSave.sceneData.Add(Settings.PersistentScene, sceneSave);return GameObjectSave;}public void ISaveableLoad(GameSave gameSave){if(gameSave.gameObjectData.TryGetValue(ISaveableUniqueID, out GameObjectSave gameObjectSave)){GameObjectSave = gameObjectSave;// Need to find inventory lists - start by trying to locate saveScene for game objectif(gameObjectSave.sceneData.TryGetValue(Settings.PersistentScene, out SceneSave sceneSave)){// list inv items array exists for persistent sceneif(sceneSave.listInvItemArray != null){inventoryLists = sceneSave.listInvItemArray;// Send events that inventory has been updatedfor(int i = 0; i < (int)InventoryLocation.count; i++){EventHandler.CallInventoryUpdatedEvent((InventoryLocation)i, inventoryLists[i]);}// Clear any items player was carryingPlayer.Instance.ClearCarriedItem();// Clear any highlights on inventory barinventoryBar.ClearHighlightOnInventorySlots();}// int array dictionary exists for sceneif(sceneSave.intArrayDictionary != null && sceneSave.intArrayDictionary.TryGetValue("inventoryListCapacityArray", out int[] inventoryCapacityArray)){inventoryListCapacityIntArray = inventoryCapacityArray;}}}}public void ISaveableStoreScene(string sceneName){// Nothing required here since the inventory manager is on a persistent scene;}public void ISaveableRestoreScene(string sceneName){// Nothing required here since the inventory manager is on a persistent scene;}

5、运行游戏

角色收集的item放到库存栏中,save game后退出游戏,重新进入游戏后load game,库存栏中的信息保持不变。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/news/907762.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

测量3D翼片的距离与角度

1&#xff0c;目的。 测量3D翼片的距离与角度。说明&#xff1a; 标注A 红色框选的区域即为翼片&#xff0c;本示例的3D 对象共有3个翼片待测。L1与L2的距离、L1与L2的角度即为所求的翼片距离与角度。 2&#xff0c;原理。 使用线结构光模型&#xff08;标定模式&#xff0…

深入理解 SQL 的 JOIN 查询:从基础到高级的第一步

在处理数据库时&#xff0c;我们常常需要从多个表中提取数据。比如想知道一个城市的天气情况&#xff0c;同时又想知道这个城市的具体位置。这就需要将 weather 表和 cities 表结合起来查询。这种操作在 SQL 中被称为 JOIN 查询。 现在看下两种表的情况 1.weather 表&#xff…

上传头像upload的简易方法,转base64调接口的

1.首页使用el-image显示数据&#xff0c;用的是转base64后端返给的 <el-table-column prop"avatar" align"center" label"头像"><template #default"scope"><el-image style"height: 40px;width: 40px;" :sr…

[AD] CrownJewel-1 Logon 4799+vss-ShadowCopy+NTDS.dit/SYSTEM+$MFT

QA QA攻擊者可以濫用 vssadmin 實用程式來建立卷影快照&#xff0c;然後提取 NTDS.dit 等敏感檔案來繞過安全機制。確定卷影複製服務進入運作狀態的時間。2024-05-14 03:42:16建立卷影快照時&#xff0c;磁碟區複製服務會使用機器帳戶驗證權限並列舉使用者群組。找到卷影複製過…

rtpmixsound:实现音频混音攻击!全参数详细教程!Kali Linux教程!

简介 一种将预先录制的音频与指定目标音频流中的音频&#xff08;即 RTP&#xff09;实时混合的工具。 一款用于将预先录制的音频与指定目标音频流中的音频&#xff08;即 RTP&#xff09;实时混合的工具。该工具创建于 2006 年 8 月至 9 月之间。该工具名为 rtpmixsound。它…

GitHub 趋势日报 (2025年05月28日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 2379 agenticSeek 1521 computer-science 841 n8n 577 langflow 351 qlib 282 skt…

threejsPBR材质与纹理贴图

1. PBR材质简介 本节课没有具体的代码&#xff0c;就是给大家科普一下PBR材质&#xff0c;所谓PBR就是&#xff0c;基于物理的渲染(physically-based rendering)。 Three.js提供了两个PBR材质相关的APIMeshStandardMaterial和MeshPhysicalMaterial,MeshPhysicalMaterial是Mes…

Android 12系统源码_多屏幕(四)自由窗口模式

一、小窗模式 1.1 小窗功能的开启方式 开发者模式下开启小窗功能 adb 手动开启 adb shell settings put global enable_freeform_support 1 adb shell settings put global force_resizable_activities 11.2 源码配置 copy file # add for freedom PRODUCT_COPY_FILES …

C# 将HTML文档、HTML字符串转换为图片

在.NET开发中&#xff0c;将HTML内容转换为图片的需求广泛存在于报告生成、邮件内容存档、网页快照等场景。Free Spire.Doc for .NET作为一款免费的专业文档处理库&#xff0c;无需Microsoft Word依赖&#xff0c;即可轻松实现这一功能。本文将深入解析HTML文档和字符串转图片两…

【HTML-15.2】HTML表单按钮全面指南:从基础到高级实践

表单按钮是网页交互的核心元素&#xff0c;作为用户提交数据、触发操作的主要途径&#xff0c;其重要性不言而喻。本文将系统性地介绍HTML表单按钮的各种类型、使用场景、最佳实践以及高级技巧&#xff0c;帮助开发者构建更高效、更易用的表单交互体验。 1. 基础按钮类型 1.1…

吴恩达MCP课程(4):connect_server_mcp_chatbot

目录 完整代码代码解释1. 导入和初始化2. 类型定义3. MCP_ChatBot 类初始化4. 查询处理 (process_query)5. 服务器连接管理6. 核心特性总结 示例 完整代码 原课程代码是用Anthropic写的&#xff0c;下面代码是用OpenAI改写的&#xff0c;模型则用阿里巴巴的模型做测试 .env 文…

C++内存学习

引入 在实例化对象时&#xff0c;不管是编译器还是我们自己&#xff0c;会使用构造函数给成员变量一个合适的初始值。 但是经过构造函数之后&#xff0c;我们还不能将其称为成员变量的初始化&#xff1a; 构造函数中的语句只能称为赋初值&#xff0c;而不能称作初始化 因为初…

MySQL 大战 PostgreSQL

一、底层架构对比 ​​维度​​​​MySQL​​​​PostgreSQL​​​​存储引擎​​多引擎支持&#xff08;InnoDB、MyISAM等&#xff09;单一存储引擎&#xff08;支持扩展如Zheap、Zedstore&#xff09;​​事务实现​​基于UNDO日志的MVCC基于堆表(Heap)的MVCC​​锁机制​​…

基于FPGA的二叉决策树cart算法verilog实现,训练环节采用MATLAB仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 5.算法完整程序工程 1.算法运行效果图预览 (完整程序运行后无水印) MATLAB训练结果 上述决策树判决条件&#xff1a; 分类的决策树1 if x21<17191.5 then node 2 elseif x21>17191…

【RAG】RAG综述|一文了解RAG|从零开始(下)

文章目录 5. RAG的架构5.1 Naive RAG5.2 Advanced RAG5.2.1 检索前处理和数据索引技术5.2.2 知识分片技术5.2.3 分层索引5.2.4 检索技术5.2.4.1 优化用户查询5.2.4.2 通过假想文档嵌入修复查询和文档不对称5.2.4.3 Routing5.2.4.5 自查询检索5.2.4.6 混合搜索5.2.4.7 图检索5.2…

山东大学软件学院项目实训-基于大模型的模拟面试系统-面试官和面试记录的分享功能(2)

本文记录在发布文章时&#xff0c;可以添加自己创建的面试官和面试记录到文章中这一功能的实现。 前端 首先是在原本的界面的底部添加了两个多选框&#xff08;后期需要美化调整&#xff09; 实现的代码&#xff1a; <el-col style"margin-top: 1rem;"><e…

FPGA纯verilog实现MIPI-DSI视频编码输出,提供工程源码和技术支持

目录 1、前言工程概述免责声明 2、相关方案推荐我已有的所有工程源码总目录----方便你快速找到自己喜欢的项目我这里已有的 MIPI 编解码方案 3、设计思路框架工程设计原理框图FPGA内部彩条RGB数据位宽转换RGB数据缓存MIPI-DSI协议层编码MIPI-DPHY物理层串化MIPI-LVDS显示屏工程…

LXQt修改开始菜单高亮

开始菜单红色高亮很难看 mkdir -p ~/.local/share/lxqt/palettes/ mkdir -p ~/.local/share/lxqt/themes/ cp /usr/share/lxqt/palettes/Dark ~/.local/share/lxqt/palettes/Darker cp -p /usr/share/lxqt/themes/dark ~/.local/share/lxqt/themes/darker lxqt-panel.qss L…

DeepSeek-R1-0528-Qwen3-8B 本地ollama离线运行使用和llamafactory lora微调

参考: https://huggingface.co/deepseek-ai/DeepSeek-R1-0528-Qwen3-8B 量化版本: https://huggingface.co/unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF https://docs.unsloth.ai/basics/deepseek-r1-0528-how-to-run-locally 1、ollama运行 升级ollama版本到0.9.0 支持直接…

vue3 + WebSocket + Node 搭建前后端分离项目 开箱即用

[TOC](vue3 WebSocket Node 搭建前后端分离项目) 开箱即用 前言 top1&#xff1a;vue3.5搭建前端H5 top2&#xff1a;Node.js koa搭建后端服务接口 top3&#xff1a;WebSocket 长连接实现用户在线聊天 top4&#xff1a;接口实现模块化 Mysql 自定义 top5&#xff1a;文件上…