Unity3d + Facebook SDK - Switching Scenes - facebook

Before trying to do anything stupid I wanted to ask the experts: what are the best practices on the scenario of switching scenes?
Does Unity3D retain the information of FB.Login() on the first scene forever, or do I need to initialize FB on every scene I loaded?
Sorry to ask before testing it, I am away from my dev machine and really curious!

I made some research and found out that if we create a static class, with a static property it will remain the same as long as the game runs.
So I created 1 static class with a static property of my FacebookUser class and it remained active while switching scenes.

Related

Struggling with Mobile build on phone, looking different on phone and Pc

Firstly I'm still fairly new to coding, saw people making games and fell in love with the idea of making your own game. So the past few months I've been learning unity tutorials and practicing basic games. I've come so far to be basically done with my first game. Everything is ready and I want to load and post it on playstore, but there's one last issue. When I run it on Unity on my pc it looks perfect but I loaded it onto my phone and the UI and some objects is either not showing or looking different than on the pc.Example1Example2Example3 These are examples of my problem. The IMG above is the way it should look like and the one underneath is how it shows on my phone when loaded.
It doesn´t look the same, due to the different resolutions.
Try to use a Canvas Scaler component. Set a reference resolution and the mode how you want to scale it.
If you want your UI elements to be anchored to the center/top/left etc. you should also set the anchor points. Here is a good Tutorial
A good way to instantly check the result is the "device simulator" It is a unity package
That's because of your Canvas settings & your UI GameObjects Anchor. But I think the easiest way to solve this for you - because you don't have that much experience about it - is to separate canvases for mobile & pc. This is the code:
private void Start()
{
if (Application.platform == RuntimePlatform.WindowsPlayer) // If your game's running on android
{
pcCanvas.SetActive(true); // Use PC designed canvas
mobileCanvas.SetActive(false); // Disable Mobile designed canvas
}
else // Your game is running on mobile
{
pcCanvas.SetActive(false);
mobileCanvas.SetActive(true);
}
}
Add this to a GameObject, Design 2 Canvases & assign them to script. (This will be a litte complicated, but will work) This link for more info
But if you want to use 1 canvas, you have to set its settings & its GameObjects anchors.

Project Solution | Architecture | Scenes and Views

Im new in Game Dev and new in development with Unity
(Come from Windows and Web development)
Now I want to make my first game. This will simple game (but with retrieve data from API etc.)
So I have some basic questions:
1) How to decide if I need to make new scene or build just make a lot canvases and switch between them?
In my game I see
1 scene - Loading
2 scene - Main screen with buttons--
1 button - open Store
2 button Open leaderborad
3 button - open something like map
etc...
Now I think
I need make 2 scenes - Loading and Game scene
In Game scene make some canvases
(MainState Canvas, Shop Canvas, MapCanvas, Leader board canvas etc...)
And when user clicks on button - show this canvas (its must be display like Popup)
2) If I want that map will grow up with more and more stop points (like in Candy Crush) - I need to set its to Assets Bundle and load new bundle ?
3) Best practices for Login/Authorization
I check many sites and I see that best practices for Game Authorization today - this is Google/Apple Game service and not Facebook. Right?
If I understand not correct - Can you guys give me a links what I need to read/learn ?
Thank you guys so much.
I suppose you are targeting mobiles.
1) On mobiles the decision is simple in this case. One simple scene, that is loading fast, to show your logo, game title etc. and the second scene to all other stuff. If the game has very complex levels you can start thinking about more scenes. (If it's simple and easy to change to next level, e.g change background, some enemies etc. like in your case I would use one scene)
2) Sorry I don't know what you want to achieve, but you can read about Asset Bundles here and in unity docs. Again it depends on the complexity of the project. For a simple game it may not be a big difference. Official unity video on Asset Bundles and about Bundle browser
3) I have no idea about Apple Game service so I will talk only about Google Services. It's really simple to setup. However some steps may be tricky, but take your time and try to setup everything as you need. The github page of google play games plugin for unity, where you can download the latest build of the plugin, contains a lot of information on how to configure it. Docs I mentioned above and some testing was enough to implement it in my games. However if you have troubles with setting it up there are a few videos on youtube when you can see how to configure it step by step. Also here is the site on which you can see how your code should look after implementing google play games

Zenject Global Bindings

I'm well aware this might not be the best place to ask a Zenject question. I've already posted the same question on Zenject google groups page as well. I'm posting this here thinking that someone who is on here (who's not on google groups) might be able to help me out.
I have a question about Zenject Global Bindings.
My AR app at the moment have several different screens (saved as scenes). Each scene can be run on it's own that way I could keep it very compartmentalised. When I press a button on 'Screen1' it loads 'Screen2' so on and so forth. I'm using a very basic AppDelegate which contains a NavigationController class which handled all the UGUI transitions so that it appears as a normal iOS navigation based app so to speak. I'm injecting AppDelegate as Singleton on all the installers I have but since there are individual CompositionRoots for individual screens (scenes), globally they are not injected as singletons.
Is there a way to do this. Have a singleton injection all throughout the app but with different composition roots?
If not, how to use Global composition root?
I've followed instructions on the guide to create a global composition root and add the installer as a prefab and all that. I deleted installer from the scene as well. But when I play nothing happens. Am I missing something obvious here.
Thanks in advance.
in your Resources folder create a project context prefab
how to make a project context prefab.
You also absolutely have to include a "SceneContext" in your scene. this spawns the first "ProjectContext".
After the creation of said object, it will load on any scene start.
along with the installers and scriptable object installers provided on the prefab. along with bindings to singletons ie:
Container.Bind<IFoo>().To<Foo>().AsSingle().NonLazy();
this means, on zenject initilization you will have an instance of your singelton ready and waiting.

The best way to implement lives and score count in Sprite Kit (static, IoC, other?)

I have background in Java but havn't been coding in years. Lately I've taken interest to warm my coding skills again and have chosen to create learning apps for my kids in Swift. I've created basic Swift game utilizing the Sprite Kit with gameviewcontroller and multiple scenes. However I run into a basic question which is related to passing basic data such as points and lives counts from scenes to gameviewcontroller.
Back in the day, I would have done it by creating a static member that would hold the lives left and score count but how is it today in Swift? I undertand that IoC would be the more modern equilevant to static members but howabout Swift and howabout this case?
Are there IoC frameworks for Swift or StackOverFlow users' proposals for solution concept?
I would also use a separate GameState singleton class to manage all of that stuff, just to make sure there's no conflicts, and you can access the data from anywhere. Here's a really good tutorial for that, and it should be a cinch to update for swift: http://www.raywenderlich.com/63235/how-to-save-your-game-data-tutorial-part-1-of-2
To pass data between several classes your variable has to be global. You have to declare your variable out of classes.
For exemple :
var score:Int = 0
class GameScene {
//Your game here
}
Like this your will call score in all others class like your GameViewController

Use multiple components in Flash AS3 - iPhone app

First of all: Happy new year!
I have a problem with Flash CS5.5, AS3. I have two ScrollPane Components in my document. They are both in another scene and the (instant)names are unique. But it isn’t working properly. When I go to the other scene with the second ScrollPane I get an error & it starts to flicker.
My error:
TypeError: Error #1006: setSize is not a function. at
application051_fla::MainTimeline/frame25()[application051_fla.MainTimeline::frame25:7]
I want to make an iPhone application and I want that multiple components working properly in one document.
My little piece of code (don’t think that the problem is in here):
ScrollPane02.source = tekst03;
ScrollPane02.setSize(350,400);
ScrollPane02.move(0, 20);
ScrollPane02.scrollDrag = false;
If you know the answer or what I am doing wrong, please comment! Searching for hours/days!
Thanks in advance!
Uploaded the .fla document. If you want to take a look at it (please), you can download it here: http://www.bregjebouwmans.nl/application061.fla
Edit:
Ok, after digging through the FLA, I finally figured out what you did . . . you right clicked on ScrollPane in the "Library", and clicked "Duplicate". Then you gave it the name ScrollPane02. Except that the duplication process did not connect the new object to the ScrollPane's setup. Instead, it created a generic MovieClip object. Since it is not an actual ScrollPane, it makes sense that all the methods on the timeline's Actionscript will fail.
This is why the solution (in the comments below) works. #AsTheWormTurns just used the first (actual) ScrollPane in two instances on the timeline; is a viable solution.
(The only caveat being that if you change the ScrollPane object in the Library, it will affect all instances. That shouldn't really be a problem, since -- for components -- you generally make changes only to instances.)
Useful tips from my initial answer:
When compiled into an SWF, scenes are just stuck one right after the other in the timeline, just like scenes in a movie. If you do not have a stop() at the end of one scene, it will continue to run right into the next scene, just like a movie. The idea of scenes is to separate content. This means that what exists in sceneA does not exist in sceneB. The scenes also have no access to each other.
My advice is to not use scenes at all. They are difficult to use correctly, and have very little use that is not better done using the timeline or Actionscript.