1

I have a library made for Unity that needs to run some codes at Application's onCreate (Its callback interface must be added at application creation). The code must be entered by user's who are going to use my library.

My question is: Is it possible to run the user's C# code at the Application's oncreate?

Consider this code:

public class MyApplication extends android.app.Application {

    @Override
    public void onCreate() {
       MyLibrary.setCallBack(new Callback {
             @Override
             void onSuccess() {
                // Here some code must be entered by user
                // Since library is for Unity it should be a c# code that user has written
             }
       });
     }
}

How can user add c# code that can be entered there when app starts?

Thanks in advance.

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
  • You won't be able to type c# code in a java file. But there are other solutions to this problem. You can check out this URL: https://stackoverflow.com/questions/33779069/how-to-call-c-sharp-function-from-java/33782015 Hope it helps – Tom Coldenhoff Mar 06 '19 at 13:40
  • No. I guess there is a misunderstanding. By C# I mean the user's logic. Looks like it's not gonna happen. – Mahdi-Malv Mar 06 '19 at 14:08

1 Answers1

1

As a short answer, no.

The whole Unity Engine needs to be up and running for any code using UnityEngine namespace (that is pretty much all unity code) to be functional. Unity needs to set up the context, allocate memory, get the Mono running etc, before the first line of code from the user gets executed.

In normal circumstances this is appropriate, maybe you can allow callback exchange at a later point of the application lifetime?

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
zambari
  • 4,797
  • 1
  • 12
  • 22