Test.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using cn.sharesdk.unity3d;
  6. using UnityEngine.UI;
  7. public class Test : MonoBehaviour
  8. {
  9. public Text Text;
  10. public Texture2D Texture2D;
  11. private string FilePath;
  12. public void Awake()
  13. {
  14. FilePath = $"{Application.persistentDataPath}/Test.png";
  15. if (!File.Exists(FilePath))
  16. {
  17. File.WriteAllBytes(FilePath, Texture2D.EncodeToPNG());
  18. }
  19. Text.text = FilePath;
  20. ShareSDK = gameObject.AddComponent<ShareSDK>();
  21. ShareSDK.Initialize();
  22. ShareSDK.shareHandler = ShareCallback;
  23. }
  24. public static ShareSDK ShareSDK;
  25. public void TestShare()
  26. {
  27. ShareContent shareContent = new ShareContent();
  28. shareContent.SetText("content");
  29. shareContent.SetTitle("title");
  30. shareContent.SetTitleUrl("www.baidu.com");
  31. shareContent.SetSite("www.baidu.com");
  32. shareContent.SetSiteUrl("www.baidu.com");
  33. shareContent.SetUrl("www.baidu.com");
  34. shareContent.SetShareType(ContentType.App);
  35. //shareContent.SetImageUrl("http://or5zgoeui.bkt.clouddn.com/game_icon.png");
  36. shareContent.SetImagePath(FilePath);
  37. ShareSDK.ShowPlatformList(null, shareContent, 100, 100);
  38. Text.text = "¿ªÊ¼·ÖÏí";
  39. }
  40. public void ShareCallback(int reqID, ResponseState state, PlatformType type, Hashtable result)
  41. {
  42. if (state == ResponseState.Success)
  43. {
  44. Text.text = "Success";
  45. }
  46. else if (state == ResponseState.Fail)
  47. {
  48. Text.text = "Fail";
  49. }
  50. else if (state == ResponseState.Cancel)
  51. {
  52. Text.text = "Cancel";
  53. }
  54. }
  55. }