Home > Blockchain >  How to add ASP.NET MVC model class to unity
How to add ASP.NET MVC model class to unity

Time:10-05

I'm learning how to use Web API to make sure my online game is safe. I already connected to my API but I want to use my model class in unity 2d project. how to add ASP.NET MVC model class to my unity project?

CodePudding user response:

Create a class library in which you define your models. Then reference that class library from both your Unity project and your API project.

CodePudding user response:

You should make your let's name it SharedlLibrary fulfill the requirements to be a Custom Unity Package (see also Packages in general) -> It is recommended to stick to the Recommended Package Layout to the needed extend - the minimum requirement would simply be the Package manifest (=package.json) file at folder root.

So that you can use it in your Unity project as a Custom Unity Package. This would be the main part answering your question hopefully. You can simply reference any local folder, git repository or even just a subfolder of a git repository as a package so on re-compilation of your Unity code it also re-fetches these package contents.


But for making your repository live easier I would have a single repository with a structure like e.g.

YourRepositoryRootFolder
|
|- Unity Project
|  |- Assets
|  |- Packages
|  |- ...
|
|- Asp.Net Backend
|  |- Program.cs
|  |- ...
|  |- SharedLibrary
|  |  |- package.json
|  |  |- YourModels.cs
|  |  |- ...

So that in Unity you reference the SharedLibrary folder as a local package in the

   YourRepositoryRootFolder/Unity Project/Packages/manifest.json

using a relative path like e.g.

   "my.stuff.sharedlibrary": "file:../../../SharedLibrary",
    

This way you can still have and maintain everything in a single repository.

  • Related