138 lines
4.7 KiB
C#
138 lines
4.7 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-12-23
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "ShareProxy" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 分享功能
|
|
/// </summary>
|
|
public class ShareProxy : F.GameProxy
|
|
{
|
|
#region Field
|
|
|
|
private readonly string[] _shareFailMessages = new string[]
|
|
{
|
|
"请分享至大于20人的群",
|
|
"注意!请分享到不同的群",
|
|
"分享失败,请您换个群重试",
|
|
"分享失败,请分享到群里",
|
|
"该群已分享过,请换个群",
|
|
};
|
|
|
|
private readonly string[] _shareTitles = new string[]
|
|
{
|
|
"快来救救妹妹吧",
|
|
"水墨江湖等你来战",
|
|
"快来测测你的本命神兵",
|
|
"快来测测你的本命神兽",
|
|
"江湖红颜等你来",
|
|
"海量武学随意搭配",
|
|
};
|
|
|
|
private readonly string[] _shareImageURL = new string[]
|
|
{
|
|
"https://mmocgame.qpic.cn/wechatgame/W6q4BrAlgf4fdlibc8qb0wMFYzfhVK95Hd1RwPNa04tQyx2oZEpkJ7a2LTvVrcegS/0",
|
|
"https://mmocgame.qpic.cn/wechatgame/W6q4BrAlgf6L6vxvUGq7J0OdqW4BLIyQhm31TIkwOx9o9d01Y4KmSTnMlauwJT8a/0",
|
|
"https://mmocgame.qpic.cn/wechatgame/W6q4BrAlgf7IuTpchA5IVr1iaia3IVxGFtcgSVL419A5BevxWicVEJCDD8aYrzTZq6v/0",
|
|
"https://mmocgame.qpic.cn/wechatgame/W6q4BrAlgf4ZcL2unDncB7yILl9IUSjzD7CP3JnI4HePicY2wjutSnWmp2gjx5puG/0",
|
|
"https://mmocgame.qpic.cn/wechatgame/W6q4BrAlgf69ypnt4tf0r85nuCVKwRyxO97BKPS9FqvHmx0mNshUrEu1Kb9E71IS/0",
|
|
"https://mmocgame.qpic.cn/wechatgame/W6q4BrAlgf6icybYqF1S9WfEtGAlMhLYxTeOMibAEnWC1zY9RmSgWVLvzx92TdFSCh/0"
|
|
};
|
|
|
|
private readonly string[] _shareImageId = new string[]
|
|
{
|
|
"7Hl4Poy4SEunDhykipwX0Q==",
|
|
"rkCGA+yKQLWMdiTx+o/owQ==",
|
|
"T+heu3aPS8CkanuzrCt2aQ==",
|
|
"mnZu+FL9RSye7JZfRlr5vw==",
|
|
"+Q0d47OXRK61zVk0WqZSdw==",
|
|
"b9rMaibMSc2/Mid2dlEc6Q=="
|
|
};
|
|
|
|
int _shareCount;
|
|
int _shareFailCount;
|
|
System.DateTime _lastShareTime;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="userData"></param>
|
|
public void ShareAppWithInvite(string userData)
|
|
{
|
|
int contentIndex = Random.Range(0, _shareTitles.Length);
|
|
var shareInfo = new KPlatform.ShareInfo
|
|
{
|
|
title = _shareTitles[contentIndex],
|
|
imgUrl = _shareImageURL[contentIndex],
|
|
imgUrlId = _shareImageId[contentIndex],
|
|
data = userData,
|
|
};
|
|
KPlatform.Instance.Share(shareInfo, (error, message) => { });
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="userData"></param>
|
|
/// <param name="callback"></param>
|
|
public void ShareAppWithFreeAd(string userData, Callback2 callback)
|
|
{
|
|
int contentIndex = Random.Range(0, _shareTitles.Length);
|
|
var shareInfo = new KPlatform.ShareInfo
|
|
{
|
|
title = _shareTitles[contentIndex],
|
|
imgUrl = _shareImageURL[contentIndex],
|
|
imgUrlId = _shareImageId[contentIndex],
|
|
data = userData,
|
|
};
|
|
|
|
var shareTime = System.DateTime.UtcNow;
|
|
KPlatform.Instance.Share(shareInfo, (error, message) =>
|
|
{
|
|
_shareCount++;
|
|
if (((System.DateTime.UtcNow - _lastShareTime).TotalSeconds < 120 && _shareFailCount >= 2) || (error == 0 && _shareCount % 2 == 0 && (System.DateTime.UtcNow - shareTime).TotalSeconds > 2.5))
|
|
{
|
|
_shareFailCount = 0;
|
|
MissionProxy.Instance.OnEvent(MissionProxy.累积分享次数);
|
|
callback(0, message);
|
|
}
|
|
else
|
|
{
|
|
_shareFailCount++;
|
|
callback(1, _shareFailMessages[Random.Range(0, _shareFailMessages.Length)]);
|
|
}
|
|
_lastShareTime = System.DateTime.UtcNow;
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 轮盘分享
|
|
|
|
#endregion
|
|
|
|
#region Unity && Proxy
|
|
|
|
public static ShareProxy Instance => GetInstance<ShareProxy>();
|
|
|
|
#endregion
|
|
}
|
|
}
|