UltravioletFramework / ultraviolet

The Ultraviolet Framework is a .NET game development framework written in C#.
https://github.com/UltravioletFramework/ultraviolet/wiki
MIT License
542 stars 46 forks source link

Template for VS2017 #57

Closed HellGate94 closed 7 years ago

HellGate94 commented 7 years ago

since the new versions no longer come with an installer that adds templates and the old one does not support vs2017, whats the right way to set up a cross platform project?

tlgkccampbell commented 7 years ago

All of the Ultraviolet libraries are available on NuGet. You can use the Ultraviolet Game (Platform) packages to create skeleton projects for each of the supported platforms.

In order to share code between the different platforms, I use Shared Projects; just create a Shared Project, move all of your non-platform-specific code into it, and then add a reference to it in all of your platform-specific projects.

One small complication is that if you're supporting Android, you may need to slightly modify the declaration of your UltravioletApplication class using preprocessor macros, like I do here.

Let me know if you run into difficulty getting anything to work.

HellGate94 commented 7 years ago

the Ultraviolet Game (Platform) did work quite well for one platform at a time but not so much with multiple. i could get it to work with the desktop project, however the android project cant seem to resolve the ultraviolet packages. most likely related to the Game.cs containing the game code now but the android one wanting it inside MainActivity.cs and i cant seem to find the project setting to change that.

would be really nice to update the documentation with a step by step way to set up a project with shared game code (and content) for all the platforms. i see how it should be in the end from the samples but i would like to know how to get there. especially since i never done any cross platform programming with c# before.

tlgkccampbell commented 7 years ago

Improved documentation is on the list for the 2.0 (previously 1.4) release. It's a matter of finding the time to write (and maintain) it, unfortunately.

Here's a walkthrough of how I would do it...

The above steps will give you your basic project structure, but if you try to build this now, the Android project will complain that it has no idea what UltravioletApplication is supposed to be. Due to how Android works, your main game class needs to inherit from UltravioletActivity instead, and needs a couple of extra annotations. So let's modify Game.cs a bit so that it will build as an UltravioletApplication on the desktop and an UltravioletActivity on Android.

This line:

    public class Game : UltravioletApplication

Needs to be changed to this:

#if __ANDROID__
    [Android.App.Activity(Label = "CrossPlatformGame", MainLauncher = true, ConfigurationChanges =
        Android.Content.PM.ConfigChanges.Orientation |
        Android.Content.PM.ConfigChanges.ScreenSize |
        Android.Content.PM.ConfigChanges.KeyboardHidden)]
    public class Game : UltravioletActivity
#else
    public class Game : UltravioletApplication
#endif

The __ANDROID__ symbol is defined automatically by Xamarin for your Android project.

At this point, everything should build without errors, and you ought to be able to deploy to an Android device using the Xamarin tools. For more information on that, I'd suggest looking through Xamarin's documentation, since that isn't unique to Ultraviolet.

You might also want to read up on how Shared Projects work generally.

HellGate94 commented 7 years ago

thats what i did and thanks to your great write up i figured out the problem. in the example it was using #if ANDROID instead of #if __ANDROID__

with that change im able to get it running

also its great to hear version 2.0 (1.4) is on its way since thats one of the key milestones im waiting for and im currently trying to get more familiar with the framework

tlgkccampbell commented 7 years ago

Yeah, that was my mistake, sorry! Ultraviolet's internal projects define an ANDROID symbol in their project files in addition to the one provided by Xamarin, which I forgot about.

Glad you got it working.