完成大地图主要界面

This commit is contained in:
suntao committed 2021-04-15 09:01:07 +08:00
1 parent 5156473bb2
commit d22eecd133
78 files changed
+8684 -6941

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b7c432b0271757f4b86f715ecc5ef931
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRectAutoFit : MonoBehaviour
{
float targetaspect = 16.0f / 9.0f;
// Start is called before the first frame update
void Start()
{
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect / targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = Camera.main;
// if scaled height is less than current height, add letterbox
if (scaleheight <= 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
camera.rect = rect;
}
else // add pillarbox
{
float scalewidth = 1.0f / scaleheight;
Rect rect = camera.rect;
rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth) / 2.0f;
rect.y = 0;
camera.rect = rect;
}
}
// Update is called once per frame
void Update()
{
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 969b87ed3066bec4a9981a69d7dfb8e4
guid: 3083a61e316cc854fb0fa28e7fd7e237
MonoImporter:
externalObjects: {}
serializedVersion: 2
+117
View File
@@ -0,0 +1,117 @@
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using Assets.Scripts.UI.UIEffect;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Item : MonoBehaviour, IPointerClickHandler
{
private Text text;
private string Text
{
get
{
return text.text;
}
set
{
text.text = value;
}
}
private Text km;
private string Distance
{
get
{
return km.text;
}
set
{
km.text = value;
}
}
private Text count;
private string Count
{
get
{
return count.text;
}
set
{
count.text = value;
}
}
public Action onClick;
private void Awake()
{
text = this.transform.Find("name").GetComponent<Text>();
km = this.transform.Find("km").GetComponent<Text>();
count = this.transform.Find("count").GetComponent<Text>();
Material material = null;
if (material == null)
{
material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
}
var rect = ((RectTransform)transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height * 0.5f, 0));
this.GetComponent<Image>().material = material;
}
public void Selected(bool value)
{
if (value)
{
this.GetComponent<UIGradient>().enabled = true;
this.GetComponent<UIGradient>().color1 = Utils.HexToColor("FF7485");
this.GetComponent<UIGradient>().color2 = Utils.HexToColor("F93086");
this.GetComponent<Image>().color = Color.white;
this.transform.Find("km").GetComponent<Text>().color = Color.white;
this.transform.Find("count").GetComponent<Text>().color = Color.white;
}
else
{
this.GetComponent<UIGradient>().enabled = false;
this.GetComponent<Image>().color = Utils.HexToColor("353543");
this.transform.Find("km").GetComponent<Text>().color = Utils.HexToColor("5C5C6E");
this.transform.Find("count").GetComponent<Text>().color = Utils.HexToColor("F93086");
}
}
public void SetModel(NearRouteModel model)
{
this.Text = model.Name;
this.Distance = model.Distance + "KM";
this.Count = model.TheHeat.ToString();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnPointerClick(PointerEventData eventData)
{
if(onClick != null)
{
onClick();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4798070a21cb55b40a0a89ac2b84f135
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+111
View File
@@ -0,0 +1,111 @@
using Assets.Scripts.Apis.Models;
using Assets.Scripts.UI.Control;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Tips : MonoBehaviour
{
public NearRouteModel Model
{
get
{
return _model;
}
}
private Text Name;
private Text Count;
private Text Distance;
private Text TotalClimb;
private PFUIButton pFUIButton;
private void Awake()
{
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
var rect = ((RectTransform)transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, 40f, 0));
this.GetComponent<Image>().material = material;
Name = this.transform.Find("Name").GetComponent<Text>();
Count = this.transform.Find("Count").GetComponent<Text>();
Distance = this.transform.Find("Distance").GetComponent<Text>();
TotalClimb = this.transform.Find("TotalClimb").GetComponent<Text>();
pFUIButton = this.transform.Find("Ride").GetComponent<PFUIButton>();
UIManager.AddEvent(pFUIButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) => {
App.RouteIdParam = _model.Id;
SceneManager.LoadScene("Ride");
});
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
NearRouteModel _model;
public void SetModel(NearRouteModel model)
{
if (this.isActiveAndEnabled)
{
if(_model.Id == model.Id)
{
//this.gameObject.SetActive(false);
return;
}
}
else
{
//this.gameObject.SetActive(true);
_model = model;
Name.text = _model.Name;
Count.text = _model.TheHeat.ToString();
Distance.text = _model.Distance.ToString("#.0")+"KM";
TotalClimb.text = _model.TotalClimb.ToString();
}
}
public void Show(Vector3 position, NearRouteModel model)
{
//if(position.y > position.z)
//{
// position.y = position.z;
//}
this.transform.position = position;
var localPosition = this.transform.localPosition;
if (localPosition.y + 150 > localPosition.z)
{
localPosition.y = localPosition.z -150;
}
if(localPosition.x * -1f > localPosition.z)
{
localPosition.x = localPosition.z * -1f;
}
else if(localPosition.x > localPosition.z *2)
{
localPosition.x = localPosition.z * 2;
}
this.transform.localPosition = localPosition;
this.transform.localScale = new Vector2(2, 2);
this.SetModel(model);
//tips.Show();
this.gameObject.SetActive(true);
}
public void Hide()
{
this.gameObject.SetActive(false);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1614be1af0822445936f92435d0162b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -7,6 +7,7 @@ using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.UI.Control;
public class ConnectDeviceModal : PFUIPanel
{
@@ -26,6 +27,8 @@ public class ConnectDeviceModal : PFUIPanel
private Image Logo;
private UnityEngine.Object deviceItem;
private VerticalLayoutGroup content;
private PFUIButton connectBtn;
private Dictionary<ushort, DeviceItem> deviceList;
protected override void Awake()
{
@@ -36,8 +39,19 @@ public class ConnectDeviceModal : PFUIPanel
var container = this.transform.Find("GameObject");
var closeBtn = container.Find("CloseBtn");
Logo = container.Find("Logo").GetComponent<Image>();
content = container.Find("Panel").Find("Scroll View").Find("Viewport").Find("Content").GetComponent<VerticalLayoutGroup>();
var panel = container.Find("Panel");
content = panel.Find("Scroll View").Find("Viewport").Find("Content").GetComponent<VerticalLayoutGroup>();
Material material = null;
if (material == null)
{
material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
}
var rect = ((RectTransform)panel.transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, 20f, 0));
panel.GetComponent<Image>().material = material;
UIManager.AddEvent(closeBtn.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
{
//this.gameObject.SetActive(false);
@@ -46,15 +60,39 @@ public class ConnectDeviceModal : PFUIPanel
deviceItem = Resources.Load("UI/Prefab/Device/DeviceItem");
connectBtn = container.Find("ConnectBtn").GetComponent<PFUIButton>();
UIManager.AddEvent(connectBtn.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
{
foreach (var item in deviceList)
{
if (item.Value.GetStatus() == false)
{
if (item.Value.DeviceInfo.Sensor == SensorType)
{
item.Value.DeviceInfo.Disconnect();
}
}
}
var dd = deviceList.Select(d => d.Value).Where(d => d.GetStatus()).FirstOrDefault();
if(dd != null)
{
dd.DeviceInfo.Connect();
}
this.Close();
}));
}
// Start is called before the first frame update
void Start()
protected override void Start()
{
SearchDevice();
}
private Dictionary<ushort, DeviceItem> deviceList;
// Update is called once per frame
void Update()
{
@@ -101,34 +139,38 @@ public class ConnectDeviceModal : PFUIPanel
if (deviceList.ContainsKey(device.DeviceNumber))
{
continue;
}
}
var gameObject = (GameObject)Instantiate(deviceItem);
gameObject.transform.SetParent(content.transform);
var deviceItemObj = gameObject.GetComponent<DeviceItem>();
deviceItemObj.DeviceInfo = device;
UIManager.AddEvent(deviceItemObj.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
{
//deviceItemObj.Select();
if(deviceItemObj.DeviceInfo.Sensor == SensorType)
{
deviceItemObj.DeviceInfo.Connect();
}
////deviceItemObj.Select();
//if(deviceItemObj.DeviceInfo.Sensor == SensorType)
//{
// deviceItemObj.DeviceInfo.Connect();
//}
deviceItemObj.Set(true);
foreach (var item in deviceList)
{
if(item.Key != deviceItemObj.DeviceInfo.DeviceNumber)
if (item.Key != deviceItemObj.DeviceInfo.DeviceNumber)
{
item.Value.Set(false);
if(item.Value.DeviceInfo.Sensor == SensorType)
{
item.Value.DeviceInfo.Disconnect();
}
//if (item.Value.DeviceInfo.Sensor == SensorType)
//{
// item.Value.DeviceInfo.Disconnect();
//}
}
}
Close();
//Close();
}));
//UIManager.AddEvent(deviceItemObj.gameObject, EventTriggerType.Deselect, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
//{
// //Debug.Log("de select");
@@ -141,11 +183,22 @@ public class ConnectDeviceModal : PFUIPanel
deviceList.Add(device.DeviceNumber, deviceItemObj);
}
var firstDevice = deviceList.Select(d => d.Value).Where(d => d.DeviceInfo.State == DeviceState.Connected).OrderByDescending(d => d.DeviceInfo.Priority).FirstOrDefault();
if(firstDevice != null)
if(deviceList.All(d=>d.Value.GetStatus() == false))
{
firstDevice.Set(true);
var firstDevice = deviceList.Select(d => d.Value).Where(d => d.DeviceInfo.State == DeviceState.Connected).OrderByDescending(d => d.DeviceInfo.Priority).FirstOrDefault();
if (firstDevice != null)
{
firstDevice.Set(true);
//connectBtn.text.text = "DISCOUNECT";
}
}
}
}
public override void Close()
{
base.Close();
DestroyImmediate(this.gameObject);
}
}
+11 -2
View File
@@ -47,7 +47,7 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
{
shadow = mText.gameObject.AddComponent<Shadow>();
}
shadow.enabled = true;
ColorUtility.TryParseHtmlString("#F93086", out Color color1);
shadow.effectColor = color1;
}
@@ -81,7 +81,10 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
//this.Select();
//DeviceInfo.Connect();
}
public bool GetStatus()
{
return this.isOn;
}
public void Set(bool value)
{
@@ -98,6 +101,12 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
else
{
mText.color = Color.white;
var shadow = mText.gameObject.GetComponent<Shadow>();
if (shadow != null)
{
//shadow = mText.gameObject.AddComponent<Shadow>();
shadow.enabled = false;
}
}
}
}
+60 -26
View File
@@ -8,19 +8,21 @@ using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.UI.UIEffect;
using Assets.Scripts;
public class DeviceView : MonoBehaviour
{
[SerializeField]
private string mType;
private SensorType mType;
private SensorType SensorType
{
get
{
//Debug.Log(mType);
Enum.TryParse(mType, out SensorType sensorType);
return sensorType;
//Enum.TryParse(mType, out SensorType sensorType);
return mType;
}
}
@@ -34,9 +36,9 @@ public class DeviceView : MonoBehaviour
private Text title;
private Text noDevice;
private Text powerValue;
private Text cadenceValue;
private Text speedValue;
private Text heartRateValue;
//private Text cadenceValue;
//private Text speedValue;
//private Text heartRateValue;
private Image logo;
/// <summary>
/// 没有设备的logo
@@ -61,33 +63,64 @@ public class DeviceView : MonoBehaviour
mPairButton = unconnectionPanel.transform.Find("PairButton").gameObject;
searchState = unconnectionPanel.transform.Find("SearchState").GetComponent<Text>();
mPairButton.SetActive(false);
connectionPanel = this.transform.Find("ConnectionPanel").gameObject;
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
var rect = ((RectTransform)transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height * 0.2f, 0));
//this.GetComponent<Image>().material = material;
var img1 = unconnectionPanel.GetComponent<Image>();
if(img1 != null)
{
img1.material = material;
var gradient = unconnectionPanel.GetComponent<UIGradient>();
if (gradient != null)
{
gradient.color1 = Utils.HexToColor("353543");
gradient.color2 = Utils.HexToColor("23232D");
}
}
var img2 = connectionPanel.GetComponent<Image>();
if(img2 != null)
{
img2.material = material;
var gradient1 = connectionPanel.GetComponent<UIGradient>();
if (gradient1 != null)
{
gradient1.color1 = Utils.HexToColor("FF7485");
gradient1.color2 = Utils.HexToColor("F93086");
}
}
logo = this.transform.Find("Logo").GetComponent<Image>();
InitLogo();
connectionPanel = this.transform.Find("ConnectionPanel").gameObject;
mDisconnectButton = connectionPanel.transform.Find("DisconnectBtn").gameObject;
var powerValueObj = connectionPanel.transform.Find("PowerValue");
if(powerValueObj != null)
{
powerValue = powerValueObj.gameObject.GetComponent<Text>();
}
var cadenceValueObj = connectionPanel.transform.Find("CadenceValue");
if (cadenceValueObj != null) {
cadenceValue = cadenceValueObj.gameObject.GetComponent<Text>();
}
var speedValueObj = connectionPanel.transform.Find("SpeedValue");
if (speedValueObj != null)
{
speedValue = speedValueObj.gameObject.GetComponent<Text>();
}
//var cadenceValueObj = connectionPanel.transform.Find("CadenceValue");
//if (cadenceValueObj != null) {
// cadenceValue = cadenceValueObj.gameObject.GetComponent<Text>();
//}
//var speedValueObj = connectionPanel.transform.Find("SpeedValue");
//if (speedValueObj != null)
//{
// speedValue = speedValueObj.gameObject.GetComponent<Text>();
//}
var heartRateValueObj = connectionPanel.transform.Find("HeartRateValue");
if(heartRateValueObj != null)
{
heartRateValue = heartRateValueObj.gameObject.GetComponent<Text>();
}
//var heartRateValueObj = connectionPanel.transform.Find("HeartRateValue");
//if(heartRateValueObj != null)
//{
// heartRateValue = heartRateValueObj.gameObject.GetComponent<Text>();
//}
connectionPanel.SetActive(false);
@@ -251,10 +284,11 @@ public class DeviceView : MonoBehaviour
case SensorType.None:
break;
case SensorType.Cadence:
cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
//cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
powerValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
break;
case SensorType.HeartRate:
heartRateValue.text = (connectedDevice as IHeartRateDevice).HeartRate.ToString();
powerValue.text = (connectedDevice as IHeartRateDevice).HeartRate.ToString();
break;
case SensorType.Power:
powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
@@ -262,10 +296,10 @@ public class DeviceView : MonoBehaviour
case SensorType.Speed:
break;
case SensorType.SpeedCadence:
speedValue.text = (connectedDevice as ISpeedDevice).Speed.ToString();
powerValue.text = (connectedDevice as ISpeedDevice).Speed.ToString();
break;
case SensorType.Trainer:
powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
//powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
//cadenceValue.GetComponent<Text>().text = (connectedDevice as ICadenceDevice).Cadence.ToString();
//speedValue.GetComponent<Text>().text = (connectedDevice as ISpeedDevice).Speed.ToString();
break;
+42
View File
@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class MainNav : MonoBehaviour
{
private void Awake()
{
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
var rect = ((RectTransform)this.transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
this.GetComponent<Image>().material = material;
var wifi = this.transform.Find("Wifi");
UIManager.AddEvent(wifi.gameObject, EventTriggerType.PointerClick, x =>
{
Debug.Log("click wifi");
UIManager.ShowDevicePanel();
});
var home = this.transform.Find("Home");
UIManager.AddEvent(home.gameObject, EventTriggerType.PointerClick, x =>
{
UIManager.ShowHomePanel();
});
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71aaed8b61d057e4a87864a667ca1486
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,441 @@
using Assets.Scripts.Apis;
using Mapbox.Unity.Map;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
using Mapbox.Unity.MeshGeneration.Data;
using Newtonsoft.Json.Linq;
using Assets.Scripts;
using Mapbox.Utils;
using UnityEngine.UI;
using Assets.Scripts.Apis.Models;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using Mapbox.Examples;
public class BigMapController : PFUIPanel
{
MapApi mapApi;
MapBoxApi mapboxApi;
AbstractMap mapManager;
//GameObject cube;
//GameObject cube1;
GameObject canvas;
GameObject content;
Text keyword;
UnityEngine.Object begin;
Sprite end;
private Dictionary<int, LineItem> linesCache = new Dictionary<int, LineItem>();
Tips tips;
int timer = 0;
protected override void Awake()
{
mapApi = new MapApi();
mapboxApi = new MapBoxApi();
begin = Resources.Load("UI/Prefab/BigMap/Begin");
mapManager = this.transform.Find("Map").GetComponent<AbstractMap>();
mapManager.OnInitialized += MapManager_OnInitialized;
mapManager.OnUpdated += MapManager_OnUpdated;
mapManager.OnMapRedrawn += () =>
{
//Debug.Log("map redrawn");
};
mapManager.OnTileFinished += (e) =>
{
//Debug.Log("finished");
};
//// mapManager.OnTileFinished += MapManager_OnTileFinished;
//mapManager.SetZoom(13);
//mapManager.SetCenterLatitudeLongitude(new Mapbox.Utils.Vector2d(32.051203, 118.771572));
this.transform.Find("Map").GetComponent<QuadTreeCameraMovement>()._referenceCamera = Camera.main;
canvas = this.transform.Find("Canvas").gameObject;
canvas.GetComponent<Canvas>().worldCamera = Camera.main;
var goList = canvas.transform.Find("GoList");
UIManager.AddEvent(goList.gameObject, EventTriggerType.PointerClick, (e) =>
{
//App.MainSceneParam.Add("Name", "MapListPanel");
//SceneManager.LoadScene("MainScene");
mapManager.Destroy();
UIManager.ShowMapListPanel();
//this.gameObject.SetActive(false);
DestroyImmediate(this.gameObject);
});
var panel = canvas.transform.Find("Panel");
SetRounded(panel,30f);
content = panel.Find("Scroll View").Find("Viewport").Find("Content").gameObject;
var input = panel.Find("InputField");
SetRounded(input, 20f);
keyword = input.Find("Text").GetComponent<Text>();
var searchBtn = input.Find("Search").gameObject;
UIManager.AddEvent(searchBtn, EventTriggerType.PointerClick, Search);
tips = ((GameObject)Instantiate(Resources.Load("UI/Prefab/BigMap/Tips"), canvas.transform.Find("TipsContainer"))).GetComponent<Tips>();
tips.Hide();
}
/// <summary>
/// 给对象设置圆角
/// </summary>
/// <param name="panel"></param>
/// <param name="radius"></param>
void SetRounded(Transform panel, float radius)
{
var rounded = Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial");
var material = Instantiate(rounded);
var rect = ((RectTransform)panel).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, radius, 0));
panel.GetComponent<Image>().material = material;
}
// Start is called before the first frame update
protected override void Start()
{
//var mapObject = this.transform.Find("Map");
}
private void Search(BaseEventData e)
{
if (string.IsNullOrWhiteSpace(keyword.text))
{
return;
}
var infoStr = mapboxApi.GetAddressInfo(keyword.text);
//Debug.Log(info);
var info = Newtonsoft.Json.Linq.JObject.Parse(infoStr);
var center = (info["features"] as JArray).First()["center"];
mapManager.UpdateMap(new Vector2d(Convert.ToDouble(center[1]), Convert.ToDouble(center[0])));
//mapManager.SetCenterLatitudeLongitude(new Vector2d(31.325053, 120.623564));
//mapManager.UpdateMap(new Vector2d(31.325053, 120.623564));
}
private void MapManager_OnInitialized()
{
Load();
}
private void MapManager_OnUpdated()
{
foreach (var item in linesCache)
{
//if(item.Value.LineObject != null)
//{
// item.Value.LineObject.Destroy();
// item.Value.LineObject = null;
//}
//if(item.Value.BeginMarker != null)
//{
// item.Value.BeginMarker.Destroy();
// item.Value.BeginMarker = null;
//}
CreateLine(item.Key, item.Value);
}
timer += 1;
Invoke("Load", 0.3f);
//Load();
}
async void Load()
{
if (timer >1)
{
timer--;
return;
}
timer = 0;
var s1 = Camera.main.ScreenToWorldPoint(new Vector3(340f, 0f, 180f));
//Debug.Log(s1);
var start = mapManager.WorldToGeoPosition(s1);
//Debug.Log(start);
var worldPoint = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 180f));
var end = mapManager.WorldToGeoPosition(worldPoint);
//cube.transform.position = worldPoint;
//cube1.transform.position = s1;
//Debug.Log(end);
//Screen.width
//map.WorldToGeoPosition(start)
var bounds = $"{ start.y },{ start.x };{ end.y },{ end.x }";
var res = await mapApi.GetNearRouteAsync((float)mapManager.CenterLatitudeLongitude.x, (float)mapManager.CenterLatitudeLongitude.y,
mapManager.Zoom, bounds);
if(res.result == false)
{
Debug.LogError(res.errMsg);
return;
}
//Debug.Log("条数:"+res.data.Count);
var lines = await mapApi.GetDetailsAsync(res.data.Select(d => d.Id).ToArray());
var aa = Newtonsoft.Json.Linq.JObject.Parse(lines);
//var points = (aa["data"] as JArray).First()["Points"] as JArray;
var ids = new List<int>();
foreach (var line in (aa["data"] as JArray))
{
var id = line.Value<int>("Id");
ids.Add(id);
var points = line["Points"] as JArray;
if (linesCache.ContainsKey(id))
{
continue;
}
var pp1 = new List<Vector2d>();
foreach (var item in points)
{
pp1.Add(new Mapbox.Utils.Vector2d(item[0].ToObject<double>(), item[1].ToObject<double>()));
}
if (!linesCache.ContainsKey(id))
{
linesCache.Add(id, new LineItem { Points = pp1, Model = res.data.Single(d=>d.Id == id) });
}
CreateLine(id, linesCache[id]);
//Load();
}
foreach (var item in linesCache.ToList())
{
if(ids.All(id=>id != item.Key))
{
item.Value.Destroy();
linesCache.Remove(item.Key);
if(item.Value.Selected)
{
tips.Hide();
}
}
}
}
//GameObject direct;
void CreateLine(int id, LineItem line)
{
#region 画线
List<Vector2d> pp1 = line.Points;
var dat = new List<Vector3>();
foreach (var item in pp1)
{
var pp = mapManager.GeoToWorldPosition(item);
pp.y += 0.3f;
dat.Add(pp);
}
var feat = new VectorFeatureUnity();
feat.Points.Add(dat);
var direct = line.LineObject;
LineRenderer lineRender;
if (direct == null)
{
direct = new GameObject($"MapRoute-{ id }");
direct.transform.SetParent(this.transform);
lineRender = direct.AddComponent<LineRenderer>();
lineRender.material = new Material(Shader.Find("Sprites/Default"));
line.LineObject = direct;
lineRender.startColor = lineRender.endColor = Utils.HexToColor("F93086");
//设置宽度
lineRender.startWidth = 1.2f;
lineRender.endWidth = 1.2f;
lineRender.numCornerVertices = 90;
}
else
{
lineRender = direct.GetComponent<LineRenderer>();
}
//lineRender.SetWidth(0.5f, 0.5f);
lineRender.positionCount = dat.Count;
//lineRender.SetVertexCount(dat.Count);
lineRender.SetPositions(feat.Points[0].ToArray());
#endregion
#region 添加左边的列表项
if (linesCache[id].Item == null)
{
var itemObject = Resources.Load("UI/Prefab/BigMap/Item");
var itemObject1 = (GameObject)Instantiate(itemObject, content.transform, false);
var iii = itemObject1.GetComponent<Item>();
iii.SetModel(line.Model);
line.Item = iii;
iii.onClick = () =>
{
if (line.Selected)
{
line.Selected = false;
tips.Hide();
//iii.Selected(false);
return;
}
line.Selected = true;
//iii.Selected(true);
var position = line.BeginMarker.transform.position;
//position.z += 25;
tips.Show(position, line.Model);
foreach (var item in linesCache)
{
if(item.Key != line.Model.Id)
{
item.Value.Selected = false;
//item.Value.Item.Selected(false);
}
}
};
}
#endregion
#region 添加marker
if (line.BeginMarker == null)
{
var beginInstance = (GameObject)Instantiate(begin, canvas.transform.Find("MarkerContainer").transform);
line.BeginMarker = beginInstance;
UIManager.AddEvent(line.BeginMarker, EventTriggerType.PointerClick, new UnityAction<BaseEventData>((e) =>
{
if (line.Selected)
{
line.Selected = false;
tips.Hide();
return;
}
line.Selected = true;
var position = line.BeginMarker.transform.position;
//position.z += 25;
tips.Show(position, line.Model);
foreach (var item in linesCache)
{
if (item.Key != line.Model.Id)
{
item.Value.Selected = false;
//item.Value.Item.Selected(false);
}
}
}));
}
line.BeginMarker.transform.localScale = new Vector3(2,2);
//beginInstance.transform.localRotation = new Quaternion(90,0,0,0);
line.BeginMarker.transform.position = ConverToPosition(line.Points.First());
#endregion
if (line.Selected)
{
line.Selected = true;
var position = line.BeginMarker.transform.position;
//position.z += 25;
tips.Show(position, line.Model);
}
}
/// <summary>
/// 转换地理坐标到屏幕坐标
/// </summary>
/// <param name="vector"></param>
/// <returns></returns>
Vector3 ConverToPosition(Vector2d vector)
{
var worldPosition = mapManager.GeoToWorldPosition(vector);//32.061255, 118.80925
var vp = Camera.main.WorldToViewportPoint(worldPosition);
vp.z = 180f;
////Debug.Log(vp);
//var wd = Camera.main.WorldToScreenPoint(worldPosition);
var wd = Camera.main.ViewportToWorldPoint(vp);
return wd;
}
// Update is called once per frame
void Update()
{
//Debug.Log(Input.mousePosition.x + "," + Input.mousePosition.y + "," + Input.mousePosition.z);
//timer += Time.deltaTime;
}
public override void Close()
{
//base.Close();
DestroyImmediate(this.gameObject);
}
class LineItem
{
public List<Vector2d> Points { get; set; }
public GameObject LineObject { get; set; }
public GameObject BeginMarker { get; set; }
public NearRouteModel Model { get; set; }
public Item Item { get; set; }
private bool _Selected = false;
public bool Selected {
get
{
return _Selected;
}
set
{
_Selected = value;
Item.Selected(value);
var lineRender = LineObject.GetComponent<LineRenderer>();
if (value)
{
lineRender.startColor = lineRender.endColor = Color.white;
}
else
{
lineRender.startColor = lineRender.endColor = Utils.HexToColor("F93086");
}
}
}
public void Destroy()
{
//Debug.Log($"销毁{ item.Key }, { item.Value.Item != null }");
LineObject.Destroy();
BeginMarker.Destroy();
Item.gameObject.Destroy();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 221b4141e3d502548ac3b7fe1b3245d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -17,7 +17,10 @@ public class DeviceController : PFUIPanel
private Sprite ant1;
protected override void Awake()
{
base.Awake();
AntConnector.Instance();
Debug.Log("device awake");
}
// Start is called before the first frame update
@@ -30,10 +33,11 @@ public class DeviceController : PFUIPanel
// UIManager.ShowHomePanel();
//});
mReturnBtn = this.transform.Find("ReturnBtn").GetComponent<Button>();
mReturnBtn = this.transform.Find("CloseBtn").GetComponent<Button>();
UIManager.AddEvent(mReturnBtn.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
{
UIManager.ShowHomePanel();
//UIManager.ShowHomePanel();
UIManager.CloseModal();
}));
var bg = this.transform.Find("Status").Find("Bg");
@@ -41,7 +45,10 @@ public class DeviceController : PFUIPanel
ant0 = Resources.Load<Sprite>("Images/ANT+_0");
ant1 = Resources.Load<Sprite>("Images/ANT+_1");
Debug.Log("device start");
}
// Update is called once per frame
void Update()
@@ -1,9 +1,11 @@
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 System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
@@ -35,35 +37,33 @@ public class HomeController : PFUIPanel
// toast.GetComponent<RectTransform>().position = new Vector3(Screen.width / 2, Screen.height / 2, 0);
// toast.transform.parent = parent;
//}
if (App.CurrentUser != null)
{
GetSummary();
}
//if (More != null)
//{
// More.onClick.AddListener(MoreFunc);
//}
BtnRide.onClick.AddListener(GoRide);
var wifi = this.transform.Find("MainToolContainer").Find("Wifi");
UIManager.AddEvent(wifi.gameObject, EventTriggerType.PointerClick, x =>
{
Debug.Log("click wifi");
UIManager.ShowDevicePanel();
});
var avatar = userInfo.Find("Avatar");
var avatar = userInfo.Find("Avatar").GetComponent<RawImage>();
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
var rect = ((RectTransform)avatar.transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
avatar.material = material;
UIManager.AddEvent(avatar.gameObject, EventTriggerType.PointerClick, x =>
{
UIManager.ShowUserInfoPanel();
});
if (App.CurrentUser == null)
UIManager.AddEvent(userInfo.Find("BtnMore").gameObject, EventTriggerType.PointerClick, x =>
{
Login();
}
UIManager.ShowAlert("test");
});
GetSummary();
}
private async void Login()
private async Task Login()
{
var result = await new UserApi().Login("13115011550", "laozhong", "");
App.CurrentUser = result.data;
@@ -91,31 +91,36 @@ public class HomeController : PFUIPanel
}
void SetCurrentUser()
void SetCurrentUser(SummaryResultModel summary)
{
userInfo.Find("NickName").GetComponent<Text>().text = App.CurrentUser.Nickname;
userInfo.Find("GroupTop").Find("FtpContainer").Find("FtpValue").GetComponent<Text>().text = App.CurrentUser.FTP.ToString();
userInfo.Find("GroupTop").Find("WeightContainer").Find("WeightValue").GetComponent<Text>().text = App.CurrentUser.Weight.ToString();
userInfo.Find("GroupTop").Find("WKGContainer").Find("WKGValue").GetComponent<Text>().text = $"{App.CurrentUser.Weight}kg/{App.CurrentUser.BicycleWeight}kg";
//userInfo.Find("CaloriesContainer").Find("CaloriesValue").GetComponent<Text>().text = App.CurrentUser.Carlories;
//userInfo.Find("KMContainer").Find("KMValue").GetComponent<Text>().text = App.CurrentUser.Distance.ToString("#0.00");
//userInfo.Find("ClimbContainer").Find("ClimbValue").GetComponent<Text>().text = App.CurrentUser.Climb;
userInfo.Find("CaloriesContainer").Find("CaloriesValue").GetComponent<Text>().text = summary.Kcal;
userInfo.Find("KMContainer").Find("KMValue").GetComponent<Text>().text = summary.TotalDistance.ToString();
userInfo.Find("ClimbContainer").Find("ClimbValue").GetComponent<Text>().text = summary.TotalClimb;
//var user = ConfigHelper.CurrentUser;
//Ftp.text = user.FTP.ToString();
//Ftp.text = summary.Ftp.ToString();
//Weight.text = user.Weight.ToString();
//WKG.text = $"{user.Weight}KG/{user.BicycleWeight}KG";
//NickName.text = user.Nickname;
//Utils.DisplayImage(StartCoroutine, userInfo.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.Avatar);
Utils.DisplayImage(StartCoroutine, userInfo.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.WxHeadImg);
}
void GetSummary()
async void GetSummary()
{
if (App.CurrentUser == null)
{
await Login();
}
var res = ConfigHelper.userApi.GetSummary();
if (res.result)
{
//App.CurrentUser.Distance = res.data.TotalDistance;
//App.CurrentUser.Climb = res.data.TotalClimb;
//App.CurrentUser.Carlories = res.data.Kcal;
SetCurrentUser();
SetCurrentUser(res.data);
//Climb.text = $"{res.data.TotalClimb.ToString()}M";
//Calories.text = $"{res.data.Kcal.ToString()}KCAL";
//Calories.text = res.data.
@@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
@@ -22,6 +22,7 @@ public class MapListController : PFUIPanel
[HideInInspector] public string hard = "全部";
private Button returnBtn;
GameObject btnMapMode;
public GameObject Content {
get
{
@@ -35,6 +36,11 @@ public class MapListController : PFUIPanel
//{
// hardSelector.onValueChanged.AddListener(ChangeHard);
//}
btnMapMode = this.transform.Find("BtnMapMode").gameObject;
UIManager.AddEvent(btnMapMode, EventTriggerType.PointerClick, (e) =>
{
UIManager.ShowBigMapPanel();
});
if (content!=null)
{
//var transform = content.transform.GetComponent<RectTransform>();