Merge several textures on screen into a single big one - unity3d

In my 2D app, I create many gameObjects with UI image components (I work with new UI). These are simple colored circles. They are placed in different positions on screen. But when I play long enough, the count of these gameObjects becomes too high and it impacts performance.
I thought since these objects are just textures (I do not need them to be animated or something, just simple textures that stay on the same place in the screen all the time), maybe there is a way to merge them into one gameObject with Image component that would hold all these circles in one texture?
I tried to capture the camera view through RenderTexture ReadPixels method, but it captures the whole screen and all objects in it, while I need to merge only these circles and in a specific rectangle on the screen.

Related

How to bring forward an object in unity?

I've a simple project with a few objects.
I tried to move "player" object (Marked in the picture) to top of other objects but still it is in backward!
How to bring it to forward?
We need some more information to give an accurate answer for your exact situation, such as the properties of the Sprite Renderer (assuming Player is a sprite) and the properties of your Canvas and UI elements (especially if it is a world space canvas), and any code you might be using to instantiate, render, or move the player.
In general though, for sprites, you can bring a sprite in front of other sprites by either changing the Z value of the transform (negative Z is closer to the camera), or better by changing the Order in Layer of the player sprite renderer, and make sure it is in a layer that is in front of the other sprites.
As for Canvas UI elements, the element at the bottom of the hierarchy will be rendered last, meaning it will show in front of everything. Think of a UI hierarchy like stacking papers on top of each other. The first piece of paper placed down will be at the bottom of the pile.

Recommendations for clipping an entire scene in Unity

I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).
Thus far I've got clipping working as I want for the terrain and a water effect:
The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.
Here's a pic showing the terrain clipping in the editor.
You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table.
The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.
While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.
Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?
The end goal is to render a scene within the bounds of some plane.
One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.
You can also use Bounds.Contains.

Unity3D: Add text to a PreFab

I'm making a 2d board-game-style game in Unity 5, and I have a prefab made up of a couple of sprites which represents a game piece. I want some text in my prefab that I can update as the game progresses.
If i try to add text, it requires a canvas, but when I create a canvas, an extraordinarily enormous canvas is created, that looks to be at least 1000x times bigger than by camera area. If I try to place this canvas inside my prefab, my prefab is now made of an enormously huge canvas, and my tiny sprite images. This makes the prefab impossible to position, or calculate sizing or animate, or anything else I want to do.
How can I add text to a prefab, and make the text contained within the size of my prefab spites?
Here's what I have tried so far:
if I set the canvas for the text to "Render Mode: World Space" I'm able to make it's rect tranform smaller. However, if I get it as small as my sprites, the text becomes an unreadably blurry mess. I guess this happens because my sprites are literally at least 1000x smaller than the canvas, so when I zoom in enough to even see the sprites, the text has been zoomed into oblivion. My sprites are so much smaller than the canvas, that if I am zoomed out to see the full canvas, my sprites are not even visible.
I'm able to kind of make things work if I recreate my prefab using UI Images instead of sprites. This way, the UI Images, and the text are both UI elements contained in the enormous canvas, so the size disparity doesn't exist. However, I don't know what the pitfalls are going to be trying to build an entire game out of ui images instead of sprites. Do I get all the state capabilities of sprites?
The canvas Unity generates that is 1000x bigger is used for GUI related objects that are not meant to directly interact with the game world like the score or buttons. In order to have moving text, try using 3DText. Have the text face the camera so that the text appears to be 2D. You can find this option in the menu under
GameObject => 3D Object => 3D Text.
From what I understand, all you need to do is parent this GameObject to your prefab and do some script magic at runtime.
For high fidelity text, either decrease the character size or increase the font size or do both.
Note: A larger character size reduces fidelity, but will take less processing power.
Source: Unity 5.2.0f3

Hexagon Unity TIles - Slow Performance

When implementing a large hexagonal grid (256x256) of tiles in a Unity game, the game becomes very slow and hardly able to function. The hexagons are in a prefab. A script controls the size of the grid and the spacing between each hexagon. How does one go about rendering a 1024x1024 grid of Unity objects?
When the game is built on Win64 it is also still quite slow.
This is an image of hexagons rendered:
http://i.imgur.com/UbA6USt.png
Try making the grid elements static and make sure static batching is turned ON in player settings. This will optimize their rendering significantly. You probably should even go as far as combining them all into a single mesh (see tools like this one for that purpose).
If you can show us the actual scene hierarchy and the actual structure of your grid nodes then we can help even more.
Because of how Unity works, non-static objects have a tendency to get heavy - they each end up with their own transforms and end up getting drawn even when they're not on screen.
It's the reason more minecraft clones aren't seen coming out of Unity.
If you can't set the hexagons to static for some reason (i.e.: creating procedural levels etc), you'll have to perhaps simulate the hexagons through creative shader manipulation (like saving each mesh into a single array of vertices with a second that tracks a corresponding mesh id) or by writing a script that creates/adds vertices and faces to a single mesh on a single game object.
You may also speed up the scene by creating smaller levels and loading/unloading them as the player moves towards them. See: Application.LoadLevelAdditive

how to handle multiple layers in single scene in cocos 2d iphone

I am learning cocos2d and that we have multiple layers in single scene.
I want to manage both layers at a time I.e, first scene with 480X320 image and second one also with same size. when I try the second one is only visible. Thats ok. But whenever touch occurs I want to add another sprite to both of the layers (different sprites for each). Could any one help with this.
Thanks
Why are you using multiple layers? Layers are for grouping multiple objects so that you can apply effects like movement to all nodes of the layer.
It sounds to me as if you should just be adding sprites to one layer. And if you add two sprites at fullscreen size, one will be on top of the other regardless unless it has transparent parts in the image.