using System;
using UnityEngine;
namespace dllTest
{
public class GenericCode
{
public static int a = 0;
// Generate a random number between min and max, including min and max
public void GenRandom (int min, int max)
{
System.Random random = new System.Random();
a = (random.Next(min, max +1));
}
}
}
unity
using UnityEngine;
using UnityEditor;
using System.Collections;
using dllTest;
public class test : MonoBehaviour {
GenericCode gc = new GenericCode();
void OnGUI () {
if(GUILayout.Button("gen random"))
{
gc.GenRandom(0,10);
int a = GenericCode.a;
Debug.Log(a);
}
}
}
it’s realy easy in visual C#, create a new class library project.
add a reference to the UnityEngine.dll in the project.
add your functions to the class.
build the dll and copy it in the assets folder.
call your functions from your script.
No, because it’s trivial to decompile DLLs. Anyway you should generally be providing source code regardless, since many people won’t buy without it. The primary reasons for using a DLL are 1) everything consolidated into one file, 2) double-clicking errors in the console goes to where it was called in your code, rather than the source code, which is much more useful when you’re actually trying to use the code as a regular user rather than as the developer, and 3) since they’re already compiled, having DLLs in your project adds nothing to script compilation times.
There’s actually a really good argument for not supplying source code. It enforces that new features be requested by users and added by the original author to the source so everyone using the product can benefit.
No, not at all. I supply source code and it’s still the case that new features are requested by users and added by me. There’s no indication that having a DLL (only) would change that behavior. As I mentioned, it’s trivial to decompile DLLs anyway.