How can I change the ingame UI skin easily? - c#

I want to change some game assets like backgrounds, images and buttons for another ones for an event and I want to let the players switch between the UI skins wherever they want.
Tested creating some GUI Skin but I think thats not what I want.
Right now, before build the game, I manually copy and paste new assets and replace old ones so the files have the same name and Unity changes every image in the game that uses that sprite. When the event finish I do the same with the old images. Bu I want to change that with just a button.
I know I could do the cahnge one by one but, there is any way to do this change withouth having to set all image sprites one by one? maybe changing the "baseSprite" name to "baseSpriteTemp" and the "eventSprite" name to "baseSprite"?
Any idea?

GUISkin is what you would use with the Immediate Mode GUI system, i.e. drawing in script OnGUI functions.
If you are talking about in game assets for the UI and other items, you have options:
Roll your own theming system
Use AssetBundle Variants
Use Addressable assets
I have used asset bundle variants in the past, and they were pretty easy to setup.
Addressables are a newer feature, and as such I have had little experience, but it looks like it can work for what you are looking for.

Related

How can my users add sprite and image resources once my app is deployed?

I'm writing a Unity 2D game. Users can select one of 12 characters to play. The character sprites are contained in a single graphics file that I have in the Resources folder, from which I then sliced them into individual sprites. The player will bring up a scrolling selection panel (think gallery) and click on the character they wish to play.
Once my game is deployed, I'd like users to be able to add new characters, perhaps from in-game purchases.
In my old Windows version, it was simple: add the individual bitmaps into the appropriate directory, then just read all of them.
How would I do this in Unity/C# such that users acquire the new character pack and it gets integrated into the game and the sprites added to the bottom of the scrolling selection panel? I can't find any discussion of this. Feel free to point me to a tutorial, if one's out there.
The best way to do this is to save changes to the disk.
.Net has the System.IO namespace for you to use for reading and writing to disk.
Because you can write to the disk during run time there will be no problems calling those resources.
You can check Brackeys on YouTube they teach a lot if you are new to unity
here is how you save and load data in unity
https://www.youtube.com/watch?v=XOjd_qU2Ido

Taking a screenshot from one of the Camera GameObjects when the game is running and then output

I want to make a game in which the player can take a picture of the view in one of the camera GameObjects whilst the game is running and then save that image and view it later in the same play session, much like taking a screenshot using a camera item in other games and then viewing it in a gallery. I was wondering if there was currently anyway of doing this within Unity as it will be a central mechanic in my game.
There are multiple ways to do this.
The simplest is Application.CaptureScreenshot, which will create an image file. To explore the screenshots, use a file explorer package, or implement your own.
The other solution is to use a RenderTexture and to export the data to a List. You can then create an UI to explore the List. The problem is that each texture will be uncompressed and kept in memory, which can become dangerously heavy after only a few screenshots. Only do this if you don't have access to files or if you only keep the last few screenshots.

DontDestroyOnLoad - how to destroy?

I'm working on a Vuforia (legacy) application.
In "Play" mode in Unity I can see that some "DontDestroyOnLoad" content is being generated, (looks like it's sort of a camera).
This might be a reason of why I have some problems when switching between the scenes, so the question is how to make these elements "destroyable"?
'DontDestroyOnLoad' It means that they won't manage it automatically. so if you want to destroy it, you should destroy manually like
GameObject.Destroy(GameObject.Find("TextureBufferCamera"));

Where to put all code/organize code in unity?

so I am a beginner at unity and cannot grasp how you are supposed to have a pattern or architecture with unity.
I am currently making a platform game which has a character that is supposed to stay on moving platforms and not fall off the screen (very basic). On the platform there are "monsters". If you touch these monsters you also lose. There is also some trees and such on the platform.
This is what I have so far:
In the "manual gameobject list" or whatever you call it:
Directional light
Main camera
Background (just a sprite that is always showing)
Player (contains a JS script that has character specific code for jumping and such)
Platformspawner (Contains only a c# script. This script spawns multiple platform gameobjects, these gameobjects then use a script called platform.cs. This class spawns monsters and the trees on each platform. The monsters and trees each use their own c# file that keeps track of collisions and such.)
For me this is pretty obvious code and I do not know how to organize it much better. Any tips? I tried following an MVC tutorial but it seems like there is not much gameobject spawning in those tutorials which is what I have to do, so they confuse me.
Your hierarchy (the area of the editor where all of your GameObjects are stored) looks pretty solid. You typically don't need much organization in there if your program is pretty small, but of course putting things into folders (for example, putting multiple canvases into a large Canvas folder) can't hurt.
As for your project, where all of your assets are stored, I believe that folders are paramount for good organization, because if you combine all of your assets it'll be hard to distinguish them. I recommend having base folders for different types of assets (/Scripts/, /Materials/, /Prefabs/, etc.) and storing individual assets in there (and of course adding more folders as you see fit). You should almost never have to have an asset directly in the /Assets/ folder.
Of course, that is only my opinion and my method of organization. Everyone has a different method of managing their project, but what I've described above is the basic system of organization. Happy coding!

how to create a responsive scene

I'm currently creating a 2D Android and iOS game using Unity3D engine. I'm testing the game on a nexus 5, and an iPhone 5s device. Everything until now is working fine and I am pretty happy with the result, but when I test that application on an iPad or a Samsung tablet all the objects in my game scene are not in the correct position anymore. Is this a common problem in Unity3D ?
I know I am missing something but I tried to do some research and what I found is only by changing the orthographic camera scale might fix this problem, but I found it as a big amount of code to write as my game have not only one scene but multiple scenes and every scene have it's own game objects.
Is there any other method to do, a good and simple work around for this problem?
It's all about setting the Anchors right.
If you're using the new UI System, make sure you anchor the objects where you want them to be, that's how you will achieve resolution independence.
For more information about anchoring, see this tutorial
Don't have separate scenes for separate devices. You can use the Screen object to check the height and width of your display. Then you can use this to set the orthographic size of your camera to something that makes everything visible as expected.
Update: I misunderstood your question, you say GameObject, i understand UI.
Please check this. I don't have this issue on my game. But when i try it with mac or windows machines, it is problematic. So maybe this can solve.
Other solution is more common which is you and Agumander say, change orthographic size of Camera.
This Is for UI
You can use Unity UI, and don't need to seperate. There are so many different resolution and density devices, you need to create so many scenes. So it is meanless separating scenes.
Unity UI has pixel based solutions which can be very helpfull for many density and resolution options. Forexample, It has VerticalLayoutGroup and HorizontalLayoutGroup for easy list like element visulation.
Most important thing is: Do you want to change UI for different screen size or resolutions? For example iPad has larger screen so user can be see more content. This change UX. Maybe you need to consider this.

Categories