MonoGame ContentManager class? - c#

I have recently got into c# with XNA and am just making the transition to MonoGame since I've read that XNA is no longer supported. With that said I have come across a problem in MonoGame that I didn't have with XNA when attempting to make a Load() method for a Sprite class in my program. The way I used to do it in XNA is as follows:
public void Load(ContentManager content)
{
content.Load<Texture2D>(AssetName);
}
Now the problem I have with MonoGame is that I cannot seem to reference ContentManager in my Sprite class. The class has all the 'using Microsoft.Xna.Framework' that my Game1 class has, and nothing in my code is static so I don't understand why I cannot reference ContentManager, since it is not recognised when I try and put it in the Load(). Is there a different way to do this in MonoGame, or am I not referencing it properly?

Hm, I don't see the issue right away, but I'll try to help:
You have probably tried right-click/resolve already, but it's worth saying it anyways.
Reminder that Loading content in Monogame is different than using XNA. You've to use the build-in pipeline tool and transfer the content over there, don't forget to build it everytime when uploading a new texture.
There has been no changes to the Content.RootDirectory?
Just making some heads-up to be sure you've done that. and hopefully this will help you out as well.

Assuming you've referenced the MonoGame.Framework.dll or NuGet package there's nothing special about the code. It should look something like this:
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace YourGameProject
{
public class Sprite
{
public string AssetName { get; set; }
public void Load(ContentManager content)
{
content.Load<Texture2D>(AssetName);
}
}
}
I just wrote that code in my own project and it compiles. If it's not working for you there must be something else wrong.

Related

Why is the Namespace "IUnityRenderPipeline" Suddenly Missing from the Vuforia Script?

I've been working in Unity the last month or so. I've gotten a few iterations of a basic AR application worked up but I've updated Unity and now my code is throwing all sorts of errors.
Last week my app was working fine when building to my Pixel phone. Now that I've updated to Unity 2018.3.9, Vuforia 8.1 is now missing the name space mentioned in the title. Does anyone have any information on this?
The app will play correctly if I restart Unity up until I try to build the application to the phone. Once I build and it fails I can't replay the application due to compiler errors.
I've typed in different namespaces in the Vuforia Script and have checked my script. Mine is the same script I've used in previous versions with zero issues. I have Vuforia in the namespace but the issue appears to be coming form the Vuforia inherent script instead.
Here's the section of the Vuforia Code that appears to have the most bugs:
\\\\
namespace Vuforia.UnityCompiled
{
public class RuntimeOpenSourceInitializer
{
static IUnityCompiledFacade sFacade;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void OnRuntimeMethodLoad()
{
InitializeFacade();
}
static void InitializeFacade()
{
if (sFacade != null) return;
sFacade = new OpenSourceUnityCompiledFacade();
UnityCompiledFacade.Instance = sFacade;
}
class OpenSourceUnityCompiledFacade : IUnityCompiledFacade
{
readonly IUnityRenderPipeline mUnityRenderPipeline = new UnityRenderPipeline();
public IUnityRenderPipeline UnityRenderPipeline
{
get { return mUnityRenderPipeline; }
}
}
class UnityRenderPipeline : IUnityRenderPipeline
{
public event Action<Camera[]> BeginFrameRendering;
public event Action<Camera> BeginCameraRendering;
public UnityRenderPipeline()
\\\\\
I'm not versed enough in C# to know the fine tunings of QC'ing the code other than the immediate lack of ";" in a lot of these lines.
What the app should be doing is building correctly to my phone. Once there it's an application that reads a sketch I drew, and shows a model or several renderings of the space based on the image target and virtual buttons placed in Unity.
Hello
Not sure how you created your app, but these errors look similar to ones you'd get if there was a mismatch between the Engine SDK version and the Vuforia samples. As the SDK evolves and APIs are created/changes, so do the samples to be compatible with them. Here's how you can check the versions of both (assuming you used Vuforia samples resources):
- SDK version: Unity Editor->Window->Vuforia Configuration.
- Samples version: Unity Editor->Project window: Assets/Vuforia/version.
also, you can delete the old version of Vuforia and re-import from the Package Manager in Unity.
Thanks,

Parse.com Android Unity Nothing works not even the test object

I have just started using Parse.com On Unity 5.0.0fb, and after getting my application to work with Parse on Unity Editor I decided to try it on my Mobile to find nothing works. I have checked the APK and Parse is inside it but when I try anything it does not work.
I have tested this with a Test APK with nothing but parse and the test script attached to a button and it also does not work.
using UnityEngine;
using System.Collections;
using Parse;
public class ScriptTest : MonoBehaviour {
public UnityEngine.UI.Text Mytext;
string mytext;
// Use this for initialization
public void MySpecial () {
ParseObject testObject = new ParseObject("TestObject");
testObject["foo"] = "bar";
testObject.SaveAsync();
mytext = "Saved";
Mytext.text = mytext;
Debug.Log (mytext);
}
// Update is called once per frame
void Update () {
}
}
It will not do anything the button will click it will say saved on my text but when I check parse TestObject nothing will be there. Is there something im missing in my build?
I have made sure stripping is also disabled.
This works 100% in editor just not in Android I have no idea or way to test iOS.
I have the exact same problem, using Unity 5.1 and Parse Unity SDK 1.5.1. It works perfectly in the editor but not on Android.
Here's my code :
ParseObject _localPlayer = new ParseObject();
Task query = _localPlayer.SaveAsync();
while (!query.IsCompleted)
yield return null;
if (!query.IsFaulted && !query.IsCanceled)
{
Debug.Log ("Player successfully created!");
}
else
{
Debug.Log("Failed to create player...");
}
The task generated with the SaveAsync() request doesn't seem to end at all (isCompleted is never true) so it becomes an infinite loop, and the actual cloud operation is not performed (no trace on the Parse dashboard). There doesn't seem to be any exception thrown and the device log doesn't show anything.
I'm really stuck at this point and haven't be able to find any solution anywhere on the web so far. :(
Using Parse SDK 1.3.2 "fixes" the issue.
-> https://parse.com/downloads/windows/Parse/1.3.2
Looks like a big fat regression. ;)
Going back to Parse Unity SDK 1.3.2 worked for me.
LogOutAsync() had to be replaced with LogOut(), but that was the only change I had to make in my code.
The solution to this problem is to reimport project settings from their blank project. It will fix any build problems you have.
The bug report, for those who would like to be kept informed:
https://developers.facebook.com/bugs/1623483557935932/

EditorWindow.GetWindow doesn't work

This is my code:
public class CrazyWindow: EditorWindow
{
[MenuItem("Window/CrazyWindow")]
public static void Window()
{
EditorWindow.GetWindow(typeof(CrazyWindow));
Debug.Log("It should have appeared!");
}
string test = "";
public void OnGUI()
{
test = EditorGUILayout.TextField ("Text Field", test );
}
}
I'm using Unity3D v. 4.3.4f1 (free version) on Windows 7.
I have no idea why this is happening, as I can see in tutorials in the internet, that's how it should be done. The script is also in the Editor folder.
I'm able to click on the option "CrazyWindow" in the window menu, and I also get the Debug message informing me that the window should be working, but nothing happens besides that. No window is created at all!
What might be the cause of my problem?
Problem solved.
As Bart mentioned, I was using a custom Editor Layout, which was the case for the window not showing.
I just switched to one of the factory editor layouts and: ta dah, the window was there...
Pretty buggy thought.
Try renaming the 'CrazyWindow' part in the MenuItem and of the class itself. Unity remembers whether a window is visible or not and somehow something goes wrong there. Probably it thinks your window is visible (in cache) while actually it is not.
As Bart said, it remembers useless things
Just make it remember what we want it to
private void OnLostFocus() {
GetWindow<CrazyWindow>().Close();
}

Rhino 3d plugin for opening a .3dm file

I am new to writing plugin for rhino 3d.
I have gone through the documentation and sample code here:
http://wiki.mcneel.com/developer/dotnetplugins
but unable to figure out how to open a .3dm file from plugin.
Can someone help me?
Thanks!!
It depends a little on what you are trying to do and which version of Rhino you are running.
If you are running Rhino 4 and using the Rhino_DotNet SDK, then you need to have your command class derive from MRhinoScriptCommand and call RhinoApp().RunScript(#"-_Open C:\path_to_model.3dm")
If you are running Rhino 5 and using the RhinoCommon SDK (recommended), then you should call RunScript in a fashion that Brian suggested above. You also need to mark your command class with the the Rhino.Commands.Style attribute of ScriptRunner
ex.
using Rhino.Commands;
[CommandStyle(ScriptRunner)]
class MyCommand : Rhino.Commands.Command
{
public override string EnglishName { get { return "MyCommand"; } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
RhinoApp.RunScript(#"-_Open C:\model.3dm");
}
}
This will open the 3dm file and make it the active document.
On the other hand if you just want to read the 3dm file into memory and inspect the contents of it, I would recommend using the Rhino.FileIO.File3dm class in RhinoCommon. There is a static Read function on that class that you can use.
You can script the Open command from inside a plug-in using:
Rhino.RhinoApp.RunScript() to script the open command. For example:
Rhino.RhinoApp.RunScript(#"-_Open C:\model.3dm");

SFML with C#, startup trouble

I want to use SFML with C# .NET. I've had to get SFML 2.0 since 1.6 apparently had some issues with AMD graphics cards. The issue is that the constructor of SFML.Window.Window enters an infinite loop.
My code:
using SFML;
using SFML.Window;
using SFML.Graphics;
namespace SFML
{
class Program
{
static void Main(string[] args)
{
SFML.Window.Window window = new SFML.Window.Window(new VideoMode(800, 600), "Test widow");
}
}
}
It seems like nobody else on the internet has this issue, and I've tried it on another computer with the same result. Any help will be extremely appreciated.
Not sure you're creating the Window appropriately. Look at the examples from the Github source. If you're doing OpenGL, you'd use RenderWindow for instantiating your window object:
https://github.com/SFML/SFML.Net/blob/master/examples/opengl/OpenGL.cs
For 2D windows:
https://github.com/SFML/SFML.Net/blob/master/examples/window/Window.cs
Also note the inclusion of Tao bindings in those examples.

Categories