Dynamically generate interface using ScriptableObjects - unity3d

Hello fellas!
Currently working on an AR application, I am learning and playing around with the ScriptableObjects.
With a little to no programming background (less than an effective year), I am struggling a little bit on some parts.
I am trying to create a frame, for a "home-made" video player, with interactive elements (aka buttons).
So far, both the sprites and external links for theses buttons (social media, shops, websites) are stored inside ScriptableObjects (same goes for the frame's sprite, and the video player related elements, such as the renderTexture or the videoClip).
I would like to go further, by creating a prefab letting me choose the number of buttons and their positioning.
For example, let say I have to create 2 different video players :
VideoPlayer_A the player and the frame, and 3 buttons (facebook, twitter and website)
VideoPlayer_B the player and the frame, and 2 buttons (facebook and website)
How can I achieve this, considering that the buttons (either be it 1, 2 or 4 -maximum-) must hold and have equal space on top of the frame (see screenshot bellow).
The final goal is to have a very modular system, creating frames according to the data I have.
As a final note, I am not asking for the "already made" solution, but more for the path to achieve what I am looking to. As I am still learning, I am looking for hints, "ways to do" but not directly the solution.
Thanks, by advance ;)

Related

Panel/Sprites won't update after being set inactive then reactivated

I've run through an entire fault tree trying to diagnose this, with no joy.
I'm writing a 2D card game in Unity/C#. I have four panels (one per player) that hold the cards, name, discard pile, etc. for each player. I need to have a pop-up dialog panel come up over the player panels when the user wants to change options. For some reason, I cannot get the pop-up to appear over the card sprites (it does appear over the other elements: interior panels, images, text boxes, etc.). I've tried adjust the Zpos for the dialog box panel, but nothing changes. That's problem one, but it leads to a more worrisome issue.
The bigger issue is this. Since the options panel won't display in front of the players' cards, I thought I'd just deactivate the player panels, display the dialog, then deactivate it and re-activate the player panels when it's closed. That works fine: for three of the panels. The fourth panel comes back on in its previous state, but the graphics on it will no longer update.
I've debugged and discovered the new cards are being handled correctly (sprite names changing, etc.), the discard pile is being updated, the player's name is being highlight/de-highlighted as the game progress, but none of it is appearing! It's visually stuck in the state it was when I deactivated it.
Investigating further, I've determined the error crops up anytime I deactivate and the re-activate that player's panel, whether I do it via the inspector (attaching those events to a button click), or do it in-line in script. I don't even have to open the options dialog box: I put SetActive(false/true) statements in my game code and it immediately kills the graphics updating for that panel. The sprites, text, etc. remain as they were when I deactivated and will not update.
player3Obj.gameObject.SetActive(false)
player3Obj.gameObject.SetActive(true);
Doing that to the other three panels has no effect and works fine. I see nothing different about panel 4. In fact, I can deactivate only one of its card sprites, and when I turn it back on, it is now "stuck" and won't update, even though all the other cards in that player's hand will. Same if I deactivate/re-activate one of the text fields. It will no longer update, but everything else does.
I've got no exception errors or anything, but this looks to me like some kind of memory problem, though I can't imagine what. It shows up in my Android build, no it's not specific to my machine. I'm throwing this question out there hoping someone has seen something similar.
If nothing else, maybe someone can tell me how to get my options panel to display over the card sprites. But I hate to leave a problem undiagnosed: they have a way of coming back and biting.
Update
Here's the code that isn't getting displayed. The cardBackSprit values are updating correctly, as is the gameObjectSprite, but the image onscreen isn't changing:
void DrawCardBitmap2(int Player, int cardSpot, int cardIndex)
{
string spriteObjectName;
spriteObjectName = "Sprite_Player" + Player + "_" + cardSpot;
gameObjectSprite = GameObject.Find(spriteObjectName);
gameObjectSprite.GetComponent<SpriteRenderer>().sprite = cardBackSprite;
}
There's a lot to unpack here. Let's break down your post into a series of questions:
1. I cannot get the pop-up to appear over the card sprites
It sounds like you're using the UI Canvas in Unity to handle your info panels for your players, but gameObjects for other elements. This is good, but the UI Canvas' sorting order is a bit different from standard game objects.
UI elements in the Canvas are drawn in the same order they appear in the Hierarchy. The first child is drawn first, the second child next, and so on. If two UI elements overlap, the later one will appear on top of the earlier one.
In order for your pop-up to appear above other elements in your canvas, they need be be higher in your scene's Canvas hierarchy.
Important to note: Canvases set to any Screen Space render mode will render over other game objects in the scene. Canvases set to World Space will render in their world position in the scene. The only render mode that uses Z Position to choose sorting order is World Space, but this is not my recommended solution to your problem.
My recommended solution:
Break your UI into multiple different canvases. Specifically, move your pop-up to a different canvas and place it higher in the scene hierarchy than your card sprites. When you enable/disable or move the pop-up, it will now appear over the card sprites.
2. Four panels (one per player) that hold the cards
From context and some of your code, it sounds like you have SpriteRenderers in your UI Canvas. This is known to be a complex rendering problem. Common advice involves using 2 cameras for rendering, and use camera depth to raise sprites over UI elements. However, redesigning your UI canvas is probably simpler.
3. Using GameObject.Find and complex strings at runtime
GameObject.Find is not performant, and it's not robust. It looks through all elements in the scene and returns the first object it finds with that name.
This poses a few problems:
You cannot have game objects with the same name anywhere in your hierarchy, even if they are nested in different places.
CPU cycles are wasted searching through all objects.
Hidden dependencies on object names that only show up during runtime.
Here's a great blog post on some better practices. I recommend using the [SerializeField] attribute and configuring it via inspector.
4. Canvas isn't updating when objects inside of it change
You can consider invoking Canvas.ForceUpdateCanvases() in LateUpdate(). This is more of a hack than an actual solution, but if this solves your problem it is likely an issue with canvas rendering. If this does not solve your problem, then this problem is likely elsewhere in your code that is currently not provided.
A canvas performs its layout and content generation calculations at the end of a frame, just before rendering, in order to ensure that it's based on all the latest changes that may have happened during that frame. This means that in the Start callback and the first Update callback, the layout and content under the canvas may not be up-to-date.

How to create vertical scrollable area in SpriteKit (Step-by-Step)?

Context
I am developing a SpriteKit game and I want to add a scrollable area to it that displays certain items.(e.g. each item can consist of image and label). Below is a picture that depicts exactly what I am trying to accomplish: you select the "basketball icon" and a list of potential balls are available to be scrolled through and selected (further details after the picture)
With that in mind, I have seen several proposals to attain that goal but the majority of the posts are outdated and most of times not detailed enough for someone to execute. Some suggestions consist of:
Embed UIKit elements such as UIScrollView, UICollectionView or UITableView to your SKScene (in this scenario I imagine my items mentioned above - image and label - instead of Skpritekit elements would need to be customised cells)
Embed UIKit elements (same as above) to an SKNode overlay that sits on top of Scene
Use an SKCameraNode to "simulate" a scrollable behaviour that just follows touches and moves along a bigger Scene (e.g. 2 times the frame size - vertically) this way displaying other SpriteKit elements
That said, I am looking for step-by-step recommendations based on:
(a) own experience (e.g. providing code snippets as answer and/or GitHub examples that are similar)
(b) Available public tutorials (youtube / articles)
(c) Other format you see fit
Ultimately this post and answers can work out as a good foundation for all other people looking for similar implementations.
Thanks in advance for your time and effort. Cheers
From my experience as a game developer, I recommend using SwiftySKScrollView.
SwiftySKScrollView is a helper class to add a UIScrollView to your SpriteKit scenes. The helper will automatically forward button presses to the relevant SKScene and node subclasses. Easy to use and to implement.
Also, it's not worth it to use an SKCamera on this kind of game, also from experience. It will be pretty hard and time consuming for you to try and reproduce the scroll area with all its effects. And in the end, the SwiftySKScrollView which is a helper class to add a UIScrollView will look more smoother and natural.

know object behind another object is fully visible

I have developed scratch card effect.I am stuck at logic of how can I know object got visible which is behind the scratch card image? So that I can show reward screen.
PS: with modifications in this link I able to work this scratch card effect in uGUI.
There are many ways you could go about this. Assuming you know the dimensions of the red "target image" that the user is trying to uncover, you could take a fixed number of samples from the area that the target is under. Once, say, 80% of those samples are transparent (i.e. the target is visible at those positions), you can consider the object visible and show the reward screen.
You can use GetPixel to get the individual samples from the scratch texture.

Rendering a 3D object from four different angles

I am working on a project where I have to render 4 different sides of a 3D object at the same time on the screen. The output should have 4 different camera outputs rendering the front side, left side, right side and back side of the 3d object.
I found that a gaming engine like Unity may help to do something like this. However, I have just started using Unity and can't figure out how to do it.
Here is the link for some examples. This is how I want the output to look like
Well first of all, welcome to Stackoverflow. And you are right, Unity is an excellent IDE to achieve what you described.
As stated in the FAQ and here, I'm going to give you an answer I deem fitting to your question. I can post the code here in about 30 minutes which does exactly what you asked for, but then we'd miss the point of learning to program and posting at StackOverflow in general. I'll show you the way on how to start on this project, but then you'll have to try yourself. If you have any troubles after trying some more, we can help you with specific problems, provided you have researched some before and show us what you tried.
As to your question, it's relative easy to do so. First create your object in the scene, then drag and place four different Camera-objects in the screen. Using the Camera's Normalized View Port Rect (Four values that indicate where on the screen this camera view will be drawn, in Screen Coordinates (values 0-1)), you can then split up the view to show the feed of each Camera.
This ofcourse happens in a script. You can read here about Scripting in Unity. Even if you are an expert in programming, that link is worth a read when you are new to Unity.
Good luck.

iPhone Word Game like Scrabble / Wordfued / Rummi

I am in process of creating a multiplayer game similar to the Scrabble / Wordfued / Rummi. I am trying to see what would be best way go about implementing the UI and their interactions.
I would be having a framework which would keep track of all the pieces on the board and the AI for knowing if it is a valid move.
I am trying to figure out what could be best solution to handle the UI part. The game board would be larger than would the current iPhone screen could support. So the board would have an effect of a scroll view. The same goes for the game tiles using which user can play. These are not fixed amount of tiles/cards and the same could be more in numbers which would also need another scroll view kind of effect.
There would be many more effect's were the user can move a complete set of tiles/cards from the board and place it in another location of the board. Or even a tile in between the set of tiles on the board.
So I am trying so see if I should go with two scroll view provided by iOS and handle all the detaching the tile/card from one scroll view and placing the same in GameBoard scroll view
Or
Should I go with something like cocos-2d which provides more advance game UI handling capabilities.
Please do let me know your thoughts and feedback on what could be the best choice for the same. Thanks in advance for all your help.
Words With Friends uses native UIKit views. It is quite simple and uses a transition to move between the two degrees of magnification (close up and not close up).
You can do everything quickly in UIKit with a UIScrollview. You can use drag events to move tiles around the screen, even changing their perspective/look during dragging. Using UIAnimation would allow you to do simple frame based animation for things like dropping a tile.
Cocos2d will be quicker if you already know a similar gaming library. However if you choose it you you'll miss out on using Interface Builder and a lot of conveniences in UIKit.
If you're starting from a base of zero with either approach, then only use Cocos2d if you want particle effects (like stars and sparkles, UIKit has nothing for this).
Otherwise I'd say try UIKit, it's easier and there are more resources on the web.