• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by tillrosemann · Oct 11, 2016 at 06:45 AM · classesimporting

How to integrate a C# Project in Unity

Hi all,

i've got a Universal Windows Project with a more or less complex data structure. It receives sensor data from a server using a RESTful API.

Now i want to create a unity 3d project to visualize some of the data. I am new to unity and don't now how to integrate my data structure into unity. Are there any recommendations? Can i import my C# project to unity or do i have to create the classes directly in unity? As far as i can see unity uses C# scripts, but can i create a complex data structure with that?

Thanks in advance!

Comment
SexPixels

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by starr_stealer · Oct 11, 2016 at 06:24 PM

As always there are many ways to complete a task, I will cover one way (base level approach to how I would do it).

First things first, Soc - Separation of Concerns. While you want to build a Unity app to visualize your data-set, it has nothing to do with the upstream application (ie focus only on the task you want to do with Unity). So "Can i import my C# project to unity", sorta but don't that directly, "do i have to create the classes directly in unity" nope you will reuse your existing custom code, "Unity C# features ... can i create a complex data structure with that" indeed you can, limitation is that of the target platform your app will run on.

Now to the question, "How to integrate a C# Project in Unity", again briefly touching on SoC.

Top level solution

  • Build the C# DLL(s) from your existing external project.

  • Create a new Unity project, then create two new folders within the Assets folder, Plugins and Scripts.

  • From the built C# project, copy over at least the DLL file (as well as mdb, meta, pdb files for debugging).

  • Now create a new C# Script in Unity (right click in the Project pane within Scripts), this can just be a sample test file to get you going, nothing fancy.

  • Set Visual Studio as the External Script Editor (you can use Mono if you want), Edit -> Preferences -> External Tools -> External Script Editor.

  • Now double click the C# Script created in Unity above, this will open Visual Studio.

  • Once Visual Studio is open, add a reference to the DLL(s) you copied into the {UnityProject}/Assets/Plugins folder. I have often found that Unity already did this step when opening Visual Studio from Unity, even if the VS Solution was already created by Unity before.

  • You can now use the C# DLL(s) you built externally from Unity.

  • Expand on the idea how ever you want, automate copying over DLL(s), etc

Some talk points:

Unity is designed for multi platform, not all of .NET C# features work on Mono (topic of its own), but if you only target Windows you don't need to be concerned with this so much, just something to keep in mind.

The external DLL(s) you build and use in your Unity project, should be built with SoC in mind. What I mean is that they should be very task specific, for example one DLL will hold all the Classes for your data "Entity Model" structure, while another one DLL handles calling into your existing REST API to present the data in the Unity App. Don't built bloated DLL(s) that include task that wont be used by Unity at all, for example the logic for how the data is processed and stored in your external service has nothing to do with Unity and doesnt belong there.

Unrelated to your question, but another question I recently talked on may have some helpful tips for your new project, Source Control with Unity: http://answers.unity3d.com/answers/1254938/view.html

Comment
Sphada

People who like this

1 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tillrosemann · Oct 12, 2016 at 06:16 AM 1
Share

thanks for that awesome answer and all the tips!

avatar image starr_stealer tillrosemann · Oct 12, 2016 at 06:25 AM 0
Share

Thank you for the feedback, maybe you could share the end result of your project on the Unity Forums. Id like to see the Visualization app you make, you could even have Unity build it for WebGL and handle the web based visualizations, then you have Desktop, Mobile and Web all in one go!

avatar image tillrosemann starr_stealer · Oct 12, 2016 at 06:44 AM 0
Share

of course i can do that. but i think it will take me a while to implement everything. maybe i also upload a video of the app, because i am using a microsoft hololens and the visualization will besomehow like augmented reality.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how do I read a variable from another class c# 4 Answers

Class extension (player.STR to player.Stats.STR) 1 Answer

Damage Clone From Projectile Script 0 Answers

Array of unique inherited classes? 0 Answers

Confused as hell about static classes and stuff. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges