109 lines
3.7 KiB
C#
109 lines
3.7 KiB
C#
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;
|
|
Transform top;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
}
|
|
public void Initial(QUserInfo user,Transform top)
|
|
{
|
|
if (user == null) return;
|
|
this.top = top;
|
|
UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
|
|
{
|
|
goMain();
|
|
});
|
|
//transform.GetComponent<Button>().onClick.AddListener();
|
|
this.user = user;
|
|
Utils.DisplayImage(StartCoroutine, transform.Find("Avatar").GetComponent<RawImage>(),user.Avatar);
|
|
transform.Find("NickNameText").GetComponent<Text>().text = user.NickName;
|
|
UIManager.AddEvent(transform.Find("BtnDelete").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
DestroySelf();
|
|
});
|
|
//transform.Find("BtnDelete").GetComponent<Button>().onClick.AddListener(DestroySelf);
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
var userInfos = UIManager.Instance.userInfos;
|
|
userInfos.RemoveAt(index);
|
|
UIManager.Instance.userInfos = userInfos;
|
|
UIManager.Instance.userInfoIndex = 0;
|
|
}
|
|
|
|
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);
|
|
}
|
|
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);
|
|
}
|
|
}
|