最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Up自制Unity預(yù)制腳本dataStore.cs

2023-04-03 15:21 作者:擁抱大自然  | 我要投稿

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System.IO;

using System.Text;



public class dataStore:MonoBehaviour

{


? ? public List<string> goSave = new List<string>();


? ? public List<string> goLoad = new List<string>();


? ? public string path = @"e:\testSave.txt";



? ? void Start()

? ? {

? ? ? ??

? ? }


? ? void Update()

? ? {

? ? ? ? if (Input.GetKeyDown(KeyCode.F8))

? ? ? ? {

? ? ? ? ? ? collectData();

? ? ? ? ? ? saveData();

? ? ? ? ? ? //存盤操作

? ? ? ? }


? ? ? ? if (Input.GetKeyDown(KeyCode.F9))

? ? ? ? {

? ? ? ? ? ? goLoad.Clear();

? ? ? ? ? ? loadData();

? ? ? ? ? ? resetPicPosition();? ? ? ?

? ? ? ? ? ? //讀盤操作

? ? ? ? }

? ? }



? ? void collectData()

? ? {

? ? ? ? //收集圖片位置以及旋轉(zhuǎn)和是否有重力的數(shù)據(jù)

? ? ? ? int picNum = transform.childCount;

? ? ? ? goSave.Clear();


? ? ? ? for (int i = 0; i < picNum; i++)

? ? ? ? {

? ? ? ? ? ? goSave.Add(transform.GetChild(i).transform.name+";"+ transform.GetChild(i).transform.position+";"+ transform.GetChild(i).transform.eulerAngles+";"+ transform.GetChild(i).GetComponent<Rigidbody>().useGravity);? ? ? ? ? ? ? ? ? ? ? ??

? ? ? ? }


? ? }


? ? void saveData()

? ? {? ? ? ??

? ? ? ? //存盤操作

? ? ? ? if (File.Exists(path))

? ? ? ? {

? ? ? ? ? ? File.Delete(path);

? ? ? ? }

? ? ? ? using(FileStream fs_write = File.Create(path))

? ? ? ? {

? ? ? ? ? ? StreamWriter sw = new StreamWriter(fs_write, Encoding.UTF8);

? ? ? ? ? ? int picNum = transform.childCount;

? ? ? ? ? ? for(int i=0; i<picNum; i++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? sw.WriteLine(goSave[i]);

? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? sw.Close();

? ? ? ? }

? ? }


? ? void loadData()

? ? {

? ? ? ? //讀盤操作

? ? ? ? FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);

? ? ? ? StreamReader sr = new StreamReader(fs);

? ? ? ? string str = "";

? ? ? ? while (str != null)

? ? ? ? {

? ? ? ? ? ? str = sr.ReadLine();

? ? ? ? ? ?

? ? ? ? ? ? if (str != null)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? goLoad.Add(str);

? ? ? ? ? ? }

? ? ? ? ? ? else?

? ? ? ? ? ? {

? ? ? ? ? ? ? ? break;?

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? sr.Close();

? ? }


? ? void resetPicPosition()

? ? {

? ? ? ? //重置圖片位置為保存的位置

? ? ? ? foreach(string i in goLoad)

? ? ? ? {

? ? ? ? ? ? string[] split = i.Split(new char[] { ';' });


? ? ? ? ? ? transform.Find(split[0]).position = StringToVector3(split[1]);


? ? ? ? ? ? transform.Find(split[0]).eulerAngles = StringToVector3(split[2]);


? ? ? ? ? ? transform.Find(split[0]).GetComponent<Rigidbody>().useGravity = bool.Parse(split[3]);


? ? ? ? }? ? ? ??

? ? }



? ? public static Vector3 StringToVector3(string temp)

? ? {

? ? ? ? //字符串轉(zhuǎn)為向量

? ? ? ? if (temp.StartsWith("(") && temp.EndsWith(")"))

? ? ? ? {

? ? ? ? ? ? temp = temp.Substring(1, temp.Length - 2);

? ? ? ? }? ? ? ? ? ? ? ??

? ? ? ? string[] sArray = temp.Split(',');

? ? ? ? ? ? ? ??

? ? ? ? Vector3 result = new Vector3(float.Parse(sArray[0]), float.Parse(sArray[1]), float.Parse(sArray[2]));


? ? ? ? return result;

? ? }



}


Up自制Unity預(yù)制腳本dataStore.cs的評論 (共 條)

分享到微博請遵守國家法律
伽师县| 新密市| 吉木萨尔县| 招远市| 红河县| 新闻| 稷山县| 西盟| 固始县| 三穗县| 承德县| 册亨县| 上犹县| 廉江市| 延川县| 赣榆县| 桂平市| 特克斯县| 大城县| 来凤县| 那坡县| 来宾市| 芜湖县| 慈溪市| 苏尼特右旗| 建昌县| 监利县| 阳泉市| 乐平市| 宝山区| 手机| 武鸣县| 兴国县| 重庆市| 海林市| 白山市| 盐城市| 温宿县| 盘锦市| 章丘市| 调兵山市|