Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by wiresnips · May 19, 2012 at 03:39 AM · variable-definition

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);
     }
 }

alt text

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · May 19, 2012 at 03:40 AM 0
Share

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!

avatar image wiresnips · May 19, 2012 at 03:44 AM 0
Share

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?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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..

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges