当前位置:网站首页>unity客户端读取文本配置
unity客户端读取文本配置
2022-07-25 08:34:00 【你只在游戏中存在】
1.声明一个数据结构类 编译生成DLL放入UNITY的reference下面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Common.Data
{
public class CharacterDefine
{
public int TID {
get; set; }
public string Name {
get; set; }
public CharacterClass Class {
get; set; }
public string Resource {
get; set; }
public string Description {
get; set; }
//基本属性
public int Speed {
get; set; }
}
}
2.文本配置的TXT:CharacterDefine.txt
{
"1": {
"TID": 1,
"Name": "战士",
"Type": "Normal",
"Class": "WARRIOR",
"Resource": "Character/Warrior",
"Description":"这是一个战士"
},
"2": {
"TID": 2,
"Name": "法师",
"Type": "Normal",
"Class": "WIZARD",
"Resource": "Character/Wizard",
"Descrption":"这是一个法师"
},
"3": {
"TID": 3,
"Name": "弓箭手",
"Type": "Normal",
"Class": "ARCHER",
"Resource": "Character/Archer",
"Descrption":"这是一个弓箭手"
}
}
3.数据解析脚本
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Events;
using System.Text;
using System;
using System.IO;
using Common.Data;
using Newtonsoft.Json;
public class DataManager : Singleton<DataManager>
{
public string DataPath;
public Dictionary<int, CharacterDefine> Characters = null;
public DataManager()
{
this.DataPath = "Data/";
Debug.LogFormat("DataManager > DataManager()");
}
public void Load()
{
json = File.ReadAllText(this.DataPath + "CharacterDefine.txt");
//json反序列化
this.Characters = JsonConvert.DeserializeObject<Dictionary<int, CharacterDefine>>(json);
}
//在场景运行时调用这个LOAD
public IEnumerator LoadData()
{
json = File.ReadAllText(this.DataPath + "CharacterDefine.txt");
this.Characters = JsonConvert.DeserializeObject<Dictionary<int, CharacterDefine>>(json);
yield return null;
}
}
4.使用
descs.text = DataManager.Instance.Characters[0].Description;//这样读取就是战士的文本描述
边栏推荐
- Literature learning (part101) -- converge clustering
- Does the server operation and maintenance need to be online 24 hours? Do you need to work overtime on weekends?
- Qt|QLable多行展示时更改行间距
- Online shopping E-commerce mall system based on jsp+servlet+mysql+
- Redis分片集群
- @Differences between requestparam, @pathparam, @pathvariable and other annotations (use of some annotations)
- Raspberry pie creation self start service
- Redis4.0.14 sentinel automatic failover failed
- Ensembles in RNA counts data in TCGA_ ID to gene_ Method of ID
- Redis best practices
猜你喜欢

Talk about your transformation test development process

Network solutions for Alibaba cloud services

Redis fragment cluster

Blue and white porcelain used by Charles

TCGA simple download tool V16 installation error

Some easy-to-use plug-ins and settings installed in vscode

Chapter 3 business function development (realize the real-time response of the select all button)

Idea failed to start the project yamlexception Chinese file encoding format

Data warehouse ODS, DWD floor, 220616, HM,

Basis 33: XPath acquisition methods of page elements under various browsers
随机推荐
记录两次多端排查问题的过程
【keras bug】Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ ref(
Idea starts the project slowly
Use of lambdaquerywrapper, lambdaupdatewrapper, lambdaquerychainwrapper
【5G NR】3GPP常用协议整理
[dark horse programmer] redis learning notes 001: introduction to redis + five basic data types
@The difference and use of value and configurationproperties
ArcGIS Pro脚本工具(10)——从图层生成.stylx样式符号
Some easy-to-use plug-ins and settings installed in vscode
Brush the title "sword finger offer" day02
Redis分片集群
@Autowired的使用
Nuscenes dataset 3D mot demo, end-to-end target detection and tracking, joint detection and tracking framework
孙子兵法随感
【着色器实现Shadow投影效果_Shader效果第八篇】
JS pop up picture Lightbox light box plug-in spotlight.js
ArcGIS Pro scripting tool (10) -- generate.Stylx style symbols from layers
Redis core principles
Node+js build time server
RTOS系列(13):汇编LDR指令、LDR伪指令、[Rn]寄存器间接引用 详细解析