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 Somian · Jul 28, 2018 at 03:31 AM · editoreditorguiextension

Override TextEditor

Hi,

I created a class derived from Text (UI namespace). For this, wold like to create a custom editor, but leave most of the original editor intact.

according to: https://docs.unity3d.com/ScriptReference/UI.TextEditor.html

"Extend this class to write a custom editor for an Text-derived component."

The problems is, however: if I do this:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEditor;
 
 
 [CustomEditor(typeof(StyledText))]
 [CanEditMultipleObjects]
 public class StyledTextEditor : TextEditor {
 
     public override void OnInspectorGUI()
     {
         GUILayout.Label("bla");
     }
 }


I get a "no suitable method to override"

I can change it to derive only from "Editor", but then all the text related controls are gone.

Is there some sample code on how to make your own TextEditor? this seems odd, because "TextEditor", being derived from "Editor" should have the OnInspectorGUI.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Jul 28, 2018 at 03:57 PM

you're right, a class that can be overriden should provide it's overridable counterpart or be sealed.
I once tried the same thing and came up with just copy and pasting the TextEditor source code you run my own editor. Out can be found here:
https://bitbucket.org/Unity-Technologies/ui/src/a3f89d5f7d145e4b6fa11cf9f2de768fea2c500f/UnityEditor.UI/UI/TextEditor.cs?at=2017.3&fileviewer=file-view-default. fun fact: according to bitbucket, it should work, because the class is neither sealed, nor is the method :/

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
0

Answer by Bunny83 · Jul 29, 2018 at 07:17 PM

There is a TextEditor class inside the UnityEngine namespace (which is a class used by the IMGUI system for input fields) as well as in the UnityEditor.UI namespace. You import the UnityEngine namespace and therefore whenever you use TextEditor you will be using the wrong one. Keep in mind that when you import both namespaces (UnityEngine and UnityEditor.UI) you get an ambiguous reference error as the compile does not know which class you want to use. You have to use the full class name like this:


 public class StyledTextEditor : UnityEditor.UI.TextEditor
 {


Keep in mind when you override a method you completely replace it. So your example code just shows your label, nothing else. You may want to call base.OnInspectorGUI() inside your overridden method. However you may want to have a look at the actual implementation. Note that the UI system is released under a permissive licence

Comment
Add comment · Show 2 · 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 Bunny83 · Jul 29, 2018 at 07:18 PM 0
Share

I've actually written this answer yesterday but missed sending it out ^^. Just stumbled across the tab again ^^.

avatar image hexagonius · Jul 30, 2018 at 06:28 PM 0
Share

also didn't know that, nice to know

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

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

How do I get the default scene GUI for a CustomEditor for RectTransform? 1 Answer

Initialising List array for use in a custom Editor 1 Answer

Custom Inspector for a List ? 2 Answers

Raycast in Editor Mode does not work 0 Answers

PropertyDrawer not painted when scrolling upwards 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