Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created June 14, 2018 12:41
Show Gist options
  • Save flushpot1125/a75e00b9bc38fa22a3ce33b49b62d963 to your computer and use it in GitHub Desktop.
Save flushpot1125/a75e00b9bc38fa22a3ce33b49b62d963 to your computer and use it in GitHub Desktop.
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