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

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

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

2023-04-04 07:10 作者:擁抱大自然  | 我要投稿

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System.IO;


public class pictureSpawner : MonoBehaviour

{

? ? public string mainFolder;

? ? string[] folders;? ? ?

? ? string folderName;


? ? public FileInfo[] fileNames;

? ? DirectoryInfo folder;


? ? float gap = 1.0f;

? ? public float deltaGap=0.1f;


? ? public float scale = 1.5f;


? ? FileStream fileStream;

? ? Texture2D texture;

? ? byte[] bytes;


? ? GameObject pointer;

? ? public GameObject pictureBoard;


? ? // Start is called before the first frame update

? ? void Start()

? ? {

? ? ? ? folders=Directory.GetDirectories(mainFolder, "*", SearchOption.AllDirectories);


? ? ? ? SpawnFolders(mainFolder);


? ? ? ? foreach(string i in folders)

? ? ? ? {

? ? ? ? ? ? SpawnFolders(i);

? ? ? ? }? ? ?

? ? }


? ? // Update is called once per frame

? ? void Update()

? ? {

? ? ? ??

? ? }


? ? void LoadFile(string tempInput)

? ? {

? ? ? ? fileStream = new FileStream(tempInput, FileMode.Open, FileAccess.Read);

? ? ? ? fileStream.Seek(0, SeekOrigin.Begin);

? ? ? ? bytes = new byte[fileStream.Length];

? ? ? ? fileStream.Read(bytes, 0, (int)fileStream.Length);

? ? ? ? fileStream.Close();


? ? ? ? texture = new Texture2D(100, 100, TextureFormat.ETC2_RGB , false);

? ? ? ? //此處設(shè)置優(yōu)化格式為ETC2_RGB,不一定是最優(yōu)化的格式,后期有機會找個更好的。


? ? ? ? texture.LoadImage(bytes);


? ? ? ? bytes = null;

? ? }


? ??

? ? void PictureBoardSpawn(string tempName)

? ? {? ? ? ??

? ? ? ? pointer = Instantiate(pictureBoard, new Vector3(transform.position.x+gap, transform.position.y+1, transform.position.z), transform.rotation);

? ? ? ? pointer.transform.localScale = new Vector3(texture.width * 0.001f*scale, 1, texture.height * 0.001f*scale);


? ? ? ? pointer.transform.name = tempName;


? ? ? ? gap += deltaGap;


? ? ? ? //pointer.GetComponent<Renderer>().material.SetTexture("_MainTex", texture);

? ? ? ? //配合無光照模式用。也就是圖片不受光照影響。


? ? ? ? pointer.GetComponent<Renderer>().material.mainTexture = texture;


? ? ? ? texture = null;? ?


? ? ? ? pointer.transform.localScale = new Vector3(pointer.transform.localScale.x * 0.1f, 1, pointer.transform.localScale.z * 0.1f);


? ? ? ? pointer.transform.parent = this.transform;


? ? }



? ? void SpawnFolders(string tempFolderName)

? ? {

? ? ? ? folder = new DirectoryInfo(tempFolderName);


? ? ? ? fileNames = folder.GetFiles("*");


? ? ? ? if (fileNames.Length > 0)

? ? ? ? {

? ? ? ? ? ? foreach (FileInfo temp in fileNames)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? LoadFile(temp.ToString());


? ? ? ? ? ? ? ? PictureBoardSpawn(temp.ToString());

? ? ? ? ? ? }


? ? ? ? ? ? fileStream.Dispose();

? ? ? ? }

? ? }


}


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

分享到微博請遵守國家法律
普安县| 平江县| 民权县| 民乐县| 郁南县| 枣阳市| 藁城市| 溧阳市| 洛扎县| 鲜城| 汝阳县| 杭锦后旗| 株洲县| 慈溪市| 鹿邑县| 山东省| 古蔺县| 乌兰县| 聊城市| 韶山市| 壶关县| 柳河县| 仙居县| 黄石市| 许昌市| 乌兰察布市| 石林| 冀州市| 库车县| 定州市| 咸阳市| 凯里市| 河津市| 大理市| 黄石市| 共和县| 玛多县| 莱阳市| 平遥县| 莲花县| 定兴县|