Created
June 14, 2018 12:41
-
-
Save flushpot1125/a75e00b9bc38fa22a3ce33b49b62d963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using System.IO; | |
public class createMesh : MonoBehaviour { | |
public GameObject cubePrefab; | |
Material[] m_PixelMaterials; | |
Color[] m_PixelColors; | |
//Ref | |
//http://tapjockey.com/archives/567/ | |
private List<string[]> pos_color = new List<string[]>(); | |
void Start () { | |
var csvFile = Resources.Load("保存したcsvファイル名。拡張子は入れない") as TextAsset; | |
var reader = new StringReader(csvFile.text); | |
while(reader.Peek() > -1) { | |
// 一行読み込む | |
var lineData = reader.ReadLine(); | |
// カンマ(,)区切りのデータを文字列の配列に変換 | |
var address = lineData.Split (','); | |
// リストに追加 | |
pos_color.Add(address); | |
} | |
foreach(var data in pos_color) { | |
Vector3 postmp = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3])); | |
var obj = Instantiate(cubePrefab, postmp ,transform.rotation);//rotationまで入れないとエラーになる。rotationの値は0,0,0でよいので、この形にしておく | |
var mat = obj.GetComponent<Renderer>().material; | |
mat.color = new Color(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6]) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment