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 /
avatar image
0
Question by Joyrider · Aug 05, 2013 at 11:21 AM · c#dllreflection

Call c# script function from managed c# script in dll

In an effort to build a custom importer, I'm hitting a wall on a practical matter.

The basic idea would be to put all the basic import logic (several c# editorscripts) into a dll for practical purposes (1 file and user screw-up free), and have a user accessible c# script in unity that would be customizable by the user. More specifically, during import, I'd like to call a function found in that user customizable script to handle custom user defined properties found on objects. So we would have:

a DLL - Containing c# editor scripts handling the import of a file/object

a script - c# Editor script with a function we wish to call from the DLL. My customizable c# script looks like this:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 public class UserPropHandler : Editor {
 
     public static void applyUserProperties (string pProp)
     {
         // write your user property handler code here
         Debug.Log("userData: "+pProp);
     }
 }

I have been trying to figure out how to call applyUserProperties from the DLL. I've tried reflection, which works when everything is in Unity as c# scripts, but once in a DLL doesn't seem to allow our function in the DLL to find the class from the script.

 System.Type upHandler = System.Type.GetType("UserPropHandler");
 System.Reflection.MethodInfo applyUserPropMethod = upHandler.GetMethod("applyUserProperties", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
 object value = applyUserPropMethod.Invoke(null,new object[]{nodeUserDataString});

I've also tried toying with the folders, but I'm guessing since the scripts are in a DLL, they are already compiled and thus where ever I put the c# script, it is compiled after.

Anyone ever tried this? Any suggestions?

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 Xtro · Aug 05, 2013 at 02:54 PM

Scripts are compiled into another dll which is something like Assembly...dll in the build folder.

Maybe you should try to load the assembly into reflection by yourself. http://stackoverflow.com/questions/14479074/c-sharp-reflection-load-assembly-and-invoke-a-method-if-it-exists

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 Joyrider · Aug 05, 2013 at 03:43 PM 0
Share

Indeed, didn't think to look for those ;) By loading the wanted assembly I'm able to get to it. Thanks!

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

15 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Android Build dll not allowed 1 Answer

Error: Failed to set the specified COM apartment state & Canon EDSDK 0 Answers

Connecting to a Qpid Broker 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