前言
网上很少有这套CSV数据表格的增改查的完整解决方案,要么需要做繁琐的环境配置和插件安装,要么需要很多繁琐的代码。所以,只能通过不断摸索、测试,最终得以实现。
演示视频
Unity对CSV数据表格的增改查演示
演示图片
代码片
//本页CSV文件的增、改、查代码为肖老师原创,如需转载,请通知作者:2978211817@qq.com。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
//using System.Data.OleDb;
using UnityEngine;
public class MakeDB : MonoBehaviour
{
[SerializeField]
string inputID = "", inputPWD = "", registerID = "", registerPWD = "";//用户登录、注册数据
string loginIndex = "", loginID = "", loginPWD = "";//成功登录后的暂存信息
public string freshScore = "";//记录当前用户最新成绩
string filePath = "";//记录数据表地址
// Start is called before the first frame update
void Start()
{
//filePath = Application.streamingAssetsPath + "\\BariumMealExamData.csv";//新建StreamingAssets文件夹,并将BariumMealExamData.csv保存到此文件夹。CSV文件可以直接用Excel或WPS打开。请勿随意删改csv表中的预留信息,以防出错。
filePath=Application.persistentDataPath+"//"+ "BariumMealExamData.csv";//保存在安卓端的地址,即apk安装后的files文件夹中
}
// Update is called once per frame
void Update()
{
Register(registerID, registerPWD);//新用户注册
Login(inputID, inputPWD);//用户登录
UpdateScore();//更新用户成绩
}
//更新用户成绩
void UpdateScore()
{