- Home /
how to access a custom editor's public variables?
I have done this before, but I can't find it again. I have a custom editor class, and I want to set the variables of the editor.
For example, check out killTex in the code below- this is a texture of a little red X that I use as an in-editor delete button (screenshot further below).
I can not for the life of me find out where I assigned that image to killTex. If I wanted, eg, to make it a green checkmark instead, where would I look for the linkage?
class NodeEditor extends Editor {
// this stuff makes the node deletion button pretty
var killTex:Texture;
var nullStyle:GUIStyle = new GUIStyle();
var bDim:int = 20;
var ScreenHeightCorrection:int = 38; //the fuck?
protected function deleteButton (pos:Vector3) :boolean {
pos = target.transform.TransformPoint( pos );
var bPos:Vector3 = sceneCam.WorldToScreenPoint(pos);
bPos.y = Screen.height - bPos.y - ScreenHeightCorrection;
bPos.y -= bDim + 2;
bPos.x += 2;
Handles.BeginGUI();
var del:boolean = GUI.Button( Rect(bPos.x, bPos.y, bDim, bDim), killTex, nullStyle );
Handles.EndGUI();
return del;
}
// note: SceneView is undocumented. If at any time in the future it breaks, we will all die horribly.
function get sceneCam () :Camera {
return SceneView.lastActiveSceneView.camera;
}
function OnInspectorGUI () {
DrawDefaultInspector();
}
function get owner () :NodeList {
return (target as NodeList);
}
}
I'm fairly certain you can only do that from within that specific editor, but if you say you've found this before then I'd be very interested in it!
If by "within that specific editor", you mean in the editor's code, then no. As you can see, the code makes no reference to any specific texture, and yet a specific texture is drawn. If by "within that specific editor" you mean some other thing, you might be talking about the answer to my question?
Answer by Bunny83 · May 19, 2012 at 03:58 AM
This could be done in some old Unity versions via the default references. However due to a lot of problems with serialization (as i understand it) they removed the default references from ScriptableObjects and editor scripts. Now default references can only be used for MonoBehaviours. See this question.
There was another question about this a few month ago. Officially they removed the support in version 2.1
, but in Unity 3.0
it's still possible. In the actual version 3.5+
they finally removed it completely
Now the only way to get assets in an editor script, is to either search for them or use an absolute path. There are many ways to load assets, the easiest is to use Resources.LoadAssetAtPath which is actually and editor only function, even it's part of the Resources class.
The bigger editor extensions like Playmaker have included their images in their dll assembly and they load them manually from the dll resource.
edit
A hacky workaround could be to create a dummy MonoBehaviour with some public variables, assign your default references to this monobebaviour script and let the editor create a temporary gameobject with that script just to get the references ;)
Haven't tried this yet.
Actually i miss this feature too. I always used a default reference for a custom skin in my custom EditorWindows. Well, i guess we have to live with it..
Your answer
Follow this Question
Related Questions
How do I get the Year I built my game in? 0 Answers
How do I display the key from input manager in GUI text? 1 Answer
Creating single variable across all app instances 2 Answers
how to define this variable input directly from script (not from editor) ? 1 Answer
Best way to assign a bunch of variables? 2 Answers