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
0
Question by shadowdiver · Oct 03, 2015 at 03:39 PM · script.textdependencies

Set own script as a dependency to a text component

Hi, i have a script that should be add to every ui text component automaticaly.

How can i do that?

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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DoTA_KAMIKADzE · Oct 04, 2015 at 12:44 AM

Variant #1 - inherit:

Create ImprovedText:

 using UnityEngine;
 using UnityEngine.UI;
 
 [RequireComponent(typeof(CustomScript))] //auto add your CustomScript
 public class ImprovedText : Text
 {
 
 }

Though you most likely will want to add some menu items as well, so here is example for those:

 using UnityEngine;
 using UnityEngine.UI;
 
 [AddComponentMenu("UI/ImprovedText")]//Add to Component menu
 [RequireComponent(typeof(CustomScript))]
 public class ImprovedText : Text
 {
 
 }

rest can be done through editor script:

 #if UNITY_EDITOR
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEditor;
 
 public sealed class PrefabCreator : Editor
 {
     private static Vector2 defaultPos { get { return new Vector2(0, 0); } }
     [MenuItem("GameObject/UI/ImprovedText", false, 10)]//Add to GameObject menu
     [MenuItem("Improved Components/Improved UI/ImprovedText")]//or create custom menu item
     private static void CreateImprovedText()
     {
         GameObject newTxt = new GameObject("New ImprovedText", typeof(ImprovedText));
         newTxt.layer = LayerMask.NameToLayer("UI");
         // newTxt.AddComponent<CustomScript>(); //this is another workaround for RequireComponent, that will work only when this function is called
         newTxt.transform.position = defaultPos;
     }
 }
 #endif

you can even add custom Editor script that will check if your component has your script component and if it doesn't then do something (for more information about Editor scripts check out API, Manual and Tutorials).

Variant #2 - purchase Unity source code license and modify it (Text component) instead of inheriting.

Variant #3 - EditorApplication.hierarchyWindowChanged, use example from the link, then just loop through objects, detect if object with Text component was added - if yes then add your script to it as well (check variant #1 - it contains example on how to add component from script).

Comment
Add comment · Show 3 · 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 shadowdiver · Oct 04, 2015 at 01:15 PM 0
Share

Option 2 seems to be what I'm looking for, but I do not know how to do that.

avatar image DoTA_KAMIKADzE shadowdiver · Oct 04, 2015 at 10:25 PM 0
Share

If you mean how to modify then look at v#1 and just do that directly with Text class ins$$anonymous$$d of creating ImprovedText.

If you mean how to purchase source code license from Unity then just contact sales person (same can be found on Get Unity page under Enterprise tab). I guess the pricing is figured out depending on various aspects, and probably it is not cheap, though TBH I don't know even approximate numbers (you can ask for example Nexon, but then again I guess it's under NDA), and I don't really think that you want source code license just for that, if I were you I'd go for v#1.

avatar image shadowdiver DoTA_KAMIKADzE · Oct 05, 2015 at 06:07 PM 0
Share

Ok, thats a little oversized. Some Guidelines will hopefully do it. Thanks for all the help.

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

30 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

Related Questions

Why isn't my C# code sending updates to my text scoreboard? 1 Answer

Score wont display 0 Answers

Text File Show Problem In Android Apk 0 Answers

C# allowing the Player to name themselves and using it later in text 1 Answer

[Help] how do I reference/access another script in unity C# 2 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