318 lines
8.6 KiB
C#
318 lines
8.6 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using DG.Tweening;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using System.Linq;
|
|||
|
|
using UnityEngine.Networking;
|
|||
|
|
|
|||
|
|
public class ZX7Controller : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public GameObject prePlace;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ԥ<><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public Transform tranPlaceParent;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>رհ<D8B1>ť
|
|||
|
|
/// </summary>
|
|||
|
|
public Button btnClose;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>һҳ<D2BB><D2B3>ť
|
|||
|
|
/// </summary>
|
|||
|
|
public Button btnNext;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>һҳ<D2BB><D2B3>ť
|
|||
|
|
/// </summary>
|
|||
|
|
public Button btnPriv;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ذ<EFBFBD>ť
|
|||
|
|
/// </summary>
|
|||
|
|
public Button btnReturn;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public Text txtCity;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ͼƬ
|
|||
|
|
/// </summary>
|
|||
|
|
public Image imgDetail;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public Text txtDetail;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Image
|
|||
|
|
/// </summary>
|
|||
|
|
public Image imgPnlTitle;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ͼƬTransform
|
|||
|
|
/// </summary>
|
|||
|
|
public Transform tranImgTitle;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string DataFileName = "CityPlaces.json";
|
|||
|
|
|
|||
|
|
public Sprite spSelected;
|
|||
|
|
|
|||
|
|
public Sprite spNormal;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ѡ<>еij<D0B5><C4B3><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
string selectedCity;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
Dictionary<string, string> dicCityPlaces = new Dictionary<string, string>();
|
|||
|
|
|
|||
|
|
string placeName;
|
|||
|
|
|
|||
|
|
public Animator anim;
|
|||
|
|
|
|||
|
|
int currentIndex;
|
|||
|
|
public RectTransform rectPlaceContent;
|
|||
|
|
|
|||
|
|
public RectTransform rectDetailContent;
|
|||
|
|
|
|||
|
|
string basePath;
|
|||
|
|
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
basePath = CommonData.DataServer + "/ZX7/";
|
|||
|
|
|
|||
|
|
StartCoroutine(JsonLoader.LoadJSON(basePath + "Data/" + DataFileName, onGetCityPlacesInfoCompleted));
|
|||
|
|
|
|||
|
|
if (btnClose != null)
|
|||
|
|
btnClose.onClick.AddListener(OnBtnCloseClick);
|
|||
|
|
if (btnPriv != null)
|
|||
|
|
btnPriv.onClick.AddListener(OnBtnPrivClick);
|
|||
|
|
if (btnNext != null)
|
|||
|
|
btnNext.onClick.AddListener(OnBtnNextClick);
|
|||
|
|
if (btnReturn != null)
|
|||
|
|
btnReturn.onClick.AddListener(OnBtnReturnClick);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnBtnReturnClick()
|
|||
|
|
{
|
|||
|
|
currentIndex = 0;
|
|||
|
|
selectedCity = null;
|
|||
|
|
rectPlaceContent.anchoredPosition = Vector2.zero;
|
|||
|
|
anim.SetTrigger("HideCity");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnBtnPrivClick()
|
|||
|
|
{
|
|||
|
|
if (currentIndex > 0)
|
|||
|
|
{
|
|||
|
|
currentIndex--;
|
|||
|
|
btnPriv.enabled = false;
|
|||
|
|
btnNext.enabled = false;
|
|||
|
|
|
|||
|
|
rectPlaceContent.anchoredPosition += Vector2.down * 138f;
|
|||
|
|
Invoke("EnableButton", 0.2f);
|
|||
|
|
//Tween myTween = rectPlaceContent.DOAnchorPosY(rectPlaceContent.anchoredPosition.y - 138, 0.2f);
|
|||
|
|
//myTween.SetEase(Ease.OutQuint).onComplete = delegate
|
|||
|
|
//{
|
|||
|
|
// btnPriv.enabled = true;
|
|||
|
|
// btnNext.enabled = true;
|
|||
|
|
//};
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
btnPriv.GetComponent<Image>().color = Color.red;
|
|||
|
|
Invoke("ResetPrivButtonColor", 0.2f);
|
|||
|
|
|
|||
|
|
//rectPlaceContent.DOShakePosition(1f, 2f);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void EnableButton()
|
|||
|
|
{
|
|||
|
|
btnPriv.enabled = true;
|
|||
|
|
btnNext.enabled = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ResetPrivButtonColor()
|
|||
|
|
{
|
|||
|
|
btnPriv.GetComponent<Image>().color = Color.white;
|
|||
|
|
}
|
|||
|
|
void ResetNextButtonColor()
|
|||
|
|
{
|
|||
|
|
btnNext.GetComponent<Image>().color = Color.white;
|
|||
|
|
}
|
|||
|
|
private void OnBtnNextClick()
|
|||
|
|
{
|
|||
|
|
if (currentIndex < rectPlaceContent.childCount - 1)
|
|||
|
|
{
|
|||
|
|
currentIndex++;
|
|||
|
|
btnPriv.enabled = false;
|
|||
|
|
btnNext.enabled = false;
|
|||
|
|
rectPlaceContent.anchoredPosition += Vector2.up * 138f;
|
|||
|
|
Invoke("EnableButton", 0.2f);
|
|||
|
|
|
|||
|
|
//Tween myTween = rectPlaceContent.DOAnchorPosY(rectPlaceContent.anchoredPosition.y + 138, 0.2f);
|
|||
|
|
//myTween.SetEase(Ease.OutQuint).onComplete = delegate
|
|||
|
|
//{
|
|||
|
|
// btnPriv.enabled = true;
|
|||
|
|
// btnNext.enabled = true;
|
|||
|
|
//};
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
btnNext.GetComponent<Image>().color = Color.red;
|
|||
|
|
Invoke("ResetNextButtonColor", 0.2f);
|
|||
|
|
|
|||
|
|
// rectPlaceContent.DOShakePosition(1f, 2f);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnBtnCloseClick()
|
|||
|
|
{
|
|||
|
|
BaseController.HideView();
|
|||
|
|
|
|||
|
|
Destroy(gameObject.transform.parent.gameObject);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public void onGetCityPlacesInfoCompleted(string data)
|
|||
|
|
{
|
|||
|
|
dicCityPlaces = JsonTools.DicFromJson<string, string>(data);
|
|||
|
|
InitialCityList();
|
|||
|
|
|
|||
|
|
#region
|
|||
|
|
//dicCityPlaces.Add("̨<><CCA8>", "Բɽ<D4B2>Ļ<EFBFBD><C4BB><EFBFBD>ַ|<7C><>ë<EFBFBD><C3AB>|̨<><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|̨<><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|<7C><><EFBFBD>п<EFBFBD><D0BF>Ļ<EFBFBD><C4BB><EFBFBD>ַ");
|
|||
|
|
//dicCityPlaces.Add("̨<><CCA8>", "<22><><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>ַ|<7C><><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>ַ");
|
|||
|
|
//dicCityPlaces.Add("̨<><CCA8>", "<22><><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>|<7C><>Ƕ<EFBFBD><C7B6>|̨<>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD>|<7C><><EFBFBD>H<EFBFBD><48><EFBFBD><EFBFBD>̨|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
//dicCityPlaces.Add("<22>û<EFBFBD>", "<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ|¹<><C2B9><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>");
|
|||
|
|
//dicCityPlaces.Add("<22><>¡", "<22><>ɳ<EFBFBD><C9B3><EFBFBD><EFBFBD>̨");
|
|||
|
|
//dicCityPlaces.Add("<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD>㸣<EFBFBD><E3B8A3><EFBFBD><EFBFBD>");
|
|||
|
|
//dicCityPlaces.Add("<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD>춫̨|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
//dicCityPlaces.Add("<22><><EFBFBD><EFBFBD>", "<22><>ɽ<EFBFBD>ؾɳ<D8BE>");
|
|||
|
|
//dicCityPlaces.Add("<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>Т<EFBFBD><D0A2>");
|
|||
|
|
|
|||
|
|
//string data = JsonTools.DicToJson(dicCityPlaces);
|
|||
|
|
//StreamWriter writer = File.CreateText(DataFileName);
|
|||
|
|
//writer.Write(data);
|
|||
|
|
//writer.Close();
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void InitialCityList()
|
|||
|
|
{
|
|||
|
|
//foreach (var item in dicCityPlaces.Keys)
|
|||
|
|
//{
|
|||
|
|
//GameObject obj = Instantiate(preName, tranNameParent);
|
|||
|
|
//obj.GetComponent<Button>().onClick.AddListener(OnBtnNameClick);
|
|||
|
|
//obj.GetComponentInChildren<Text>().text = item.Key;
|
|||
|
|
//obj.name = item.Key;
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnBtnCityClick()
|
|||
|
|
{
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
|
|||
|
|
GameObject obj = EventSystem.current.currentSelectedGameObject;
|
|||
|
|
|
|||
|
|
if (selectedCity != obj.name)
|
|||
|
|
{
|
|||
|
|
selectedCity = obj.name;
|
|||
|
|
txtCity.text = obj.name;
|
|||
|
|
|
|||
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵľ<C9B5><C4BE><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
for (int i = 0; i < tranPlaceParent.childCount; i++)
|
|||
|
|
{
|
|||
|
|
Destroy(tranPlaceParent.GetChild(i).gameObject);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD>µľ<C2B5><C4BE><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
string place = dicCityPlaces[obj.name];
|
|||
|
|
lstPlaces = place.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
|
|||
|
|
isNewCity = true;
|
|||
|
|
if (lstPlaces != null)
|
|||
|
|
{
|
|||
|
|
int count = lstPlaces.Count;
|
|||
|
|
|
|||
|
|
ShowResult(lstPlaces[0]);
|
|||
|
|
|
|||
|
|
for (int i = 0; i < count; i++)
|
|||
|
|
{
|
|||
|
|
CreatePlace();
|
|||
|
|
// Invoke("CreatePlace", 0.3f * i);
|
|||
|
|
}
|
|||
|
|
// OnBtnPlaceClick();
|
|||
|
|
Invoke("OnBtnPlaceClick", 0.1f);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
anim.SetTrigger("ShowCity");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
List<string> lstPlaces;
|
|||
|
|
|
|||
|
|
void CreatePlace()
|
|||
|
|
{
|
|||
|
|
GameObject objPlace = Instantiate(prePlace, tranPlaceParent);
|
|||
|
|
objPlace.name = lstPlaces[0];
|
|||
|
|
objPlace.GetComponentInChildren<Text>().text = lstPlaces[0];
|
|||
|
|
objPlace.GetComponent<Button>().onClick.AddListener(OnBtnPlaceClick);
|
|||
|
|
lstPlaces.RemoveAt(0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GameObject objSelected;
|
|||
|
|
bool isNewCity;
|
|||
|
|
|
|||
|
|
public void OnBtnPlaceClick()
|
|||
|
|
{
|
|||
|
|
GameObject obj = EventSystem.current.currentSelectedGameObject;
|
|||
|
|
|
|||
|
|
if (isNewCity)
|
|||
|
|
{
|
|||
|
|
obj = tranPlaceParent.GetChild(0).gameObject;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
isNewCity = false;
|
|||
|
|
|
|||
|
|
if (objSelected != null)
|
|||
|
|
{
|
|||
|
|
objSelected.GetComponent<Image>().sprite = spNormal;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
obj.GetComponent<Image>().sprite = spSelected;
|
|||
|
|
|
|||
|
|
objSelected = obj;
|
|||
|
|
|
|||
|
|
rectDetailContent.anchoredPosition = Vector2.zero;
|
|||
|
|
|
|||
|
|
ShowResult(obj.name);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="placeName"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
public void ShowResult(string placeName)
|
|||
|
|
{
|
|||
|
|
txtCity.text = string.Format("{0}<7D><>{1}<7D><>", selectedCity, placeName);
|
|||
|
|
StartCoroutine(JsonLoader.LoadJSON(basePath + "Data/" + placeName +".txt", OnGetTextDetailsInfoCompleted));
|
|||
|
|
StartCoroutine(ImageLoader<Image>.LoadImage(basePath + "Images/" + placeName + ".jpg", imgDetail));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
void OnGetTextDetailsInfoCompleted(string data)
|
|||
|
|
{
|
|||
|
|
txtDetail.text = "\u3000\u3000" + data.Trim();
|
|||
|
|
}
|
|||
|
|
}
|