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 { /// /// 景点预设体 /// public GameObject prePlace; /// /// 预设体所在父对象 /// public Transform tranPlaceParent; /// /// 关闭按钮 /// public Button btnClose; /// /// 下一页按钮 /// public Button btnNext; /// /// 上一页按钮 /// public Button btnPriv; /// /// 返回按钮 /// public Button btnReturn; /// /// 城市标题 /// public Text txtCity; /// /// 结果图片 /// public Image imgDetail; /// /// 结果文本 /// public Text txtDetail; /// /// 标题面板Image /// public Image imgPnlTitle; /// /// 标题图片Transform /// public Transform tranImgTitle; /// /// 数据文件名 /// public string DataFileName = "CityPlaces.json"; public Sprite spSelected; public Sprite spNormal; /// /// 选中的城市 /// string selectedCity; /// /// 城市景点列表 /// Dictionary dicCityPlaces = new Dictionary(); 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().color = Color.red; Invoke("ResetPrivButtonColor", 0.2f); //rectPlaceContent.DOShakePosition(1f, 2f); } } void EnableButton() { btnPriv.enabled = true; btnNext.enabled = true; } void ResetPrivButtonColor() { btnPriv.GetComponent().color = Color.white; } void ResetNextButtonColor() { btnNext.GetComponent().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().color = Color.red; Invoke("ResetNextButtonColor", 0.2f); // rectPlaceContent.DOShakePosition(1f, 2f); } } private void OnBtnCloseClick() { BaseController.HideView(); Destroy(gameObject.transform.parent.gameObject); } /// /// 获取姓名列表 /// public void onGetCityPlacesInfoCompleted(string data) { dicCityPlaces = JsonTools.DicFromJson(data); InitialCityList(); #region //dicCityPlaces.Add("台北", "圆山文化遗址|红毛城|台北公会堂|台北府城|大坌坑文化遗址"); //dicCityPlaces.Add("台东", "长滨文化遗址|卑南文化遗址"); //dicCityPlaces.Add("台南", "热兰遮城|赤嵌城|台南孔子庙|二鯤鯓炮台|祀典武庙|五妃庙|大天后宫"); //dicCityPlaces.Add("彰化", "彰化孔子庙|道东书院|鹿港龙山寺"); //dicCityPlaces.Add("基隆", "二沙湾炮台"); //dicCityPlaces.Add("新竹", "金广福公馆"); //dicCityPlaces.Add("澎湖", "西屿东台|西屿西台|澎湖天后宫"); //dicCityPlaces.Add("高雄", "凤山县旧城"); //dicCityPlaces.Add("金门", "邱良功母节孝坊"); //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