本文档运用Unity2019进行演示
下载unitypackage
从Mob的github地址下载ShareSDK.unitypackage:Git地址,如下图所示
)![image.png]//download.sdk.mob.com/2022/06/22/15/165588252810937.61.png)
下载完成后得到一个.unitypackage结束的文件,如下图:
导入unitypackage
双击导入到unity项目中并勾选,如下图:
Demo.cs是demo的示例页面,可通用
Android (只需求勾选SSDKU3D.jar)
demokey.keystore:demo的打包签名文件
SSDKU3D.jar:java桥接层文件
iOS (全部勾选)
MOBTool:自动打包东西
ShareSDK:SDK必要的文件
按图选好之后,点击import导入
挂载ShareSDK.cs脚本文件
在unity界面左边挑选要运用的场景(例如Main Camera),点击Add Component 按钮增加ShareSDK.cs(ShareSDK中心文件),或许直接拖进去。假如要测试作用,也能够增加Demo.cs(ShareSDK示例UI),如下图所示:
挂接后会发现供给了当前支持的渠道和及其装备信息,需求注意的是当前的编译环境是Android还是iOS,其字段名称是不同的哦!
修正编译环境
Platform设置,在unity中挑选菜单栏-File-Build Settings,会翻开Build Settings操作框,根据自己所编译的环境挑选,假如是iOS的请挑选iOS环境,假如是Android请挑选Android环境,然后点击Switch Platform切换环境,如下图:
Android端集成编译装备
资源修正
1.把demokey.keystore和SSDKU3D.jar文件移动到上层目录下,也就从ShareSDK文件夹移动到Android文件夹;
2.删掉ShareSDK文件夹;
3.删掉Android目录下的baseProjectTemplate.gradle、launcherTemplate.gradle等文件;
终究Android目录下文件内容为下图:
修正Unity设置
生成Gradle文件
坚持Build Settings操作框中左边Platform列表中Android项的选中状态,点击Player Settings,会翻开Project Settings操作框,如下图:
左边切换到Player标签,然后在右侧挑选Publishing Settings卡片,勾选Custom Launcher Gradle Template和Custom Base Gradle Template选项,如下图:
该操作会在”工程\Assets\Plugins\Android目录下“生成baseProjectTemplate.gradle、launcherTemplate.gradle文件。
修正gradle文件
修正baseProjectTemplate.gradle文件
翻开baseProjectTemplate.gradle文件后有两处需求操作:
1.在classpath ‘com.android.tools.build:gradle’后增加mob的classpath
classpath "com.mob.sdk:MobSDK:2018.0319.1724"
2.增加mob自己的maven库房
maven { url "https://mvn.mob.com/android/"}
终究baseProjectTemplate.gradle文件的参阅成果为:
修正launcherTemplate.gradle文件
翻开launcherTemplate.gradle,在文件的最下方参加以下代码:
apply plugin: 'com.mob.sdk'
MobSDK {
appKey "moba0b0c0d0"
appSecret "5713f0d88511f9f4cf100cade0610a34"
spEdition "fp"
ShareSDK {
devInfo {
Wechat {
appId "wx4868b35061f87885"
appSecret "64020361b8ec4c99936c0e3999a9f249"
withShareTicket true
bypassApproval false
enable true
}
}
}
}
这儿的装备和Android原生装备无异,可参阅Mob官方链接
装备签名文件
1.菜单翻开Build Settings,左边Platform列表选中Android,点击Player Settings,在翻开的Project Settings操作框中,左边挑选Player标签,右侧挑选Publishing Settings卡片;
2.勾选Project Keystore下的Custom Key store;
3.点击Project Keystore下的Select挑选一个keystore文件;
4.填写Project Keystore下的Password;
5.如Project Keystore下的Password填写正确,则Project Key下的Alias下拉框亮起,挑选自己的别号;
6.填写Project Key下的Password;
iOS端编译装备
默认一切渠道都现已初始化,客户需求做的操作:
修正初始化我们SDK的AppKey和AppSecret
装备您自己的ShareSDK的AppKey和AppSecret (获取能够点击检查注册流程)
public class ShareSDK : MonoBehaviour
{
private int reqID;
#elif UNITY_IPHONE
public string appKey = "3276d3e413040";
public string appSecret = "4280a3a6df667cfce37528dec03fd9c3";
public string mobNetLater = "2";
public List<string> customAssociatedDomains = new List<string>();
#endif
''' '''
}
修正第三方社交渠道初始化信息装备
能够找到ShareSDKDevInfo.cs文件,进行修正。装备所需的渠道信息
挑选所需求的渠道,不想要的能够直接注释或删掉
public class DevInfoSet
{
public SinaWeiboDevInfo sinaweibo;
public WeChat wechat;
public QQ qq;
public QZone qzone;
}
装备对应渠道的信息(直接修正字符串值即可),例如微信渠道修正
public class WeChat : DevInfo
{
#if UNITY_ANDROID
public string SortId = "5";
public const int type = (int) PlatformType.WeChat;
public string AppId = "wx4868b35061f87885";
public string AppSecret = "64020361b8ec4c99936c0e3999a9f249";
public string UserName = "gh_afb25ac019c9@app";
public string Path = "/page/API/pages/share/share";
public bool BypassApproval = false;
public bool WithShareTicket = true;
public string MiniprogramType = "0";
#elif UNITY_IPHONE
public const int type = (int) PlatformType.WeChat;
public string app_id = "wx617c77c82218ea2c";
public string app_secret = "c7253e5289986cf4c4c74d1ccc185fb1";
public string app_universalLink = "https://70imc.share2dlink.com/";
#endif
}
[Serializable]
public class WeChatMoments : DevInfo
{
#if UNITY_ANDROID
public string SortId = "6";
public const int type = (int) PlatformType.WeChatMoments;
public string AppId = "wx4868b35061f87885";
public string AppSecret = "64020361b8ec4c99936c0e3999a9f249";
public bool BypassApproval = true;
#elif UNITY_IPHONE
public const int type = (int) PlatformType.WeChatMoments;
public string app_id = "wx617c77c82218ea2c";
public string app_secret = "c7253e5289986cf4c4c74d1ccc185fb1";
public string app_universalLink = "https://70imc.share2dlink.com/";
#endif
}
[Serializable]
public class WeChatFavorites : DevInfo
{
#if UNITY_ANDROID
public string SortId = "7";
public const int type = (int) PlatformType.WeChatFavorites;
public string AppId = "wx4868b35061f87885";
public string AppSecret = "64020361b8ec4c99936c0e3999a9f249";
#elif UNITY_IPHONE
public const int type = (int) PlatformType.WeChatFavorites;
public string app_id = "wx617c77c82218ea2c";
public string app_secret = "c7253e5289986cf4c4c74d1ccc185fb1";
public string app_universalLink = "https://70imc.share2dlink.com/";
#endif
}
public class WechatSeries : DevInfo
{
#if UNITY_ANDROID
//for android,please set the configuraion in class "Wechat" ,class "WechatMoments" or class "WechatFavorite"
//关于安卓端,请在类Wechat,WechatMoments或WechatFavorite中装备相关信息↑
#elif UNITY_IPHONE
public const int type = (int) PlatformType.WechatPlatform;
public string app_id = "wx617c77c82218ea2c";
public string app_secret = "c7253e5289986cf4c4c74d1ccc185fb1";
public string app_universalLink = "https://70imc.share2dlink.com/";
#endif
}
确定文件里修正了AppKey等信息之后,要去挂载脚本那儿同步看下AppKey是否修正,能够点击Reset,刷新,同步下修正后的信息,也能够自己直接在挂载脚本里面改,最终要确定脚本文件里和挂载脚本里都现已改为了自己的信息
接口调用
回传用户隐私授权成果(submitPolicyGrantResult)
调用示例
传入的第一个参数为Boolean类型的,true 代表赞同授权、false代表不赞同授权
mobsdk.submitPolicyGrantResult(true);
注意:该接口有必要接入,否则或许造成无法运用MobTech各SDK供给的相关服务。
共享(ShowPlatformList)
首要引入命名空间:
using cn.sharesdk.unity3d;
public ShareSDK ssdk;
结构共享信息
ShareContent content = new ShareContent();
content.SetText("this is a test string.");
content.SetImageUrl("https://f1.webshare.mob.com/code/demo/img/1.jpg");
content.SetTitle("test title");
content.SetTitleUrl("http://www.mob.com");
content.SetSite("Mob-ShareSDK");
content.SetSiteUrl("http://www.mob.com");
content.SetUrl("http://www.mob.com");
content.SetComment("test description");
content.SetMusicUrl("http://mp3.mwap8.com/destdir/Music/2009/20090601/ZuiXuanMinZuFeng20090601119.mp3");
content.SetShareType(ContentType.Webpage);
常用的几个传参数办法阐明(不常用的办法请看Assets/Plugins/ShareSDK/ShareContent.cs脚本):
Text :共享的文字
Title: 共享的标题
TitleUrl :标题的网络链接(QQ和QQ空间运用 )
SetImageUrl :iOS渠道,本地以及网络图片都运用此办法
image:android渠道共享本地图片与网络图片都用此办法
Url: 共享的链接(微信,微博,易信,Facebook等渠道)
ShareType:共享类型(微信,易信)
FilePath:共享文件途径 (微信,易信)
MusicUrl :共享的音乐链接(微信,QQ,易信)
设置共享回调
ssdk.shareHandler = ShareResultHandler;
//以下为回调的界说:
void ShareResultHandler (int reqID, ResponseState state, PlatformType type, Hashtable result)
{
if (state == ResponseState.Success)
{
print ("share result :");
print (MiniJSON.jsonEncode(result));
}
else if (state == ResponseState.Fail)
{
print ("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
}
else if (state == ResponseState.Cancel)
{
print ("cancel !");
}
}
进行共享
//经过共享菜单共享
ssdk.ShowPlatformList (null, content, 100, 100);
//直接经过修改界面共享
ssdk.ShowShareContentEditor (PlatformType.SinaWeibo, content);
//直接共享
ssdk.ShareContent (PlatformType.SinaWeibo, content);
授权(Authorize)
(每次都会跳转到第三方渠道进行授权)
设置授权回调
ssdk.authHandler = AuthResultHandler;
//以下为回调的界说:
void AuthResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
{
if (state == ResponseState.Success)
{
print ("authorize success !");
}
else if (state == ResponseState.Fail)
{
print ("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
}
else if (state == ResponseState.Cancel)
{
print ("cancel !");
}
}
进行授权
ssdk.Authorize(PlatformType.SinaWeibo);
获取用户信息(GetUserInfo)
(只会在第一次跳转到第三方渠道进行授权)
指定获取用户信息的回调
sdk.showUserHandler = GetUserInfoResultHandler;
//以下为回调的界说:
void GetUserInfoResultHandler (int reqID, ResponseState state, PlatformType type, Hashtable result)
{
if (state == ResponseState.Success)
{
print ("get user info result :");
print (MiniJSON.jsonEncode(result));
}
else if (state == ResponseState.Fail)
{
print ("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
}
else if (state == ResponseState.Cancel)
{
print ("cancel !");
}
}
获取用户信息
ssdk.GetUserInfo(PlatformType.SinaWeibo);
注意:auth和getuser接口都能够完成授权登录功用,能够恣意调用一个
打包运用
进行上述一切修正后,现已能够执行打包操作。
如集成过程中遇到问题,可详询MobTech技术支持,点击立即QQ咨询