本文主要是介绍U3D将场景数据存为表格,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在游戏中,经常会遇到将游戏信息存储起来,以便于策划调配的工作。
利用csv表格行列的特性,可以将数据通过逗号隔开,从而实现表格生成。
具体函数为
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Reflection;using UnityEditor;public class MapGameobjectCreat : MonoBehaviour {static readonly string TableReaderFolder = "Assets/Tables";// Use this for initializationvoid Start () {AssetDatabase.Refresh();Directory.CreateDirectory(TableReaderFolder);using (StreamWriter writer = File.CreateText(TableReaderFolder + "/"+gameObject.name+".csv")){string csvStr = "障碍物ID,x坐标,z坐标\n";foreach (Transform _tran in transform){csvStr += _tran.name + ",";csvStr += (float)_tran.position.x + ",";csvStr += (float)_tran.position.z + ",";csvStr += "\n";}writer.Write(csvStr);}AssetDatabase.Refresh();Debug.Log(gameObject.name + "转表完毕");}// Update is called once per framevoid Update () {}
}
测试工程请见下载地址:https://download.csdn.net/download/Tel17610887670/12040003
这篇关于U3D将场景数据存为表格的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!