FacebookForDeveloperInUnity

https://developers.facebook.com/docs/unity/

Facebook SDK for Unity

Build cross-platform games with Facebook rapidly and easily

Download the SDK

Requires Unity 5.4 and up.

v7.15.1 See Change Log or Upgrade Guide.

 

Get Started
Basic guide for Unity SDK

SDK Reference Docs
API Reference Docs

View Source
View Source On Github

The Unity engine and ecosystem gives developers a world class technology platform from which they can build games that work seamlessly across multiple platforms quickly and effectively.

The Facebook SDK for Unity complements Unity Technologies' cross-platform support, providing a pure-Unity write-once, run-everywhere experience across the key gaming platforms of WebGL, Unity Web Player, Android and iOS. By maintaing a single codebase, you'll be able to deploy socially integrated gaming experiences to your players, regardless of platform.

The Facebook SDK for Unity provides a comprehensive collection of Facebook's social features, giving players of your Unity game the ability to share content with their friends and allowing you to create a personal, social gaming experience. In addition to providing a base set of features that are invoked consistently across platforms, the SDK also offers support for Facebook features that are unique to a particular platform (e.g. payments on the Web or App Invites on mobile). This will allow you to keep your code clean, using a simple, consistent model for everything your game can do on Facebook.

In Unity SDK

Login

People can easily sign in to your game with their Facebook Login.

Share

People can share content with their friends. They can also share Custom Stories with Open Graph.

Game Invites

People can send invites to friends from your game.

App Events

Understand people's actions in your game and measure the effectiveness of your Mobile App Ads.

Graph API

Get data in and out of Facebook's social graph. Query data, post stories, upload photos and do other tasks.

Ads

Drive installs with Mobile App Install Ads. Increase engagement with Mobile App Engagement Ads. Find your target audience with Custom Audiences for Mobile Apps. Monetize in your game with Audience Network.

App Links

Link to a context in your game.

Audience Network

Monetize your mobile property with Facebook ads.

Other Resources

Porting From Mobile to Canvas

Guide for mobile developers thinking about bringing their games to Facebook Canvas.

Getting Started Facebook for Unity

The Facebook SDK for Unity works with Unity 5.0 and above.

No matter what your target platform is, you'll need to start with creating a Facebook App ID for your game. The App ID is used to configure your Facebook SDK within Unity.

If you've never developed a game with Facebook before, or have never registered as a developer, follow the Developer Onboarding Guide first.

Create your app on Facebook

Step 1: If you do not already have a Facebook App ID for your app, you should create one:

Create a New App

 
Step 2: Once completed, you'll see your app's Basic Settings page. Here you can find your App ID, which is required within your Unity game's configuration, in order to integrate with Facebook.

Add the SDK to your Unity project

Step 1: Create a new project in the Unity Editor.

Step 2: Download the latest Facebook SDK for Unity from our Downloads page. Unzip this package after downloading. The code for this sample project will be included.

Step 3: In the Unity Editor, select from the menu 'Assets', 'Import Package' and then 'Custom Package…'. Navigate to the directory where you downloaded the Facebook for Unity SDK and select FacebookSDK.unitypackage.

Step 4: Import all of the assets in the package.

Step 5: Save your project. A post-build script will add a new menu item "Facebook" to the Unity Editor. If you don't see this, check your build for compilation errors and try building again.

Step 6: Select 'Edit Settings' from the 'Facebook' menu.

The inspector will show "FacebookSettings". In the input box under 'App Id:', paste in your Facebook App ID, found as described in the steps above.

Run the sample project

Step 1: In the Project panel, under 'Assets', there is a folder named 'FacebookSDK'. Inside this folder are all the files for the Facebook SDK for Unity. Open the folder titled 'Examples'. Double click on the 'MainMenu' scene to open the sample project menu.

Step 2: In the Unity Editor, select from the menu 'File' and then 'Build Settings'.

Select all the Unity Scenes in the 'Examples' folder from above and drag them over to the Build Settings Panel and drop them in the 'Scenes In Build' area. Drag the 'MainMenu' scene to be in order position 0 as below.

Step 3: Enter Play mode to run our example code for a simple demo of Facebook functionality.

Note: The Unity Editor environment offers limited functionality, and all the functions are stubbed. You may receive warnings and errors regarding the game's inability to reach Facebook and read assets from us; it's safe to ignore them.

Platform Specific Next Steps

After the basic configuration of the Unity SDK refer to the guides below to continue with platform specific configurations.

Select Your Platform:

iOS

Android

Facebook Canvas

Getting Started with the Facebook SDK for Unity on iOS

iOS 9 introduces some changes to the way that apps integrate with Facebook. A preview release of the Facebook SDK for Unity has been prepared for testing with iOS 9 and is available on our iOS 9 documentation.

Related Topics

  • Facebook SDK for Unity Reference
  • Facebook SDK for Unity Examples

Note: This guide is organized to follow after the shared setup steps for the Facebook SDK for Unity detailed in the Getting Stared guide. If you have not yet completed these steps please do so first.

This document provides an follow up step-by-step guide to get started with the Facebook SDK for Unity on iOS. We will build and deploy the sample Unity app bundled with the Unity SDK to allow you to get working on a Facebook integration quickly and effectively. If you're more comfortable working on Android or Web, you can switch to the Getting Started guides for those platforms.

Configuring your app for iOS

Step 1: Switch to the iOS Platform

Go to the Unity Editor. From the menu, choose 'File', 'Build Settings…' In the Build Settings dialog, under 'Platform', select 'iOS' as the target and click 'Switch Platform'. Ensure the sample project scenes have been added to the 'Scenes in Build' as previously described here.

 

Step 2: Set minimum iOS Version

The Facebook SDK for Unity only supports iOS version 8.0 and above. In order to prevent issues any issues on older devices, ensure the 'Target minimum iOS Version' is set to 8.0 or higher.

Step 3: Configure Bundle ID

With the Build Settings dialog still open, click 'Player Settings...' Then, in the Inspector pane go to 'Settings for iOS', then 'Other Settings'. Fill in the 'Bundle Identifier' field with a valid bundle identifier, usually formed using your company name and product name.

Whatever value you put there, you'll need to configure the same value in your app's Facebook settings. Go to the 'iOS' pane in the Basic tab of your app's 'Settings' page, and fill in the 'Bundle ID' field.

Step 4: Build

Now, back in the Unity Editor, click the 'Build' button. When prompted for an output directory name, call it unity_ios. Once Unity finishes building, open the file Unity-iPhone.xcodeproj in the directory that was created with Xcode.

You can hit the 'Play' button in Xcode to run the app in your default target (by default, the simulator), or use Xcode's usual functionality to run it on real iOS devices.

Now you're up and running on iOS. Congratulations!

Next steps

Feel free to explore the sample app to try out the various features of the SDK. Start by clicking the FB.Initbutton at the top of the sample, which will enable the other features of the sample. As a next step, modify the code included in the sample and add it to your game project; this will get your Facebook integration off to a flying start.

For more details on integrating the Facebook SDK into your Unity game, check out the SDK reference and SDK Examples. And if you'd like to see how easy it is to deploy to Facebook Canvas and Android, check out their respective Getting Started guides.

Getting Started with the Facebook SDK for Unity on Android

Related Topics

  • Facebook SDK for Unity Reference
  • Facebook SDK for Unity Examples

Note: This guide is organized to follow after the shared setup steps for the Facebook SDK for Unity detailed in the Getting Stared guide. If you have not yet completed these steps please do so first.

This document provides an follow up step-by-step guide to get started with the Facebook SDK for Unity on Android. We will build and deploy the sample Unity app bundled with the Unity SDK to allow you to get working on a Facebook integration quickly and effectively. If you're more comfortable working on iOS or Web, you can switch to the Getting Started guides for those platforms.

Configuring your app for Android

Step 1: Switch to the Android Platform

Go to the Unity Editor. From the menu, choose 'File', 'Build Settings…' In the Build Settings dialog, under 'Platform', select 'Android' as the target and click 'Switch Platform'. Ensure the sample project scenes have been added to the 'Scenes in Build' as previously described here.

Step 2: Set Android Miniimum API Level

Click on Player Settings and make sure the android Minimum API level is set to "Android 4.0.3 'Ice Cream Sandwich' (API level 15)" or higher.

Step 3: Configure Bundle ID and Key Hash

With the Build Settings dialog still open, click 'Player Settings...' Then, in the Inspector pane go to 'Settings for Android', then 'Other Settings'. Fill in the 'Bundle Identifier' field with a valid bundle identifier, usually formed using your company name and product name. Save your project.

Now select 'Edit Settings' from the 'Facebook' menu.

Find and note the value of the 'Debug Android Key Hash' in the 'Android Build Facebook Settings' panel. Also note the value of the 'Class Name'.

Now, let's add the Bundle ID, Key Hash, and Class Name to your app's Facebook settings. Go to the 'Android' pane in the Basic tab of your app's 'Settings' page, and fill in the 'Bundle ID', 'Key Hashes' , and 'Class Name' fields. Now save your changes.

Step 4: Build

Now, back in the Unity Editor, click the 'Build' button. When prompted for an output directory name, call it unity_android. You can choose to export an APK file directly, which you can install on a test device, or to export a project file to be opened in your Android IDE.

Now you're up and running on Android. Congratulations!

Next steps

Feel free to explore the sample app to try out the various features of the SDK. Start by clicking the FB.Initbutton at the top of the sample, which will enable the other features of the sample. As a next step, modify the code included in the sample and add it to your game project; this will get your Facebook integration off to a flying start.

For more details on integrating the Facebook SDK into your Unity game, check out the SDK reference and SDK Examples. And if you'd like to see how easy it is to deploy to Facebook Canvas and iOS, check out their respective Getting Started guides.

Getting Started with the Facebook SDK for Unity on Facebook Web Games

Related Topics

  • Facebook SDK for Unity Reference
  • Facebook SDK for Unity Examples

Note: This guide is organized to follow after the shared setup steps for the Facebook SDK for Unity detailed in the Getting Stared guide. If you have not yet completed these steps please do so first.

This document provides a follow up step-by-step guide to get started with the Facebook SDK for Unity on Facebook Web Games. We will build and deploy the sample Unity app bundled with the Unity SDK to allow you to get working on a Facebook integration quickly and effectively. If you're more comfortable working on iOS or Android, you can switch to the Getting Started guides for those platforms.

WebGL vs Unity Web Player

In Unity 5.0, the WebGL deployment target was introduced as a new way to build Web games. Unlike deploying with the Unity Web Player, WebGL has no dependency on a browser plug-in; games will simply run in any modern browser.

An additional motivation for deploying with WebGL is to support browsers where the Unity Web Player is no longer a viable solution. One such browser is Google Chrome, which ended general support for Netscape Plug-in API (NPAPI). Since Unity Web Player is an NPAPI plug-in, these changes make the Unity Web Player unusable in Chrome.

Configure your app for Facebook Web Games

Step 1: Switch to a Web Platform

Go to the Unity Editor. From the menu, choose 'File', 'Build Settings…' In the Build Settings dialog, under 'Platform', select 'WebGL' or 'Web Player' as the target and click 'Switch Platform'. Ensure the sample project scenes have been added to the 'Scenes in Build' as previously described here.

Note: Select 'WebGL' to build with HTML5 technologies or select 'Web Player' to build for the Unity Web Player to target older browsers.

Step 2: Build

With the Build Settings dialog open, click the 'Build' button. When prompted for an output directory name, call it web.

See the Building for Web section below for best practices.

Step 3: Deploy the game

Upload the files from the output directory to an SSL/TLS-capable Web server. The game object must be served over HTTPS. During development you will find it easier to serve your game file from a local web server supporting HTTPS. Plenty of solutions exist on the web to help you get started, most of which are free and open source. Check out XAMPP as a starting point.

Step 4: Configure Facebook Web Games Settings

Navigate to your app's Facebook settings. Go to the 'Facebook Web Games' pane in the Basic tab of your app's 'Settings' page and fill in the 'Facebook Web Games URL (https)' field with the URL where you are serving your game. Now save your changes.

When using version 7 or later of the Unity SDK, ensure you leave both 'Legacy Unity Integration' and 'Unity Web Player Install Flow' un-checked. These are legacy settings for usage with older versions of the Unity SDK.

Step 5: Run

Navigate to 'https://apps.facebook.com/[your_app_id]'. You should now be able to see a running example of the game.

Congratulations, you have setup a basic Unity sample and have it running successfully on Facebook.com!

Building for Web

Building with WebGL requires a special consideration. Take note of the steps outlined below:

  1. Read through the Unity documentation on WebGL before you begin building to the WebGL deployment target. There are a number of limitations in features and in browser compatibility to be aware of such as no support for threading or sockets.
  2. Use the latest Unity 5 Release. There are numerous improvements for WebGL in each Unity 5 release and you should not be building without them.
  3. Refer to the Unity documentation on building a WebGL project for information about optimizing build size and performance.
  4. Learn from the community. Read blogs from developers who detail their transition to WebGL, like Jelly Button and Leviathan Games.
  5. Check out the webinar recording embedded below for details on common challenges with WebGL deployment and best practices for web games.

Hybrid Deployment

Due to the varied levels of support for WebGL across browers it can be desirable to maintain both a WebGL and Web Player deployment of your game.

In order to accomplish this you will need to build and host both versions of your game. Instead of pointing the Facebook Web Games URL (https) setting to one of the builds, create a new Pre-Loader that will decide which build to redirect to.

// Simple Pre-Loader Example in Javascript
// Redirects Google Chrome v42 User Agent to WebGL
// Redirects all else to Web Player
DOCTYPE html>

                    
                    

你可能感兴趣的:(U3d&IOS)