暂存
This commit is contained in:
1 parent
f4cbad819b
commit
0346b650aa
64 files changed
+12634
-12935
No files matched your search
@@ -1,12 +1,24 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MapItem : MonoBehaviour
|
||||
public class PropNames
|
||||
{
|
||||
public static List<string> icons = new List<string> { "icon1", "icon2", "icon3" };
|
||||
public static List<string> texts = new List<string> { "DistanceText", "EleText", "SlopeText" };
|
||||
public static Dictionary<bool, string> colorDict = new Dictionary<bool, string>
|
||||
{
|
||||
{ true,"#ffffff"},{false,"#5c5c6e" }
|
||||
};
|
||||
}
|
||||
public class MapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
//[SerializeField] Text text;
|
||||
@@ -19,20 +31,44 @@ public class MapItem : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
float? localY = null;
|
||||
MapRoute map;
|
||||
public void Initial(MapRoute myMap)
|
||||
{
|
||||
gameObject.GetComponent<Button>().onClick.AddListener(()=>
|
||||
map = myMap;
|
||||
//localY = transform.GetComponent<RectTransform>().rect.height;
|
||||
//Debug.Log(localY);
|
||||
//UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (Base) =>
|
||||
//{
|
||||
// UIManager.ShowMapDetailPanel(myMap.Id);
|
||||
//});
|
||||
//UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerEnter, (Base) =>
|
||||
//{
|
||||
// if (localY == null)
|
||||
// {
|
||||
// localY = transform.localPosition.y;
|
||||
// }
|
||||
// //transform.localPosition.Set(transform.localPosition.x,localY.Value+8, transform.localPosition.z);
|
||||
// //transform.DOLocalMoveY(localY.Value + 8, 0.5f);
|
||||
// //transform.domov(localY+8, 0.5f);
|
||||
//});
|
||||
//UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerExit, (Base) =>
|
||||
//{
|
||||
// //transform.localPosition.Set(transform.localPosition.x, localY.Value, transform.localPosition.z);
|
||||
// //transform.DOLocalMoveY(localY.Value, 0.5f);
|
||||
//});
|
||||
transform.GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
Debug.Log(123);
|
||||
UIManager.ShowMapDetailPanel(myMap.Id);
|
||||
//SceneManager.LoadScene("4-Demo", LoadSceneMode.Additive);
|
||||
});
|
||||
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
||||
Utils.DisplayImage(StartCoroutine, transform.Find("MapTitleImg").GetComponent<RawImage>(), myMap.CoverImage);
|
||||
transform.Find("CollectImg").gameObject.SetActive(myMap.IsFavorite);
|
||||
|
||||
transform.Find("Hot").gameObject.SetActive(myMap.IsFire);
|
||||
var props = transform.Find("Props");
|
||||
var props = transform.Find("Props");
|
||||
props.Find("DistanceText").GetComponent<Text>().text = $"{myMap.Distance.ToString("#0.00")}KM";
|
||||
props.Find("EleText").GetComponent<Text>().text = $"{(myMap.TotalClimb ?? 0.0).ToString("#0.00")}M";
|
||||
props.Find("SlopeText").GetComponent<Text>().text = $"{myMap.AverageGrade.ToString("#0.00")}%";
|
||||
@@ -42,5 +78,85 @@ public class MapItem : MonoBehaviour
|
||||
diff.Find("Text").GetComponent<Text>().text = myMap.Hard;
|
||||
tabContainer.Find("3d").gameObject.SetActive(myMap.Enable3D);
|
||||
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(myMap.CountryCode);
|
||||
transform.Find("CollectImg").GetComponent<Button>().onClick.AddListener(Collect);
|
||||
transform.Find("CollectImg").gameObject.SetActive(false);
|
||||
transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
||||
UIManager.Instance.collectDict[myMap.IsFavorite];
|
||||
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
||||
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
||||
Utils.DisplayImage(StartCoroutine, transform.Find("MapHBImg").GetComponent<RawImage>(), myMap.AltitudeGraph);
|
||||
SetActive4Button(false);
|
||||
}
|
||||
|
||||
private void Ride()
|
||||
{
|
||||
App.RouteIdParam = map.Id;
|
||||
SceneManager.LoadScene("Ride");
|
||||
}
|
||||
|
||||
private void Info()
|
||||
{
|
||||
UIManager.ShowMapDetailPanel(map.Id);
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (localY == null)
|
||||
{
|
||||
localY = transform.localPosition.y;
|
||||
}
|
||||
transform.Find("CollectImg").gameObject.SetActive(true);
|
||||
transform.DOLocalMoveY(localY.Value + 5, 0.5f);
|
||||
SetActive4Button(true);
|
||||
SetColor(map.IsFavorite);
|
||||
}
|
||||
void SetActive4Button(bool b)
|
||||
{
|
||||
transform.Find("MapHBImg").gameObject.SetActive(!b);
|
||||
transform.Find("BtnInfo").gameObject.SetActive(b);
|
||||
transform.Find("BtnRide").gameObject.SetActive(b);
|
||||
}
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
transform.DOLocalMoveY(localY.Value, 0.5f);
|
||||
transform.Find("CollectImg").gameObject.SetActive(false);
|
||||
SetActive4Button(false);
|
||||
SetColor(false);
|
||||
}
|
||||
private void SetColor(bool isFav)
|
||||
{
|
||||
PropNames.icons.ForEach((v) =>
|
||||
{
|
||||
transform.Find("Props").Find(v).GetComponent<Image>().color = Utils.HexToColorHtml(
|
||||
PropNames.colorDict[isFav]);
|
||||
});
|
||||
PropNames.texts.ForEach((v) =>
|
||||
{
|
||||
transform.Find("Props").Find(v).GetComponent<Text>().color = Utils.HexToColorHtml(
|
||||
PropNames.colorDict[isFav]);
|
||||
});
|
||||
}
|
||||
async void Collect()
|
||||
{
|
||||
JsonResult<object> r;
|
||||
if (map.IsFavorite)
|
||||
{
|
||||
r = await ConfigHelper.mapApi.CancelFav(map.Id.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
r = await ConfigHelper.mapApi.AddFav(map.Id.ToString());
|
||||
}
|
||||
if (r.result)
|
||||
{
|
||||
map.IsFavorite = !map.IsFavorite;
|
||||
transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
||||
UIManager.Instance.collectDict[map.IsFavorite];
|
||||
SetColor(map.IsFavorite);
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.ShowAlert(r.errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user