I'm working on a Unity project and want to test/try some code: i.e. loading a CSV and save in a different Dictionaries. As for now, I'm coding in Visual Studio/Code and have to switch back to Unity to run it.
Is there a way to test run the code in the Visual Studio/Code directly - only for console output?
This would be great for testing, instead of switching back and forward all the time.
Thanks
For a game project of mine, I set up a seperate VS project independent from the Unity project, and bound all the cs files in there.
The files tested this way did not use UnityEngine at all, but you could also set up a dummy-UnityEngine for the test. Location of this folder is outside of the Unity project folder to prevent Unity from touching those test cs files and vcproj files.
From the VS project, I can simply include any cs files from the Unity-project Assets folder.
My dir structure:
ProjectRoot/ <== real project root folder.
.git/ <== git tracking for unity part and testcode.
Unity/ <== Unity's project homedirectory.
Assets/
script
... various scripts.
mats/
scenes/
..... <== lots of Unity project stuff
testcode.sln
testcode.vcproj <== refers to cs files from testcode AND Unity.
testcode/
testclass.cs
.....
For testing, I open the testcode.sln in VS, and compile-and-run it all in there. Unity need not be open.
Related
I have a unity project from which I want to export multiple exe files (build the project multiple times). The way I do this is by running in a loop and every time changing the part in the project I want to be different and then building the project.
The problem I'm having is that when I build the project automatically the scene gets destroyed and I can't access the gameobject in it and edit them one I go through the loop again.
I tried to come up with a solution to this problem by loading the scene again but that didn't fix it.
What do you suggest?
Thanks!
As I know, editing and building at the same time is impossible.
Here is an idea:
Copy the whole project to another folder.
Open both 2 projects with 2 unity instances.
Every time you make some change, copy the file from the first project to the second one.
Run your auto build code in the second one.
I've gone through all the recommended steps to prepare a Unity project for a Git repository following the directions here:
Unity Git - Ignore Library
I've correctly setup the .gitignore file etc.
However when I clone my newly created Git repo on a different machine I noticed that my scene, assets etc. are missing. The scripts seem to be there.
I noticed that when I copy over the Library folder the missing things (scene, assets) come back.
I'm assuming that there is something in the Library folder that just can't be ignored or that the "forcing assets to text" just isn't working properly.
I'm using Unity 5.3.5f1.
I'm still fairly new to Unity/Git etc. so I may have overlooked something obvious but I've followed all suggested directions.
Any help would be much appreciated.
apparently Unity has changed the Library Folder many times in Unity 4.X that folder could be ignored. Now, it seems not.
I did some tests and the huge junk of files are for my in the ShaderCache and this folder seemed to be fine to delete. The other Folders should not be touched.
https://forum.unity3d.com/threads/26-581-bin-files-in-library-shadercache-folder-can-i-delete-these.326312/
Fell into same problem with Unity 2020.3
Some research showed that was needed files LastSceneManagerSetup.txt, CurrentLayout-default.dwlt for scene. And EditorSnapSettings.asset, EditorUserBuildSettings.asset for game window, game view and UI.
Maybe, I miss some other settings, so I saved files in Library root and replaced /[Ll]ibrary/ with:
/[Ll]ibrary/APIUpdater/
/[Ll]ibrary/Artifacts/
/[Ll]ibrary/BuildPlayerData/
/[Ll]ibrary/PackageCache/
/[Ll]ibrary/PackageManager/
/[Ll]ibrary/PlayerDataCache/
/[Ll]ibrary/ScriptAssemblies/
/[Ll]ibrary/ShaderCache/
/[Ll]ibrary/StateCache/
/[Ll]ibrary/TempArtifacts/
/[Ll]ibrary/UIElements/
Scenes are not entirely missing, as you can simply load them from Assets/Scenes. Their original order in the scene hierarchy, however, is lost.
I did even more tests than Jimmy and found out the only required things from Library are StateCache folder and LastSceneManagerSetup.txt file (less than 2 kB total in my case). Everything else located in Library folder can be safely removed.
Save these two:
StateCache/
LastSceneManagerSetup.txt
I put the music(mp3) file in the music folder and created a Song song; object in the game class.
Then I did song = Content.Load<Song>("music file name here") in the ContentLoad method and did MediaPlayer.Play(song).
But it gives me an error saying:
Could not load music asset
I tried making the "Copy to Output Directory" to "Copy always". But this also didn't solve the problem.
I heared about monogame not having a content pipe line, but I don't understand what it is. Can anyone explain what I should do to make my music file playable?
You can find a tutorial (written by me) explaining exactly how to use sounds in Monogame here.
But basically, all you need to do is:
Create a new Game project with XNA.
Add the desired sound file to the content project.
Compile.
Go to the output folder and copy the sound xnb file to your monogame one (add it on the Content folder).
Change it's properties to "Content" and "Copy if newer" so that it works.
The image has a spritefont selected, but the same applies to sound effects.
Then you can use it as you would in a typical XNA game.
As of today, I have not been able to find another way to load them without needing XNA. Same goes for sprite fonts. You need to generate the xnb files by using the Content project provided by XNA.
Remember that you can install XNA on VS 2012+ and Windows 8 without a problem thanks to XNA Refresh.
One more thing to add, the last time I used Monogame (September, 2014); there was a bug in the templates downloaded from the Monogame site that would not allow for any sound effect (song, effect, instance, etc) to be played; and this would happen with no errors being thrown.
The solution at that time was to download the Monogame templates by using Nuget.
I have an C# source code of some software my company is using. This source code contains .xaml, .cs files, and one: App.config, packages.config. However there is no main project file that I can open in Visual Studio.
The original source code can not be found, and the programmer who made it has left the company long ago.
My question is - can I open such a project in C# somehow, without the main project file, so that I could make some changes and compile this application?
Just create a new WPF application project and add the existing files.
You can compile the code using the c# compiler csc (which you can find in the .NET Framework installation folder), or just create a new project in Visual studio and add the WPF files to it. The last option is the easiest one.
I've been trying to use XNA framework along with Visual Studio 2012. Since the xna framework is not yet compatible with Visual Studio 2012 I had to set it manualy.
Yet, I managed to succesfully import xna references and create default game methods allowing me to run my program.
The problem came when I tried to add texture to my project and load it. I manually created a "Content" folder in which I added my textures following msdn documentation at http://msdn.microsoft.com/en-US/library/bb313966(v=xnagamestudio.30).aspx
The problem is, since it's not XNA game project I wont have the properties window showing my texture file as a texture but just as a resource file.
And the following code:
Load<Texture2D>("GrassTexture");
Will systematically lead to an error file not found.
I've set my ContentManger as it follows:
ContentManager.RootDirectory = "Content";
Does anyone know how to properly set the content folder ?
I had this problem too, but there is a opportunity to enable the xna game project for vs 12.
Look here: https://stackoverflow.com/a/10881007/1780038