Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by hoy_smallfry · Jan 21, 2013 at 10:49 PM · dllmonobehaviourlibraryhiding

Obfuscating DLL classes from the users

This might sound like an odd request, but here goes:

So I'm writing a DLL where many classes are MonoBehaviour scripts. However, I don't want my users to directly access certain scripts (no dragging them to objects, no calling AddComponent() on them, etc).

I'm trying to make this library a black box, so if they want to make an object with one of those scripts, they need to request it through the one main script in the DLL that is available.

Is there a way to hide scripts in a DLL from the user, or at least, is there a way to make sure users can't directly add scripts either dragging or calling AddComponent()?

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 tnetennba · Jan 22, 2013 at 12:53 PM 0
Share

Disabling addcomponent should not be possible from the chain of inheritance monobehaviour->behaviour->component. So all your classes inheriting from monobehaviour in the dll will have type component and can therefore be added using add component. One way to make sure that aspects of the dll are hidden would be to use the internal keyword and possibly user the TypeBuilder class to create the types on the fly. This way you could use a factory to return new instances of the types that you actually want to create. This should also help with addcomponent.

avatar image Bunny83 · Jan 22, 2013 at 02:58 PM 0
Share

Components can only be created with AddComponent. You cant create them with "new".

avatar image kat0r · Jan 22, 2013 at 03:40 PM 0
Share

If the user shouldn't be able to attack those scripts to GameObject, why are they $$anonymous$$onoBehaviour scripts?

avatar image hoy_smallfry · Jan 22, 2013 at 06:44 PM 0
Share

The reason is that we want a unified look and behavior for specific menus along all the products we're making. We're a big company, so our little studios have a tendency to take what we make for them and modify it somehow for their ends, then complain when it breaks because of their modifications.

We want to avoid that whole ordeal by giving them only the access to create the menu and hook certain callbacks to it for info. In other words, we're trying to take away the gun that they shoot their foot with.

I've been successful so far in making it a standalone library, except I'm concerned that having the classes exposed in Assets can be a problem. If they wanted to, they could make their own menu layout and just hook the logic in, and now we have different looks across our products, headache, etc.

1 Reply

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

Answer by Bunny83 · Jan 22, 2013 at 02:57 PM

It's not possible since Unity has to register all MonoBehaviour classes in the AssetDatabase to actually be able to attach it to a GameObject. If you manage to hide it from Unity, you won't be able to attach it to a GameObject.

What you can do is create a MonoBehaviour wrapper class that get linked to one of your custom classes. However such a construct can't be serialized by Unity, so you have to find your own way. I don't see the reason for this anyway.

edit
Ok if it's just to save the user from extending stuff they shouldn't, just make your classes sealed like Unity does with it's internal stuff.

Since Mono is a managed environment you can't prevent others from decompiling / reuse your code. If they do and they get in trouble that's their problem ;) Obfuscating is nice, but doesn't help much. Reuse is always possible.

I wouldn't even try to prevent the user from adding a certain component to a GameObject. That just irritates the user more than it's useful and might even break things. It's better to implement some checks in the component if it has been created "correctly". this could be done by adding a serialized hidden value which get set by your creator script.

Make use of Debug.LogWarning (or in rare cases Debug.LogError) to inform the user what's wrong.

Comment
Add comment · Show 1 · 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 Julien-Lynge · Jan 22, 2013 at 03:39 PM 0
Share

You could immediately remove the component whenever it's added, either by using [ExecuteInEdit$$anonymous$$ode] or by using a custom editor.

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

12 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

Related Questions

Cannot compile .exe with specific .dll. (but with other .dlls created the same way) 0 Answers

Acessing Scripts in Assets folder using .dll 1 Answer

Using 2 DLLs with the same name 2 Answers

'The type or namespace name could not be found' 1 Answer

It's possbile to export data to excel(.xls) in unity? 1 Answer


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