Skip to content

Call C# static method #23

Locked Answered by exodrifter
dragxnd asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it's possible. I'm guessing you didn't add the assembly TestStatic is in to the IronPython runtime. For example:

C Sharp:

var engine = UnityPython.CreateEngine();
var scope = engine.CreateScope();
var source = engine.CreateScriptSourceFromString(text.text);

source.Engine.Runtime.LoadAssembly(
	AppDomain.CurrentDomain.GetAssemblies()
		.SelectMany(t => t.GetTypes())
		.Where(t => t.Namespace == "Foobar")
		.Select(t => t.Assembly)
		.First()
);

source.Execute(scope);

...

namespace Foobar
{
	public static class TestStatic
	{
		public static void TestStaticMethod()
		{
			Debug.Log(">> Test Static");
		}
	}
}

Python:

import Foobar

Foobar.TestStatic.TestStaticMethod()

There's probab…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by exodrifter
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #23 on December 21, 2020 15:25.