GithubHelp home page GithubHelp logo

friendsmash-unity's Introduction

Friend Smash sample Facebook game

Authors:

  • Colin Creitz (ccreitz)
  • Marco Alvarez (marcoa)
  • Andy Borrell (andyborrell)
  • Chris Lewis (cmlewis89)

Overview

To help better understand different products and services available to game developers, Facebook maintains a sample game called Friend Smash!

The game is implemented on different platforms:

There are minor differences between the four implementations, but overall the goal and structure of all is similar. This is the Unity version of the game.

What is “Friend Smash!”?

Friend Smash is a simple game which utilizes Facebook platform to enhance the gameplay by making it more fun and social. It uses variety of products and services, such as Facebook Login, Graph API, Game Requests and Sharing. The code examples serve as a guide of how they may be used in a games context. It also serves as an implementation guide - parts of source code relevant to Facebook integration are clearly separated from the pure gaming-logic and clearly documented with in code comments.

Please note that Friend Smash! was not designed as an example of how to design or code a game. The focus is on Facebook integration - other parts of the project may not be as clear and well designed and documented.

Friends Smash! is a game in which players are tasked with "smashing" (mouse-clicking or screen-tapping) pictures of a specific person while avoiding smashing pictures of anyone else. Player gets points for each correct picture smashed. Each miss or wrong smash causes the player to lose a heart. After losing 3 lives, the game is over. Player can also smash images of coins to collect them and later redeem these coins to buy bombs. In turn, bombs can be used in game to smash all correct pictures on the screen, helping to achieve a higher score. Additionally, the web version of the game allows players to purchase coins with Facebook Payments.

Facebook integration

To make the experience more fun and social, players are asked to log in with Facebook and grant user_friends permission. When granted, the game will have access to subset of player's friends data, specifically those who also logged in to Friend Smash! and granted user_friends permission. This means the game will use the profile picture of randomly selected friend as the picture the player is asked to smash. If user_friends permission hasn’t been granted or the player doesn't have friends who also logged in to Friend Smash! and granted user_friends permission, a picture of randomly selected celebrity is used instead.

At different points in the game player has an opportunity to share to Facebook. For example after the game is over, player can brag about the score achieved by posting a custom Open Graph story. The game also shows how to ask for publish_actions permission (which is required for API based sharing) and how to handle the case when publish_actions permission is not granted. If publish_actions permission is granted - the game uses Scores API to publish and store the top score achieved by the player.

Game Requests are used in the game for two main purposes. First to let the player invite their friends who are not playing the game to try it. Second, to send a challenge to a friend who is already playing to bring them back to the game. Additionally on the web version, the game uses Facebook Payments to allow players to purchase in-game currency and In-Game Gifting to allow purchasing gifts for players’ friends. The web example also includes reference implementation of a payments server handling static pricing and payments verification.

Friend Smash! also logs App Events, which enables Facebook Analytics for Apps - a free tool allowing developers to learn how people use their app across all platforms and devices, get insights about the people using the app, and improve marketing.

How to use “Friend Smash!”?

All versions of Friend Smash! are available as part of Facebook Platform Samples on github: Web, Android, iOS, Unity.

The recommended way to explore the projects is to begin with how Facebook products are integrated. To make it easier code responsible for Facebook integration is separated and well documented with in code comments for all versions. You can find it here for different versions: Web, Android, iOS, Unity. The reference implementation of a payments server is included in the Web repository.

To play the Unity version of Friend Smash! on Web, simply go to apps.facebook.com/friendsmashunity. To play it on mobile, download the Android, iOS or Unity project and build it from source and try on your device.

Please note it is likely that unless you have friends who also installed Friend Smash! you will not see any of your friends in the game. If this is the case, you can invite some of your friends to play Friend Smash! to fully explore how social integration works in Friend Smash!

Installing

Before running the sample, please see the Getting Started on Unity guide.

When deploying to the web, update config.php with your Facebook app and server configuration.

Additional Resources

Contributing

All contributors must agree to and sign the Facebook CLA prior to submitting Pull Requests. We cannot accept Pull Requests until this document is signed and submitted.

friendsmash-unity's People

Contributors

aliparr- avatar jamesgpearce avatar skoggkatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

friendsmash-unity's Issues

Keyboard not popping up when deployed to Nexus 5

Hi All,

I ran through the example, and got the friend smash project running on my nexus 5. However, when i click on login with facebook, and the sign in dialog pops-up. When i try to click a text field the keyboard never gets displayed as expected. This only happens on device. Has anyone else seen this issue?
I'm on unity version 4.6.1, and download facebook unity SDK 6.0.

-Eli

Error while generating .apk

Hello:

I am trying to run this project on android device. While generating .apk I am getting following error
I am using latest facebook sdk: https://developers.facebook.com/docs/unity/downloads/
Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for details.
E:\Personal Project\Setups\Android\android-sdk\build-tools\18.0.1\aapt.exe package --auto-add-overlay -v -f -m -J gen -M AndroidManifest.xml -S "res" -I "E:/Personal Project/Setups/Android/android-sdk/platforms/android-18\android.jar" -F bin/resources.ap_ --extra-packages -S "C:\Users\Admin\Desktop\New folder (3)\friendsmash-unity-master\friendsmash-unity-master\Assets\Plugins\Android\facebook\res"

stderr[
C:\Users\Admin\Desktop\New folder (3)\friendsmash-unity-master\friendsmash-unity-master\Assets\Plugins\Android\facebook\res\values\strings.xml: error: Duplicate file.
res\values\strings.xml: Original is here.
]
stdout[
Processing raw dir 'C:\Users\Admin\Desktop\New folder (3)\friendsmash-unity-master\friendsmash-unity-master\Assets\Plugins\Android\facebook\res'
]

Any idea how can I fix this?

Thanks,
Ashwani

Store and advanced requests!

Hello!

When will be available more examples about advanced requests (gifting, differentiated requests like ammo and lives and exchange of game goods between friends) and handling purchases on unity. Thanks in advance

Ed

Doesn't work with latest Facebook SDK v4.3.4

I used Unity v4.2.2 with latest version of Facebook SDK v4.3.4 package. When I imported the package into the FriendSmash Unity project I got this error:
Assets/Scripts/MainMenu.cs(24,12): error CS0117: FB does not contain a definition for `GetAuthResponse'

It did worked with Facebook SDK v4.2.4 package.

Unity Canvas Payments Complete - Coin packages don't show up!!

Okay so I have corrected the initial errors, namely:
1- 'Facebook' not found. Corrected by importing the latest facebook unity sdk.
2- Internal Compiler Error. Corrected the AppRequest params to not have names.

But i am still stuck, as the coin packages dont show up!!! I am using my own own App Id here. Can someone please help me out?

400 Bad Request invitable_friends

Hi

The projects works but I get a 400 Bad Request because of this part :
,invitable_friends.limit(100).fields(first_name,id,picture.width(128).height(128))

on the meQueryString initialisation.

Removing it, and keeping only :
//string meQueryString = "/v2.0/me?fields=id,first_name,friends.limit(100).fields(first_name,id,picture.width(128).height(128))";

works and I don t get any error 400 but I miss half of my friends.

How can I fix that ?

Unity 4.3.4 error

Added latest Facebook API into friendsmash example projects and getting this error.

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: Mono.CSharp.InternalErrorException: Internal error
at Mono.CSharp.MethodGroupExpr.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, System.Reflection.MethodBase& method, System.Boolean& params_expanded_form) [0x00000] in :0
at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& Arguments, Boolean may_fail, Location loc) [0x00000] in :0
at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.If.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in :0

Unity Facebook SDk how to store players data on Facebook

I am using the unity SDK for a game. I followed the FriendSmah tutorial and I replicated everything in my game correctly. In the mentioned demo players data such number of coins, bombs and hearts are always reset to their default standards everytime you enter the game. I would like instead to store those values somewhere on the server, especially if a player buys a game item, he should have to find that item when he will enter the game again. Do I have to create a Data Base structure on my web site or is it possible to use something on Facebook side? Thanks

How To Let People On Facebook Play Game Against Each Other?

@cmlewis89 @youminkim ...
Hello , :) thanks for your nice sharing code really helpful.
I did same thing to my game Facebook Login , Logout , Sharing , Requesting ...
Now I want to let people who installed this app and get the Facebook authentication to play against each other ... Any idea for this issue?! Please help, much appreciated TIA :)

IOS export failed for unity 4.3.4

I'm getting this error when trying to publish the sample project to IOS.

IOException: Sharing violation on path /Users/mac/IOS/Unity-iPhone.xcodeproj/project.pbxproj
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/FileStream.cs:320)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding, Int32 bufferSize) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/StreamWriter.cs:124)
System.IO.StreamWriter..ctor (System.String path, Boolean append)
(wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (string,bool)
System.IO.File.CreateText (System.String path) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/File.cs:159)
UnityEditor.XCodeEditor.XCProject.Save () (at Assets/Facebook/Editor/iOS/third_party/XCodeEditor-for-Unity/XCProject.cs:596)
UnityEditor.FacebookEditor.XCodePostProcess.OnPostProcessBuild (BuildTarget target, System.String path) (at Assets/Facebook/Editor/FacebookPostprocess.cs:35)
UnityEditor.HostView:OnGUI()

Score deletes after refresh

i build this game and upload for test , i play it but after refresh my score is 0 and test payment coins also deleted.

so where it saves user data? Facebook server or our own?

Error on FBUtil.cs

Assets/Scripts/FBUtil.cs(48,30): error CS0103: The name `MiniJSON' does not exist in the current context

and many similar errors on this script

The best overloaded method match for `FB.AppRequest(string, string[]

Hello! Unity 4.6.2f1 FB SDK Package 6.2.1 Friend Smash Project - friendsmash_payments_complete. Error in Unity:
The best overloaded method match for `FB.AppRequest(string, string[], System.Collections.Generic.List, string[], int?, string, string, Facebook.FacebookDelegate)' has some invalid arguments

Source Error code:
FB.AppRequest(
message: "I just smashed you " + GameStateManager.Score.ToString() + " times! Can you beat it?",
to: recipient,
filters : "",
excludeIds : null,
maxRecipients : null,
data: "{"challenge_score":" + GameStateManager.Score.ToString() + "}",
title: "Friend Smash Challenge!",
callback:appRequestCallback
);

Facebook Unity SDK

When exporting to iOS it seems to only work the first time, the second one it corrupts the .plist file. Throwing:

'''
XmlException: 'dict' is expected'
'''

It actually has to do with a flawed generation of a tag.

Issue with iOS / 2nd start

  1. If you run Friends Smash for the first time everything works fine.
  2. If you start Friends Smash again the log in screen disappears, the texture of the player is nor visible and in the game, only the blue guy appears instead of the randomly chosen FB friend.

The workaround for this issue is that you enforce the logout at the Start() function.
In this case, the user has to log in each time he starts the game.

Facebook Unity SDK...

I am using Unity 5.0.2 with Facebook SDK v7.8.0 where everything is working properly, I am able to log in , log out , share , invite bla bla bla... But , the problem is that when I log in I grant the user access token and permission , isn't it? Suppose now the user logged out and then want to sign in with same account here is the problem it gives Login error:....
This is because the user accepted the permissions and bla bla ...
The question is how to avoid it ? How to let user login automatically if he/she granted permissions ? Thanks in advance :) ...
@andyborrell

Rebuilding Library because the asset database could not be found!

Unity 4.3.4

Just download master package, open any of the projects and get the following error.

Assets/Scripts/MainMenu.cs(6,7): error CS0246: The type or namespace name `Facebook' could not be found. Are you missing a using directive or an assembly reference?

After importing latest Facebook SDK (5.1), getting the next:

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: Mono.CSharp.InternalErrorException: Internal error
at Mono.CSharp.MethodGroupExpr.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, System.Reflection.MethodBase& method, System.Boolean& params_expanded_form) [0x00000] in :0
at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& Arguments, Boolean may_fail, Location loc) [0x00000] in :0
at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.If.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in :0

Can anyone provide with some instructions how to use the plugin and where to get working version?
Facebook is a REAL PAIN!!!

No overload for method `AppRequest' takes `6' arguments

Assets/Scripts/MainMenu.cs(641,16): error CS1501: No overload for method AppRequest' takes6' arguments

in this part :

FB.AppRequest(
to: null,
filters : "",
excludeIds : null,
message: "Friend Smash is smashing! Check it out.",
title: "Play Friend Smash with me!",
callback:appRequestCallback
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.