chicken_dy/Assets/HCMiniSdk/Scripts/WebGL/HCSDKManager.cs

171 lines
6.6 KiB
C#
Raw Normal View History

2024-03-07 12:12:48 +00:00
using System;
using System.Collections.Generic;
using HC;
using JetBrains.Annotations;
public partial class HCSDKManager
{
protected override void OnInstanceCreate()
{
base.OnInstanceCreate();
#if UNITY_WEBGL || WEBGL_BYTEDANCE
var hcWebGLSdkManager = HCWebGLSDKManager.Instance;
#endif
}
public void Share(string title, [CanBeNull] string imgUrl = null, [CanBeNull] string content = null, [CanBeNull] Action<bool> callback = null, int type = 0)
{
#if UNITY_WEBGL || WEBGL_BYTEDANCE
HCWebGLSDKManager.Share.Share(title, imgUrl, content, callback);
#else
// TODO 暂时不支持
callback?.Invoke(false);
#endif
}
public void ExitApp()
{
HCWebGLSDKManager.Base.ExitApp();
}
/// <summary>
/// 购买
/// </summary>
/// <param name="paymentArgs"></param>
public void Buy(HCPaymentArgs paymentArgs)
{
HCAnalyticsManager.Instance.IAPBtnClick(paymentArgs.productName, paymentArgs.gameExtraParam, "CNY", paymentArgs.money, paymentArgs.gameExtraParam);
#if UNITY_WEBGL || WEBGL_BYTEDANCE
HCWebGLSDKManager.Purchase.Buy(paymentArgs);
#endif
}
/// <summary>
/// 奖励下发成功
/// </summary>
/// <param name="orderID"></param>
public void Awarded(string orderID)
{
#if UNITY_WEBGL || WEBGL_BYTEDANCE
HCWebGLSDKManager.Purchase.Awarded(orderID);
#endif
}
#if WEBGL_BYTEDANCE
public void DyShare(Action<bool> callback, StarkSDKSpace.UNBridgeLib.LitJson.JsonData jsonData)
{
var json = jsonData.ToJson();
HCDebugger.LogDebug("分享:" + json);
HCWebGLSDKManager.Share.DYShare(callback, jsonData);
}
public void DyShareRecordVideo(string title, string[] videoTopicList, Action<bool, string, Dictionary<string, object>> callback)
{
HCDebugger.LogDebug($"[DyShareRecordVideo] title = {title} videoTopicList = {videoTopicList}");
var topics = new List<string>();
if (videoTopicList != null)
{
topics.AddRange(videoTopicList);
}
StarkSDKSpace.StarkSDK.API.GetStarkGameRecorder().ShareVideoWithTitleTopics(result =>
{
HCDebugger.LogDebug($"[DyShareRecordVideo] [successCallback]");
callback?.Invoke(true, "success", result);
}, msg =>
{
HCDebugger.LogDebug($"[DyShareRecordVideo] [failedCallback] msg = {msg}");
callback?.Invoke(false, msg, new Dictionary<string, object>());
}, () =>
{
HCDebugger.LogDebug($"[DyShareRecordVideo] [cancelledCallback]");
callback?.Invoke(false, "cancelled", new Dictionary<string, object>());
}, title,
topics);
}
public void DyShareVideo(string videoPath, string title, string[] videoTopicList, string[] hashtagList, Action<bool> callback)
{
var videoTopics = new StarkSDKSpace.UNBridgeLib.LitJson.JsonData();
videoTopics.SetJsonType(StarkSDKSpace.UNBridgeLib.LitJson.JsonType.Array);
if (videoTopicList != null)
{
foreach (var s in videoTopicList)
{
videoTopics.Add(s);
}
}
var hashtags = new StarkSDKSpace.UNBridgeLib.LitJson.JsonData();
hashtags.SetJsonType(StarkSDKSpace.UNBridgeLib.LitJson.JsonType.Array);
if (hashtagList != null)
{
foreach (var s in hashtagList)
{
hashtags.Add(s);
}
}
var jsonData = new StarkSDKSpace.UNBridgeLib.LitJson.JsonData
{
["channel"] = "video",
["title"] = title,
["extra"] = new()
{
["videoPath"] = videoPath,
["videoTopics"] = videoTopics,
["hashtag_list"] = hashtags,
},
};
DyShare(callback, jsonData);
}
/// <summary>
/// 开始录屏
/// <param name="isRecordAudio">是否录制声音,默认为录制声音</param>
/// <param name="maxRecordTimeSec">最大录制时长,单位 s。小于等于 0 则无限制。默认为10分钟</param>
/// <param name="startCallback">视频录制开始回调</param>
/// <param name="errorCallback">视频录制失败回调</param>
/// </summary>
/// <returns>函数调用状态调用成功返回true否则返回false</returns>
public bool StartRecord(bool isRecordAudio, int maxRecordTimeSec = 600, Action startCallback = null, Action<int, string> errorCallback = null, Action<string> timeoutCallback = null)
{
return ((HCBytedanceBase)HCWebGLSDKManager.Base).StartRecord(isRecordAudio, maxRecordTimeSec, startCallback, errorCallback, timeoutCallback);
}
/// <summary>
/// 停止录屏
/// <param name="completeCallback">视频录制完成回调</param>
/// <param name="errorCallback">视频录制失败回调</param>
/// <param name="clipRanges">停止后需要对视频进行裁剪的时间片段如果为null或空列表则不对视频进行裁剪</param>
/// <param name="autoMerge">是否对视频裁剪片段进行自动合并。
/// 合并规则:
/// 如果有两段重叠的时间片段并且重叠部分小于等于1秒则对这两段进行合并为一段
/// 若autoMerge为true比如时间片段为{[1000, 5000], [4000, 7000]},会被合并为{[1000, 7000]}。
/// 若autoMerge为false将按原始传入的时间片段进行裁剪是否有重叠由调用方保证。主要用于自定义裁剪。 </param>
/// </summary>
/// <returns>函数调用状态调用成功返回true否则返回false</returns>
public bool StopRecord(Action<string> completeCallback = null, Action<int, string> errorCallback = null, List<TimeRange> clipRanges = null, bool autoMerge = true)
{
return ((HCBytedanceBase)HCWebGLSDKManager.Base).StopRecord(completeCallback, errorCallback, clipRanges, autoMerge);
}
public void CheckScene(string scene, Action<bool> success, Action complete, Action<int, string> error)
{
((HCBytedanceBase)HCWebGLSDKManager.Base).CheckScene(scene, success, complete, error);
}
public void NavigateToScene(string scene, Action success, Action complete, Action<int, string> error)
{
((HCBytedanceBase)HCWebGLSDKManager.Base).NavigateToScene(scene, success, complete, error);
}
public void OnShowWithDict(Action<Dictionary<string, object>> paramCallback)
{
((HCBytedanceBase)HCWebGLSDKManager.Base).OnShowWithDict(paramCallback);
}
#endif
}