using System; using System.Collections.Generic; using TapTap.Login.Internal.Http; using UnityEngine; using UnityEngine.UI; namespace TapTap.Login.Internal { public class WebWithPermissionsController : WebController { private readonly RectTransform contentTransform; private readonly Text titleText; private readonly Transform authTransform; private readonly List toggles; private TapLoginPermission[] allPermissions; public WebWithPermissionsController(Transform transform, Action onAuth) : base(transform, onAuth) { contentTransform = transform.Find("Permission/Content").GetComponent(); titleText = transform.Find("Permission/Content/Title").GetComponent(); authTransform = transform.Find("Permission/Content/Permissions/Viewport/Content"); toggles = new List(); } public void Load(string clientId, string name, TapLoginPermission[] permissions) { this.allPermissions = permissions; LoadBasicInfo(clientId); titleText.text = $"登录授权后 {name} 将获得您 TapTap 账号以下信息:"; if (permissions != null) { foreach (TapLoginPermission permission in permissions) { GameObject authItem = GameObject.Instantiate(Resources.Load("Prefabs/TapLogin/PermissionItem")) as GameObject; Text text = authItem.transform.Find("Label").GetComponent(); text.text = permission.Description; authItem.transform.SetParent(authTransform); Toggle toggle = authItem.GetComponent(); toggles.Add(toggle); } } LayoutRebuilder.ForceRebuildLayoutImmediate(contentTransform); } protected override void OnJumpClicked() { // 生成 permissions List ps = new List(); for (int i = 0; i < toggles.Count; i++) { if (toggles[i].isOn) { ps.Add(allPermissions[i].Permission); } } base.permissions = ps.ToArray(); base.OnJumpClicked(); } } }