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 /
This question was closed Jan 06, 2016 at 11:18 AM by Sarseth for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Sarseth · Jan 07, 2016 at 06:45 PM · prefabtexteditor-scripting

Unity editor context scripts - on object selected draw text near it

I've created public class EditorMenuMyPrefab {

     [MenuItem ("GameObject/Create Other/MyOwnPrefab")]
     static void addMyPrefab(MenuCommand menuCommand) {
         Object prefab = AssetDatabase.LoadAssetAtPath ("Assets/Prefabs/Path/MyOwnPrefab.prefab", typeof(GameObject)); 
         if (prefab != null) {
             GameObject newGameObject = (GameObject)PrefabUtility.InstantiatePrefab (prefab);
             GameObjectUtility.SetParentAndAlign (newGameObject, menuCommand.context as GameObject);
 
             Undo.RegisterCreatedObjectUndo (newGameObject, "Create " + newGameObject.name);
             Selection.activeObject = newGameObject;
         }
     }

Now I wish to have a method which will draw text near this new generated object when I have it selected. That's the first question. Only in Editor context! So I do not want to put it in element script, I want it outside of game. Editor**.cs

Then I want to draw text near this. When I move object, this text would move with itself. I guess I'd have element, then I can take transform to take this position and print this text on that. But I can't print simplemessage using Handles, need example to use in method whcih is called on selecting elements. Ofc it'd have to be only attached to elements of some kind of prefabs, not all elements and filter it. It wouldn't be optimize.

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Sarseth · Jan 06, 2016 at 11:07 AM

I've managed to draw text:

 [CustomEditor (typeof(MyPrefab))]
 public class EditorMyPrefab : Editor {
     void OnSceneGUI () {
         GameObject selectedObject = Selection.activeGameObject;
         Handles.Label (selectedObject.transform.position, "SDADASD");
     }
 }

selectedObject can be null.
MyPrefab is a script attached to this prefab.
Can not answer my own question till atigin for moderation :( shame. But I could convert ^^ hacked ;d

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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I programmatically assign a GameObject to a prefab? 6 Answers

Viewpport for Custom Editor 1 Answer

Mark gameobject field as changed from prefab 2 Answers

How do I get the Text Mesh Pro UGUI working in a prefab? 1 Answer

Basic: Text sub-component of sprite prefab not showing 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