160 lines
5.6 KiB
C#
160 lines
5.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
using Script;
|
|
using Stary.Evo;
|
|
using Stary.Evo.UIFarme;
|
|
using UnityEngine;
|
|
using UnityEngine.U2D;
|
|
using UnityEngine.UI;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace Unity.RenderStreaming
|
|
{
|
|
public class StartPanel : BasePanel
|
|
{
|
|
/// <summary>
|
|
/// 返回按钮
|
|
/// </summary>
|
|
private Button _arrowLeft;
|
|
|
|
private Text _meetingId;
|
|
|
|
/// <summary>
|
|
/// 房间号输入框
|
|
/// </summary>
|
|
private InputField _meetingNameInput;
|
|
|
|
private Image _profileImage;
|
|
|
|
/// <summary>
|
|
/// 头像按钮
|
|
/// </summary>
|
|
private Button _profilePhoto;
|
|
|
|
private int _profileSpriteIndex;
|
|
private Sprite[] _profileSprites;
|
|
|
|
/// <summary>
|
|
/// 随机房间号按钮
|
|
/// </summary>
|
|
private Button _randomMeetingId;
|
|
|
|
/// <summary>
|
|
/// 头像Sprite Atlas
|
|
/// </summary>
|
|
private SpriteAtlas _spriteAtlas;
|
|
|
|
/// <summary>
|
|
/// 开始按钮
|
|
/// </summary>
|
|
private Button _startButton;
|
|
|
|
/// <summary>
|
|
/// 时间下拉选择框
|
|
/// </summary>
|
|
private Dropdown _timeDropdown;
|
|
|
|
|
|
public override UITweenType TweenType => UITweenType.Fade;
|
|
|
|
public override string UIPath => "XREALVirtualController(Clone)/Canvas";
|
|
|
|
public override void Initialize(GameObject panelGo)
|
|
{
|
|
base.Initialize(panelGo);
|
|
_arrowLeft = panelGo.transform.Find("Herder/arrow-left").GetComponent<Button>();
|
|
_profilePhoto = panelGo.transform.Find("HeadPortraits/MeetingInfoCard").GetComponent<Button>();
|
|
_profileImage = _profilePhoto.transform.Find("mask/sprite").GetComponent<Image>();
|
|
_meetingNameInput = panelGo.transform.Find("card/search/InputField").GetComponent<InputField>();
|
|
_meetingId = panelGo.transform.Find("card/huiyiID/connectionId").GetComponent<Text>();
|
|
_randomMeetingId = panelGo.transform.Find("card/huiyiID/Button").GetComponent<Button>();
|
|
_timeDropdown = panelGo.transform.Find("card/time/Dropdown").GetComponent<Dropdown>();
|
|
_startButton = panelGo.transform.Find("invite").GetComponent<Button>();
|
|
_spriteAtlas = Resources.Load<SpriteAtlas>("SpriteAtlas");
|
|
if (_spriteAtlas != null)
|
|
{
|
|
_profileSprites = new Sprite[_spriteAtlas.spriteCount];
|
|
_spriteAtlas.GetSprites(_profileSprites);
|
|
}
|
|
|
|
_profileSpriteIndex = 0;
|
|
OnClickProfilePhoto();
|
|
}
|
|
|
|
public override void OnEnter(Action complete = null)
|
|
{
|
|
base.OnEnter(complete);
|
|
_arrowLeft.onClick.AddListener(OnClickArrowLeft);
|
|
_profilePhoto.onClick.AddListener(OnClickProfilePhoto);
|
|
_randomMeetingId.onClick.AddListener(OnClickRandomMeetingId);
|
|
|
|
_startButton.onClick.AddListener(OnClickStartButton);
|
|
}
|
|
|
|
|
|
public override void OnExit(float delay = 0)
|
|
{
|
|
base.OnExit(delay);
|
|
_arrowLeft.onClick.RemoveListener(OnClickArrowLeft);
|
|
_profilePhoto.onClick.RemoveListener(OnClickProfilePhoto);
|
|
_randomMeetingId.onClick.RemoveListener(OnClickRandomMeetingId);
|
|
_startButton.onClick.RemoveListener(OnClickStartButton);
|
|
}
|
|
|
|
private void OnClickProfilePhoto()
|
|
{
|
|
if (_profileSprites == null || _profileSprites.Length == 0) return;
|
|
_profileImage.sprite = _profileSprites[_profileSpriteIndex];
|
|
var avatar = _profileSprites[_profileSpriteIndex].name.Replace("(Clone)", "");
|
|
this.GetSystem<IGlobalConfigSystem>().SetConnectionTexture(avatar);
|
|
_profileSpriteIndex = (_profileSpriteIndex + 1) % _profileSprites.Length;
|
|
}
|
|
|
|
private void OnClickArrowLeft()
|
|
{
|
|
}
|
|
|
|
private void OnClickRandomMeetingId()
|
|
{
|
|
var meetingId = $"{Random.Range(100, 999)}-{Random.Range(100, 999)}-{Random.Range(100, 999)}";
|
|
_meetingId.text = meetingId;
|
|
if (string.IsNullOrEmpty(_meetingNameInput.text)) _meetingNameInput.text = $"{meetingId}的房间";
|
|
}
|
|
|
|
private string OnClickRandomUserId()
|
|
{
|
|
return $"user_{Random.Range(100, 999)}";
|
|
}
|
|
|
|
private void OnClickStartButton()
|
|
{
|
|
this.GetSystem<IGlobalConfigSystem>().SetUserId(OnClickRandomUserId());
|
|
this.GetSystem<IGlobalConfigSystem>().SetConnectionTimeType(_timeDropdown.value);
|
|
this.GetSystem<IGlobalConfigSystem>().SetConnectionId(_meetingId.text);
|
|
|
|
this.GetSystem<IGlobalConfigSystem>().SetConnectionName(_meetingNameInput.text);
|
|
if (!SignalingMessageHelper.IsReady())
|
|
{
|
|
Debug.LogError("Signaling 未就绪");
|
|
return;
|
|
}
|
|
|
|
var avatar = _profileImage.sprite.name.Replace("(Clone)", "");
|
|
var userInfo = new
|
|
{
|
|
type = "host-userInfo",
|
|
data = new
|
|
{
|
|
id = this.GetSystem<IGlobalConfigSystem>().GetUserId(),
|
|
name = _meetingNameInput.text,
|
|
avatar = $"{this.GetSystem<IGlobalConfigSystem>().IP}/images/head/{avatar}.png"
|
|
}
|
|
};
|
|
SignalingMessageHelper.SendMessage(JsonConvert.SerializeObject(userInfo));
|
|
this.GetSystem<IRenderStreamingSystem>().SetUp();
|
|
PanelSystem.PopQueue<StartPanel>();
|
|
PanelSystem.PushQueue<MainPanel>();
|
|
}
|
|
}
|
|
} |