Question by
imfrager55 · Sep 15, 2018 at 04:16 AM ·
c#unityeditor
C# Unity class Arrays for Editor GUI textures. Beginner problem.
I've been looking at this for a long time. i think the problem has something to do with the class Notes. probably the part where i thought it was a good idea to add in an array. but i have been looking at this for days now and i cant find the problem.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class hello : EditorWindow {
//-----------------------stuff & paths-----------------------------
//------------------------variables------------------------------------------
Note[] NotesList;
Rect Header, ToolButtons, LeftNote, RightNote;
int _menue, NoteNum;
Texture2D Hcol, Ncol1, Ncol2;
//-------------------------Main activators---------------------------------
[MenuItem("Window/hello")]
static void showmenue() {
hello something = (hello)GetWindow(typeof(hello));
something.minSize = new Vector2(600f, 400f);
something.Show();
}
private void OnEnable() {
ReadTextFromeNote(NotesList);
}
private void OnGUI() {
parameters();
Menues();
}
// -------------------this is where all the RECT's are defined -----------------------------
void parameters() {
Header = new Rect(0f, 0f, Screen.width, 75f);
ToolButtons = new Rect(0f, Header.height, Screen.width, 20);
LeftNote = new Rect(0f, Header.height + ToolButtons.height, 255f, Screen.height);
RightNote = new Rect(Header.height, LeftNote.width, Screen.width, Screen.height);
}
//--------------------All the extra functions--------------------------------------------------------
public Texture2D readtexture(string name) {
Texture2D text;
byte[] bytes;
bytes = File.ReadAllBytes(Application.dataPath + "/Editor/Resources/Images/" + name);
text = new Texture2D(1, 1, TextureFormat.ARGB32, true);
text.LoadImage(bytes);
text.Apply();
return text;
}
//---------------------Stuff and theyre paths----------------------------------------
//---------------------Reading & writing---------------------------------------------
public void ReadTextFromeNote(Note[] notes) {
using (StreamReader SD = new StreamReader(Application.dataPath + "/Editor/Everything.txt")) {
int t, g;
string placeholder;
//CREATE Amount of notes
NoteNum = int.Parse(SD.ReadLine());
notes = new Note[NoteNum + 3];
for (int j = 0; j < NoteNum + 2; j++) {
notes[j] = new Note();
}
//Reads
for (int i = 0; i < NoteNum; i++) {
t = 0;
g = 0;
notes[i].Namefm = SD.ReadLine();
notes[i].Description = SD.ReadLine();
while ((placeholder = SD.ReadLine()) != "^") {
if (placeholder.Substring(0, 3) == "#@#") {
notes[i].intorINF[t] = int.Parse(placeholder.Substring(3, 5));
notes[i].info[t] = placeholder.Substring(9, placeholder.Length - 9);
t++;
} else if (placeholder.Substring(0, 3) == "#~#") {
notes[i].intorIMG[g] = int.Parse(placeholder.Substring(3, 5));
notes[i].randomIMGS[g] = Resources.Load<Texture>("Images/" + placeholder.Substring(9, placeholder.Length - 9));
//readtexture(placeholder.Substring(9, placeholder.Length - 9));
g++;
}
}
}
}
}
//-------------------Main buttons and screen-----------------------------------------
public void Menues() {
_menue = GUI.Toolbar(ToolButtons, _menue, new string[] { "Notes", "Textures", "Materials"});
switch (_menue) {
case 0:
//basically the problem is here
GUI.DrawTexture(LeftNote, NotesList[0].randomIMGS[0]);
break;
case 1:
break;
case 2:
break;
}
//-------------------extra classes and structs--------------------------------------------
public class Note {
public string Namefm;
public string Description;
public string Category;
public bool SearchingBlob;
public Texture[] randomIMGS = new Texture[10];
public string[] info = new string[10];
public float[] intorIMG = new float[10];
public float[] intorINF = new float[10];
}
}
Comment
Well NullReferenceExceptions are actually not allowed as questions on this forum, as they are inevitably user error or inexperience. Going to send this back to moderation, but line 97 for you is:
GUI.DrawTexture(LeftNote, NotesList[0].randomI$$anonymous$$GS[0]);
$$anonymous$$ake sure your your NotesList
array has been instantiated and that whatever the randomI$$anonymous$$GS
collection is also exists.