抖音开放平台Logo
开发者文档
控制台

移动端开播适配

收藏
我的收藏
接入云同步能力的玩法,在完成接入适配后方可于移动端挂载并运行单机模式。
💡提示:
    术语定义:本文中所提及的“移动端”,特指通过抖音手机端进行开播的操作方式。与之相对的,在 PC 端使用直播伴侣进行开播,则不属于移动端范畴。
    请注意:在接入云同步能力后,当前移动端仅支持玩法内的单人模式,暂不支持多人联机模式。(另参考下文#移动端环境判断)

触摸 touches 事件

需要开发者接入触摸 touches 事件(移动端)。

ICloudSync.OnTouches (事件)

事件:触摸操作(移动端)。
定义:
// 事件:触摸操作(移动端) public event TouchesEventHandler OnTouches; public delegate void TouchesEventHandler(ICloudSeat seat, RemoteTouchesEvent touchesEvent);
事件参数:
参数
类型
说明
seat
ICloudSeat
发生该操作的用户席位
touchesEvent
RemoteTouchesEvent
远端触摸事件,包含touches触摸数据
RemoteTouchesEvent 触摸数据说明:
/// 触摸事件 public struct RemoteTouchesEvent : IRemoteInputEvent { public IVirtualDevice device { get; set; } public string InputType => "Touch"; public byte displayIndex; /// 触摸touches数据列表 public List<RemoteTouch> touches; } /// 触摸Touch(单个手指的数据) public struct RemoteTouch { /// 触摸手指id public int touchId; /// 触摸阶段类型。 枚举值按`UnityEngine.InputSystem.TouchPhase`对齐,推荐使用。 public RemoteTouchPhase phase; /// 触摸动作类型。 枚举值按云游戏的定义。 public TouchAction action; /// `viewPosition` 左上角坐标 ( 0, 1 ) , 原点在左下角,值范围 0~1.0 public Vector2 viewPosition; /// `position` 左上角坐标 ( 0, Screen.Height ) , 原点在左下角,值范围 0~Screen宽高 public Vector2Int position; }
【示例代码】:
// 监听事件:触摸操作(移动端) ICloudSync.Instance.OnTouches += OnTouches; // 收到事件:触摸操作(移动端) private void OnTouches(ICloudSeat seat, RemoteTouchesEvent evt) { foreach (var t in evt.touches) { if (isTouchVerboseLog) Debug.Log($"OnTouch 触摸: 用户 {seat.Index}, touchId: {t.touchId} {t.phase}, viewPos: {t.viewPosition:F3}, pos: {t.position:F0}, #{Time.frameCount}f"); var viewPos = t.viewPosition; if (t.phase == RemoteTouchPhase.Ended) { ProcessClicked(seat, viewPos, evt.InputType); } } }
备注:
在移动端开播时,不会触发鼠标事件 ICloudSync.OnMouse

移动端环境判断

使用特定功能时,开发者可以判断是否移动端环境,使得特定功能在移动端、PC 端,能区别实现。

ICloudSyncEnv.IsMobile()

是否移动端。
定义:
// 是否移动端 public bool IsMobile();
【示例代码】:
此示例为某按钮点击响应时,实现判断如果是移动端,则弹出提示。
private void OnClickMatch() { if (ICloudSync.Env.IsMobile()) { ShowHostNote("移动端暂不支持同玩"); return; } StartMatch(); }
备注:
    若是 true,是使用抖音手机端开播玩法。 若 false,则PC端使用直播伴侣开播玩法。
    注意:目前在移动端,只能单人模式、单播。移动端暂未支持云同步的多人同玩能力。