- Home /
Question by
Arin_Jisoo · Dec 29, 2017 at 08:05 AM ·
c#unity 5inspectorfile
Save on FileStream using WriteLine
What i want is. when the user press save button. all the string below will be saved and update in a pad. they said i must use sw.WriteLine("yow");. but i don't want to print "yow" this is why i want to print [string.Format("{2}", x, y, map[y][x] )] the holder of my string
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.IO;
public class LevelEditor : EditorWindow
{
int width;
int height;
int[][] map;
Color[] colors = new Color[] { Color.red, Color.yellow, Color.blue, Color.magenta, Color.green, Color.cyan, Color.gray, Color.black, Color.white};
// string[] colorNames = new string[]{"Red", "Yellow", "Blue", "Magenta", "Green", "Cyan", "Gray", "Black", "white"};
Color colors1 = Color.red;
int[] ButtonColorIndexs;
int ButtonCounter=0;
bool buttonClicked = false;
[MenuItem("Window/Level Editor")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(LevelEditor));
}
void Start(){
}
void OnGUI()
{
if(buttonClicked)
GUI.color = Color.red;
GUILayout.BeginVertical();
{
width = EditorGUILayout.IntField(width);
height = EditorGUILayout.IntField(height);
if (GUILayout.Button("Generate" ,GUILayout.Width(1350), GUILayout.Height(40)))
{
UpdateArray(width, height);
ButtonColorIndexs = new int[(width * height)+1];
}
if (map != null)
{
ButtonCounter = 0;
foreach (var y in Enumerable.Range(0, map.Length))
{
GUILayout.BeginHorizontal();
{
foreach (var x in Enumerable.Range(0, map[y].Length))
{
GUI.color = colors[ButtonColorIndexs[ButtonCounter]];
if (GUILayout.Button(string.Format("{2}", x, y, map[y][x] ), GUILayout.Height(50)))
{
ButtonColorIndexs[ButtonCounter]++;
if (ButtonColorIndexs[ButtonCounter] > colors.Length - 1)
ButtonColorIndexs[ButtonCounter] = 0;
map[y][x]++;
ButtonCounter++;
if (map[y][x] >= 9) {
map[y][x] = 0;
}
// colorChanger++;
Debug.Log("Main Button clicked!");
}
ButtonCounter++;
}
}
GUILayout.EndHorizontal();
}
GUI.color = colors1;
if (GUILayout.Button("Save")){
using (FileStream fs = new FileStream("assets/LevelResources/LevEd.txt",FileMode.Create, FileAccess.Write)){
fs.Close();
using (FileStream fs2 = new FileStream("assets/LevelResources/LevEd.txt",FileMode.Open, FileAccess.Write)){
using (StreamWriter sw = new StreamWriter(fs2)){
sw.WriteLine("yow");
sw.Close();
fs2.Close();
}
}
}//end of FileStream
}
}
}
GUILayout.EndVertical();
GUILayout.BeginVertical ();
{
if(map != null){
ButtonCounter = 0;
foreach(var y in Enumerable.Range(0, map.Length))
{
GUILayout.BeginHorizontal();
{
foreach(var x in Enumerable.Range(0, map[y].Length))
{
GUILayout.Label(string.Format("{2}", x, y, map[y][x])+",");
//ButtonCounter++;
}
}
GUILayout.EndHorizontal();
}
}
}
GUILayout.EndVertical();
}
void UpdateArray(int width, int height)
{
map = new int[height][];
foreach (var y in Enumerable.Range(0, height))
{
map[y] = new int[width];
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Could not load file or assembly 'nunit.core.interfaces (Unity 5.3 and 5.4 only) 0 Answers
Distribute terrain in zones 3 Answers
Will System.IO.File work on Macs 2 Answers
How do I hide methods from the animation event inspector window? 2 Answers
Instantiated Object Wont save a reference to the prefab, instead sets to itself 1 Answer