• 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
Question by MasterLetch · Feb 12, 2013 at 12:16 AM · editorinspectorserializabledrawer

Serializable class with interactivity

I'm curious to know, is it possible to call functions from serializable classes similar to the a custom editor for creating buttons and toggles.

example

 [CustomPropertyDrawer(typeof(PathNode))]
 public class PathNodeDrawer : PropertyDrawer {
     
     
      public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
         EditorGUIUtility.LookLikeControls ();
         position.xMin += 4;
         position.xMax -= 4;
         
         //EditorGUI.BeginProperty (position, label, property);
         position = EditorGUI.PrefixLabel(position,GUIUtility.GetControlID (FocusType.Passive), label);
         property.FindPropertyRelative("location").vector3Value = EditorGUI.Vector3Field(new Rect (position.x, position.y - 16, position.width, position.height),"", property.FindPropertyRelative("location").vector3Value);
         //EditorGUI.EndProperty ();
         
     }    
 }

creates something that looks like this in the inspector (see image)

where the class "location" Vector3 is I want to place a button that does a function for the in the scene

so i have some ideas on how i should do that, (like storing the functions and variables for the editor in the class itself). anyone else have a cleaner method?

capture.png (9.9 kB)
Comment

People who like this

0 Show 5
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 iwaldrop · Feb 12, 2013 at 06:51 AM 0
Share

You can create your own static class with helper methods which you can call from anywhere.

avatar image MasterLetch · Feb 12, 2013 at 11:38 AM 0
Share

this is true, but that doesn't work in this case. i essentially need a button in custom gui so that i can activate widgets in the scene that change the fields you see there

avatar image iwaldrop · Feb 12, 2013 at 04:26 PM 0
Share

Buttons can call static methods in external classes...

avatar image MasterLetch · Feb 12, 2013 at 04:55 PM 0
Share

I'm sorry i wasn't very clear lol, I need a button that can act on an array of instances of something that has been created in a class through inspector (like waypoints in a pathing system that each have special ways of setting them but still need to do it through inspector)

avatar image iwaldrop · Feb 12, 2013 at 09:27 PM 0
Share

Well I'm afraid I'm still not clear on your problem. You mention in your question something about a "location" class, but nothing like that is visible in the screenshot you posted. So I'm unsure now if you're talking about a button in the scene or in the inspector. Either way, having a button in the inspector that calls a method in a static class should be doable. That method would poll the scene for whatever kind of object you're interested in and do its work on n number of objects found. You shouldn't dirty up your game code with values that will only be used in the editor. :)

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 People are following this question.

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

Related Questions

Custom Inspector for a [System.Serializable] 2 Answers

Edit array element properties in editor 0 Answers

Logic Problems using for loops 0 Answers

Editor -- Best way to know that no controls are being used? 0 Answers

Custom names for variables (array-elements!!) in the inspector?? 3 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