• 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 · Jan 28, 2013 at 04:53 AM · editorinspectorcustom

Custom Editor problems

I'm having problems getting types and functions working from javascript examples. can anyone help me with a C# version here is the code

 [CustomEditor(typeof(Container))]
 public class ContainerEditor : Editor  {
     
     public override void OnInspectorGUI (){
     EditorGUILayout.EnumMaskField ("droptype");
     }
 }

this is the script its editing

 public class Container :  MonoBehaviour, CanDrop

{

 public GameObject element;
 public float borderDimension;
 public int viewcount;
 public int count = 0;
 public int maxsize;
 public TransformToTransform moveMethod;
 public bool initialized = false, CallOnAwake = false, quickscale = false, invert = false;
 public DropType type;
 
 GameObject placement;
 Vector3 topleftcorner;
 float elementw, elementl;
 float width, length;
 float elementx, elementz;
 float offset = 0;
 float maxoffset = 0;
 int scrollcount = 0;

so essentially, I can't figure out how to get DropType (enum) type into the custom editor. any help would be good.

Comment

People who like this

0 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 numberkruncher · Jan 28, 2013 at 05:02 AM 0
Share

Do you want to be able to select multiple flags for the type field, or just a single value?

avatar image MasterLetch · Jan 28, 2013 at 06:07 PM 0
Share

multiple flags... but thats not even the problem. i can't figure out how to get my variables that i want effected in class inheriting editor.

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by numberkruncher · Jan 28, 2013 at 07:42 PM

It is generally better to do this using SerializedProperty and SerializedObject to benefit from automatic undo/redo and persistence:

 [CustomEditor(typeof(Container))]
 public class ContainerEditor : Editor {

     SerializedProperty typeProp;

     void OnEnable() {
         typeProp = serializedObject.FindProperty("type");
     }

     public override void OnInspectorGUI() {
         serializedObject.Update();
         
         typeProp.intValue = (int)(DropType)EditorGUILayout.EnumMaskField("Label string", (DropType)typeProp.intValue);
         
         serializedObject.ApplyModifiedProperties();
     }

 }

Warning, the above has not been tested, but it should work :-)

Comment
MasterLetch

People who like this

1 Show 0 · 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
avatar image

Answer by MalikDrako · Jan 28, 2013 at 06:47 PM

you can use "target" to get the first object your editor is editing, and "targets" to get an array of all objects your editor is editing (if you want to support multi-editing). You will probably want to assign a variable with the correct type so you dont have to keep casting the target

Then you can do

 Container targetContainer = (Container)target;
 targetContainer.type = (DropType)EditorGUILayout.EnumMaskField("Label string", targetContainer.type);
Comment
Bunny83

People who like this

1 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

11 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 avatar image

Related Questions

Custom inspector, show string instead of component type 0 Answers

How would I go about creating a custom Unity Event in a Custom Unity Editor/Inspector? 0 Answers

Unity editor and inspector header 0 Answers

Open new editor window from editor class 2 Answers

Editor GUI: Object preview icon 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