Today I am just trying to make custom Unity script inspector, but I am facing a problem: I can´t get content of file.
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
[CustomEditor(typeof(MonoScript))]
public class SimpleEditCore : Editor {
public string text;
public string path;
public SimpleEditCore(){
text = new StreamReader (path).ReadToEnd ();
}
public override void OnInspectorGUI()
{
path = AssetDatabase.GetAssetPath (target);
// code using text and path
}
}
And now the problem: I need to set textarea text ot text of file (script), but to make it editable I need to use other function than OnInspectorGUI(), but when I put code into public SimpleEditCore(), I just can´t get the path of file, because the path of the file is target and this target is only defined in OnInspectorGUI(). How to solve that?