栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Unity3D

Json 技术实现登入注册

Unity3D 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Json 技术实现登入注册

using LitJson;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class Model 
{
    //创建一个字典来储存账号信息
    public static Dictionary allAccount = new Dictionary();
    private static Model instance;
    private Model()
    {

    }

    public static Model getInstance()
    {
        if (null == instance)         //生成单例
        instance = new Model();
        return instance;
    }

    public void setQQNumber(string a, string b)   //存输入的账号
    {
        // 将数据存入字典中
        allAccount.Add(a, b);
        // 将数据存入Json文件中
        //声明一个字符串类型来储存文件的位置
        string path = Application.dataPath + "/Json/tu.txt";
        //记录储存文件的信息
        FileInfo file = new FileInfo(path);
        if (!file.Exists)
        {
            //如果找不到文件则警告
            Debug.LogError("找不到储存文件!!!!!");
        }
        //开始写入数据
        //创建一个写入对象,用于写入数据
        StreamWriter writer = new StreamWriter(path);
        JsonData jd = JsonMapper.ToJson(allAccount);
        //写入数据
        writer.Write(jd);
        //关闭写入器
        writer.Close();
        //刷新储存文件
        file.Refresh();
        // fs.Flush();
    }

    public Dictionary getQQNumber()//返回账号
    {
        //读取数据
        //声明一个字符串类型来储存文件的位置
        string path = Application.dataPath + "/Json/tu.txt";
        //记录储存文件的信息
        FileInfo file = new FileInfo(path);
        if (!file.Exists)
        {
            //如果找不到文件则警告
            Debug.LogError("找不到储存文件!!!!!");
        }
        //读取数据
        string all = File.ReadAllText(path);
        allAccount = JsonMapper.ToObject>(all);
        return allAccount;
    }
}
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class View : MonoBehaviour
{//注册
    //public InputField account, password, passwords;
    public Text tap;
    Button fanHuiBut, resBut;
    Transform loginPanel, resPanle, successPanel, canvas;
    public InputField ac;
    public InputField pwd;
    public InputField pwds;
    void Start()
    {
        canvas = GameObject.Find("Canvas").transform;
        loginPanel = canvas.GetChild(0);
        resPanle = canvas.GetChild(3);
        successPanel = canvas.GetChild(4);
        fanHuiBut = resPanle.GetChild(7).GetComponent

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/899778.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号