108 lines
3.7 KiB
C#
Raw Normal View History

2021-04-06 15:30:36 +08:00
using Assets.Scripts;
using Assets.Scripts.Apis;
using Assets.Scripts.Apis.Models;
using DG.Tweening;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class QuickLoginUser : MonoBehaviour
{
QUserInfo user;
2021-04-16 17:49:11 +08:00
Transform top;
2021-04-06 15:30:36 +08:00
// Start is called before the first frame update
void Start()
{
}
2021-04-16 17:49:11 +08:00
public void Initial(QUserInfo user,Transform top)
2021-04-06 15:30:36 +08:00
{
if (user == null) return;
2021-04-16 17:49:11 +08:00
this.top = top;
2021-04-19 15:44:11 +08:00
UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
2021-04-06 15:30:36 +08:00
{
2021-04-19 15:44:11 +08:00
goMain();
2021-04-06 15:30:36 +08:00
});
2021-04-19 15:44:11 +08:00
//transform.GetComponent<Button>().onClick.AddListener();
2021-04-06 15:30:36 +08:00
this.user = user;
Utils.DisplayImage(StartCoroutine, transform.Find("Avatar").GetComponent<RawImage>(),user.Avatar);
transform.Find("NickNameText").GetComponent<Text>().text = user.NickName;
2021-04-19 15:44:11 +08:00
UIManager.AddEvent(transform.Find("BtnDelete").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
{
DestroySelf();
});
//transform.Find("BtnDelete").GetComponent<Button>().onClick.AddListener(DestroySelf);
2021-04-06 15:30:36 +08:00
}
// Update is called once per frame
void Update()
{
2021-04-19 15:44:11 +08:00
}
async void goMain()
{
ApiBase.SetCookie(user.Cookie);
var r = await ConfigHelper.userApi.QuickLogin();
if (r.result)
{
top.GetComponent<LoginController>().SaveInfo(r.data);
App.CurrentUser = r.data;
SceneManager.LoadScene("MainScene");
}
else
{
Utils.showToast(gameObject, r.errMsg);
}
2021-04-06 15:30:36 +08:00
}
private void OnDestroy()
{
}
void DestroySelf()
{
var content = transform.parent;
var index = transform.GetSiblingIndex() - 1;
DestroyImmediate(gameObject);
//if (content.childCount == 2)
//{
// var info = Instantiate(Resources.Load<GameObject>("UI/Prefab/Login/QuickUserInfo")).transform;
// info.GetComponent<QuickLoginUser>().Initial(null);
// info.parent = content;
// info.localScale = new Vector3(1, 1, 1);
// content.Find("empty1").transform.SetSiblingIndex(0);
// content.Find("empty2").transform.SetSiblingIndex(content.childCount - 1);
//}
content.parent.parent.GetComponent<QuickLoginScroll>().Initial();
DeleteList(index);
}
private void DeleteList(int index)
{
2021-04-16 17:49:11 +08:00
var userInfos = UIManager.Instance.userInfos;
2021-04-06 15:30:36 +08:00
userInfos.RemoveAt(index);
2021-04-16 17:49:11 +08:00
UIManager.Instance.userInfos = userInfos;
2021-04-06 15:30:36 +08:00
}
public void setActive()
{
//ColorUtility.TryParseHtmlString("#ffffffff", out Color color);
//transform.Find("Avatar").GetComponent<RawImage>().color = color;
transform.Find("Avatar").GetComponent<RawImage>().DOFade(1f, 0.3f);
transform.GetComponent<Button>().enabled = true;
transform.Find("NickNameText").GetComponent<Text>().enabled = true;
transform.Find("BtnDelete").GetComponent<Button>().gameObject.SetActive(true);
2021-04-06 15:30:36 +08:00
}
public void setNoActive()
{
//ColorUtility.TryParseHtmlString("#ffffff80", out Color color);
//transform.Find("Avatar").GetComponent<RawImage>().color = color;
transform.Find("Avatar").GetComponent<RawImage>().DOFade(0.5f, 0.3f);
transform.GetComponent<Button>().enabled = false;
transform.Find("NickNameText").GetComponent<Text>().enabled = false;
transform.Find("BtnDelete").GetComponent<Button>().gameObject.SetActive(false);
2021-04-06 15:30:36 +08:00
}
}