Facebook sdk接入
This commit is contained in:
1 parent
4260cf05d3
commit
6423007638
123 files changed
+6764
-39
No files matched your search
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
internal class ConsoleBase : MonoBehaviour
|
||||
{
|
||||
private const int DpiScalingFactor = 160;
|
||||
private static Stack<string> menuStack = new Stack<string>();
|
||||
private string status = "Ready";
|
||||
private string lastResponse = string.Empty;
|
||||
private Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
// DPI scaling
|
||||
private float? scaleFactor;
|
||||
private GUIStyle textStyle;
|
||||
private GUIStyle buttonStyle;
|
||||
private GUIStyle textInputStyle;
|
||||
private GUIStyle labelStyle;
|
||||
|
||||
protected static int ButtonHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return Constants.IsMobile ? 60 : 24;
|
||||
}
|
||||
}
|
||||
|
||||
protected static int MainWindowWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return Constants.IsMobile ? Screen.width - 30 : 700;
|
||||
}
|
||||
}
|
||||
|
||||
protected static int MainWindowFullWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return Constants.IsMobile ? Screen.width : 760;
|
||||
}
|
||||
}
|
||||
|
||||
protected static int MarginFix
|
||||
{
|
||||
get
|
||||
{
|
||||
return Constants.IsMobile ? 0 : 48;
|
||||
}
|
||||
}
|
||||
|
||||
protected static Stack<string> MenuStack
|
||||
{
|
||||
get
|
||||
{
|
||||
return ConsoleBase.menuStack;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ConsoleBase.menuStack = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected string Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.status;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.status = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected Texture2D LastResponseTexture { get; set; }
|
||||
|
||||
protected string LastResponse
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.lastResponse;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.lastResponse = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected Vector2 ScrollPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.scrollPosition;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.scrollPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Note we assume that these styles will be accessed from OnGUI otherwise the
|
||||
// unity APIs will fail.
|
||||
protected float ScaleFactor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!this.scaleFactor.HasValue)
|
||||
{
|
||||
this.scaleFactor = Screen.dpi / ConsoleBase.DpiScalingFactor;
|
||||
}
|
||||
|
||||
return this.scaleFactor.Value;
|
||||
}
|
||||
}
|
||||
|
||||
protected int FontSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)Math.Round(this.ScaleFactor * 16);
|
||||
}
|
||||
}
|
||||
|
||||
protected GUIStyle TextStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.textStyle == null)
|
||||
{
|
||||
this.textStyle = new GUIStyle(GUI.skin.textArea);
|
||||
this.textStyle.alignment = TextAnchor.UpperLeft;
|
||||
this.textStyle.wordWrap = true;
|
||||
this.textStyle.padding = new RectOffset(10, 10, 10, 10);
|
||||
this.textStyle.stretchHeight = true;
|
||||
this.textStyle.stretchWidth = false;
|
||||
this.textStyle.fontSize = this.FontSize;
|
||||
}
|
||||
|
||||
return this.textStyle;
|
||||
}
|
||||
}
|
||||
|
||||
protected GUIStyle ButtonStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.buttonStyle == null)
|
||||
{
|
||||
this.buttonStyle = new GUIStyle(GUI.skin.button);
|
||||
this.buttonStyle.fontSize = this.FontSize;
|
||||
}
|
||||
|
||||
return this.buttonStyle;
|
||||
}
|
||||
}
|
||||
|
||||
protected GUIStyle TextInputStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.textInputStyle == null)
|
||||
{
|
||||
this.textInputStyle = new GUIStyle(GUI.skin.textField);
|
||||
this.textInputStyle.fontSize = this.FontSize;
|
||||
}
|
||||
|
||||
return this.textInputStyle;
|
||||
}
|
||||
}
|
||||
|
||||
protected GUIStyle LabelStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.labelStyle == null)
|
||||
{
|
||||
this.labelStyle = new GUIStyle(GUI.skin.label);
|
||||
this.labelStyle.fontSize = this.FontSize;
|
||||
}
|
||||
|
||||
return this.labelStyle;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
// Limit the framerate to 60 to keep device from burning through cpu
|
||||
Application.targetFrameRate = 60;
|
||||
}
|
||||
|
||||
protected bool Button(string label)
|
||||
{
|
||||
return GUILayout.Button(
|
||||
label,
|
||||
this.ButtonStyle,
|
||||
GUILayout.MinHeight(ConsoleBase.ButtonHeight * this.ScaleFactor),
|
||||
GUILayout.MaxWidth(ConsoleBase.MainWindowWidth));
|
||||
}
|
||||
|
||||
protected void LabelAndTextField(string label, ref string text)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(label, this.LabelStyle, GUILayout.MaxWidth(200 * this.ScaleFactor));
|
||||
text = GUILayout.TextField(
|
||||
text,
|
||||
this.TextInputStyle,
|
||||
GUILayout.MaxWidth(ConsoleBase.MainWindowWidth - 150));
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
protected bool IsHorizontalLayout()
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
return Screen.orientation == ScreenOrientation.Landscape;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected void SwitchMenu(Type menuClass)
|
||||
{
|
||||
ConsoleBase.menuStack.Push(this.GetType().Name);
|
||||
SceneManager.LoadScene(menuClass.Name);
|
||||
}
|
||||
|
||||
protected void GoBack()
|
||||
{
|
||||
if (ConsoleBase.menuStack.Any())
|
||||
{
|
||||
SceneManager.LoadScene(ConsoleBase.menuStack.Pop());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8659f5605d094c19a8b7ef9471c3603
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
internal class LogView : ConsoleBase
|
||||
{
|
||||
private static string datePatt = @"M/d/yyyy hh:mm:ss tt";
|
||||
private static IList<string> events = new List<string>();
|
||||
|
||||
public static void AddLog(string log)
|
||||
{
|
||||
events.Insert(0, string.Format("{0}\n{1}\n", DateTime.Now.ToString(datePatt), log));
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
//GUILayout.Space(Screen.safeArea.yMin + 10);
|
||||
if (this.Button("Back"))
|
||||
{
|
||||
this.GoBack();
|
||||
}
|
||||
|
||||
#if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
|
||||
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
|
||||
{
|
||||
Vector2 scrollPosition = this.ScrollPosition;
|
||||
scrollPosition.y += Input.GetTouch(0).deltaPosition.y;
|
||||
this.ScrollPosition = scrollPosition;
|
||||
}
|
||||
#endif
|
||||
this.ScrollPosition = GUILayout.BeginScrollView(
|
||||
this.ScrollPosition,
|
||||
GUILayout.MinWidth(ConsoleBase.MainWindowFullWidth));
|
||||
|
||||
GUILayout.TextArea(
|
||||
string.Join("\n", events.ToArray()),
|
||||
this.TextStyle,
|
||||
GUILayout.ExpandHeight(true),
|
||||
GUILayout.MaxWidth(ConsoleBase.MainWindowWidth));
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 910cbe16250cb4363b70464c39fc701a
|
||||
timeCreated: 1434143113
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
internal abstract class MenuBase : ConsoleBase
|
||||
{
|
||||
private static ShareDialogMode shareDialogMode;
|
||||
|
||||
protected abstract void GetGui();
|
||||
|
||||
protected virtual bool ShowDialogModeSelector()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual bool ShowBackButton()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void HandleResult(IResult result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
this.LastResponse = "Null Response\n";
|
||||
LogView.AddLog(this.LastResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
this.LastResponseTexture = null;
|
||||
|
||||
// Some platforms return the empty string instead of null.
|
||||
if (!string.IsNullOrEmpty(result.Error))
|
||||
{
|
||||
this.Status = "Error - Check log for details";
|
||||
this.LastResponse = "Error Response:\n" + result.Error;
|
||||
}
|
||||
else if (result.Cancelled)
|
||||
{
|
||||
this.Status = "Cancelled - Check log for details";
|
||||
this.LastResponse = "Cancelled Response:\n" + result.RawResult;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(result.RawResult))
|
||||
{
|
||||
this.Status = "Success - Check log for details";
|
||||
this.LastResponse = "Success Response:\n" + result.RawResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LastResponse = "Empty Response\n";
|
||||
}
|
||||
|
||||
LogView.AddLog(result.ToString());
|
||||
}
|
||||
|
||||
protected void HandleLimitedLoginResult(IResult result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
this.LastResponse = "Null Response\n";
|
||||
LogView.AddLog(this.LastResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
this.LastResponseTexture = null;
|
||||
|
||||
// Some platforms return the empty string instead of null.
|
||||
if (!string.IsNullOrEmpty(result.Error))
|
||||
{
|
||||
this.Status = "Error - Check log for details";
|
||||
this.LastResponse = "Error Response:\n" + result.Error;
|
||||
}
|
||||
else if (result.Cancelled)
|
||||
{
|
||||
this.Status = "Cancelled - Check log for details";
|
||||
this.LastResponse = "Cancelled Response:\n" + result.RawResult;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(result.RawResult))
|
||||
{
|
||||
this.Status = "Success - Check log for details";
|
||||
this.LastResponse = "Success Response:\n" + result.RawResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LastResponse = "Empty Response\n";
|
||||
}
|
||||
|
||||
String resultSummary = "Limited login results\n\n";
|
||||
var profile = FB.Mobile.CurrentProfile();
|
||||
resultSummary += "name: " + profile.Name + "\n";
|
||||
resultSummary += "id: " + profile.UserID + "\n";
|
||||
resultSummary += "email: " + profile.Email + "\n";
|
||||
resultSummary += "pic URL: " + profile.ImageURL + "\n";
|
||||
resultSummary += "birthday: " + profile.Birthday + "\n";
|
||||
resultSummary += "age range: " + profile.AgeRange + "\n";
|
||||
resultSummary += "first name: " + profile.FirstName + "\n";
|
||||
resultSummary += "middle name: " + profile.MiddleName + "\n";
|
||||
resultSummary += "last name: " + profile.LastName + "\n";
|
||||
resultSummary += "friends: " + String.Join(",", profile.FriendIDs) + "\n";
|
||||
resultSummary += "hometown: " + profile.Hometown?.Name + "\n";
|
||||
resultSummary += "location: " + profile.Location?.Name + "\n";
|
||||
resultSummary += "gender: " + profile.Gender + "\n";
|
||||
|
||||
LogView.AddLog(resultSummary);
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
if (this.IsHorizontalLayout())
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical();
|
||||
}
|
||||
|
||||
//GUILayout.Space(Screen.safeArea.yMin + 10);
|
||||
GUILayout.Label(this.GetType().Name, this.LabelStyle);
|
||||
|
||||
this.AddStatus();
|
||||
|
||||
#if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
|
||||
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
|
||||
{
|
||||
Vector2 scrollPosition = this.ScrollPosition;
|
||||
scrollPosition.y += Input.GetTouch(0).deltaPosition.y;
|
||||
this.ScrollPosition = scrollPosition;
|
||||
}
|
||||
#endif
|
||||
this.ScrollPosition = GUILayout.BeginScrollView(
|
||||
this.ScrollPosition,
|
||||
GUILayout.MinWidth(ConsoleBase.MainWindowFullWidth));
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (this.ShowBackButton())
|
||||
{
|
||||
this.AddBackButton();
|
||||
}
|
||||
|
||||
this.AddLogButton();
|
||||
if (this.ShowBackButton())
|
||||
{
|
||||
// Fix GUILayout margin issues
|
||||
GUILayout.Label(GUIContent.none, GUILayout.MinWidth(ConsoleBase.MarginFix));
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
if (this.ShowDialogModeSelector())
|
||||
{
|
||||
this.AddDialogModeButtons();
|
||||
}
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
// Add the ui from decendants
|
||||
this.GetGui();
|
||||
GUILayout.Space(10);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void AddStatus()
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
GUILayout.Box("Status: " + this.Status, this.TextStyle, GUILayout.MinWidth(ConsoleBase.MainWindowWidth));
|
||||
}
|
||||
|
||||
private void AddBackButton()
|
||||
{
|
||||
GUI.enabled = ConsoleBase.MenuStack.Any();
|
||||
if (this.Button("Back"))
|
||||
{
|
||||
this.GoBack();
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
private void AddLogButton()
|
||||
{
|
||||
if (this.Button("Log"))
|
||||
{
|
||||
this.SwitchMenu(typeof(LogView));
|
||||
}
|
||||
}
|
||||
|
||||
private void AddDialogModeButtons()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
foreach (var value in Enum.GetValues(typeof(ShareDialogMode)))
|
||||
{
|
||||
this.AddDialogModeButton((ShareDialogMode)value);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void AddDialogModeButton(ShareDialogMode mode)
|
||||
{
|
||||
bool enabled = GUI.enabled;
|
||||
GUI.enabled = enabled && (mode != shareDialogMode);
|
||||
if (this.Button(mode.ToString()))
|
||||
{
|
||||
shareDialogMode = mode;
|
||||
FB.Mobile.ShareDialogMode = mode;
|
||||
}
|
||||
|
||||
GUI.enabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f28f9112a7d44d3c999fbd95333abbb
|
||||
timeCreated: 1465553943
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f187a1fd548e2a049a6cfef1dcef73e6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
internal class AccessTokenMenu : MenuBase
|
||||
{
|
||||
protected override void GetGui()
|
||||
{
|
||||
if (this.Button("Refresh Access Token"))
|
||||
{
|
||||
FB.Mobile.RefreshCurrentAccessToken(this.HandleResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cc408e158eec46b28b93a44fc8819ff
|
||||
timeCreated: 1447720427
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class AppEvents : MenuBase
|
||||
{
|
||||
protected override void GetGui()
|
||||
{
|
||||
if (this.Button("Log FB App Event"))
|
||||
{
|
||||
this.Status = "Logged FB.AppEvent";
|
||||
FB.LogAppEvent(
|
||||
AppEventName.UnlockedAchievement,
|
||||
null,
|
||||
new Dictionary<string, object>()
|
||||
{
|
||||
{ AppEventParameterName.Description, "Clicked 'Log AppEvent' button" }
|
||||
});
|
||||
LogView.AddLog(
|
||||
"You may see results showing up at https://www.facebook.com/analytics/"
|
||||
+ FB.AppId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3c0dd81ff77c4c30834810815c69f6d
|
||||
timeCreated: 1435018470
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
internal class AppLinks : MenuBase
|
||||
{
|
||||
protected override void GetGui()
|
||||
{
|
||||
if (this.Button("Get App Link"))
|
||||
{
|
||||
FB.GetAppLink(this.HandleResult);
|
||||
}
|
||||
|
||||
if (Constants.IsMobile && this.Button("Fetch Deferred App Link"))
|
||||
{
|
||||
FB.Mobile.FetchDeferredAppLinkData(this.HandleResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9f0b7257fa054227be6e26bf1f6b339
|
||||
timeCreated: 1435164891
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
internal class AppRequests : MenuBase
|
||||
{
|
||||
private string requestMessage = string.Empty;
|
||||
private string requestTo = string.Empty;
|
||||
private string requestFilter = string.Empty;
|
||||
private string requestExcludes = string.Empty;
|
||||
private string requestMax = string.Empty;
|
||||
private string requestData = string.Empty;
|
||||
private string requestTitle = string.Empty;
|
||||
private string requestObjectID = string.Empty;
|
||||
private int selectedAction = 0;
|
||||
private string[] actionTypeStrings =
|
||||
{
|
||||
"NONE",
|
||||
OGActionType.SEND.ToString(),
|
||||
OGActionType.ASKFOR.ToString(),
|
||||
OGActionType.TURN.ToString()
|
||||
};
|
||||
|
||||
protected override void GetGui()
|
||||
{
|
||||
if (this.Button("Select - Filter None"))
|
||||
{
|
||||
FB.AppRequest("Test Message", callback: this.HandleResult);
|
||||
}
|
||||
|
||||
if (this.Button("Select - Filter app_users"))
|
||||
{
|
||||
List<object> filter = new List<object>() { "app_users" };
|
||||
|
||||
// workaround for mono failing with named parameters
|
||||
FB.AppRequest("Test Message", null, filter, null, 0, string.Empty, string.Empty, this.HandleResult);
|
||||
}
|
||||
|
||||
if (this.Button("Select - Filter app_non_users"))
|
||||
{
|
||||
List<object> filter = new List<object>() { "app_non_users" };
|
||||
FB.AppRequest("Test Message", null, filter, null, 0, string.Empty, string.Empty, this.HandleResult);
|
||||
}
|
||||
|
||||
// Custom options
|
||||
this.LabelAndTextField("Message: ", ref this.requestMessage);
|
||||
this.LabelAndTextField("To (optional): ", ref this.requestTo);
|
||||
this.LabelAndTextField("Filter (optional): ", ref this.requestFilter);
|
||||
this.LabelAndTextField("Exclude Ids (optional): ", ref this.requestExcludes);
|
||||
this.LabelAndTextField("Filters: ", ref this.requestExcludes);
|
||||
this.LabelAndTextField("Max Recipients (optional): ", ref this.requestMax);
|
||||
this.LabelAndTextField("Data (optional): ", ref this.requestData);
|
||||
this.LabelAndTextField("Title (optional): ", ref this.requestTitle);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(
|
||||
"Request Action (optional): ",
|
||||
this.LabelStyle,
|
||||
GUILayout.MaxWidth(200 * this.ScaleFactor));
|
||||
|
||||
this.selectedAction = GUILayout.Toolbar(
|
||||
this.selectedAction,
|
||||
this.actionTypeStrings,
|
||||
this.ButtonStyle,
|
||||
GUILayout.MinHeight(ConsoleBase.ButtonHeight * this.ScaleFactor),
|
||||
GUILayout.MaxWidth(ConsoleBase.MainWindowWidth - 150));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
this.LabelAndTextField("Request Object ID (optional): ", ref this.requestObjectID);
|
||||
|
||||
if (this.Button("Custom App Request"))
|
||||
{
|
||||
OGActionType? action = this.GetSelectedOGActionType();
|
||||
if (action != null)
|
||||
{
|
||||
FB.AppRequest(
|
||||
this.requestMessage,
|
||||
action.Value,
|
||||
this.requestObjectID,
|
||||
string.IsNullOrEmpty(this.requestTo) ? null : this.requestTo.Split(','),
|
||||
this.requestData,
|
||||
this.requestTitle,
|
||||
this.HandleResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
FB.AppRequest(
|
||||
this.requestMessage,
|
||||
string.IsNullOrEmpty(this.requestTo) ? null : this.requestTo.Split(','),
|
||||
string.IsNullOrEmpty(this.requestFilter) ? null : this.requestFilter.Split(',').OfType<object>().ToList(),
|
||||
string.IsNullOrEmpty(this.requestExcludes) ? null : this.requestExcludes.Split(','),
|
||||
string.IsNullOrEmpty(this.requestMax) ? 0 : int.Parse(this.requestMax),
|
||||
this.requestData,
|
||||
this.requestTitle,
|
||||
this.HandleResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OGActionType? GetSelectedOGActionType()
|
||||
{
|
||||
string actionString = this.actionTypeStrings[this.selectedAction];
|
||||
if (actionString == OGActionType.SEND.ToString())
|
||||
{
|
||||
return OGActionType.SEND;
|
||||
}
|
||||
else if (actionString == OGActionType.ASKFOR.ToString())
|
||||
{
|
||||
return OGActionType.ASKFOR;
|
||||
}
|
||||
else if (actionString == OGActionType.TURN.ToString())
|
||||
{
|
||||
return OGActionType.TURN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b4c675f81a254b87adc8ad01006c580
|
||||
timeCreated: 1435018470
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
internal class DialogShare : MenuBase
|
||||
{
|
||||
// Custom Share Link
|
||||
private string shareLink = "https://developers.facebook.com/";
|
||||
private string shareTitle = "Link Title";
|
||||
private string shareDescription = "Link Description";
|
||||
private string shareImage = "http://i.imgur.com/j4M7vCO.jpg";
|
||||
|
||||
// Custom Feed Share
|
||||
private string feedTo = string.Empty;
|
||||
private string feedLink = "https://developers.facebook.com/";
|
||||
private string feedTitle = "Test Title";
|
||||
private string feedCaption = "Test Caption";
|
||||
private string feedDescription = "Test Description";
|
||||
private string feedImage = "http://i.imgur.com/zkYlB.jpg";
|
||||
private string feedMediaSource = string.Empty;
|
||||
|
||||
protected override bool ShowDialogModeSelector()
|
||||
{
|
||||
#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override void GetGui()
|
||||
{
|
||||
bool enabled = GUI.enabled;
|
||||
if (this.Button("Share - Link"))
|
||||
{
|
||||
FB.ShareLink(new Uri("https://developers.facebook.com/"), callback: this.HandleResult);
|
||||
}
|
||||
|
||||
// Note: Web dialog doesn't support photo urls.
|
||||
if (this.Button("Share - Link Photo"))
|
||||
{
|
||||
FB.ShareLink(
|
||||
new Uri("https://developers.facebook.com/"),
|
||||
"Link Share",
|
||||
"Look I'm sharing a link",
|
||||
new Uri("http://i.imgur.com/j4M7vCO.jpg"),
|
||||
callback: this.HandleResult);
|
||||
}
|
||||
|
||||
this.LabelAndTextField("Link", ref this.shareLink);
|
||||
this.LabelAndTextField("Title", ref this.shareTitle);
|
||||
this.LabelAndTextField("Description", ref this.shareDescription);
|
||||
this.LabelAndTextField("Image", ref this.shareImage);
|
||||
if (this.Button("Share - Custom"))
|
||||
{
|
||||
FB.ShareLink(
|
||||
new Uri(this.shareLink),
|
||||
this.shareTitle,
|
||||
this.shareDescription,
|
||||
new Uri(this.shareImage),
|
||||
this.HandleResult);
|
||||
}
|
||||
|
||||
GUI.enabled = enabled && (!Constants.IsEditor || (Constants.IsEditor && FB.IsLoggedIn));
|
||||
if (this.Button("Feed Share - No To"))
|
||||
{
|
||||
FB.FeedShare(
|
||||
string.Empty,
|
||||
new Uri("https://developers.facebook.com/"),
|
||||
"Test Title",
|
||||
"Test caption",
|
||||
"Test Description",
|
||||
new Uri("http://i.imgur.com/zkYlB.jpg"),
|
||||
string.Empty,
|
||||
this.HandleResult);
|
||||
}
|
||||
|
||||
this.LabelAndTextField("To", ref this.feedTo);
|
||||
this.LabelAndTextField("Link", ref this.feedLink);
|
||||
this.LabelAndTextField("Title", ref this.feedTitle);
|
||||
this.LabelAndTextField("Caption", ref this.feedCaption);
|
||||
this.LabelAndTextField("Description", ref this.feedDescription);
|
||||
this.LabelAndTextField("Image", ref this.feedImage);
|
||||
this.LabelAndTextField("Media Source", ref this.feedMediaSource);
|
||||
if (this.Button("Feed Share - Custom"))
|
||||
{
|
||||
FB.FeedShare(
|
||||
this.feedTo,
|
||||
string.IsNullOrEmpty(this.feedLink) ? null : new Uri(this.feedLink),
|
||||
this.feedTitle,
|
||||
this.feedCaption,
|
||||
this.feedDescription,
|
||||
string.IsNullOrEmpty(this.feedImage) ? null : new Uri(this.feedImage),
|
||||
this.feedMediaSource,
|
||||
this.HandleResult);
|
||||
}
|
||||
|
||||
GUI.enabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e93c4155902d3496399630ee494eab6b
|
||||
timeCreated: 1435018470
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
internal class GraphRequest : MenuBase
|
||||
{
|
||||
private string apiQuery = string.Empty;
|
||||
private Texture2D profilePic;
|
||||
|
||||
protected override void GetGui()
|
||||
{
|
||||
bool enabled = GUI.enabled;
|
||||
GUI.enabled = enabled && FB.IsLoggedIn;
|
||||
if (this.Button("Basic Request - Me"))
|
||||
{
|
||||
FB.API("/me", HttpMethod.GET, this.HandleResult);
|
||||
}
|
||||
|
||||
if (this.Button("Retrieve Profile Photo"))
|
||||
{
|
||||
FB.API("/me/picture", HttpMethod.GET, this.ProfilePhotoCallback);
|
||||
}
|
||||
|
||||
if (this.Button("Take and Upload screenshot"))
|
||||
{
|
||||
this.StartCoroutine(this.TakeScreenshot());
|
||||
}
|
||||
|
||||
this.LabelAndTextField("Request", ref this.apiQuery);
|
||||
if (this.Button("Custom Request"))
|
||||
{
|
||||
FB.API(this.apiQuery, HttpMethod.GET, this.HandleResult);
|
||||
}
|
||||
|
||||
if (this.profilePic != null)
|
||||
{
|
||||
GUILayout.Box(this.profilePic);
|
||||
}
|
||||
|
||||
GUI.enabled = enabled;
|
||||
}
|
||||
|
||||
private void ProfilePhotoCallback(IGraphResult result)
|
||||
{
|
||||
if (string.IsNullOrEmpty(result.Error) && result.Texture != null)
|
||||
{
|
||||
this.profilePic = result.Texture;
|
||||
}
|
||||
|
||||
this.HandleResult(result);
|
||||
}
|
||||
|
||||
private IEnumerator TakeScreenshot()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
var width = Screen.width;
|
||||
var height = Screen.height;
|
||||
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
|
||||
|
||||
// Read screen contents into the texture
|
||||
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
||||
tex.Apply();
|
||||
byte[] screenshot = tex.EncodeToPNG();
|
||||
|
||||
var wwwForm = new WWWForm();
|
||||
wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
|
||||
wwwForm.AddField("message", "herp derp. I did a thing! Did I do this right?");
|
||||
FB.API("me/photos", HttpMethod.POST, this.HandleResult, wwwForm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23c3cb06c2209474e9a8441e2712d5d2
|
||||
timeCreated: 1435018470
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
internal sealed class MainMenu : MenuBase
|
||||
{
|
||||
|
||||
enum Scope {
|
||||
PublicProfile = 0b_0000_0001,
|
||||
UserFriends = 0b_0000_0010,
|
||||
UserBirthday = 0b_0000_0100,
|
||||
UserAgeRange = 0b_0000_1000,
|
||||
PublishActions = 0b_0001_0000,
|
||||
UserLocation = 0b_0010_0000,
|
||||
UserHometown = 0b_0100_0000,
|
||||
UserGender = 0b_1000_0000,
|
||||
};
|
||||
|
||||
protected override bool ShowBackButton()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void GetGui()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
|
||||
bool enabled = GUI.enabled;
|
||||
if (this.Button("FB.Init"))
|
||||
{
|
||||
FB.Init(this.OnInitComplete, this.OnHideUnity);
|
||||
this.Status = "FB.Init() called with " + FB.AppId;
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUI.enabled = enabled && FB.IsInitialized;
|
||||
if (this.Button("Classic login"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.ENABLED, Scope.PublicProfile);
|
||||
this.Status = "Classic login called";
|
||||
}
|
||||
if (this.Button("Get publish_actions"))
|
||||
{
|
||||
this.CallFBLoginForPublish();
|
||||
this.Status = "Login (for publish_actions) called";
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (this.Button("Limited login"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.LIMITED, Scope.PublicProfile);
|
||||
this.Status = "Limited login called";
|
||||
|
||||
}
|
||||
if (this.Button("Limited login +friends"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.LIMITED, Scope.PublicProfile | Scope.UserFriends);
|
||||
this.Status = "Limited login +friends called";
|
||||
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (this.Button("Limited Login+bday"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.LIMITED, Scope.PublicProfile | Scope.UserBirthday);
|
||||
this.Status = "Limited login +bday called";
|
||||
}
|
||||
|
||||
if (this.Button("Limited Login+agerange"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.LIMITED, Scope.PublicProfile | Scope.UserAgeRange);
|
||||
this.Status = "Limited login +agerange called";
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (this.Button("Limited Login + location"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.LIMITED, Scope.PublicProfile | Scope.UserLocation);
|
||||
}
|
||||
|
||||
if (this.Button("Limited Login + Hometown"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.LIMITED, Scope.PublicProfile | Scope.UserHometown);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (this.Button("Limited Login + Gender"))
|
||||
{
|
||||
this.CallFBLogin(LoginTracking.LIMITED, Scope.PublicProfile | Scope.UserGender);
|
||||
}
|
||||
|
||||
|
||||
GUI.enabled = FB.IsLoggedIn;
|
||||
|
||||
|
||||
// Fix GUILayout margin issues
|
||||
GUILayout.Label(GUIContent.none, GUILayout.MinWidth(ConsoleBase.MarginFix));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
// Fix GUILayout margin issues
|
||||
GUILayout.Label(GUIContent.none, GUILayout.MinWidth(ConsoleBase.MarginFix));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
#if !UNITY_WEBGL
|
||||
if (this.Button("Logout"))
|
||||
{
|
||||
CallFBLogout();
|
||||
this.Status = "Logout called";
|
||||
}
|
||||
#endif
|
||||
|
||||
GUI.enabled = enabled && FB.IsInitialized;
|
||||
if (this.Button("Share Dialog"))
|
||||
{
|
||||
this.SwitchMenu(typeof(DialogShare));
|
||||
}
|
||||
|
||||
if (this.Button("App Requests"))
|
||||
{
|
||||
this.SwitchMenu(typeof(AppRequests));
|
||||
}
|
||||
|
||||
if (this.Button("Graph Request"))
|
||||
{
|
||||
this.SwitchMenu(typeof(GraphRequest));
|
||||
}
|
||||
|
||||
if (Constants.IsWeb && this.Button("Pay"))
|
||||
{
|
||||
this.SwitchMenu(typeof(Pay));
|
||||
}
|
||||
|
||||
if (this.Button("App Events"))
|
||||
{
|
||||
this.SwitchMenu(typeof(AppEvents));
|
||||
}
|
||||
|
||||
if (this.Button("App Links"))
|
||||
{
|
||||
this.SwitchMenu(typeof(AppLinks));
|
||||
}
|
||||
|
||||
if (Constants.IsMobile && this.Button("Access Token"))
|
||||
{
|
||||
this.SwitchMenu(typeof(AccessTokenMenu));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUI.enabled = enabled;
|
||||
}
|
||||
|
||||
private void CallFBLogin(LoginTracking mode, Scope scopemask)
|
||||
{
|
||||
List<string> scopes = new List<string>();
|
||||
|
||||
if((scopemask & Scope.PublicProfile) > 0) {
|
||||
scopes.Add("public_profile");
|
||||
}
|
||||
if((scopemask & Scope.UserFriends) > 0)
|
||||
{
|
||||
scopes.Add("user_friends");
|
||||
}
|
||||
if((scopemask & Scope.UserBirthday) > 0)
|
||||
{
|
||||
scopes.Add("user_birthday");
|
||||
}
|
||||
if((scopemask & Scope.UserAgeRange) > 0)
|
||||
{
|
||||
scopes.Add("user_age_range");
|
||||
}
|
||||
|
||||
if ((scopemask & Scope.UserLocation) > 0)
|
||||
{
|
||||
scopes.Add("user_location");
|
||||
}
|
||||
|
||||
if ((scopemask & Scope.UserHometown) > 0)
|
||||
{
|
||||
scopes.Add("user_hometown");
|
||||
}
|
||||
|
||||
if ((scopemask & Scope.UserGender) > 0)
|
||||
{
|
||||
scopes.Add("user_gender");
|
||||
}
|
||||
|
||||
|
||||
if (mode == LoginTracking.ENABLED)
|
||||
{
|
||||
FB.Mobile.LoginWithTrackingPreference(LoginTracking.ENABLED, scopes, "classic_nonce123", this.HandleResult);
|
||||
}
|
||||
else // mode == loginTracking.LIMITED
|
||||
{
|
||||
FB.Mobile.LoginWithTrackingPreference(LoginTracking.LIMITED, scopes, "limited_nonce123", this.HandleLimitedLoginResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void CallFBLoginForPublish()
|
||||
{
|
||||
// It is generally good behavior to split asking for read and publish
|
||||
// permissions rather than ask for them all at once.
|
||||
//
|
||||
// In your own game, consider postponing this call until the moment
|
||||
// you actually need it.
|
||||
FB.LogInWithPublishPermissions(new List<string>() { "publish_actions" }, this.HandleResult);
|
||||
}
|
||||
|
||||
private void CallFBLogout()
|
||||
{
|
||||
FB.LogOut();
|
||||
}
|
||||
|
||||
private void OnInitComplete()
|
||||
{
|
||||
this.Status = "Success - Check log for details";
|
||||
this.LastResponse = "Success Response: OnInitComplete Called\n";
|
||||
string logMessage = string.Format(
|
||||
"OnInitCompleteCalled IsLoggedIn='{0}' IsInitialized='{1}'",
|
||||
FB.IsLoggedIn,
|
||||
FB.IsInitialized);
|
||||
LogView.AddLog(logMessage);
|
||||
if (AccessToken.CurrentAccessToken != null)
|
||||
{
|
||||
LogView.AddLog(AccessToken.CurrentAccessToken.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHideUnity(bool isGameShown)
|
||||
{
|
||||
this.Status = "Success - Check log for details";
|
||||
this.LastResponse = string.Format("Success Response: OnHideUnity Called {0}\n", isGameShown);
|
||||
LogView.AddLog("Is game shown: " + isGameShown);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 922e3ad8d88a146b3b392cd8c84edd6a
|
||||
timeCreated: 1465553943
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
||||
* copy, modify, and distribute this software in source code or binary form for use
|
||||
* in connection with the web services and APIs provided by Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use of
|
||||
* this software is subject to the Facebook Developer Principles and Policies
|
||||
* [http://developers.facebook.com/policy/]. This copyright notice shall be
|
||||
* included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Facebook.Unity.Example
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
internal class Pay : MenuBase
|
||||
{
|
||||
private string payProduct = string.Empty;
|
||||
|
||||
protected override void GetGui()
|
||||
{
|
||||
this.LabelAndTextField("Product: ", ref this.payProduct);
|
||||
if (this.Button("Call Pay"))
|
||||
{
|
||||
this.CallFBPay();
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
}
|
||||
|
||||
private void CallFBPay()
|
||||
{
|
||||
FB.Canvas.Pay(this.payProduct, callback: this.HandleResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f08c9721703046ec883e57562184726
|
||||
timeCreated: 1435018470
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user