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
繁體地址,請注明出處:http://hk.pswp.cn/news/907762.shtml
英文地址,請注明出處:http://en.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;文件上…