Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Fercho5656 · Jun 25, 2018 at 10:02 PM · buttonunityeditorbuttonscustom editorcustom-inspector

How can i create a button in a custom class with UnityEditor using custom editor?

I have a script to make dialogues, i create a second class in that script with the [System.Serializable] so i can see that class in the inspector, but i want to create a button that is supposed to be showed in the inspector, but i just can create the button in the primary class, i cant do it with the other class This is the Second class that i created in my script

 [System.Serializable]
 public class Dialogos{
     [TextArea(5,3)]
     public string dialogo;
     public Vector3 offset;
 }

How can i create a button so that i can see in the inspector(i declared that class as a array so i want that the button is created in any index i can create in the inspector) I hope i explained well :D

Comment
Add comment · Show 14
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 Sonky108 · Jun 26, 2018 at 07:07 AM 0
Share

Deleted previous comment as I finally read the question :D

You need to create another script DialogosEditor and put it in Editor directory. It should have an attribute [CustomEditor(typeof(Dialogos))].

Check both links: https://docs.unity3d.com/ScriptReference/Editor.html

https://unity3d.com/learn/tutorials/topics/interface-essentials/adding-buttons-custom-inspector

avatar image Fercho5656 Sonky108 · Jun 27, 2018 at 01:45 AM 0
Share

Thats what i made!!, but the button just go to the bottom in the inspector, i cannot do that the buttons appears under the Vector3 variable, i cant adjust the position of the button

avatar image NoDumbQuestion Fercho5656 · Jun 27, 2018 at 01:57 AM 0
Share

if you want the button below Vector3 field, you cannot use Draw Default editor. You have to remake every property step by step, line by line

https://docs.unity3d.com/ScriptReference/EditorGUILayout.PropertyField.html

 [CustomEditor(typeof($$anonymous$$yGameObjectScript))]
 [CanEdit$$anonymous$$ultipleObjects]
 public class EditorGUILayoutPropertyField : Editor
 {
     SerializedProperty m_IntProp;
     SerializedProperty m_VectorProp;
     SerializedProperty m_GameObjectProp;
 
     void OnEnable()
     {
         // Fetch the objects from the GameObject script to display in the inspector
         m_IntProp = serializedObject.FindProperty("m_$$anonymous$$yInt");
         m_VectorProp = serializedObject.FindProperty("m_$$anonymous$$yVector");
         m_GameObjectProp = serializedObject.FindProperty("m_$$anonymous$$yGameObject");
     }
 
     public override void OnInspectorGUI()
     {
         EditorGUILayout.BeginVertical();
         //The variables and GameObject from the $$anonymous$$yGameObject script are displayed in the Inspector with appropriate labels
         EditorGUILayout.PropertyField(m_IntProp, new GUIContent("Int Field"), GUILayout.Height(20));
         EditorGUILayout.PropertyField(m_VectorProp, new GUIContent("Vector Object"));
 
         if (GUILayout.Button("I am a regular Automatic Layout Button"))
             Debug.Log("Clicked Button");
 
         EditorGUILayout.PropertyField(m_GameObjectProp, new GUIContent("Game Object"));
 
         // Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI.
        EditorGUILayout.EndVertical();
         serializedObject.Apply$$anonymous$$odifiedProperties();
     }
 }
Show more comments
avatar image Fercho5656 Sonky108 · Jun 27, 2018 at 01:50 AM 0
Share

This is the editor script i made

  using UnityEngine;
     using UnityEditor;
     [CustomEditor(typeof(Dialogo), true)]
     public class DialogoEditor : Editor {
     
         public override void OnInspectorGUI(){
             DrawDefaultInspector();
         }
     
     }

As you can see, is a Little bit empty, thats why i dont put it in the question xD

avatar image Sonky108 Fercho5656 · Jun 27, 2018 at 05:25 AM 0
Share

First of all you have a typo: Dialogo ins$$anonymous$$d of Dialogos in CustomEditor :)

Show more comments

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.

Follow this Question

Answers Answers and Comments

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

Related Questions

Make a custom inspector that shows a group of variables in form of list 2 Answers

Custom Inspector: Making Individual Vertical Containers and Dynamically Adding & Removing Child Elements 1 Answer

How to make a custom inspector to preview tile? 0 Answers

Custom Window with Hierarchy 1 Answer

Are unity objects ID is static in project? 1 Answer


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