DialogShare.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  3. *
  4. * You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  5. * copy, modify, and distribute this software in source code or binary form for use
  6. * in connection with the web services and APIs provided by Facebook.
  7. *
  8. * As with any software that integrates with the Facebook platform, your use of
  9. * this software is subject to the Facebook Developer Principles and Policies
  10. * [http://developers.facebook.com/policy/]. This copyright notice shall be
  11. * included in all copies or substantial portions of the software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  15. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  16. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  17. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  18. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. namespace Facebook.Unity.Example
  21. {
  22. using System;
  23. using System.Collections;
  24. using System.Collections.Generic;
  25. using System.Linq;
  26. using UnityEngine;
  27. internal class DialogShare : MenuBase
  28. {
  29. // Custom Share Link
  30. private string shareLink = "https://developers.facebook.com/";
  31. private string shareTitle = "Link Title";
  32. private string shareDescription = "Link Description";
  33. private string shareImage = "http://i.imgur.com/j4M7vCO.jpg";
  34. // Custom Feed Share
  35. private string feedTo = string.Empty;
  36. private string feedLink = "https://developers.facebook.com/";
  37. private string feedTitle = "Test Title";
  38. private string feedCaption = "Test Caption";
  39. private string feedDescription = "Test Description";
  40. private string feedImage = "http://i.imgur.com/zkYlB.jpg";
  41. private string feedMediaSource = string.Empty;
  42. protected override bool ShowDialogModeSelector()
  43. {
  44. #if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)
  45. return true;
  46. #else
  47. return false;
  48. #endif
  49. }
  50. protected override void GetGui()
  51. {
  52. bool enabled = GUI.enabled;
  53. if (this.Button("Share - Link"))
  54. {
  55. FB.ShareLink(new Uri("https://developers.facebook.com/"), callback: this.HandleResult);
  56. }
  57. // Note: Web dialog doesn't support photo urls.
  58. if (this.Button("Share - Link Photo"))
  59. {
  60. FB.ShareLink(
  61. new Uri("https://developers.facebook.com/"),
  62. "Link Share",
  63. "Look I'm sharing a link",
  64. new Uri("http://i.imgur.com/j4M7vCO.jpg"),
  65. callback: this.HandleResult);
  66. }
  67. this.LabelAndTextField("Link", ref this.shareLink);
  68. this.LabelAndTextField("Title", ref this.shareTitle);
  69. this.LabelAndTextField("Description", ref this.shareDescription);
  70. this.LabelAndTextField("Image", ref this.shareImage);
  71. if (this.Button("Share - Custom"))
  72. {
  73. FB.ShareLink(
  74. new Uri(this.shareLink),
  75. this.shareTitle,
  76. this.shareDescription,
  77. new Uri(this.shareImage),
  78. this.HandleResult);
  79. }
  80. GUI.enabled = enabled && (!Constants.IsEditor || (Constants.IsEditor && FB.IsLoggedIn));
  81. if (this.Button("Feed Share - No To"))
  82. {
  83. FB.FeedShare(
  84. string.Empty,
  85. new Uri("https://developers.facebook.com/"),
  86. "Test Title",
  87. "Test caption",
  88. "Test Description",
  89. new Uri("http://i.imgur.com/zkYlB.jpg"),
  90. string.Empty,
  91. this.HandleResult);
  92. }
  93. this.LabelAndTextField("To", ref this.feedTo);
  94. this.LabelAndTextField("Link", ref this.feedLink);
  95. this.LabelAndTextField("Title", ref this.feedTitle);
  96. this.LabelAndTextField("Caption", ref this.feedCaption);
  97. this.LabelAndTextField("Description", ref this.feedDescription);
  98. this.LabelAndTextField("Image", ref this.feedImage);
  99. this.LabelAndTextField("Media Source", ref this.feedMediaSource);
  100. if (this.Button("Feed Share - Custom"))
  101. {
  102. FB.FeedShare(
  103. this.feedTo,
  104. string.IsNullOrEmpty(this.feedLink) ? null : new Uri(this.feedLink),
  105. this.feedTitle,
  106. this.feedCaption,
  107. this.feedDescription,
  108. string.IsNullOrEmpty(this.feedImage) ? null : new Uri(this.feedImage),
  109. this.feedMediaSource,
  110. this.HandleResult);
  111. }
  112. GUI.enabled = enabled;
  113. }
  114. }
  115. }