Combining Windows Forms and XNA, but lacks "Game" instance - c#

I am currently working on a Map Editor for my 3D game, but I am having some problems getting the using Microsoft.Xna.Framework.Game included.
My 3D engine is stored in a library, and the constructor for it needs the Game instance and a GraphicsDevice.
The GraphicsDevice is not a problem since i used some example from App Hub (link text), but using the "Game" is not included in it. Does anyone know how I would fix this? Thanks :)

Pretty much the entire point of the WinForms sample is to remove the use of Game (and the Microsoft.Xna.Framework.Game assembly). The Game class does things that you probably do not want to have happen within your editor.
I would recommend modifying your 3D engine so that it does not require an instance of the Game class, in order to be created.
What are you using from Game, anyway? A ContentManager, perhaps? Just pass that in directly.
But if you really must reference the Game class, add a reference to the Microsoft.Xna.Framework.Game assembly to your project. Do this by right clicking the project in the solution explorer, selecting Add Reference and finding it in the list of .NET assemblies. Make sure you get correct version.

I too am writing a 3D engine in XNA, called 'Vanquish'
Now that I've seen your constructor, you need to remove the Game variable from this. Create a public static variable called Instance in your Engine. Then, in your constructor add the following:
Instance = this;
From your WinForm application, whenever you need to use Game you can use engine.Instance.

Related

Image as a Texture in HoloLens -Issue

Good evening,
Recently I was trying to create an app in Unity where with a button I could open an image or a pdf while the app remains open and running. I tried to do it with Unity, and I didn't see any problem. However, when I used the HoloLens emulator, every time I did it the app opens the file but then closes.
I thought that maybe if I defined several 2D Empty Objects (as Images, Raw Images...) the app would still run while doing this. To do this, I used the WWW class and the example of the Unity Scripting API.
https://docs.unity3d.com/ScriptReference/WWW.html
However, I don't know why when I run the app the Image doesn't change... I also tried the SetTexture() method it still doesn't work. So I was wondering if you have encountered the same problem, and if you could help me to solve it out.
Thanks a lot for your help!
Best Regards
I'd suggest looking up the following post: change texture
It comes down to defining a gameobject, making a prefab out of the Image and setting the material of the prefab. You can easily make new materials by importing an image or making one using projects tab>Create>Material. You could try making 2 Materials with different colors to test it.
It could also be code that needs to be run using UWP outside of the editor, if that's the case, you could use
#if !UNITY_EDITOR
//Put your code here.
#endif

Is it possible to budle Unity application, transfer it to the device and run it in some kind of player?

It may be a silly question, but I dont know what to google.
Consider this, we are building unity AR application that run on IOS. Every client has custom need, so there is custom application for every one of them. Because of that whole application lifecycle managment is nigthmare.
We would like to build just one appliaction as player and download all content (unity app) from server and just run it.
Is something like that possible? How can we achieve that?
You could make a variable that can be selected to set up the application based on that one global variable.
For example make a class called "Global" as a Singleton class, then call that class from wherever you need custom needs set up to see in which way they should be adjusted.
If it's not only IOS related, you can use Platform Dependent Compilation: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
AssetBundle recommended by #Everts seems like good fit, it does not solve everything but for sure helps a lot.

How to use Unity Scripting with Vuforia

This maybe a stupid question but this keeps moving in my mind.
here's the situation.
I have a small application deployed in Hololens and using vuforia extensions, I'm able to track and recognize a real 3d object. I'm able to make holograms appear too, as long as holograms are children of the target object.
What I want to do is to activate or deactivate holograms that is not a child of the target object. I can't do it through code since the script i'm manipulating is a name space.
I tried putting methods inside the namespace itself but i keep having exceptions and nothing works.
I hope you can help me with this one.
Ty
You can use Instantiate https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
to create an object as soon as Vuforia has recognizes a specific target (Wich you can check by using one of the targetablemanagers.)

How to use Unity in a C# project

I just started to use unity3d.
I create a small scene with a first view controller, a script etc.etc. But I want to know how I can load and play a scene in a C# code project (Visual Studio).
Let me explain.
I've already made a C# project, with many variable, interfaces etc.
How can I use an Unity libraries, and some methods in c# code to load and play an unity scene.
Is this kind of code exist ? like :
using System.Unity.Scene;
......
{
loadScene(myscene);
playScene(myscene);
...
}
....
?
While you can load Scene's from code in the Unity API (See Application.LoadLevel), You can't exactly use the Unity API outside of unity. While you may have some luck importing the library's, the actually functionality won't be there because of the way the Unity IDE/Editor works.
Might I suggest building your non-unity project into a library (Make sure you set the Target framework to 3.5 or below as Unity uses mono 2.0 libraries instead of .NET), and then using that in your unity project.
You may also wish to look at UnityVS, It's a hands down the best Extension for unity: It gives a great deal of extension and usability for those who prefer VisualStudios over MonoDev.
To load a Unity scene using C#:
using UnityEngine;
using System;
class YourClass
{
// ...
public void LoadScene( string sceneName )
{
Application.LoadLevel( sceneName );
}
// ...
}
http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevel.html
But as others have mentioned, you should really start Googling some basic Unity C# tutorials.
I think you are looking at this the wrong way, Unity3D is a development environment, and provides much of the tools and structure you need to work within the framework they provide, the meta-data behind the scenes enables much of it's features, to link objects together from the scene to the C# classes.
My suggestion is to look at integrating other libraries into the Unity3D project, rather than the other way around, which will work fine.
I have done similar things before, such as integrating some serialization libraries and API's.
One option you could look at is to hook the Unity3D project up to a web service, and control things that way, allowing you to have some of that logic outside of the Unity3D project
I suggest here as a good start for learning Unity3D:
https://www.assetstore.unity3d.com/#/content/5087
Try using monodevelop instead. Unity integrates really well with Monodevelop and it comes packaged with unity.
In your editor on the top menu Assets->Create->C# Script
Double Click on your newly created C# script and it should open in monodevelop.
Then code away!
Every C# script should use
using UnityEngine;
To access the framework, this is usually set up automatically by default.
To load a scene:
Application.LoadLevel("Level Name");

How to create different "pages" in XNA?

(I think I heard this being called a "state-based" game, but I'm not sure...)
Basically what I want to do is have my start screen be one class, and then it passes on control (of the window/drawing/updating) to another class (ie the game class) and I can pass back control to the start screen class from the actual game class.
I want to switch logic control without opening a new window, and closing the original, but just seamlessly transfering to another class.
EDIT: I'm not looking for anyone to tell me exactly how to do this, just please nudge me in the right direction because I couldn't find it on Google...
There's a sample for that: XNA Game State Management sample.

Categories