CutePet/Assets/Scripts/GameScene/Panel/IdeaPanel.cs
2024-10-25 11:10:04 +08:00

62 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class IdeaPanel : BasePanel
{
//关闭
public Button btnClose;
//提交
public Button btnSubmit;
//意见输入框
public InputField inputIdea;
//ToggleGroup 组件
public ToggleGroup toggleGroup;
public override void Init()
{
btnClose.onClick.AddListener(() =>
{
UIManager.Instance.HidePanel<IdeaPanel>();
});
btnSubmit.onClick.AddListener(() =>
{
if (inputIdea!=null)
{
SendIdea();
}
inputIdea.text = null;
});
}
private void SendIdea()
{
IdeaMsg idea = new IdeaMsg();
idea.openId = GameDataMgr.Instance.player.openId;
idea.username = GameDataMgr.Instance.player.username;
idea.ideaContent = inputIdea.text;
GetText(idea);
if (idea.ideaContent!=""&&idea.ideaType!=null)
{
StartCoroutine(NetMgr.Instance.IdeaPost(idea));
}
}
public void GetText(IdeaMsg idea)
{
// 遍历 ToggleGroup 里的所有 Toggle
foreach (Toggle toggle in toggleGroup.GetComponentsInChildren<Toggle>())
{
if (toggle.isOn)
{
idea.ideaType = toggle.GetComponentInChildren<Text>().text;
return; // 只需要找到第一个选中的 Toggle 即可
}
}
}
}