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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Display texture in a custom inspector? 1 Answer

Working with very tiny objects / Reducing editor camera fly speed 1 Answer

Wanted editor extension called only when changed 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges