2021-03-26 16:36:31 +08:00
|
|
|
|
using Assets.Scripts;
|
|
|
|
|
|
using DG.Tweening;
|
2021-03-25 16:55:36 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using UnityEngine;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
2021-03-25 16:55:36 +08:00
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
using UnityEngine.UI;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
//记录:小f 是-457和-681
|
2021-04-01 11:01:05 +08:00
|
|
|
|
public class LoginForm
|
|
|
|
|
|
{
|
|
|
|
|
|
public InputField phone;
|
|
|
|
|
|
public InputField pwd;
|
|
|
|
|
|
}
|
2021-03-25 17:53:48 +08:00
|
|
|
|
public class LoginController : MonoBehaviour
|
2021-03-25 16:55:36 +08:00
|
|
|
|
{
|
2021-04-01 11:01:05 +08:00
|
|
|
|
[SerializeField] InputField[] loginForm;
|
2021-03-25 16:55:36 +08:00
|
|
|
|
[SerializeField] Button login;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
[SerializeField] Button loginNewAccount;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
[SerializeField] Button loginReturn2;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
[SerializeField] Button returnQuick;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
[SerializeField] Button regNext;
|
|
|
|
|
|
[SerializeField] Button regPrev;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
[SerializeField] Button sign;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
[SerializeField] Button remember;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
[SerializeField] GameObject loginScrollView;
|
|
|
|
|
|
[SerializeField] GameObject signScrollView;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
[SerializeField] GameObject avatarScrollView;
|
2021-03-25 16:55:36 +08:00
|
|
|
|
[SerializeField] RawImage loading;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
[SerializeField] Button exit;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
private ScrollRect scrollPanel;
|
|
|
|
|
|
private ScrollRect scrollSign;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
private ScrollRect scrollAvatar;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
private Transform imagexf;
|
2021-03-25 16:55:36 +08:00
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
2021-03-30 14:14:24 +08:00
|
|
|
|
//transform.Find("RawImage").DOMove(new Vector3(0.5f,0.5f,0),1);
|
2021-04-01 11:01:05 +08:00
|
|
|
|
if (loginForm.Length == 2 && loginForm[0]!=null && loginForm[1]!=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var ipt in loginForm)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.AddEvent(ipt.gameObject, EventTriggerType.PointerClick, new UnityAction<BaseEventData>
|
|
|
|
|
|
((BaseEventData arg0) => { OnLoginInputSelect(arg0, ipt.gameObject); }));
|
|
|
|
|
|
UIManager.AddEvent(ipt.gameObject, EventTriggerType.Select, new UnityAction<BaseEventData>
|
|
|
|
|
|
((BaseEventData arg0) => { OnLoginInputSelect(arg0, ipt.gameObject); }));
|
|
|
|
|
|
UIManager.AddEvent(ipt.gameObject, EventTriggerType.Deselect, new UnityAction<BaseEventData>
|
|
|
|
|
|
((BaseEventData arg0) => { OnLoginInputDeSelect(arg0, ipt.gameObject); }));
|
|
|
|
|
|
}
|
|
|
|
|
|
//loginForm[0].
|
|
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
if (login != null)
|
2021-03-25 16:55:36 +08:00
|
|
|
|
{
|
|
|
|
|
|
login.onClick.AddListener(Submit);
|
2021-03-30 14:14:24 +08:00
|
|
|
|
//login.onClick.AddListener(Submit);
|
2021-03-25 16:55:36 +08:00
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
if (loading != null)
|
2021-03-25 16:55:36 +08:00
|
|
|
|
{
|
|
|
|
|
|
loading.texture.wrapMode = TextureWrapMode.Repeat;
|
|
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
if (loginScrollView != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollPanel = loginScrollView.GetComponent<ScrollRect>();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (signScrollView != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollSign = signScrollView.GetComponent<ScrollRect>();
|
|
|
|
|
|
}
|
2021-04-01 11:01:05 +08:00
|
|
|
|
if (avatarScrollView != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollAvatar = avatarScrollView.GetComponent<ScrollRect>();
|
|
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
if (loginNewAccount != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
loginNewAccount.onClick.AddListener(goLogin);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (returnQuick != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
returnQuick.onClick.AddListener(ReturnQuick);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (sign != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
sign.onClick.AddListener(goSign);
|
|
|
|
|
|
}
|
2021-04-01 11:01:05 +08:00
|
|
|
|
if (loginReturn2 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
loginReturn2.onClick.AddListener(goLoginReturn2);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (regNext != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
regNext.onClick.AddListener(goRegNext);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (regPrev != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
regPrev.onClick.AddListener(goRegPrev);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (exit != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
exit.onClick.AddListener(() => Application.Quit());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (remember != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
remember.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var gou = remember.transform.Find("Gou");
|
|
|
|
|
|
if (gou.gameObject.activeSelf)
|
|
|
|
|
|
{
|
|
|
|
|
|
gou.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
gou.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
imagexf = transform.Find("Panel").Find("LoginContainer").Find("Imagexf");
|
|
|
|
|
|
}
|
2021-04-01 11:01:05 +08:00
|
|
|
|
|
|
|
|
|
|
private void OnLoginInputDeSelect(BaseEventData arg0, GameObject game)
|
|
|
|
|
|
{
|
|
|
|
|
|
var image = game.transform.GetComponent<Image>();
|
|
|
|
|
|
image.sprite = Resources.Load<Sprite>("Images/gl-no");
|
|
|
|
|
|
//var rect = game.transform.GetComponent<RectTransform>();
|
|
|
|
|
|
//rect.SetSiblingIndex(rect.childCount-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnLoginInputSelect(BaseEventData arg0,GameObject game)
|
|
|
|
|
|
{
|
|
|
|
|
|
var image = game.transform.GetComponent<Image>();
|
|
|
|
|
|
image.sprite = Resources.Load<Sprite>("Images/gl");
|
|
|
|
|
|
//var rect = game.transform.GetComponent<RectTransform>();
|
|
|
|
|
|
//rect.SetSiblingIndex(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void goRegPrev()
|
|
|
|
|
|
{
|
|
|
|
|
|
StartScrollSign(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void goRegNext()
|
|
|
|
|
|
{
|
|
|
|
|
|
StartScrollSign(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void goLoginReturn2()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.StartScrollPanel(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-30 14:14:24 +08:00
|
|
|
|
void ReturnQuick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (imagexf != null)
|
|
|
|
|
|
{
|
2021-04-01 11:01:05 +08:00
|
|
|
|
imagexf.DOLocalMove(new Vector3(0, -447, 0), 0.3f);
|
2021-03-30 14:14:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.StartScrollPanel(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
void goLogin()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (imagexf != null)
|
|
|
|
|
|
{
|
2021-04-01 11:01:05 +08:00
|
|
|
|
imagexf.DOLocalMove(new Vector3(0, -635, 0), 0.3f);
|
2021-03-30 14:14:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.StartScrollPanel(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
void goSign()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.StartScrollPanel(2);
|
2021-04-01 11:01:05 +08:00
|
|
|
|
this.StartScrollSign(0);
|
2021-03-25 16:55:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
async void Submit()
|
|
|
|
|
|
{
|
2021-04-01 11:01:05 +08:00
|
|
|
|
if (loginForm[0] == null || loginForm[1] == null)
|
2021-03-25 16:55:36 +08:00
|
|
|
|
{
|
|
|
|
|
|
Utils.showToast(gameObject, "未绑定", 1);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//if (string.IsNullOrEmpty(phone.text) || string.IsNullOrEmpty(pwd.text))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Utils.showToast(gameObject, "请输入信息", 1);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//}
|
|
|
|
|
|
//var res = await Global.userApi.Login(phone.text, pwd.text, "");
|
|
|
|
|
|
//测试用
|
2021-03-25 17:53:48 +08:00
|
|
|
|
var res = await ConfigHelper.userApi.Login("15651831367", "123456", "");
|
2021-03-25 16:55:36 +08:00
|
|
|
|
//var res = await NoAuthApi.Login(phone.text, pwd.text);
|
|
|
|
|
|
if (res.result)
|
|
|
|
|
|
{
|
2021-03-25 17:53:48 +08:00
|
|
|
|
ConfigHelper.CurrentUser = res.data;
|
2021-03-29 09:10:59 +08:00
|
|
|
|
SceneManager.LoadScene("MainScene");
|
2021-03-25 16:55:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
2021-04-01 11:01:05 +08:00
|
|
|
|
//Debug.Log($"{phone.isFocused}, ${pwd != null}, ${Input.GetKeyDown(KeyCode.Tab)}");
|
|
|
|
|
|
if (loginForm[0].isFocused && loginForm[1] != null && Input.GetKeyDown(KeyCode.Tab))
|
2021-03-25 16:55:36 +08:00
|
|
|
|
{
|
2021-04-01 11:01:05 +08:00
|
|
|
|
loginForm[1].ActivateInputField();
|
2021-03-25 16:55:36 +08:00
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
goScrollPanel();
|
|
|
|
|
|
goScrollSign();
|
2021-03-25 16:55:36 +08:00
|
|
|
|
//if (Input.GetKeyDown(KeyCode.Return) && )
|
|
|
|
|
|
//{
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (Input.GetKeyDown(KeyCode.Return)) {
|
|
|
|
|
|
// Debug.Log("回车键");
|
|
|
|
|
|
// if (pwd.isFocused)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// this.Submit();
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
|
|
|
|
|
|
#region 主页面滑动逻辑
|
|
|
|
|
|
private int tmpImdex = 0;
|
|
|
|
|
|
private int scrollPanelIndex = 2;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
//private float scrollValue = 0.5f;
|
2021-03-30 14:14:24 +08:00
|
|
|
|
private bool startScrollPanel = false;
|
|
|
|
|
|
private void StartScrollPanel(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (startScrollPanel) return;
|
|
|
|
|
|
scrollPanelIndex = index;
|
|
|
|
|
|
startScrollPanel = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
private void goScrollPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
var index = scrollPanelIndex;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
var scrollValue = 1f/(3 - 1);
|
2021-03-30 14:14:24 +08:00
|
|
|
|
var value = index * scrollValue;
|
|
|
|
|
|
if (scrollPanel != null && startScrollPanel)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scrollPanel.horizontalNormalizedPosition >= value)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollPanel.horizontalNormalizedPosition -= (scrollValue / 20);
|
|
|
|
|
|
if (scrollPanel.horizontalNormalizedPosition <= value)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollPanel.horizontalNormalizedPosition = value;
|
|
|
|
|
|
startScrollPanel = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollPanel.horizontalNormalizedPosition += (scrollValue / 20);
|
|
|
|
|
|
if (scrollPanel.horizontalNormalizedPosition >= value)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollPanel.horizontalNormalizedPosition = value;
|
|
|
|
|
|
startScrollPanel = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
private void Test()
|
|
|
|
|
|
{
|
|
|
|
|
|
//if (startScrollPanel) return;
|
|
|
|
|
|
//scrollPanelIndex = ((int)System.Math.Pow(tmpImdex, 3)
|
|
|
|
|
|
// + 2*(int)System.Math.Pow(tmpImdex, 2)
|
|
|
|
|
|
// + 1) % 4;
|
|
|
|
|
|
//tmpImdex++;
|
|
|
|
|
|
//Debug.Log(scrollPanelIndex);
|
|
|
|
|
|
//startScrollPanel = true;
|
|
|
|
|
|
if (startScrollSign) return;
|
|
|
|
|
|
scrollSignIndex = (scrollSignIndex + 1) % 2;
|
|
|
|
|
|
Debug.Log(scrollSignIndex);
|
|
|
|
|
|
startScrollSign = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
#region 注册页面滑动逻辑
|
|
|
|
|
|
private bool startScrollSign = false;
|
|
|
|
|
|
private int scrollSignIndex = 0;
|
2021-04-01 11:01:05 +08:00
|
|
|
|
private void StartScrollSign(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (startScrollSign) return;
|
|
|
|
|
|
scrollSignIndex = index;
|
|
|
|
|
|
startScrollSign = true;
|
|
|
|
|
|
}
|
2021-03-30 14:14:24 +08:00
|
|
|
|
private void goScrollSign()
|
|
|
|
|
|
{
|
|
|
|
|
|
float value = scrollSignIndex;
|
|
|
|
|
|
if (scrollSign != null && startScrollSign)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scrollSignIndex == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollSign.horizontalNormalizedPosition -= (1f / 20);
|
|
|
|
|
|
if (scrollSign.horizontalNormalizedPosition <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollSign.horizontalNormalizedPosition = 0;
|
|
|
|
|
|
startScrollSign = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (scrollSignIndex == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollSign.horizontalNormalizedPosition += (1f / 20);
|
|
|
|
|
|
if (scrollSign.horizontalNormalizedPosition >= 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollSign.horizontalNormalizedPosition = 1;
|
|
|
|
|
|
startScrollSign = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
2021-03-25 16:55:36 +08:00
|
|
|
|
}
|