Code Monkey home page Code Monkey logo

Comments (4)

nelisk avatar nelisk commented on June 25, 2024 1

To make this library work with android games made with Unity Engine, it needs to be compiled with the ANDROID symbol. When adding this symbol, the solution will "switch" to the android mode, requiring the Android namespace to access native structures (to get the IP address, I think). Now comes the problem:

To get the Android namespace I must add the Mono.Android (xamarin) reference, but this reference requires Mono 4.0 and Unity currently doesn't supports Mono 4.0, so I can't add the reference and consequently I can't build the library and can't use it.

I don't know if i'm making some mistake here, I'm not an expert, sorry.

from lidgren-network-gen3.

AgentFire avatar AgentFire commented on June 25, 2024

So, what exactly is wrong with this library?

from lidgren-network-gen3.

jagt avatar jagt commented on June 25, 2024

I can confirm it's working nicely on iOS with Unity 5.3.4. Note that you have to use the UNITY compile flag. I haven't tried Android yet, will report back soon.

EDIT: I can now confirm it's working on Android w/ mono/il2cpp backends.

from lidgren-network-gen3.

jmcgraw94 avatar jmcgraw94 commented on June 25, 2024

Friendly necropost for the wandering soul looking for help with this. There's a lot of good information scattered about several threads online, however few include encompassing instructions. If you're attempting to use Ligdren on Unity Android mobile, here are the steps you'll need to take. My setup for this process included Unity 2017.2.0f3 Personal and Visual Studio Community 2017. My target and minimum Android API levels in Unity are Android 7.1 'Noutgat' (API level 25) and Android 5.0 'Lollipop' (API level 21) respectively. Lidgren was successfully tested on a Google Pixel XL running Android 8.1.0.

You'll need to build your own dll for Unity with a few changes having been made. Here's how you'll go through the process of building a Unity android compatible dll.

  1. Download and open the latest version of Lidgren from the repo if you haven't already
  2. With the solution loaded, right click on References under the Lidgren.Network project in Visual Studio's Solution Explorer. Select 'Add Reference' and click 'Browse> Browse...'
  3. Navigate to Unity's managed dlls folder (C:\Program Files\Unity\Editor\Data\Managed) and add 'UnityEngine.dll'. This will make Unity's data types visible to Lidgren and should clear any undefined references in PlatformUnityExtras.cs if there were any.
  4. Expand the References explorer to ensure UnityEngine is present. Click on UnityEngine and in the 'UnityEngine Reference Properties' ensure that 'Copy Local' is set to true. This will place an extra copy of the UnityEngine dll in your output folder when you build.
  5. Press (Alt + Enter) or Right Click on the Lidgren.Network library in the Solution Explorer and select 'Properties'
  6. Under 'Application > Target framework', select 'Unity 3.5 .net Subset Base Class Libraries' from the drop down. In targeting .NET 3.5 the dll becomes actually usable by Unity
  7. Move to the 'Build' tab of the properties window and under 'General', include 'UNITY _CONSTRAINED_ ANDROID' in the Conditional compilation symbols. This will switch out which functionality gets compiled into the dll
  8. Save and compile the project
  9. Check your build folder (..\Lidgren.Network\bin\Debug...) for your Unity mobile ready Ligdren dll
  10. Copy all the contents of the build folder into a new folder within Unity's Asset folder,
    you may chose to structure your directory to resemble something like (..\MyUnityProject\Assets\Plugins\Lidgren...)
  11. Close and Reopen your Unity C# project in Visual Studio and look at the Solution Explorer. Make sure each of Visual Studio's projects includes Lidgren,Network as Unity should automatically have done.
  12. Include Lidgren.Network in your usings and you should be good to go! Deploy a small test demo to mobile and check that it works. I hope these instructions were applicable and easy to follow.

As a note, Unity will likely produce an error and question your placement of an extra UnityEngine.dll in the Assets folder. There are ways to tell Lidgren where to find the UnityEngine.dll, however this saves the most amount of time. Clear that error and it won't show up again.

Obviously, if you're building to Android, ensure that you've already gone through the process of setting up Unity Android support. There are plenty of tutorials online if you haven't already.

from lidgren-network-gen3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.