212 lines
6.1 KiB
C#
212 lines
6.1 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SearchCtrl : SingletonMonoBehaviour<SearchCtrl>
|
|
{
|
|
[SerializeField] GameObject opsion;
|
|
|
|
[SerializeField] TMP_InputField name;
|
|
[SerializeField] TMP_Dropdown suitStyle;
|
|
[SerializeField] TMP_Dropdown suitType;
|
|
[SerializeField] TMP_Dropdown region;
|
|
[SerializeField] TMP_Dropdown animalTypes;
|
|
[SerializeField] Toggle[] colors;
|
|
[SerializeField] Sprite[] isOnSprite;
|
|
|
|
[SerializeField] GameObject item;
|
|
[SerializeField] Transform results;
|
|
[SerializeField] RectTransform content;
|
|
|
|
[SerializeField] Animator searchUI;
|
|
|
|
[SerializeField] ModalCtrl model;
|
|
|
|
private SearchRequest request;
|
|
private List<Library> librarys;
|
|
|
|
private bool hasMore;
|
|
|
|
private List<GameObject> itemPrefabs;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
itemPrefabs = new List<GameObject>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
hasMore = false;
|
|
model.gameObject.SetActive(false);
|
|
searchUI.SetTrigger("reset");
|
|
ResetButton();
|
|
ObjectClear();
|
|
}
|
|
|
|
private void ObjectClear()
|
|
{
|
|
//TODO 재활용 할 수 있게 만들기
|
|
if (itemPrefabs.Count != 0)
|
|
{
|
|
for (int n = 0; n < itemPrefabs.Count; n++)
|
|
{
|
|
Destroy(itemPrefabs[n]);
|
|
}
|
|
itemPrefabs.Clear();
|
|
}
|
|
}
|
|
|
|
|
|
public void OpsionButton()
|
|
{
|
|
//옵션창이 나오지 않았을때 250,100
|
|
//옵션창이 나왔을때 60 ,290
|
|
bool isSelf = !opsion.activeSelf;
|
|
searchUI.SetBool("isSelf", isSelf);
|
|
ResetButton();
|
|
}
|
|
|
|
public void SearchButton()
|
|
{
|
|
ObjectClear();
|
|
request = new SearchRequest();
|
|
request.fursuitName = name.text;
|
|
if (suitStyle.value != 0)
|
|
request.suitStyle = GameManager.Instance.suitStyle[suitStyle.value - 1].code_id;
|
|
if (suitType.value != 0)
|
|
request.suitType = GameManager.Instance.suitType[suitType.value - 1].code_id;
|
|
if (region.value != 0)
|
|
request.suitRegion = GameManager.Instance.region[region.value - 1].code_id;
|
|
if (animalTypes.value != 0)
|
|
request.suitAnimalType = GameManager.Instance.animalTypes[animalTypes.value - 1].code_id;
|
|
NetworkManager.Instance.CreateRequest<SearchResponse>("library/select/suiters", request, (data) =>
|
|
{
|
|
librarys = data.data;
|
|
results.gameObject.SetActive(true);
|
|
ItemPrefab[] items = new ItemPrefab[5];
|
|
for (int n = 0; n < 5; n++)
|
|
{
|
|
GameObject prefab = Instantiate(item, results);
|
|
itemPrefabs.Add(prefab);
|
|
items[n] = prefab.GetComponent<ItemPrefab>();
|
|
}
|
|
for (int n = 0; n < data.data.Count; n++)
|
|
{
|
|
items[n].Set(data.data[n]);
|
|
}
|
|
hasMore = data.hasMore;
|
|
//LayoutRebuilder.ForceRebuildLayoutImmediate(content);
|
|
});
|
|
}
|
|
|
|
public void NextSearch()
|
|
{
|
|
hasMore = false;
|
|
request.page++;
|
|
NetworkManager.Instance.CreateRequest<SearchResponse>("library/select/suiters", request, (data) =>
|
|
{
|
|
librarys.AddRange(data.data);
|
|
ItemPrefab[] items = new ItemPrefab[5];
|
|
for (int n = 0; n < 5; n++)
|
|
{
|
|
GameObject prefab = Instantiate(item, results);
|
|
itemPrefabs.Add(prefab);
|
|
items[n] = prefab.GetComponent<ItemPrefab>();
|
|
}
|
|
for (int n = 0; n < data.data.Count; n++)
|
|
{
|
|
items[n].Set(data.data[n]);
|
|
}
|
|
hasMore = data.hasMore;
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(content);
|
|
});
|
|
}
|
|
|
|
public void GetImage(ItemPrefab itemPrefab, Library library)
|
|
{
|
|
NetworkManager.Instance.CreateImageRequest(library.imageBase64.Substring(1), new object(), (data) =>
|
|
{
|
|
library._suit_image = Sprite.Create(data, new Rect(0, 0, data.width, data.height), new Vector2(0.5f, 0.5f));
|
|
itemPrefab.ImageSet();
|
|
}, null, BestHTTP.HTTPMethods.Get);
|
|
}
|
|
|
|
public void ResetButton()
|
|
{
|
|
suitStyle.value = 0;
|
|
suitType.value = 0;
|
|
region.value = 0;
|
|
animalTypes.value = 0;
|
|
for(int n = 0; n < colors.Length; n++)
|
|
{
|
|
colors[n].isOn = false;
|
|
colors[n].image.sprite = isOnSprite[0];
|
|
}
|
|
}
|
|
|
|
public void OnToggle(int velue)
|
|
{
|
|
colors[velue].image.sprite = isOnSprite[(colors[velue].isOn ? 1 : 0)];
|
|
}
|
|
|
|
public void ModelSet(Library library)
|
|
{
|
|
model.Set(library);
|
|
}
|
|
|
|
public void ScrollValue(RectTransform Content) {
|
|
if(Content.anchoredPosition.y < 0.0f)
|
|
{
|
|
Content.anchoredPosition = Vector2.zero;
|
|
}
|
|
else if(hasMore && Content.sizeDelta.y != Screen.height && Content.sizeDelta.y - Screen.height < Content.anchoredPosition.y)
|
|
{
|
|
NextSearch();
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SearchRequest
|
|
{
|
|
public int xid;
|
|
public string fursuitName = ""; /*오너,슈트 이름*/
|
|
public string suitMaker; /*사용안함*/
|
|
public string suitRegion = ""; /*활동 국가*/
|
|
public string suitStyle = ""; /*슈트 스타일*/
|
|
public string suitAnimalType = ""; /*슈트 동물 종*/
|
|
public string suitType = ""; /*슈트 형태*/
|
|
public List<string> colorList = new List<string>(); /*슈트 색상*/
|
|
public int page = 1;
|
|
public int size = 5;
|
|
public int offset = 0;
|
|
}
|
|
public class SearchResponse
|
|
{
|
|
public List<Library> data;
|
|
public bool hasMore;
|
|
}
|
|
public class ImageResponse
|
|
{
|
|
public byte[] imageBytes;
|
|
}
|
|
|
|
public class Library
|
|
{
|
|
public string imageBase64;
|
|
public string suit_name;
|
|
public string owner_id;
|
|
public string owner_name;
|
|
public string production_date;
|
|
public string suit_image;//사용안함
|
|
public Sprite _suit_image = null;
|
|
public string maker;
|
|
public string region;
|
|
public string animal_type;
|
|
public string suit_style;
|
|
public string suit_type;
|
|
public List<string> suit_color;
|
|
} |