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

· Add your reply
  • Sort: 
avatar image
1
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
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
avatar image
1

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

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

Unity editor and inspector header 0 Answers

Arranging KeyCode type variables in custom editor 0 Answers

Custom Inspector Variables 1 Answer

Questions Regarding Images in Custom Inspector/Editor 1 Answer

How would I go about creating a custom Unity Event in a Custom Unity Editor/Inspector? 0 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