👨?💻個人主頁:@元宇宙-秩沅
👨?💻 hallo 歡迎 點贊👍 收藏? 留言📝 加關注?!
👨?💻 本文由 秩沅 原創
👨?💻 專欄交流 | 🧧 |
---|---|
🟥Unity100個實戰基礎? | 🎁 |
🟦 Unity100個精華一記? | 🎁 |
🟩 Unity50個demo案例教程? | 🎁 |
🟨 Unity100個精華細節BUG? | 🎁 |
文章目錄
- ?前言?
- 🎶(==1==) 數據相互轉換
- 🎶(==2==) 文件操作
- 🎶(==3==) 文件夾操作
- 🎶(==4==) 序列化
- 🎶(==5==) 反序列化
- 🎶(==6==)二進制加密
- 🎶(==7==)Unity中使用Ecxel
- Excel的使用基礎
- Excel的實踐
- ExcelTool(讀取Excel數據生成數據結構、容器、二進制文件)
- 🎶(==8==) BinaryData管理器
- ?🅰?系統路線學習點擊跳轉?
?前言?
有符號 sbyte int short long
無符號 byte uint ushort ulong
浮點 float double decimal
特殊 bool char string
變量的本質是2進制,內存中以字節的形式存儲,sizeof方法可以看到常用變量類型占用的字節空間長度
sizeof(sbyte)
sizeof(long) …
- 節約存儲空間,提升效率
- 提升安全性
🎶(1) 數據相互轉換
-
在Unity中各類型數據和字節數據相互轉換
-
1.將各類型轉字節
byte[] bytes = BitConverter.GetBytes(256);
- 2.字節數組轉各類型
int i = BitConverter.ToInt32(bytes, 0);
為保證編碼的正確性,編碼要規范化、標準化,即需有標準的編碼格式。
在C#中有一個專門的編碼格式類 來幫助我們將字符串和字節數組進行轉換
游戲開發中常用編碼格式 UTF-8
中文相關編碼格式 GBK
英文相關編碼格式 ASCII
- 1.將字符串以指定編碼格式轉字節
byte[] bytes = Encoding.UTF8.GetBytes("你好");
- 2.字節數組以指定編碼格式轉字符串
string str = Encoding.UTF8.GetString(bytes);
🎶(2) 文件操作
命名空間: System.IO
- 1.判斷文件是否存在
if(File.Exists(Application.dataPath + "/Text")){//存在}
- 2.創建文件
FileStream fstream = File.Create(Application.dataPath + "/text");
- 3.寫入文件
//字節數組 寫入到指定路徑的文件中byte[] bytes = BitConverter.GetBytes(100);File.WriteAllBytes(Application.dataPath + "/text", bytes);//string數組內容 一行行寫入到指定路徑中
string[] strs = new string[] { "姓名", "你好", "1", "23"};
File.WriteAllLines(Application.dataPath + "/text", strs);//字符串寫入指定路徑
File.WriteAllText(Application.dataPath + "/text", "xahhll");
- 4.讀取文件
//讀取字節數據bytes = File.ReadAllBytes(Application.dataPath + "/text");print(BitConverter.ToInt32(bytes, 0));//讀取所有行信息
strs = File.ReadAllLines(Application.dataPath + "/text");for (int i = 0; i < strs.Length; i++){print(strs[i]);}//讀取所有文本信息
print(File.ReadAllText(Application.dataPath + "/text"));
- 5.刪除文件
File.Delete(Application.dataPath + "/text");//文件前提是關閉的
- 6.復制文件
參數一:現有文件 需要是流關閉狀態
參數二:目標文件File.Copy(Application.dataPath + "/text", Application.dataPath + "/text2", true);
- 7.文件替換
//參數一:用來替換的路徑//參數二:被替換的路徑//參數三:備份路徑File.Replace(Application.dataPath + "/text", Application.dataPath + "/text2", Application.dataPath + "/備份text");
- 8.以流的形式 打開文件并寫入或讀取
//參數一:路徑
//參數二:打開模式
//參數三:訪問模式
FileStream fs = File.Open(Application.dataPath + "/text",
FileMode.OpenOrCreate, FileAccess.ReadWrite);
🎶(3) 文件夾操作
命名空間:using System.IO
作用:增刪查改文件夾
- 1.判斷文件夾是否存在
if( Directory.Exists(Application.dataPath + "/文件夾名"))
{print("存在");
}
- 2.創建文件夾
DirectoryInfo info = Directory.CreateDirectory(Application.dataPath + "/文件夾名");
- 3.刪除文件夾
//參數一:路徑
//參數二:true,將刪除整個目錄,false,僅當該目錄為空時才刪除
Directory.Delete(Application.dataPath + "/文件夾名");
- 4.查找文件夾和文件
//得到所有文件夾名
string[] strs = Directory.GetDirectories(Application.dataPath);
for (int i = 0; i < strs.Length; i++)
{print(strs[i]);
}
//得到所有文件名
strs = Directory.GetFiles(Application.dataPath);
for (int i = 0; i < strs.Length; i++)
{print(strs[i]);
}
- 5.移動文件夾
//移動會把文件夾中的所有內容一起移到新的路徑
Directory.Move(Application.dataPath + "/文件夾名", Application.dataPath + "/路徑");//該路徑下面需為空
- 6.創建文件夾方法的返回值
DirectoryInfo Info = Directory.CreateDirectory(Application.dataPath + "/文件夾名");
//全路徑
print(Info .FullName);
//文件名
print(Info .Name);
- 7.查找上級文件夾信息
Info = Directory.GetParent(Application.dataPath + "/文件夾名");
//全路徑
print(Info .FullName);
//文件名
print(Info .Name);
- 8.得到所有子文件夾的目錄信息
DirectoryInfo[] dInfos = Info.GetDirectories();
FileInfo[] fInfos = dInfo.GetFiles();
for (int i = 0; i < fInfos.Length; i++)
{print("**************");print(fInfos[i].Name);//文件名print(fInfos[i].FullName);//路徑print(fInfos[i].Length);//字節長度print(fInfos[i].Extension);//后綴名
}
🎶(4) 序列化
序列化類對象
- 1.第一步申明類對象
注意:如果要使用C#自帶的序列化2進制方法
申明類時需要添加[System.Serializable]特性
[System.Serializable]
public class Person
{public int age = 1;public string name = "唐老獅";public int[] ints = new int[] { 1, 2, 3, 4, 5 };public List<int> list = new List<int>() { 1, 2, 3, 4 };public Dictionary<int, string> dic = new Dictionary<int, string>() { { 1,"123"},{ 2,"1223"},{ 3,"435345" } };public StructTest st = new StructTest(2, "123");//結構體public ClssTest ct = new ClssTest();//類
}
- 第二步—將對象進行2進制序列化
方法一:使用內存流得到2進制字節數組
主要用于得到字節數組 可以用于網絡傳輸
1.內存流對象
類名:MemoryStream
命名空間:System.IO
2.2進制格式化對象
類名:BinaryFormatter
命名空間:System.Runtime.Serialization.Formatters.Binary、
Person p = new Person(); //主要方法:序列化方法 Serializeusing (MemoryStream ms = new MemoryStream()){//2進制格式化程序BinaryFormatter bf = new BinaryFormatter();//序列化對象 生成2進制字節數組 寫入到內存流當中bf.Serialize(ms, p);//得到對象的2進制字節數組byte[] bytes = ms.GetBuffer();//存儲字節File.WriteAllBytes(Application.dataPath + "/文件", bytes);//關閉內存流ms.Close();}
方法二:使用文件流進行存儲
主要用于存儲到文件中
Person p = new Person(); using (FileStream fs = new FileStream(Application.dataPath + "/文件名", FileMode.OpenOrCreate, FileAccess.Write)){//2進制格式化程序BinaryFormatter bf = new BinaryFormatter();//序列化對象 生成2進制字節數組 寫入到內存流當中bf.Serialize(fs, p);fs.Flush();fs.Close();}}
}
🎶(5) 反序列化
- 1.反序列化文件中數據
主要類
FileStream文件流類
BinaryFormatter 2進制格式化類
主要方法
Deserizlize
通過文件流打開指定的2進制數據文件
using (FileStream fs = File.Open(Application.dataPath + "/文件名", FileMode.Open, FileAccess.Read)){//申明一個 2進制格式化類BinaryFormatter bf = new BinaryFormatter();//反序列化Person p = bf.Deserialize(fs) as Person;fs.Close();}
- 2.反序列化網絡傳輸過來的2進制數據
主要類
MemoryStream內存流類
BinaryFormatter 2進制格式化類
主要方法
Deserizlize
目前沒有網絡傳輸 我們還是直接從文件中獲取
byte[] bytes = File.ReadAllBytes(Application.dataPath + "/文件名");//申明內存流對象 一開始就把字節數組傳輸進去using (MemoryStream ms = new MemoryStream(bytes)){//申明一個 2進制格式化類BinaryFormatter bf = new BinaryFormatter();//反序列化Person p = bf.Deserialize(ms) as Person;ms.Close();}
🎶(6)二進制加密
- 1,何時加密?何時解密?
當我們將類對象轉換為2進制數據時進行加密
當我們將2進制數據轉換為類對象時進行解密
- 2.常用加密算法
MD5算法
SHA1算法
HMAC算法
AES/DES/3DES算法
等等等,ye 有很多的別人寫好的第三發加密算法庫
可以直接獲取用于在程序中對數據進行加密
- 3.簡單的異或加密和解密
Person p = new Person();byte key = 199;using (MemoryStream ms = new MemoryStream()){BinaryFormatter bf = new BinaryFormatter();bf.Serialize(ms, p);byte[] bytes = ms.GetBuffer();//異或加密for (int i = 0; i < bytes.Length; i++){bytes[i] ^= key;}File.WriteAllBytes(Application.dataPath + "/文件夾名", bytes);}//解密byte[] bytes2 = File.ReadAllBytes(Application.dataPath + "/文件夾名");for (int i = 0; i < bytes2.Length; i++){bytes2[i] ^= key;}using (MemoryStream ms = new MemoryStream(bytes2)){BinaryFormatter bf = new BinaryFormatter();Person p2 = bf.Deserialize(ms) as Person;ms.Close();}
🎶(7)Unity中使用Ecxel
- 導入官方提供的Excel相關DLL文件,在Editor文件夾下
Excel的使用基礎
- 1.打開Excel表
主要知識點:
1.FileStream讀取文件流
2.IExcelDataReader類,從流中讀取Excel數據
3.DataSet 數據集合類 將Excel數據轉存進其中方便讀取
[MenuItem("GameTool/打開Excel表")]private static void OpenExcel(){using (FileStream fs = File.Open(Application.dataPath + "/文件夾/Excel表明.xlsx", FileMode.Open, FileAccess.Read )){//通過我們的文件流獲取Excel數據IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);//將excel表中的數據轉換為DataSet數據類型 方便我們 獲取其中的內容DataSet result = excelReader.AsDataSet();//得到Excel文件中的所有表信息for (int i = 0; i < result.Tables.Count; i++){Debug.Log("表名:" + result.Tables[i].TableName);Debug.Log("行數:" + result.Tables[i].Rows.Count);Debug.Log("列數:" + result.Tables[i].Columns.Count);}fs.Close();}}
- 2.獲取Excel表中單元格的信息
主要知識點:
1.FileStream讀取文件流
2.IExcelDataReader類,從流中讀取Excel數據
3.DataSet 數據集合類 將Excel數據轉存進其中方便讀取
4.DataTable 數據表類 表示Excel文件中的一個表
5.DataRow 數據行類 表示某張表中的一行數據
[MenuItem("GameTool/讀取Excel里的具體信息")]private static void ReadExcel(){using (FileStream fs = File.Open(Application.dataPath + "/文件夾/Excel表明.xlsx", FileMode.Open, FileAccess.Read)){IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);DataSet result = excelReader.AsDataSet();for (int i = 0; i < result.Tables.Count; i++){//得到其中一張表的具體數據DataTable table = result.Tables[i];//得到其中一行的數據//DataRow row = table.Rows[0];//得到行中某一列的信息//Debug.Log(row[1].ToString());DataRow row;for (int j = 0; j < table.Rows.Count; j++){//得到每一行的信息row = table.Rows[j];Debug.Log("*********新的一行************");for (int k = 0; k < table.Columns.Count; k++){Debug.Log(row[k].ToString());}}}fs.Close();}}
- 3.獲取Excel表中信息對于我們的意義?
我們可以根據表中數據來動態的生成相關數據
1.數據結構類
2.容器類
3.2進制數據
為什么不直接讀取Excel表而要把它轉成2進制數據
1.提升讀取效率
2.提升數據安全性
Excel的實踐
- 1.自定義Excel表的規則
第一行:字段
第二行:數據類型
第三行:主鍵
第四行:注釋
之后:數據
(可用字典的形式存儲<key,數據容器>)
- 我們想通過Ecxel表中的內容生成數據結構,生成容器腳本,如何實現呢
見下文
ExcelTool(讀取Excel數據生成數據結構、容器、二進制文件)
導入包
-
在Assets文件夾下創建 ArtRes/Excel,然后放入編輯好的Excel文件
-
然后點擊上方GenerateEXcel,即可生成
using Excel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;public class ExcelTool
{/// <summary>/// excel文件存放的路徑/// </summary>public static string EXCEL_PATH = Application.dataPath + "/ArtRes/Excel/";/// <summary>/// 數據結構類腳本存儲位置路徑/// </summary>public static string DATA_CLASS_PATH = Application.dataPath + "/Scripts/ExcelData/DataClass/";/// <summary>/// 容器類腳本存儲位置路徑/// </summary>public static string DATA_CONTAINER_PATH = Application.dataPath + "/Scripts/ExcelData/Container/";/// <summary>/// 真正內容開始的行號/// </summary>public static int BEGIN_INDEX = 4;[MenuItem("GameTool/GenerateExcel")]private static void GenerateExcelInfo(){//記在指定路徑中的所有Excel文件 用于生成對應的3個文件DirectoryInfo dInfo = Directory.CreateDirectory(EXCEL_PATH);//得到指定路徑中的所有文件信息 相當于就是得到所有的Excel表FileInfo[] files = dInfo.GetFiles();//數據表容器DataTableCollection tableConllection;for (int i = 0; i < files.Length; i++){//如果不是excel文件就不要處理了if (files[i].Extension != ".xlsx" &&files[i].Extension != ".xls")continue;//打開一個Excel文件得到其中的所有表的數據using (FileStream fs = files[i].Open(FileMode.Open, FileAccess.Read)){IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);tableConllection = excelReader.AsDataSet().Tables;fs.Close();}//遍歷文件中的所有表的信息foreach (DataTable table in tableConllection){//生成數據結構類GenerateExcelDataClass(table);//生成容器類GenerateExcelContainer(table);//生成2進制數據GenerateExcelBinary(table);}}}/// <summary>/// 生成Excel表對應的數據結構類/// </summary>/// <param name="table"></param>private static void GenerateExcelDataClass(DataTable table){//字段名行DataRow rowName = GetVariableNameRow(table);//DataRow數據行//字段類型行DataRow rowType = GetVariableTypeRow(table);//判斷路徑是否存在 沒有的話 就創建文件夾if (!Directory.Exists(DATA_CLASS_PATH))Directory.CreateDirectory(DATA_CLASS_PATH);//如果我們要生成對應的數據結構類腳本 其實就是通過代碼進行字符串拼接 然后存進文件就行了string str = "public class " + table.TableName + "\n{\n";//變量進行字符串拼接for (int i = 0; i < table.Columns.Count; i++){str += " public " + rowType[i].ToString() + " " + rowName[i].ToString() + ";\n";}str += "}";//把拼接好的字符串存到指定文件中去File.WriteAllText(DATA_CLASS_PATH + table.TableName + ".cs", str);//刷新Project窗口AssetDatabase.Refresh();}/// <summary>/// 生成Excel表對應的數據容器類/// </summary>/// <param name="table"></param>private static void GenerateExcelContainer(DataTable table){//得到主鍵索引int keyIndex = GetKeyIndex(table);//得到字段類型行DataRow rowType = GetVariableTypeRow(table);//沒有路徑創建路徑if (!Directory.Exists(DATA_CONTAINER_PATH))Directory.CreateDirectory(DATA_CONTAINER_PATH);string str = "using System.Collections.Generic;\n";str += "public class " + table.TableName + "Container" + "\n{\n";str += " ";str += "public Dictionary<" + rowType[keyIndex].ToString() + ", " + table.TableName + ">";str += "dataDic = new " + "Dictionary<" + rowType[keyIndex].ToString() + ", " + table.TableName + ">();\n";str += "}";File.WriteAllText(DATA_CONTAINER_PATH + table.TableName + "Container.cs", str);//刷新Project窗口AssetDatabase.Refresh();}/// <summary>/// 生成excel2進制數據/// </summary>/// <param name="table"></param>private static void GenerateExcelBinary(DataTable table){//沒有路徑創建路徑if (!Directory.Exists(BinaryDataMgr.DATA_BINARY_PATH))Directory.CreateDirectory(BinaryDataMgr.DATA_BINARY_PATH);//創建一個2進制文件進行寫入using (FileStream fs = new FileStream(BinaryDataMgr.DATA_BINARY_PATH + table.TableName + ".tang", FileMode.OpenOrCreate, FileAccess.Write)){//存儲具體的excel對應的2進制信息//1.先要存儲我們需要寫多少行的數據 方便我們讀取//-4的原因是因為 前面4行是配置規則 并不是我們需要記錄的數據內容fs.Write(BitConverter.GetBytes(table.Rows.Count - 4), 0, 4);//2.存儲主鍵的變量名string keyName = GetVariableNameRow(table)[GetKeyIndex(table)].ToString();byte[] bytes = Encoding.UTF8.GetBytes(keyName);//存儲字符串字節數組的長度fs.Write(BitConverter.GetBytes(bytes.Length), 0, 4);//存儲字符串字節數組fs.Write(bytes, 0, bytes.Length);//遍歷所有內容的行 進行2進制的寫入DataRow row;//得到類型行 根據類型來決定應該如何寫入數據DataRow rowType = GetVariableTypeRow(table);for (int i = BEGIN_INDEX; i < table.Rows.Count; i++){//得到一行的數據row = table.Rows[i];for (int j = 0; j < table.Columns.Count; j++){switch (rowType[j].ToString()){case "int":fs.Write(BitConverter.GetBytes(int.Parse(row[j].ToString())), 0, 4);break;case "float":fs.Write(BitConverter.GetBytes(float.Parse(row[j].ToString())), 0, 4);break;case "bool":fs.Write(BitConverter.GetBytes(bool.Parse(row[j].ToString())), 0, 1);break;case "string":bytes = Encoding.UTF8.GetBytes(row[j].ToString());//寫入字符串字節數組的長度fs.Write(BitConverter.GetBytes(bytes.Length), 0, 4);//寫入字符串字節數組fs.Write(bytes, 0, bytes.Length);break;}}}fs.Close();}AssetDatabase.Refresh();}/// <summary>/// 獲取變量名所在行/// </summary>/// <param name="table"></param>/// <returns></returns>private static DataRow GetVariableNameRow(DataTable table){return table.Rows[0];}/// <summary>/// 獲取變量類型所在行/// </summary>/// <param name="table"></param>/// <returns></returns>private static DataRow GetVariableTypeRow(DataTable table){return table.Rows[1];}/// <summary>/// 獲取主鍵索引/// </summary>/// <param name="table"></param>/// <returns></returns>private static int GetKeyIndex(DataTable table){DataRow row = table.Rows[2];for (int i = 0; i < table.Columns.Count; i++){if (row[i].ToString() == "key")return i;}return 0;}
}
🎶(8) BinaryData管理器
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using UnityEngine;/// <summary>
/// 2進制數據管理器
/// </summary>
public class BinaryDataMgr
{/// <summary>/// 2進制數據存儲位置路徑/// </summary>public static string DATA_BINARY_PATH = Application.streamingAssetsPath + "/Binary/";/// <summary>/// 用于存儲所有Excel表數據的容器/// </summary>private Dictionary<string, object> tableDic = new Dictionary<string, object>();/// <summary>/// 數據存儲的位置/// </summary>private static string SAVE_PATH = Application.persistentDataPath + "/Data/";private static BinaryDataMgr instance = new BinaryDataMgr();public static BinaryDataMgr Instance => instance;private BinaryDataMgr(){InitData();}public void InitData(){//在此處編寫初始化數據}/// <summary>/// 加載Excel表的2進制數據到內存中 /// </summary>/// <typeparam name="T">容器類名</typeparam>/// <typeparam name="K">數據結構類類名</typeparam>public void LoadTable<T,K>(){//讀取 excel表對應的2進制文件 來進行解析using (FileStream fs = File.Open(DATA_BINARY_PATH + typeof(K).Name + ".tang", FileMode.Open, FileAccess.Read)){byte[] bytes = new byte[fs.Length];fs.Read(bytes, 0, bytes.Length);fs.Close();//用于記錄當前讀取了多少字節了int index = 0;//讀取多少行數據int count = BitConverter.ToInt32(bytes, index);index += 4;//讀取主鍵的名字int keyNameLength = BitConverter.ToInt32(bytes, index);index += 4;string keyName = Encoding.UTF8.GetString(bytes, index, keyNameLength);index += keyNameLength;//創建容器類對象Type contaninerType = typeof(T);object contaninerObj = Activator.CreateInstance(contaninerType);//得到數據結構類的TypeType classType = typeof(K);//通過反射 得到數據結構類 所有字段的信息FieldInfo[] infos = classType.GetFields();//讀取每一行的信息for (int i = 0; i < count; i++){//實例化一個數據結構類 對象object dataObj = Activator.CreateInstance(classType);foreach (FieldInfo info in infos){if( info.FieldType == typeof(int) ){//相當于就是把2進制數據轉為int 然后賦值給了對應的字段info.SetValue(dataObj, BitConverter.ToInt32(bytes, index));index += 4;}else if (info.FieldType == typeof(float)){info.SetValue(dataObj, BitConverter.ToSingle(bytes, index));index += 4;}else if (info.FieldType == typeof(bool)){info.SetValue(dataObj, BitConverter.ToBoolean(bytes, index));index += 1;}else if (info.FieldType == typeof(string)){//讀取字符串字節數組的長度int length = BitConverter.ToInt32(bytes, index);index += 4;info.SetValue(dataObj, Encoding.UTF8.GetString(bytes, index, length));index += length;}}//讀取完一行的數據了 應該把這個數據添加到容器對象中//得到容器對象中的 字典對象object dicObject = contaninerType.GetField("dataDic").GetValue(contaninerObj);//通過字典對象得到其中的 Add方法MethodInfo mInfo = dicObject.GetType().GetMethod("Add");//得到數據結構類對象中 指定主鍵字段的值object keyValue = classType.GetField(keyName).GetValue(dataObj);mInfo.Invoke(dicObject, new object[] { keyValue, dataObj });}//把讀取完的表記錄下來tableDic.Add(typeof(T).Name, contaninerObj);fs.Close();}}/// <summary>/// 得到一張表的信息/// </summary>/// <typeparam name="T">容器類名</typeparam>/// <returns></returns>public T GetTable<T>() where T:class{string tableName = typeof(T).Name;if (tableDic.ContainsKey(tableName))return tableDic[tableName] as T;return null;}/// <summary>/// 存儲類對象數據/// </summary>/// <param name="obj"></param>/// <param name="fileName"></param>public void Save(object obj, string fileName){//先判斷路徑文件夾有沒有if (!Directory.Exists(SAVE_PATH))Directory.CreateDirectory(SAVE_PATH);using (FileStream fs = new FileStream(SAVE_PATH + fileName + ".tang", FileMode.OpenOrCreate, FileAccess.Write)){BinaryFormatter bf = new BinaryFormatter();bf.Serialize(fs, obj);fs.Close();}}/// <summary>/// 讀取2進制數據轉換成對象/// </summary>/// <typeparam name="T"></typeparam>/// <param name="fileName"></param>/// <returns></returns>public T Load<T>(string fileName) where T:class{//如果不存在這個文件 就直接返回泛型對象的默認值if( !File.Exists(SAVE_PATH + fileName + ".tang") )return default(T);T obj;using (FileStream fs = File.Open(SAVE_PATH + fileName + ".tang", FileMode.Open, FileAccess.Read)){BinaryFormatter bf = new BinaryFormatter();obj = bf.Deserialize(fs) as T;fs.Close();}return obj;}
}
2.刷新Project窗口內容
因為我們用代碼創建完文件后需要被刷新之后才可以看到
// Directory.CreateDirectory(Application.dataPath + "/測試文件夾");AssetDatabase.Refresh();
?🅰?系統路線學習點擊跳轉?
👨?💻 Unity程序基礎學習路線 | 🧧 |
---|---|
?【Unityc#專題篇】之c#進階篇】 | 🎁 |
?【Unityc#專題篇】之c#核心篇】 | 🎁 |
?【Unityc#專題篇】之c#基礎篇】 | 🎁 |
?【Unity-c#專題篇】之c#入門篇】 | 🎁 |
?【Unityc#專題篇】—進階章題單實踐練習 | 🎁 |
?【Unityc#專題篇】—基礎章題單實踐練習 | 🎁 |
?【Unityc#專題篇】—核心章題單實踐練習 | 🎁 |
你們的點贊👍 收藏? 留言📝 關注?是我持續創作,輸出優質內容的最大動力!、