当前位置:网站首页>Record the method of reading excel provided by unity and the solution to some pits encountered
Record the method of reading excel provided by unity and the solution to some pits encountered
2022-06-27 02:39:00 【Nokiagame studio】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Excel;
using System.IO;
using UnityEngine.Networking;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
public class MoveCameraByMouse : MonoBehaviour
{
public Transform CenObj;// Surrounding objects
public float speed;// Rotation speed
public float speedup;// Speed of rise
public GameObject CubePre;// Generated block
float xuanzhaun=180;// The rotation angle when generating
public GameObject weizhi;// Where the block is generated
int gaodu = 2;// Initial block height
int shuliang;// Read file assignment count
public GameObject ui;// Generated ui
public GameObject flaggo;// Generated red flag
int toindex;// Read resource count
public Image[] tempImage;// Components
private Texture2D pic;
private Sprite[] sp;//??
public string[] diyihang;// Read excel Acceptance of the first line
public string[] dierhang;// The second line
public string[] disanhang;// The third line
public List<Texture> textureList;// Read all png
private void Awake()
{
InvokeRepeating("shengcheng", 1f, 2f);// Generate the Ctrip of the object
GameReadExcel(); // Read excel
}
void Start()
{
string[] filePath = Directory.GetFiles(Application.streamingAssetsPath,"*.png");// Read all png
StartCoroutine(LoadImage(filePath));
//StartCoroutine(LoadTextureFromInternet());
}
void Update()
{
if (toindex<=0)// prevent index Crossing the boundary
{
return;
}
transform.Rotate(Vector3.down*Time.deltaTime * speed, Space.World);// rotate
//transform.RotateAround(CenObj.position, Vector3.up, -30 * Time.deltaTime * speed);
transform.Translate(transform.up * Time.deltaTime * speedup);
xuanzhaun=xuanzhaun++;
}
// The distance and proximity of the lens
public void shengcheng()// Generate
{
if (toindex <= 0)
{
return;
}
gaodu = gaodu + 1;
sp=new Sprite[toindex];
GameObject go= Instantiate(CubePre, weizhi.transform.position , Quaternion.Euler(0,-90, 0));
go.GetComponent<Transform>().localScale = new Vector3(1f, gaodu, 1);
GameObject to = Instantiate(ui, new Vector3(go.transform.position.x,go.transform.position.y+(go.transform.position.y/2)-0.5f,go.transform.position.z-0.53f), Quaternion.Euler(0,0,0));
to.transform.parent = go.transform;
Text[] ziwuti=to.GetComponentsInChildren<Text>();
ziwuti[0].text = toindex.ToString();
Text[] ziwutiname = to.GetComponentsInChildren<Text>();
ziwutiname[1].text= diyihang[shuliang];
Image[] ziwutiico=to.GetComponentsInChildren<Image>();
//StartCoroutine(LoadTextureFromInternet());
ziwutiico[0].sprite = Sprite.Create((Texture2D)textureList[shuliang], new Rect(0, 0, textureList[shuliang].width, textureList[shuliang].height), Vector2.zero);
GameObject flag = Instantiate(flaggo, new Vector3(go.transform.position.x+0.2f, go.transform.position.y + (go.transform.position.y / 2)+1.5f, go.transform.position.z), Quaternion.Euler(0,-180 ,90));
flag.transform.parent = go.transform;
MeshRenderer mr = flag.GetComponent<MeshRenderer>();
mr.material.mainTexture = textureList[shuliang];
shuliang = shuliang + 1;
toindex = toindex - 1;
}
IEnumerator LoadImage(string[] filePath)// Read all png
{
foreach (var item in filePath)
{
UnityWebRequest request = UnityWebRequestTexture.GetTexture(item);
yield return request.SendWebRequest();
textureList.Add(DownloadHandlerTexture.GetContent(request));
}
}
//[System.Obsolete]
//IEnumerator LoadTextureFromInternet()
//{
// tempImage = new Image[toindex];
// for (int i = 0; i < toindex; i++)
// {
// UnityWebRequest request = new UnityWebRequest(Application.streamingAssetsPath +"/"+ dierhang[i]);
// DownloadHandlerTexture texture = new DownloadHandlerTexture(true);
// request.downloadHandler = texture;
// yield return request.Send();
// if (string.IsNullOrEmpty(request.error))
// {
// pic = texture.texture;
// }
// //tempImage = GameObject.Find("Image").GetComponent<Image>();
// sp = Sprite.Create((Texture2D)pic, new Rect(0, 0, pic.width, pic.height), Vector2.zero);
// tempImage[i].sprite = sp;
// //Debug.Log(dierhang[i]);
// //GameObject go = GameObject.Find("Cube");
// //go.GetComponent<MeshRenderer>().material.mainTexture = pic;
// }
//}
public void GameReadExcel()// Read excel
{
FileStream stream = File.Open(Application.streamingAssetsPath +"/config.xlsx", FileMode.Open, FileAccess.Read);
//IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
toindex = result.Tables[0].Columns.Count;// Get the number of columns
int rows = result.Tables[0].Rows.Count;// Get the number of lines
// Start with the second line
//for (int i = 1; i < rows; i++)
//{
diyihang = new string[toindex];
dierhang = new string[toindex];
disanhang = new string[toindex];
for (int j = 0; j < toindex; j++)
{
diyihang[j] = result.Tables[0].Rows[1][j].ToString();
//Debug.Log(diyihang[j]);
}
//}
for (int j = 0; j < toindex; j++)
{
dierhang[j] = result.Tables[0].Rows[2][j].ToString();
//Debug.Log(dierhang);
}
for (int j = 0; j < toindex; j++)
{
disanhang[j] = result.Tables[0].Rows[3][j].ToString();
// Debug.Log(disanhang);
}
}
}
On the first code , edition 2020.3.26f1c1, First, notice the namespace , The second import link :https://pan.baidu.com/s/1N8tZ7nCg2Ak4LDplwYt3tQ?pwd=1234
Extraction code :1234
To Assets Decompress , modify 
118 If you don't download it here, go to the corresponding address of your installation package , The key point here is to remember !!! My address :C:\Program Files\Unity\Hub\Editor\2020.3.26f1c1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit
Remember to remember to remember !!!
The code is messy , After all, I don't just do this function ! Again, this is just a record of the pit encountered , Choose the function you want , The function of this code is also relatively complete .
边栏推荐
- Don't be brainwashed. This is the truth about the wages of 90% of Chinese people
- DAMA、DCMM等数据管理框架各个能力域的划分是否合理?有内在逻辑吗?
- 元透实盘周记20220627
- Yalm 100b: 100billion parameter open source large model from yandex, Russia, allowing commercial use
- canvas粒子篇之鼠标跟随js特效
- h5液体动画js特效代码
- pytorch_grad_cam——pytorch下的模型特征(Class Activation Mapping, CAM)可视化库
- Cs5213 HDMI to VGA (with audio) single turn scheme, cs5213 HDMI to VGA (with audio) IC
- LeetCode 785:判断二分图
- Test the respective roles of nohup and &
猜你喜欢

企业数字化转型:信息化与数字化

How does source insight (SI) display the full path? (do not display omitted paths) (turn off trim long path names with ellipses)

Installing the Damon database using the command line

超级详细,2 万字详解,吃透 ES!

CVPR2022 | PointDistiller:面向高效紧凑3D检测的结构化知识蒸馏

Brief introduction of 228 dropout methods of pytorch and fast implementation of dropblock with 4 lines of code based on dropout

dat.gui.js星星圆圈轨迹动画js特效

1. Project preparation and creation

Flink learning 5: how it works

ConstraintLayout(约束布局)开发指南
随机推荐
"All majors are persuading them to quit." is it actually the most friendly to college students?
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
YaLM 100B:来自俄罗斯Yandex的1000亿参数开源大模型,允许商业用途
Flink学习1:简介
我是怎样简化开源系统中的接口的开发的?
Precautions for using sneakemake
Flink learning 4:flink technology stack
Flink learning 3: data processing mode (stream batch)
D's appendto packaging
C language -- Design of employee information management system
Sample development of WiFi IOT Hongmeng development kit
对数器
学习太极创客 — MQTT(七)MQTT 主题进阶
解决cherry pick提交报错问题
Flink learning 2: application scenarios
Oracle/PLSQL: Length Function
达梦数据库安装
Don't be brainwashed. This is the truth about the wages of 90% of Chinese people
Learn from Taiji Maker - mqtt Chapter 2 (I) QoS service quality level
C# Tcp服务器如何限制同一个IP的连接数量?