- Home /
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?
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
Indeed, didn't think to look for those ;) By loading the wanted assembly I'm able to get to it. Thanks!
Your answer
Follow this Question
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