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 /
  • Help Room /
avatar image
6
Question by jhand · Oct 05, 2015 at 01:12 AM · guirecttransformcustomeditor

How do I get the default inspector for a CustomEditor for RectTransform?

Below is how my RectTransform inspector looks before including the editor script:

alt text

After I add the following script:

 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(RectTransform))]
 public class MyRectTransformEditor : Editor
 {
   public override void OnInspectorGUI()
   {
     DrawDefaultInspector();
     if (GUI.changed)
       Debug.Log("test");
   }
 }

I get this:

alt text

The console does output "test" when the values are changed after the script is added to the project.

What I'm trying to accomplish is changing the behaviour of RectTransforms (specific gameobjects) to go by tile index instead so that I can lock the width/height to an interval of whatever the tile width/height is. However, I don't want to sacrifice the way RectTransform works currently. How can I accomplish this?

recttransformi-1.png (187.9 kB)
recttransformi-2.png (185.2 kB)
Comment
Add comment · Show 4
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 bittarello · Oct 27, 2015 at 08:19 PM 0
Share

I have the same problem. Does somebody know the answer?

avatar image gameplay4all · Oct 27, 2015 at 10:00 PM 0
Share

Notice that the first editor is actually already a custom editor. So it makes sense that the default inspector looks different. I don't know a fix for sure but you could try to find the editor script for the rect and modify it. Or use the EditorGUI.propertyfield to draw the whole rect class in one go. I'm not sure about these so that's why the comment :) good luck

avatar image bittarello gameplay4all · Oct 27, 2015 at 11:43 PM 0
Share

You are right, I got the same conclusion. $$anonymous$$aybe if I could extend this custom editor it could be done, but I don't know what class does it. I searched in the list of classes in unity.engine and unity,editor.

For now, the solution is: create a new component base and create the new custom editor. Thanks for replying.

avatar image Mr_Mow · Jul 17, 2018 at 09:39 PM 1
Share

3 years later, same problem. Did you finally found the RectTransformEditor class ? Edit: found the solution here : https://forum.unity.com/threads/recttransform-custom-editor-ontop-of-unity-recttransform-custom-editor.455925/

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by UDN_52bf9f4d-2d40-4386-bad9-b8048056a414 · Dec 24, 2016 at 11:48 PM

For any one looking for the aswer, you can use "Editor.CreatEditor(object)". Where object is the object(s) you want to display.

https://docs.unity3d.com/ScriptReference/Editor.CreateEditor.html

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 RudyTheDev · Aug 25, 2018 at 01:18 PM

CreateEditor(targets, typeof(Editor).Assembly.GetType("UnityEditor.RectTransformEditor")).OnInspectorGUI();

will draw the Unity's editor for RectTransforms.

Disclaimer: this is an internal class and if Unity changes stuff, your code will break.

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

38 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

Related Questions

Convert global or local position to anchorPosition for a RectTransform? 0 Answers

MoveTowards and Lerp not working on RectTransform? 1 Answer

EditorGUILayout.BeginVertical("Box") not filling the inspector 0 Answers

How to make a health bar with multiple fields along the same bar? , 0 Answers

Help with Time Crisis crosshair 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