完成大地图主要界面

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

+6 -1
View File
@@ -78,7 +78,12 @@ namespace Assets.Scripts.Apis
protected async Task<byte[]> GetAsync(string url)
{
AddLanguage();
var httpResponseMessage = await httpClient.GetAsync(ConfigHelper.Host + url, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);
var _url = url;
if(_url.IndexOf("http") == -1)
{
_url = ConfigHelper.Host + url;
}
var httpResponseMessage = await httpClient.GetAsync(_url, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);
if (!httpResponseMessage.IsSuccessStatusCode)
{
return null;
+18 -1
View File
@@ -1,4 +1,5 @@
using Assets.Scenes.Ride.Scripts.Model;
using Assets.Scenes.Ride.Scripts.Model;
using Assets.Scripts.Apis.Models;
using System;
using System.Collections.Generic;
@@ -87,5 +88,21 @@ namespace Assets.Scripts.Apis
return null;
}
public async Task<JsonResult<List<NearRouteModel>>> GetNearRouteAsync(float lat, float lng, float zoom, string bounds)
{
var res = await GetAsync<JsonResult<List<NearRouteModel>>>($"/Map/GetNearRoute?lat={ lat }&lng={ lng }&zoom={zoom}&bounds={ bounds }");
//var result = System.Text.Encoding.UTF8.GetString(res);
return res;
}
public async Task<string> GetDetailsAsync(int[] ids)
{
var res = await GetAsync("/Map/GetDetails?ids=" + string.Join(",", ids));
return Encoding.UTF8.GetString(res);
}
}
}
+21
View File
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Apis
{
public class MapBoxApi: ApiBase
{
public string GetAddressInfo(string address)
{
var url = $"https://a.tiles.mapbox.com/geocoding/v5/mapbox.places/{ address }.json?access_token={ App.MapBoxAccessToken }";
var res = Get(url);
//return System.Text.Encoding.UTF8.GetString(res);
return res;
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 969b87ed3066bec4a9981a69d7dfb8e4
guid: 97ae508c230356844bf73819c3e1b451
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Apis.Models
{
public class NearRouteModel
{
public int Id { get; set; }
public string Name { get; set; }
public string DirPath { get; set; }
public string CreateTime { get; set; }
public int UserId { get; set; }
public double Distance { get; set; }
public double EleDifference { get; set; }
public double TotalClimb { get; set; }
public double AverageGrade { get; set; }
public string CoverImage { get; set; }
public string ElevationPath { get; set; }
public List<double> Point { get; set; }
public string Address { get; set; }
/// <summary>
/// 骑行热度
/// </summary>
public int TheHeat { get; set; }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df1953478a7c274448dcde606e6718e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+9
View File
@@ -13,4 +13,13 @@ public static class App
public static UserResultModel CurrentUser { get; set; }
public static string WxAppId = "wx9e8ca734e024f084";
public static string WxAppSecret = "906abafb2a18bc7a66ccfa5550f859b6";
public static string MapBoxAccessToken => "pk.eyJ1IjoiYW5keXNqdCIsImEiOiJja2ZhajE5OGwwamRiMnltcW96bHk0ZWFuIn0.GvKanc6UveWSvIjS9HfBPA";
/// <summary>
/// 场景跳转传值
/// Name,MapListPanel
/// xxx,bbb
/// </summary>
public static System.Collections.Generic.Dictionary<string, string> MainSceneParam = new Dictionary<string, string>();
}
+23 -6
View File
@@ -1,24 +1,41 @@
using System.Collections;
using Mapbox.Examples;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainController : MonoBehaviour
{
[SerializeField]GameObject root;
private void Awake()
{
}
// Start is called before the first frame update
void Start()
{
UIManager.Instance.Root = root;
UIManager.Instance.MainPanel = this.transform.Find("Panel").GetComponent<PFUIPanel>();
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").GetComponent<PFUIPanel>();
//MainMenu.transform.Find("Home").GetComponent<Button>().onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
UIManager.ShowHomePanel();
//UIManager.ShowUserInfoPanel();
//UIManager.ShowEditUserPanel();
if (App.MainSceneParam.ContainsKey("Name"))
{
if(App.MainSceneParam["Name"] == "MapListPanel")
{
UIManager.ShowMapListPanel();
}
}
else
{
UIManager.ShowHomePanel();
//UIManager.ShowUserInfoPanel();
//UIManager.ShowEditUserPanel();
//UIManager.ShowBigMapPanel();
}
}
// Update is called once per frame
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.Control
{
[RequireComponent(typeof(Button))]
public class PFUIRoundButton : PFUIComponentBase
{
private Image image;
private Text text;
protected void Awake()
{
image = gameObject.GetComponent<Image>();
text = this.transform.Find("Text").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));
image.material = material;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a96e12724c645a498af7c9434c9170f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+4 -1
View File
@@ -21,9 +21,10 @@ namespace Assets.Scripts.UI.Control
[SerializeField] Type mType;
private Image image;
private Text text;
public Text text;
private Texture2D cursor;
private Outline outline;
protected void Awake()
{
outline = this.GetComponent<Outline>();
@@ -65,6 +66,8 @@ namespace Assets.Scripts.UI.Control
case Type.Border:
{
outline.enabled = true;
outline.effectColor = ConvertColor("#474759");
image.color = ConvertColor("#3D3E4D");
}
break;
+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()
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3083a61e316cc854fb0fa28e7fd7e237
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+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>();
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 332b0c4457df8c643a527441f5be862e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d3d31d70cf492e34096ffdc82042d396
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,565 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
#if TMP_PRESENT
using System.Collections.Generic;
using TMPro;
#if UNITY_EDITOR
using UnityEditor;
using System.IO;
using System.Linq;
#endif
#endif
namespace Assets.Scripts.UI.UIEffect.Common
{
/// <summary>
/// Base class for effects that modify the generated Mesh.
/// It works well not only for standard Graphic components (Image, RawImage, Text, etc.) but also for TextMeshPro and TextMeshProUGUI.
/// </summary>
[ExecuteInEditMode]
public abstract class BaseMeshEffect : UIBehaviour, IMeshModifier
{
//################################
// Constant or Static Members.
//################################
#if TMP_PRESENT
static readonly List<Vector2> s_Uv0 = new List<Vector2> (4096);
static readonly List<Vector2> s_Uv1 = new List<Vector2> (4096);
#if UNITY_2017_1_OR_NEWER
static readonly List<Vector2> s_Uv2 = new List<Vector2> (4096);
static readonly List<Vector2> s_Uv3 = new List<Vector2> (4096);
#endif
static readonly List<Vector3> s_Vertices = new List<Vector3> (4096);
static readonly List<int> s_Indices = new List<int> (4096);
static readonly List<Vector3> s_Normals = new List<Vector3> (4096);
static readonly List<Vector4> s_Tangents = new List<Vector4> (4096);
static readonly List<Color32> s_Colors = new List<Color32> (4096);
static readonly VertexHelper s_VertexHelper = new VertexHelper ();
static readonly List<TMP_SubMeshUI> s_SubMeshUIs = new List<TMP_SubMeshUI> (4096);
static readonly List<Mesh> s_Meshes = new List<Mesh> (4096);
static readonly List<UIVertex> s_UIVertices = new List<UIVertex> (4096);
static readonly List<BaseMeshEffect> s_TmpEffects = new List<BaseMeshEffect>(4);
#endif
static readonly Material[] s_EmptyMaterials = new Material[0];
//################################
// Public Members.
//################################
/// <summary>
/// The Graphic attached to this GameObject.
/// </summary>
public Graphic graphic { get { Initialize(); return _graphic; } }
/// <summary>
/// The CanvasRenderer attached to this GameObject.
/// </summary>
public CanvasRenderer canvasRenderer { get { Initialize(); return _canvasRenderer; } }
#if TMP_PRESENT
/// <summary>
/// The TMP_Text attached to this GameObject.
/// </summary>
public TMP_Text textMeshPro { get { Initialize (); return _textMeshPro; } }
#endif
/// <summary>
/// The RectTransform attached to this GameObject.
/// </summary>
public RectTransform rectTransform { get { Initialize(); return _rectTransform; } }
#if UNITY_5_6_OR_NEWER
/// <summary>
/// Additional canvas shader channels to use this component.
/// </summary>
public virtual AdditionalCanvasShaderChannels requiredChannels { get { return AdditionalCanvasShaderChannels.None; } }
#endif
/// <summary>
/// Is TextMeshPro or TextMeshProUGUI attached to this GameObject?
/// </summary>
public bool isTMPro
{
get
{
#if TMP_PRESENT
return textMeshPro != null;
#else
return false;
#endif
}
}
/// <summary>
/// The material for rendering.
/// </summary>
public virtual Material material
{
get
{
#if TMP_PRESENT
if (textMeshPro)
{
return textMeshPro.fontSharedMaterial;
}
else
#endif
if (graphic)
{
return graphic.material;
}
else
{
return null;
}
}
set
{
#if TMP_PRESENT
if (textMeshPro)
{
textMeshPro.fontSharedMaterial = value;
}
else
#endif
if (graphic)
{
graphic.material = value;
}
}
}
public virtual Material[] materials
{
get
{
#if TMP_PRESENT
if (textMeshPro)
{
return textMeshPro.fontSharedMaterials ?? s_EmptyMaterials;
}
else
#endif
if (graphic)
{
_materials[0] = graphic.material;
return _materials;
}
else
{
return s_EmptyMaterials;
}
}
}
/// <summary>
/// Call used to modify mesh. (legacy)
/// </summary>
/// <param name="mesh">Mesh.</param>
public virtual void ModifyMesh(Mesh mesh)
{
}
/// <summary>
/// Call used to modify mesh.
/// </summary>
/// <param name="vh">VertexHelper.</param>
public virtual void ModifyMesh(VertexHelper vh)
{
}
/// <summary>
/// Mark the vertices as dirty.
/// </summary>
public virtual void SetVerticesDirty()
{
#if TMP_PRESENT
if (textMeshPro)
{
foreach (var info in textMeshPro.textInfo.meshInfo)
{
var mesh = info.mesh;
if (mesh)
{
mesh.Clear ();
mesh.vertices = info.vertices;
mesh.uv = info.uvs0;
mesh.uv2 = info.uvs2;
mesh.colors32 = info.colors32;
mesh.normals = info.normals;
mesh.tangents = info.tangents;
mesh.triangles = info.triangles;
}
}
if (canvasRenderer)
{
canvasRenderer.SetMesh (textMeshPro.mesh);
GetComponentsInChildren (false, s_SubMeshUIs);
foreach (var sm in s_SubMeshUIs)
{
sm.canvasRenderer.SetMesh (sm.mesh);
}
s_SubMeshUIs.Clear ();
}
textMeshPro.havePropertiesChanged = true;
}
else
#endif
if (graphic)
{
graphic.SetVerticesDirty();
}
}
public void ShowTMProWarning(Shader shader, Shader mobileShader, Shader spriteShader, System.Action<Material> onCreatedMaterial)
{
#if UNITY_EDITOR && TMP_PRESENT
if(!textMeshPro || !textMeshPro.fontSharedMaterial)
{
return;
}
// Is the material preset for dissolve?
Material m = textMeshPro.fontSharedMaterial;
if (m.shader != shader && m.shader != mobileShader)
{
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.HelpBox (string.Format("{0} requires '{1}' or '{2}' as a shader for material preset.", GetType().Name, shader.name, mobileShader.name), MessageType.Warning);
if(GUILayout.Button ("Fix"))
{
var correctShader = m.shader.name.Contains ("Mobile") ? mobileShader : shader;
textMeshPro.fontSharedMaterial = ModifyTMProMaterialPreset (m, correctShader, onCreatedMaterial);
}
EditorGUILayout.EndHorizontal ();
return;
}
// Is the sprite asset for dissolve?
TMP_SpriteAsset spriteAsset = textMeshPro.spriteAsset ?? TMP_Settings.GetSpriteAsset ();
// Sprite asset might not exist at all
if(spriteAsset == null) {
return;
}
m = spriteAsset.material;
if (m && m.shader != spriteShader && textMeshPro.richText && textMeshPro.text.Contains("<sprite="))
{
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.HelpBox (string.Format ("{0} requires '{1}' as a shader for sprite asset.", GetType().Name,spriteShader.name), MessageType.Warning);
if (GUILayout.Button ("Fix"))
{
GetComponentsInChildren<TMP_SubMesh> ().Select (x => x.gameObject).ToList ().ForEach (DestroyImmediate);
GetComponentsInChildren<TMP_SubMeshUI> ().Select (x => x.gameObject).ToList ().ForEach (DestroyImmediate);
textMeshPro.spriteAsset = ModifyTMProSpriteAsset (m, spriteShader, onCreatedMaterial);
}
EditorGUILayout.EndHorizontal ();
return;
}
}
Material ModifyTMProMaterialPreset (Material baseMaterial, Shader shader, System.Action<Material> onCreatedMaterial)
{
string path = AssetDatabase.GetAssetPath (baseMaterial);
string filename = Path.GetFileNameWithoutExtension (path) + " (" + GetType ().Name + ")";
Material mat = Resources.Load<Material> (TMP_Settings.defaultFontAssetPath + filename);
if (!mat)
{
mat = new Material (baseMaterial)
{
shaderKeywords = baseMaterial.shaderKeywords,
shader = shader,
};
onCreatedMaterial (mat);
AssetDatabase.CreateAsset (mat, Path.GetDirectoryName (path) + "/" + filename + ".mat");
EditorUtility.FocusProjectWindow ();
EditorGUIUtility.PingObject (mat);
}
else
{
mat.shader = shader;
}
EditorUtility.SetDirty (mat);
return mat;
}
TMP_SpriteAsset ModifyTMProSpriteAsset (Material baseMaterial, Shader shader, System.Action<Material> onCreatedMaterial)
{
string path = AssetDatabase.GetAssetPath (baseMaterial);
string filename = Path.GetFileNameWithoutExtension (path) + " (" + this.GetType ().Name + ")";
TMP_SpriteAsset spriteAsset = Resources.Load<TMP_SpriteAsset> (TMP_Settings.defaultSpriteAssetPath + filename);
if (!spriteAsset)
{
AssetDatabase.CopyAsset (path, Path.GetDirectoryName (path) + "/" + filename + ".mat");
spriteAsset = Resources.Load<TMP_SpriteAsset> (TMP_Settings.defaultSpriteAssetPath + filename);
spriteAsset.material.shader = shader;
spriteAsset.material.name = shader.name;
onCreatedMaterial (spriteAsset.material);
EditorUtility.FocusProjectWindow ();
EditorGUIUtility.PingObject (spriteAsset);
}
else
{
spriteAsset.material.shader = shader;
}
EditorUtility.SetDirty (spriteAsset);
return spriteAsset;
#endif
}
//################################
// Protected Members.
//################################
/// <summary>
/// Should the effect modify the mesh directly for TMPro?
/// </summary>
protected virtual bool isLegacyMeshModifier { get { return false; } }
protected virtual void Initialize()
{
if (!_initialized)
{
_initialized = true;
_graphic = _graphic ?? GetComponent<Graphic>();
_canvasRenderer = _canvasRenderer ?? GetComponent<CanvasRenderer>();
_rectTransform = _rectTransform ?? GetComponent<RectTransform>();
#if TMP_PRESENT
_textMeshPro = _textMeshPro ?? GetComponent<TMP_Text> ();
#endif
}
}
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
_initialized = false;
SetVerticesDirty();
#if TMP_PRESENT
if (textMeshPro)
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Add (OnTextChanged);
}
#endif
#if UNITY_EDITOR && TMP_PRESENT
if (graphic && textMeshPro)
{
GraphicRebuildTracker.TrackGraphic (graphic);
}
#endif
#if UNITY_5_6_OR_NEWER
if (graphic)
{
AdditionalCanvasShaderChannels channels = requiredChannels;
var canvas = graphic.canvas;
if (canvas && (canvas.additionalShaderChannels & channels) != channels)
{
Debug.LogWarningFormat(this, "Enable {1} of Canvas.additionalShaderChannels to use {0}.", GetType().Name, channels);
}
}
#endif
}
/// <summary>
/// This function is called when the behaviour becomes disabled () or inactive.
/// </summary>
protected override void OnDisable()
{
#if TMP_PRESENT
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove (OnTextChanged);
#endif
SetVerticesDirty();
#if UNITY_EDITOR && TMP_PRESENT
if (graphic && textMeshPro)
{
GraphicRebuildTracker.UnTrackGraphic (graphic);
}
#endif
}
/// <summary>
/// LateUpdate is called every frame, if the Behaviour is enabled.
/// </summary>
protected virtual void LateUpdate()
{
#if TMP_PRESENT
if (textMeshPro)
{
if (textMeshPro.havePropertiesChanged || _isTextMeshProActive != textMeshPro.isActiveAndEnabled)
{
SetVerticesDirty ();
}
_isTextMeshProActive = textMeshPro.isActiveAndEnabled;
}
#endif
}
/// <summary>
/// Callback for when properties have been changed by animation.
/// </summary>
protected override void OnDidApplyAnimationProperties()
{
SetVerticesDirty();
}
#if UNITY_EDITOR
/// <summary>
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
/// </summary>
protected override void OnValidate()
{
SetVerticesDirty();
}
#endif
//################################
// Private Members.
//################################
bool _initialized;
CanvasRenderer _canvasRenderer;
RectTransform _rectTransform;
Graphic _graphic;
Material[] _materials = new Material[1];
#if TMP_PRESENT
bool _isTextMeshProActive;
TMP_Text _textMeshPro;
/// <summary>
/// Called when any TextMeshPro generated the mesh.
/// </summary>
/// <param name="obj">TextMeshPro object.</param>
void OnTextChanged (Object obj)
{
// Skip if the object is different from the current object or the text is empty.
var textInfo = textMeshPro.textInfo;
if (textMeshPro != obj || textInfo.characterCount - textInfo.spaceCount <= 0)
{
return;
}
GetComponents<BaseMeshEffect>(s_TmpEffects);
for (int i = 0; i < s_TmpEffects.Count; i++)
{
if (s_TmpEffects[i].enabled)
{
if (s_TmpEffects[i] == this)
break;
else
return;
}
}
// Collect the meshes.
s_Meshes.Clear ();
foreach (var info in textInfo.meshInfo)
{
s_Meshes.Add (info.mesh);
}
// Modify the meshes.
foreach (var e in s_TmpEffects)
{
if (!e.enabled)
continue;
if (e.isLegacyMeshModifier)
{
// Legacy mode: Modify the meshes directly.
foreach (var m in s_Meshes)
{
if (m)
{
e.ModifyMesh(m);
}
}
}
else
{
// Convert meshes to VertexHelpers and modify them.
foreach (var m in s_Meshes)
{
if (m)
{
FillVertexHelper(s_VertexHelper, m);
e.ModifyMesh(s_VertexHelper);
s_VertexHelper.FillMesh(m);
}
}
}
}
// Set the modified meshes to the CanvasRenderers (for UI only).
if (canvasRenderer)
{
canvasRenderer.SetMesh (textMeshPro.mesh);
GetComponentsInChildren (false, s_SubMeshUIs);
foreach (var sm in s_SubMeshUIs)
{
sm.canvasRenderer.SetMesh (sm.mesh);
}
s_SubMeshUIs.Clear ();
}
// Clear.
s_Meshes.Clear ();
}
void FillVertexHelper (VertexHelper vh, Mesh mesh)
{
vh.Clear ();
mesh.GetVertices (s_Vertices);
mesh.GetColors (s_Colors);
mesh.GetUVs (0, s_Uv0);
mesh.GetUVs (1, s_Uv1);
mesh.GetNormals (s_Normals);
mesh.GetTangents (s_Tangents);
mesh.GetIndices (s_Indices, 0);
#if UNITY_2017_1_OR_NEWER
mesh.GetUVs (2, s_Uv2);
mesh.GetUVs (3, s_Uv3);
bool useUv2 = 0 < s_Uv2.Count;
bool useUv3 = 0 < s_Uv3.Count;
#endif
s_UIVertices.Clear();
UIVertex v = default(UIVertex);
for (int i = 0; i < s_Vertices.Count; i++)
{
v.position = s_Vertices[i];
v.color = s_Colors[i];
v.uv0 = s_Uv0[i];
v.uv1 = s_Uv1[i];
#if UNITY_2017_1_OR_NEWER
if (useUv2 && i < s_Uv2.Count)
v.uv2 = s_Uv2[i];
if (useUv3 && i < s_Uv3.Count)
v.uv3 = s_Uv3[i];
#endif
v.normal = s_Normals[i];
v.tangent = s_Tangents[i];
s_UIVertices.Add(v);
}
s_VertexHelper.AddUIVertexStream(s_UIVertices, s_Indices);
}
#endif
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c52a957894a7bbf418d6b190bd7816a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+386
View File
@@ -0,0 +1,386 @@
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// UIGradient.
/// </summary>
[DisallowMultipleComponent]
[AddComponentMenu("UI/MeshEffectForTextMeshPro/UIGradient", 101)]
public class UIGradient : Assets.Scripts.UI.UIEffect.Common.BaseMeshEffect
{
//################################
// Constant or Static Members.
//################################
/// <summary>
/// Gradient direction.
/// </summary>
public enum Direction
{
Horizontal,
Vertical,
Angle,
Diagonal,
}
/// <summary>
/// Gradient space for Text.
/// </summary>
public enum GradientStyle
{
Rect,
Fit,
Split,
}
//################################
// Serialize Members.
//################################
[Tooltip("Gradient Direction.")]
[SerializeField] Direction m_Direction;
[Tooltip("Color1: Top or Left.")]
[SerializeField] Color m_Color1 = Color.white;
[Tooltip("Color2: Bottom or Right.")]
[SerializeField] Color m_Color2 = Color.white;
[Tooltip("Color3: For diagonal.")]
[SerializeField] Color m_Color3 = Color.white;
[Tooltip("Color4: For diagonal.")]
[SerializeField] Color m_Color4 = Color.white;
[Tooltip("Gradient rotation.")]
[SerializeField] [Range(-180, 180)] float m_Rotation;
[Tooltip("Gradient offset for Horizontal, Vertical or Angle.")]
[SerializeField] [Range(-1, 1)] float m_Offset1;
[Tooltip("Gradient offset for Diagonal.")]
[SerializeField] [Range(-1, 1)] float m_Offset2;
[Tooltip("Gradient style for Text.")]
[SerializeField] GradientStyle m_GradientStyle;
[Tooltip("Color space to correct color.")]
[SerializeField] ColorSpace m_ColorSpace = ColorSpace.Uninitialized;
[Tooltip("Ignore aspect ratio.")]
[SerializeField] bool m_IgnoreAspectRatio = true;
//################################
// Public Members.
//################################
public Graphic targetGraphic { get { return base.graphic; } }
/// <summary>
/// Gradient Direction.
/// </summary>
public Direction direction
{
get { return m_Direction; }
set
{
if (m_Direction != value)
{
m_Direction = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Color1: Top or Left.
/// </summary>
public Color color1
{
get { return m_Color1; }
set
{
if (m_Color1 != value)
{
m_Color1 = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Color2: Bottom or Right.
/// </summary>
public Color color2
{
get { return m_Color2; }
set
{
if (m_Color2 != value)
{
m_Color2 = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Color3: For diagonal.
/// </summary>
public Color color3
{
get { return m_Color3; }
set
{
if (m_Color3 != value)
{
m_Color3 = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Color4: For diagonal.
/// </summary>
public Color color4
{
get { return m_Color4; }
set
{
if (m_Color4 != value)
{
m_Color4 = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Gradient rotation.
/// </summary>
public float rotation
{
get
{
return m_Direction == Direction.Horizontal ? -90
: m_Direction == Direction.Vertical ? 0
: m_Rotation;
}
set
{
if (!Mathf.Approximately(m_Rotation, value))
{
m_Rotation = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Gradient offset for Horizontal, Vertical or Angle.
/// </summary>
public float offset
{
get { return m_Offset1; }
set
{
if (m_Offset1 != value)
{
m_Offset1 = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Gradient offset for Diagonal.
/// </summary>
public Vector2 offset2
{
get { return new Vector2(m_Offset2, m_Offset1); }
set
{
if (m_Offset1 != value.y || m_Offset2 != value.x)
{
m_Offset1 = value.y;
m_Offset2 = value.x;
SetVerticesDirty();
}
}
}
/// <summary>
/// Gradient style for Text.
/// </summary>
public GradientStyle gradientStyle
{
get { return m_GradientStyle; }
set
{
if (m_GradientStyle != value)
{
m_GradientStyle = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Color space to correct color.
/// </summary>
public ColorSpace colorSpace
{
get { return m_ColorSpace; }
set
{
if (m_ColorSpace != value)
{
m_ColorSpace = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Ignore aspect ratio.
/// </summary>
public bool ignoreAspectRatio
{
get { return m_IgnoreAspectRatio; }
set
{
if (m_IgnoreAspectRatio != value)
{
m_IgnoreAspectRatio = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Call used to modify mesh.
/// </summary>
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive())
return;
// Gradient space.
Rect rect = default(Rect);
UIVertex vertex = default(UIVertex);
if (m_GradientStyle == GradientStyle.Rect)
{
// RectTransform.
rect = graphic.rectTransform.rect;
}
else if (m_GradientStyle == GradientStyle.Split)
{
// Each characters.
rect.Set(0, 0, 1, 1);
}
else if (m_GradientStyle == GradientStyle.Fit)
{
// Fit to contents.
rect.xMin = rect.yMin = float.MaxValue;
rect.xMax = rect.yMax = float.MinValue;
for (int i = 0; i < vh.currentVertCount; i++)
{
vh.PopulateUIVertex(ref vertex, i);
rect.xMin = Mathf.Min(rect.xMin, vertex.position.x);
rect.yMin = Mathf.Min(rect.yMin, vertex.position.y);
rect.xMax = Mathf.Max(rect.xMax, vertex.position.x);
rect.yMax = Mathf.Max(rect.yMax, vertex.position.y);
}
}
// Gradient rotation.
float rad = rotation * Mathf.Deg2Rad;
Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad));
if (!m_IgnoreAspectRatio && Direction.Angle <= m_Direction)
{
dir.x *= rect.height / rect.width;
dir = dir.normalized;
}
// Calculate vertex color.
Color color;
Vector2 nomalizedPos;
Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y); // Get local matrix.
for (int i = 0; i < vh.currentVertCount; i++)
{
vh.PopulateUIVertex(ref vertex, i);
// Normalize vertex position by local matrix.
if (m_GradientStyle == GradientStyle.Split)
{
// Each characters.
nomalizedPos = localMatrix * s_SplitedCharacterPosition[i % 4] + offset2;
}
else
{
nomalizedPos = localMatrix * vertex.position + offset2;
}
// Interpolate vertex color.
if (direction == Direction.Diagonal)
{
color = Color.LerpUnclamped(
Color.LerpUnclamped(m_Color1, m_Color2, nomalizedPos.x),
Color.LerpUnclamped(m_Color3, m_Color4, nomalizedPos.x),
nomalizedPos.y);
}
else
{
color = Color.LerpUnclamped(m_Color2, m_Color1, nomalizedPos.y);
}
// Correct color.
vertex.color *= (m_ColorSpace == ColorSpace.Gamma) ? color.gamma
: (m_ColorSpace == ColorSpace.Linear) ? color.linear
: color;
vh.SetUIVertex(vertex, i);
}
}
//################################
// Private Members.
//################################
static readonly Vector2[] s_SplitedCharacterPosition = { Vector2.up, Vector2.one, Vector2.right, Vector2.zero };
/// <summary>
/// Matrix2x3.
/// </summary>
struct Matrix2x3
{
public float m00, m01, m02, m10, m11, m12;
public Matrix2x3(Rect rect, float cos, float sin)
{
const float center = 0.5f;
float dx = -rect.xMin / rect.width - center;
float dy = -rect.yMin / rect.height - center;
m00 = cos / rect.width;
m01 = -sin / rect.height;
m02 = dx * cos - dy * sin + center;
m10 = sin / rect.width;
m11 = cos / rect.height;
m12 = dx * sin + dy * cos + center;
}
public static Vector2 operator *(Matrix2x3 m, Vector2 v)
{
return new Vector2(
(m.m00 * v.x) + (m.m01 * v.y) + m.m02,
(m.m10 * v.x) + (m.m11 * v.y) + m.m12
);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7245fe6cb36dc7b4e921e9ae44200f43
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+40 -12
View File
@@ -20,6 +20,8 @@ public class UIManager : MonoBehaviour
}
}
public GameObject Root;
private HomeController mHomePanel;
public HomeController HomePanel
{
@@ -46,7 +48,7 @@ public class UIManager : MonoBehaviour
return this.GetPanelInstance("DevicePanel", ref this.mDeviceController);
}
}
private MapListController mMapListController;
public MapListController MapListPanel
{
@@ -98,13 +100,13 @@ public class UIManager : MonoBehaviour
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private T GetPanelInstance<T>(string prefabName, ref T internalComponent)
@@ -157,12 +159,27 @@ public class UIManager : MonoBehaviour
}
else
{
if(prePanel != null)
var root = UIManager.Instance.Root;
for (int i = 0; i < root.transform.childCount; i++)
{
var panel1 = root.transform.GetChild(i).GetComponent<PFUIPanel>();
if (panel1 != null)
{
panel1.Close();
}
}
if (prePanel != null)
{
prePanel.Close();
}
prePanel = panelToShow;
}
if (parent != null && parent.IsActive() == false)
{
parent.gameObject.SetActive(true);
}
//foreach (Transform child in parent.transform)
//{
// //GameObject.Destroy(child);
@@ -186,7 +203,7 @@ public class UIManager : MonoBehaviour
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
}
panelToShow.transform.localScale = parent.transform.localScale;
panelToShow.transform.localScale = parent.transform.localScale;
}
@@ -207,7 +224,7 @@ public class UIManager : MonoBehaviour
public static void ShowDevicePanel()
{
UIManager.Show(UIManager.Instance.DevicePanel, UIManager.Instance.MainPanel);
UIManager.Show(UIManager.Instance.DevicePanel, null, true);
}
public static void ShowEditUserPanel()
@@ -218,7 +235,7 @@ public class UIManager : MonoBehaviour
public static void ShowLoadingDialogBox()
{
}
public static void ShowMapListPanel()
public static void ShowMapListPanel()
{
UIManager.Show(UIManager.Instance.MapListPanel, UIManager.Instance.MainPanel);
}
@@ -229,6 +246,16 @@ public class UIManager : MonoBehaviour
UIManager.Show(UIManager.Instance.MapDetailPanel, UIManager.Instance.MainPanel);
}
public static void ShowBigMapPanel()
{
UIManager.Instance.MainPanel.gameObject.SetActive(false);
var obj = Resources.Load("UI/Prefab/Panel/BigMapPanel");
//var root = UIManager.Instance.MainPanel.transform.parent.parent;
var bigMap = (GameObject)Instantiate(obj, UIManager.Instance.Root.transform);
//prePanel = bigMap.GetComponent<PFUIPanel>();
}
public static void AddEvent(GameObject gameObject, EventTriggerType eventTriggerType, UnityAction<BaseEventData> call)
{
EventTrigger et = gameObject.GetComponent<EventTrigger>();
@@ -256,18 +283,18 @@ public class UIManager : MonoBehaviour
//UIManager.Instance.ModalsPanel.transform.DetachChildren();
//UIManager.Instance.ModalsPanel.transform.childCount
for (int i = 0; i < 1; i++)
//for (int i = 0; i < UIManager.Instance.ModalsPanel.transform.childCount; i++)
{
var obj = UIManager.Instance.ModalsPanel.transform.GetChild(i);
var obj = UIManager.Instance.ModalsPanel.transform.GetChild(UIManager.Instance.ModalsPanel.transform.childCount - 1);
obj.gameObject.SetActive(false);
DestroyImmediate(obj.gameObject);
//DestroyImmediate(obj.gameObject);
}
}
public Alert alert = null;
public static void ShowAlert(string msg)
{
if(UIManager.Instance == null)
if (UIManager.Instance == null)
{
return;
}
@@ -278,7 +305,8 @@ public class UIManager : MonoBehaviour
UIManager.Instance.alert.SetText(msg);
UIManager.Show(UIManager.Instance.alert, null, true);
}
else {
else
{
UIManager.Instance.alert.Show();
UIManager.Instance.alert.SetText(msg);
}
+14
View File
@@ -91,5 +91,19 @@ namespace Assets.Scripts
byte b = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
return new Color32(r, g, b, byte.MaxValue);
}
/// <summary>
/// Generate random digit code
/// </summary>
/// <param name="length">Length</param>
/// <returns>Result string</returns>
public static string GenerateRandomDigitCode(int length)
{
var random = new System.Random();
string str = string.Empty;
for (int i = 0; i < length; i++)
str = String.Concat(str, random.Next(10).ToString());
return str;
}
}
}