Unity_Web/Assets/1_Script/ScreenMove.cs

132 lines
3.8 KiB
C#

using BestHTTP;
using UnityEngine;
public class ScreenMove : MonoBehaviour
{
[SerializeField] RectTransform rectTransform;
[SerializeField] RectTransform test_rectTransform;
[SerializeField] GameObject searchView;
[SerializeField] GameObject fursuitAdd;
[SerializeField] GameObject[] closeUI;
readonly Vector2 stretch = new Vector2(0f, 0.5f);
readonly Vector2 middle = new Vector2(1f, 0.5f);
readonly Vector2 center = new Vector2(0.5f, 0.5f);
readonly Vector2 pos = new Vector2(-58.5f, 20f);
readonly Vector2 moveSize = new Vector2(-343f, 100f);
readonly Vector2 idleSize = new Vector2(553f, 100f);
bool isMobile;
void Awake()
{
isMobile = Application.isMobilePlatform;
SearchView();
}
private void Start()
{
//모바일은 한번만 업데이트
if (isMobile)
{
rectTransform.sizeDelta = new Vector2(Screen.width, Screen.height);
if (Screen.width < 1280)
{
test_rectTransform.anchorMin = center;
test_rectTransform.anchorMax = center;
test_rectTransform.anchoredPosition = pos;
test_rectTransform.sizeDelta = idleSize;
}
else
{
test_rectTransform.anchorMin = stretch;
test_rectTransform.anchorMax = middle;
test_rectTransform.anchoredPosition = pos;
test_rectTransform.sizeDelta = moveSize;
}
}
}
private void Update()
{
//pc는 실시간 업데이트
if (!isMobile)
{
rectTransform.sizeDelta = new Vector2(Screen.width, Screen.height);
if (Screen.width < 1280)
{
test_rectTransform.anchorMin = center;
test_rectTransform.anchorMax = center;
test_rectTransform.anchoredPosition = pos;
test_rectTransform.sizeDelta = idleSize;
}
else
{
test_rectTransform.anchorMin = stretch;
test_rectTransform.anchorMax = middle;
test_rectTransform.anchoredPosition = pos;
test_rectTransform.sizeDelta = moveSize;
}
}
}
public void SearchView()
{
searchView.SetActive(true);
fursuitAdd.SetActive(false);
for(int n = 0; n < closeUI.Length; n++)
{
closeUI[n].SetActive(false);
}
}
public void FursuitAdd()
{
#if UNITY_EDITOR
GameManager.Instance.xid = "Fursuit_Library";
GameManager.Instance.xname = "퍼슈트도서관";
#endif
if (GameManager.Instance.xid == string.Empty)
{
HTTPRequest http = NetworkManager.Instance.CreateRequest<Session>("common/session/user", new object(), (data) =>
{
if(data.status == "L0002")
{
Application.OpenURL($"{NetworkManager.Instance.baseUrl}/oauth2/authorization/twitter");
}
else
{
GameManager.Instance.xid = data.userId;
GameManager.Instance.xname = data.userName;
searchView.SetActive(false);
fursuitAdd.SetActive(true);
for (int n = 0; n < closeUI.Length; n++)
{
closeUI[n].SetActive(false);
}
}
}, null, HTTPMethods.Get);
http.Send();
return;
}
searchView.SetActive(false);
fursuitAdd.SetActive(true);
for (int n = 0; n < closeUI.Length; n++)
{
closeUI[n].SetActive(false);
}
}
class Session
{
public string status;
public string userId;
public string userName;
}
}