完成大地图主要界面
This commit is contained in:
1 parent
5156473bb2
commit
d22eecd133
78 files changed
+8684
-6941
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user