I built the DLL of some code I have been working on and dropped it into a folder in my projects folder (Assets/Scipts/DLL) but when attempting to add the "using" declaration to a c# script, the DLL's namespace didn't appear. In my IDE (VS2015Community), the project(s) (.CSharp, .CSharp.Editor, .CSharp.Editor.Plugins and .CSharp.Plugins) didn't have the DLL under their References, and I am unable to add new entries into any of them. The DLL is compiled using .NET 3.5 as the target, and Unity displays no errors in the console, or in the inspector when the DLL is selected. When clicking the drop-down on the DLL, I can see the class name, so Unity is reading the DLL, I am just unable to use it. What have I done wrong to cause this?
As far as i know any custom dll plugin needs to be placed in Assets/Plugins/Your.dll and the .NET version has to be 2.0 otherwise unity will give you errors.
Actually, when I target .NET 2.0 I am unable to build the DLL, I think some of the libraries in UnityEngine, which my DLL uses, have been updated beyond 2.0. I realised the Plugins folder thing and tried that, my DLL now appears in the IntelliSense for Using, the class is visible when trying to use it, but none of the functions are usable, which is strange because they are public.
And you're not doing something like trying to access the functions from the class when you should be using an instance?
I don't believe so, I think I have set up the library and using it correctly, and it doesn't do anything terribly complicated.
3.5 actually. It might be clearer if you post some code from the DLL and how you're trying to use it in your project.
I can do 1 better As the library is so small, and designed for convenience mostly, it is small enough for me to post the project entirely. This is something I plan on releasing for free to the Asset Store once I have added support for the other shader variations and a couple of controllable functions, so any help you can render in getting this functional will be added to the credits.
Your project seems to work fine for me. Managed dlls don't have to be in any Plugins folder by the way.
Just to confirm, you can access (use in another script) the functions INSIDE the ShaderProperties class?
Hmm, just restarted my computer and Unity felt the need to re-import everything, it now works. The only thing missing now is the ability to call it inside a function, instead of inheriting it. So, I would do something like: Code (CSharp): void Start() { ShaderProperties.Color(UnityEngine.Color.red); ShaderProperties.AlbedoMap(SomeTexture); } But this still seems to be missing. I've never had problems like this before, but then again I don't work with DLL's very often.
Would this not cause object reference errors on the GetComponent declarations? EDIT: Yes it does Changing all the functions to static causes this: Error CS0120 An object reference is required for the non-static field, method, or property 'Component.GetComponent<Renderer>()' For every instance of it. Not entirely sure what else I can do to get this working.
Make a decision about how you want people to use the code you've written Either they reference them statically or they grab component references and use them as instances.
All I want to be able to do is use a function as a shortcut. The problem I think is that things like SetColor don't seem to return anything, so I am at a complete loss of how to actually implement this. Any ideas?
I didn't look at your project so honestly I don't know what you're trying to achieve. Judging by the names you've given stuff I'm guessing you're trying to set properties for shaders in every material instance. If you want to use this more as a utility type of thing then I'd make users pass in the GameObject or Renderer instance that they want to modify as well as the property they're setting. So your SetColor method would take a GameObject and a Color and then the method would find all the materials on that GameObject and set the color property on the shader. But really - it's up to you how you want people to use the code you've written.
Yes, don't use ShaderProperties.Color. Just call Color(). Let's just strip down your class to the one method and demonstrate: Code (csharp): public class ShaderProperties : MonoBehavior { public void Color(Color color) { GetComponent<Renderer>().material.SetColor("_Color", color); } //other stuff } Those are set to public, so if you inherit it you'll be just fine... but you're not going to be able to use it statically because it has to access non-static stuff (i.e. GetComponent<Renderer>) which are going to be instance specific. So the best way to do it is: Code (csharp): public class CustomShaderProperties : ShaderProperties { void Start() { //These methods are called on the base class Color(UnityEngine.Color.red); AlbedoMap(SomeTexture); } } Maybe the best thing to do would be to make ShaderProperties abstract so it has to be inherited, but those methods cannot be static because they rely on a specific game object instance..