适配c2;新版设计稿;对战切换手势;主逻辑接通;使用think的阻力值,修改影子模式船位置
This commit is contained in:
1 parent
e6f3e2ecfa
commit
ab653b994f
82 files changed
+25241
-8988
No files matched your search
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerDevicePanel : PFUIPanel
|
||||
{
|
||||
protected override void Awake()
|
||||
{
|
||||
UIManager.AddEvent(transform.Find("Container/Tools/Back").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
Close();
|
||||
});
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
float timer = 1f;
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
if (App.MainDeviceAdapter.GetState(Assets.Scripts.Devices.ConnectionInterface.BLE) == Assets.Scripts.Devices.DeviceAdapterState.On)
|
||||
{
|
||||
transform.Find("Container/Tools/BlueTooth").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/RowerNew/ICON_bluetooth_44_on");
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.Find("Container/Tools/BlueTooth").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/RowerNew/ICON_bluetooth_44");
|
||||
}
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 169dd57411866874882869d55e047e57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,543 @@
|
||||
using Assets.Scripts;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.UI.Prefab.Login;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class RowerMultiModeScript : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
[SerializeField]
|
||||
GameObject rank;
|
||||
|
||||
Transform scroll,m2;
|
||||
Vector3 startPosition,boatStartPosition;
|
||||
TKPanRecognizer pan;
|
||||
|
||||
ScrollRect scrollRank;
|
||||
|
||||
Dictionary<string, Texture> caches;
|
||||
public class Trace
|
||||
{
|
||||
public int userId { get; set; }
|
||||
public Transform trace { get; set; }
|
||||
}
|
||||
|
||||
public class TraceData
|
||||
{
|
||||
public List<RowerChartModel> list { get; set; }
|
||||
public string NickName { get; set; }
|
||||
public string Avatar { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public bool isMine { get; set; }
|
||||
public int currentDistance { get; set; }
|
||||
public string Country { get; set; }
|
||||
}
|
||||
List<Trace> traceList;
|
||||
List<float> initialPosYList;
|
||||
void Awake()
|
||||
{
|
||||
scroll = transform.Find("Rower/Modes/Scroll");
|
||||
startPosition = scroll.localPosition;
|
||||
if (PlayerPrefs.GetFloat("RowerMultiModeLocationX") != 0f)
|
||||
{
|
||||
scroll.localPosition = new Vector3(PlayerPrefs.GetFloat("RowerMultiModeLocationX"), startPosition.y, startPosition.z);
|
||||
}
|
||||
AddTouchEvent();
|
||||
m2 = transform.Find("Rower/Modes/Scroll/M2");
|
||||
caches = new Dictionary<string, Texture>();
|
||||
traceList = new List<Trace>()
|
||||
{
|
||||
new Trace{ userId=0, trace=m2.Find("Track/T1") },
|
||||
new Trace{ userId=0, trace=m2.Find("Track/T2") },
|
||||
new Trace{ userId=0, trace=m2.Find("Track/T3") },
|
||||
new Trace{ userId=0, trace=m2.Find("Track/T4") },
|
||||
new Trace{ userId=0, trace=m2.Find("Track/T5") },
|
||||
};
|
||||
initialPosYList = new List<float>
|
||||
{
|
||||
m2.Find("Track/T1").localPosition.y,
|
||||
m2.Find("Track/T2").localPosition.y,
|
||||
m2.Find("Track/T3").localPosition.y,
|
||||
m2.Find("Track/T4").localPosition.y,
|
||||
m2.Find("Track/T5").localPosition.y,
|
||||
};
|
||||
scrollRank = transform.Find("Rower/Modes/Scroll/M2/Rank/Scroll View").GetComponent<ScrollRect>();
|
||||
var countryJson = Resources.Load<TextAsset>("UI/flags-mini").text;
|
||||
countryList = JsonConvert.DeserializeObject<List<CountryModel>>(countryJson);
|
||||
}
|
||||
|
||||
public void HandleTimeTick(RowerChartModel data)
|
||||
{
|
||||
currentSecond++;
|
||||
myData.list.Add(data);
|
||||
SortByCurrentDistance();
|
||||
DisplayUserRanks();
|
||||
DisplayTraces();
|
||||
}
|
||||
private void SortByCurrentDistance()
|
||||
{
|
||||
if (currentSecond >= 0)
|
||||
{
|
||||
userList.ForEach(x =>
|
||||
{
|
||||
var _list = x.list;
|
||||
var _distance = 0;
|
||||
if (_list.Count == 0)
|
||||
{
|
||||
_distance = 0;
|
||||
}
|
||||
else if (currentSecond >= _list.Count)
|
||||
{
|
||||
_distance = _list[_list.Count - 1].Distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
_distance = _list[currentSecond].Distance;
|
||||
}
|
||||
x.currentDistance = _distance;
|
||||
});
|
||||
}
|
||||
userList = userList.OrderByDescending(x => x.currentDistance).ToList();
|
||||
}
|
||||
private List<TraceData> HandleData()
|
||||
{
|
||||
//仅取5个
|
||||
var mineIndex = userList.FindIndex(x => x.isMine);
|
||||
if (mineIndex < 2)
|
||||
{
|
||||
return userList.Where((x, i) => i < 5).ToList();
|
||||
}
|
||||
else if (mineIndex > userList.Count - 3)
|
||||
{
|
||||
return userList.Where((x, i) => i >= userList.Count - 5).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return userList.Where((x, i) => i >= mineIndex - 2 && i <= mineIndex + 2).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
List<TraceData> userList;
|
||||
TraceData myData;
|
||||
List<RowerRank> shadowList;
|
||||
private async void Start()
|
||||
{
|
||||
rowerType = GetComponent<RowerHomeScript>().rowerType;
|
||||
//#if UNITY_EDITOR
|
||||
// rowerType = new RowerTaskPanel.RowerType { type = 1, value = 250 };
|
||||
//#endif
|
||||
GetShadowList(rowerType);
|
||||
}
|
||||
|
||||
public async void GetShadowList(RowerTaskPanel.RowerType rowerType)
|
||||
{
|
||||
currentSecond = -1;
|
||||
var res = await ConfigHelper.rowerApi.GetShadowList(rowerType);
|
||||
shadowList = res.data;
|
||||
var _tmpList = shadowList.Select(x => new TraceData
|
||||
{
|
||||
list = x.list,
|
||||
NickName = x.NickName,
|
||||
Avatar = x.WxHeadImg,
|
||||
UserId = x.UserId,
|
||||
isMine = false,
|
||||
currentDistance = 0,
|
||||
Country = x.Country
|
||||
}).ToList();
|
||||
|
||||
myData = new TraceData();
|
||||
myData.list = new List<RowerChartModel>();
|
||||
myData.UserId = App.CurrentUser.Id;
|
||||
myData.NickName = App.CurrentUser.Nickname;
|
||||
myData.Avatar = App.CurrentUser.WxHeadImg;
|
||||
myData.isMine = true;
|
||||
myData.Country = App.CurrentUser.Country;
|
||||
_tmpList.Add(myData);
|
||||
userList = _tmpList.OrderByDescending(x => x.currentDistance).ToList();
|
||||
DisplayUserRanks(true);
|
||||
DisplayTraces();
|
||||
}
|
||||
private void DisplayTraces()
|
||||
{
|
||||
var list = HandleData();
|
||||
//CompareTraceList(traceList, list);
|
||||
int i = 0;
|
||||
var mineData = list.FirstOrDefault(x => x.isMine);
|
||||
for (i = 0; i < list.Count;i++)
|
||||
{
|
||||
var sq = DOTween.Sequence();
|
||||
var item = traceList[i];
|
||||
var t = item.trace;
|
||||
var data = list[i];
|
||||
t.gameObject.SetActive(true);
|
||||
TweenCallback callback = () =>
|
||||
{
|
||||
Utils.DisplayImageTempDict(t.Find("Left/Avatar").GetComponent<RawImage>(), data.Avatar, caches);
|
||||
var _c = countryList.SingleOrDefault(x => x.country == data.Country);
|
||||
if (_c != null)
|
||||
{
|
||||
t.Find("Left/Avatar/Country").GetComponent<Image>().sprite = Resources.Load<Sprite>(_c.source);
|
||||
}
|
||||
t.Find("Left/NickName").GetComponent<Text>().text = data.NickName;
|
||||
|
||||
if (data.list.Count == 0)
|
||||
{
|
||||
t.Find("Left/Time").GetComponent<Text>().text = TimeSpan.FromSeconds(0).ToString(@"mm\:ss");
|
||||
}
|
||||
else if (currentSecond >= 0 && currentSecond < data.list.Count)
|
||||
{
|
||||
var _d = data.list[currentSecond];
|
||||
t.Find("Left/Time").GetComponent<Text>().text = TimeSpan.FromSeconds(_d.Pace).ToString(@"mm\:ss");
|
||||
}
|
||||
else
|
||||
{
|
||||
var _d = data.list[data.list.Count - 1];
|
||||
t.Find("Left/Time").GetComponent<Text>().text = TimeSpan.FromSeconds(_d.Pace).ToString(@"mm\:ss");
|
||||
}
|
||||
var diff = data.currentDistance - mineData.currentDistance;
|
||||
if (diff > 0)
|
||||
{
|
||||
t.Find("Main/Diff").GetComponent<Text>().text = diff.ToString("+#0M");
|
||||
}
|
||||
else if (diff == 0)
|
||||
{
|
||||
t.Find("Main/Diff").GetComponent<Text>().text = data.isMine ? "" : diff.ToString("#0M");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.Find("Main/Diff").GetComponent<Text>().text = diff.ToString("#0M");
|
||||
}
|
||||
if (data.isMine)
|
||||
{
|
||||
t.transform.Find("Left/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
t.transform.Find("Left/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.transform.Find("Left/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
t.transform.Find("Left/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
}
|
||||
};
|
||||
if (item.userId != data.UserId)
|
||||
{
|
||||
var sq1 = DOTween.Sequence();
|
||||
var tmp = traceList[i].trace.DOLocalRotate(new Vector3(90, 0, 0), 0.3f);
|
||||
tmp.onComplete = callback;
|
||||
sq1.Append(tmp);
|
||||
sq1.Append(traceList[i].trace.DOLocalRotate(new Vector3(0, 0, 0), 0.3f));
|
||||
sq.Join(sq1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sq.AppendCallback(callback);
|
||||
}
|
||||
item.userId = data.UserId;
|
||||
|
||||
|
||||
if (currentSecond >= 0 && currentSecond < list[i].list.Count)
|
||||
{
|
||||
var _d = data.list[currentSecond];
|
||||
if (currentSecond > 0)
|
||||
{
|
||||
var _pred = data.list[currentSecond - 1];
|
||||
if (_pred.StrokeCount != _d.StrokeCount)
|
||||
{
|
||||
//上次划桨次数和这次不一样 说明需要划桨一次
|
||||
var spDict = GetComponent<RowerHomeScript>().spriteDict;
|
||||
int spDictIndex = 0;
|
||||
sq.Join(DOTween.To(() => spDictIndex, x => t.Find("Main/Boat").GetComponent<Image>().sprite = spDict[x], 14, 0.3f));
|
||||
sq.AppendCallback(() =>
|
||||
{
|
||||
int spDictIndex2 = 14;
|
||||
DOTween.To(() => spDictIndex2, x => t.Find("Main/Boat").GetComponent<Image>().sprite = spDict[x], 0, 0.6f);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
var width = t.Find("Main").GetComponent<RectTransform>().sizeDelta.x - t.Find("Main/Boat").GetComponent<RectTransform>().sizeDelta.x;
|
||||
var diffWidth = data.currentDistance - mineData.currentDistance + 50;
|
||||
if (diffWidth >= 0 && diffWidth <= 100)
|
||||
{
|
||||
if (data.currentDistance <= 50)
|
||||
{
|
||||
diffWidth = data.currentDistance;
|
||||
}
|
||||
else if (rowerType.type == 1 && rowerType.value - data.currentDistance <= 50)
|
||||
{
|
||||
diffWidth = 100 - ((int)rowerType.value - data.currentDistance);
|
||||
}
|
||||
var tWidth = (diffWidth / 100f) * width;
|
||||
t.Find("Main/Boat").gameObject.SetActive(true);
|
||||
//t.Find("Main/Boat").localPosition = new Vector3(25 + tWidth, t.Find("Main/Boat").localPosition.y, t.Find("Main/Boat").localPosition.z);
|
||||
sq.Join(t.Find("Main/Boat").DOLocalMoveX(21.5f + tWidth, 0.9f));
|
||||
}
|
||||
else
|
||||
{
|
||||
t.Find("Main/Boat").localPosition = new Vector3(-21.5f, t.Find("Main/Boat").localPosition.y, t.Find("Main/Boat").localPosition.z);
|
||||
t.Find("Main/Boat").gameObject.SetActive(false);
|
||||
}
|
||||
sq.Play();
|
||||
}
|
||||
for (; i < traceList.Count; i++)
|
||||
{
|
||||
traceList[i].userId = 0;
|
||||
traceList[i].trace.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void CompareTraceList(List<Trace> traceList, List<TraceData> list)
|
||||
{
|
||||
if (traceList.Count(x => x.userId == 0) == 5) return;
|
||||
var originUserList = traceList.Select(x => x.userId).ToList();
|
||||
var newUserList = list.Select(x => x.UserId).ToList();
|
||||
if (newUserList.Count != 5)
|
||||
{
|
||||
for (int i = newUserList.Count; i < 5; i++)
|
||||
{
|
||||
newUserList.Add(0);
|
||||
}
|
||||
}
|
||||
var diffRank = new List<int?>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
int _origin = originUserList[i], _new = newUserList[i];
|
||||
if (_origin == _new)
|
||||
{
|
||||
//相等 则排名没变化
|
||||
diffRank.Add(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
//不相等 分情况
|
||||
var newIndex = originUserList.FindIndex(x => x == _new);
|
||||
if (newIndex != -1)
|
||||
{
|
||||
diffRank.Add(newIndex - _origin);
|
||||
}
|
||||
else
|
||||
{
|
||||
diffRank.Add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetRank(GameObject game, TraceData item,int i)
|
||||
{
|
||||
game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
|
||||
game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
|
||||
Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.Avatar, caches);
|
||||
var _c = countryList.FirstOrDefault(x => item.Country == x.country);
|
||||
if (_c != null)
|
||||
{
|
||||
game.transform.Find("Content/Country").GetComponent<Image>().sprite = Resources.Load<Sprite>(_c.source);
|
||||
}
|
||||
if (currentSecond < 0)
|
||||
{
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().text = "0M";
|
||||
game.transform.Find("Content/Power").GetComponent<Text>().text = "0W";
|
||||
}
|
||||
else if (currentSecond >= 0 && currentSecond < item.list.Count)
|
||||
{
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().text = item.list[currentSecond].Distance.ToString("#0M");
|
||||
game.transform.Find("Content/Power").GetComponent<Text>().text = item.list[currentSecond].Power.ToString("#0W");
|
||||
}
|
||||
else
|
||||
{
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().text = item.list[item.list.Count - 1].Distance.ToString("#0M");
|
||||
game.transform.Find("Content/Power").GetComponent<Text>().text = item.list[item.list.Count - 1].Power.ToString("#0W");
|
||||
}
|
||||
if (item.isMine)
|
||||
{
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
game.transform.Find("Content/Power").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
}
|
||||
else
|
||||
{
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
game.transform.Find("Content/Power").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
}
|
||||
}
|
||||
private void DisplayUserRanks(bool isRefresh = false)
|
||||
{
|
||||
if (isRefresh)
|
||||
{
|
||||
scrollRank.content.DestroyChildren();
|
||||
}
|
||||
if (scrollRank.content.childCount == 0)
|
||||
{
|
||||
for (int i = 0; i < userList.Count; i++)
|
||||
{
|
||||
var item = userList[i];
|
||||
var game = Instantiate<GameObject>(rank);
|
||||
SetRank(game, item, i);
|
||||
game.transform.SetParent(scrollRank.content);
|
||||
game.transform.localScale = Vector3.one;
|
||||
game.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
foreach (Transform t in scrollRank.content)
|
||||
{
|
||||
var item = userList[i];
|
||||
SetRank(t.gameObject, item, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
transform.Find("Rower/Modes/Scroll/M2/Rank/MyRank").GetComponent<Text>().text = $"<color=#f93086>{userList.FindIndex(x => x.isMine) + 1}</color> / {userList.Count}";
|
||||
}
|
||||
private void AddTouchEvent()
|
||||
{
|
||||
pan = new TKPanRecognizer();
|
||||
pan.gestureRecognizedEvent += (r) =>
|
||||
{
|
||||
var startPoint = r.startPoint;
|
||||
if (((RectTransform)transform.Find("Rower/Modes")).isPointInTransfrom(startPoint))
|
||||
{
|
||||
if (scroll.localPosition.x < startPosition.x - (730 / 2)
|
||||
&& ((RectTransform)transform.Find("RankS")).isPointInTransfrom(startPoint))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var offset = pan.deltaTranslation;
|
||||
scroll.localPosition += new Vector3(offset.x, 0, 0);
|
||||
}
|
||||
};
|
||||
pan.gestureCompleteEvent += (r) =>
|
||||
{
|
||||
float x = 0;
|
||||
if (scroll.localPosition.x >= startPosition.x - (730 / 2))
|
||||
{
|
||||
x = startPosition.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = startPosition.x - 730;
|
||||
}
|
||||
scroll.DOLocalMoveX(x, 0.5f);
|
||||
PlayerPrefs.SetFloat("RowerMultiModeLocationX", x);
|
||||
};
|
||||
TouchKit.addGestureRecognizer(pan);
|
||||
}
|
||||
//交换A,B索引的赛道
|
||||
void ChangeTrace(int indexA, int indexB)
|
||||
{
|
||||
if (indexA >= traceList.Count || indexB >= traceList.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (traceList.Count(x => x.trace.gameObject.activeInHierarchy) == 0) return;
|
||||
Trace a = traceList[indexA], b = traceList[indexB];
|
||||
//2个排名
|
||||
//先视觉交换
|
||||
float aniTime = 0.3f;
|
||||
Vector3 aloc = a.trace.localPosition;
|
||||
var sq = DOTween.Sequence();
|
||||
sq.Join(a.trace.DOLocalMoveY(b.trace.localPosition.y, aniTime));
|
||||
sq.Join(b.trace.DOLocalMoveY(aloc.y, aniTime));
|
||||
//逻辑交换
|
||||
var tmp = traceList[indexA];
|
||||
traceList[indexA] = traceList[indexB];
|
||||
traceList[indexB] = tmp;
|
||||
|
||||
var sq1 = DOTween.Sequence();
|
||||
if (traceList.Count(x => x.trace.gameObject.activeInHierarchy) != 5) return;
|
||||
if (indexA == 1 && indexB == 2)
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (i == 4)
|
||||
{
|
||||
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[4] - 50.4f, aniTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[i + 1], aniTime));
|
||||
}
|
||||
}
|
||||
sq1.AppendCallback(() =>
|
||||
{
|
||||
traceList[4].trace.localPosition = new Vector3(traceList[0].trace.localPosition.x, initialPosYList[0] + 49.5f, traceList[0].trace.localPosition.z);
|
||||
});
|
||||
sq1.Append(traceList[4].trace.DOLocalMoveY(initialPosYList[0], aniTime));
|
||||
sq.Append(sq1);
|
||||
sq.Play().onComplete = () =>
|
||||
{
|
||||
tmp = traceList[4];
|
||||
for (int i = 4; i >= 1; i--)
|
||||
{
|
||||
traceList[i] = traceList[i - 1];
|
||||
}
|
||||
traceList[0] = tmp;
|
||||
};
|
||||
}
|
||||
else if (indexA == 2 && indexB == 3)
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[0] + 50.4f, aniTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[i - 1], aniTime));
|
||||
}
|
||||
}
|
||||
sq1.AppendCallback(() =>
|
||||
{
|
||||
traceList[0].trace.localPosition = new Vector3(traceList[0].trace.localPosition.x, initialPosYList[4] - 49.5f, traceList[0].trace.localPosition.z);
|
||||
});
|
||||
sq1.Append(traceList[0].trace.DOLocalMoveY(initialPosYList[4], aniTime));
|
||||
sq.Append(sq1);
|
||||
sq.Play().onComplete = () =>
|
||||
{
|
||||
tmp = traceList[0];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
traceList[i] = traceList[i + 1];
|
||||
}
|
||||
traceList[4] = tmp;
|
||||
};
|
||||
}
|
||||
}
|
||||
float timer = 1f;
|
||||
int currentSecond = -1;
|
||||
private List<CountryModel> countryList;
|
||||
|
||||
public RowerTaskPanel.RowerType rowerType { get; private set; }
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
timer -= Time.deltaTime;
|
||||
if (timer < 0)
|
||||
{
|
||||
//var r = new System.Random();
|
||||
//int a = r.Next(1, 3);
|
||||
//print($"{a},{a+1}");
|
||||
//ChangeTrace(a, a+1);
|
||||
HandleTimeTick(new RowerChartModel()
|
||||
{
|
||||
Distance = 0,
|
||||
});
|
||||
currentSecond++;
|
||||
timer += 1f;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee3b67ceb2893134a887a9e30922821e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,269 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.UI.Control;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
|
||||
public class RowerTaskPanel : PFUIPanel
|
||||
{
|
||||
public class RowerType
|
||||
{
|
||||
/// <summary>
|
||||
/// 1 里程 2 时间
|
||||
/// </summary>
|
||||
public int type { get; set; }
|
||||
/// <summary>
|
||||
/// 里程:m 时间:s
|
||||
/// </summary>
|
||||
public float value { get; set; }
|
||||
}
|
||||
Transform selector, distance, time;
|
||||
RowerType rowerType;
|
||||
|
||||
public Action<RowerType> callBack { get; set; }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
distance = transform.Find("Main/Distance");
|
||||
time = transform.Find("Main/Time");
|
||||
rowerType = new RowerType();
|
||||
UIManager.AddEvent(transform.Find("Main/BtnGo").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
Go();
|
||||
});
|
||||
UIManager.AddEvent(transform.Find("Main/BtnCancel").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
Close();
|
||||
});
|
||||
//var bg = transform.Find("Main/Time/Inputbg").gameObject;
|
||||
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.PointerEnter, b =>
|
||||
// {
|
||||
// bg.GetComponent<Outline>().enabled = true;
|
||||
// bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#353543");
|
||||
// });
|
||||
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.Select, b =>
|
||||
//{
|
||||
// bg.GetComponent<Outline>().enabled = true;
|
||||
// bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#f93086");
|
||||
//});
|
||||
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.Deselect, b =>
|
||||
//{
|
||||
// bg.GetComponent<Outline>().enabled = false;
|
||||
//});
|
||||
formList = new List<object>
|
||||
{
|
||||
distance.Find("Btn500").GetComponent<Button>(),
|
||||
distance.Find("Btn2000").GetComponent<Button>(),
|
||||
distance.Find("Btn5000").GetComponent<Button>(),
|
||||
distance.Find("Btn10000").GetComponent<Button>(),
|
||||
distance.Find("Customize").GetComponent<PFUIInputField>(),
|
||||
time.Find("Btn30").GetComponent<Button>(),
|
||||
time.Find("CustomizeMin").GetComponent<PFUIInputField>(),
|
||||
time.Find("CustomizeS").GetComponent<PFUIInputField>(),
|
||||
};
|
||||
InitDistance();
|
||||
}
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
InitAll();
|
||||
}
|
||||
private void Go()
|
||||
{
|
||||
if (rowerType.type == 0 || rowerType.value == 0)
|
||||
{
|
||||
Utils.showToast(null, "请选择课程");
|
||||
return;
|
||||
}
|
||||
if (callBack != null)
|
||||
{
|
||||
callBack.Invoke(rowerType);
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
List<object> formList = null;
|
||||
private void InitDistance()
|
||||
{
|
||||
Func<Transform, float, float, float> calc = (t, a, b) => t.parent.name == "Distance" ? a : a * 60 + b;
|
||||
AddListener(formList, (t, v) =>
|
||||
{
|
||||
if (t.parent.name == "Distance")
|
||||
{
|
||||
rowerType.type = 1;
|
||||
if (float.TryParse(v, out float f))
|
||||
{
|
||||
rowerType.value = f;
|
||||
}
|
||||
else
|
||||
{
|
||||
rowerType.value = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rowerType.type = 2;
|
||||
rowerType.value = 0;
|
||||
var min = time.Find("CustomizeMin").GetComponent<InputField>().text;
|
||||
var s = time.Find("CustomizeS").GetComponent<InputField>().text;
|
||||
if (float.TryParse(min, out float a))
|
||||
{
|
||||
rowerType.value += 60 * a;
|
||||
}
|
||||
if (float.TryParse(s, out float b))
|
||||
{
|
||||
if (b < 0 || b > 59)
|
||||
{
|
||||
Utils.showToast(null, "Please enter an integer between 0-59.");
|
||||
time.Find("CustomizeS").GetComponent<InputField>().text = "";
|
||||
return;
|
||||
}
|
||||
rowerType.value += b;
|
||||
}
|
||||
}
|
||||
}, calc);
|
||||
}
|
||||
private void AddListener(IEnumerable<object> list, UnityAction<Transform,string> inputCustomAction, Func<Transform, float,float,float> calcButton = null)
|
||||
{
|
||||
var btns = list.Where(x => x is Button).Select(x => x as Button);
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (item is Button)
|
||||
{
|
||||
var btn = item as Button;
|
||||
btn.onClick.RemoveAllListeners();
|
||||
btn.onClick.AddListener(() =>
|
||||
{
|
||||
rowerType.type = btn.transform.parent.name == "Distance" ? 1 : 2;
|
||||
if (calcButton == null)
|
||||
{
|
||||
rowerType.value = float.Parse(btn.name.Replace("Btn", ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
rowerType.value = calcButton.Invoke(btn.transform ,float.Parse(btn.name.Replace("Btn", "")), 0);
|
||||
}
|
||||
ClickDistanceBtn(btn, btns);
|
||||
});
|
||||
}
|
||||
else if (item is PFUIInputField)
|
||||
{
|
||||
var input = item as PFUIInputField;
|
||||
input.CustomSelect = () =>
|
||||
{
|
||||
ClickDistanceBtn(null, btns);
|
||||
rowerType.type = input.transform.parent.name == "Distance" ? 1 : 2;
|
||||
SetTextColor(input.gameObject, true);
|
||||
SetBgColor(input,2);
|
||||
};
|
||||
input.CustomDeSelect = () =>
|
||||
{
|
||||
SetTextColor(input.gameObject, false);
|
||||
SetBgColor(input, 3);
|
||||
};
|
||||
input.CustomEnter = () =>
|
||||
{
|
||||
SetBgColor(input, 1);
|
||||
};
|
||||
if (inputCustomAction != null)
|
||||
{
|
||||
input.GetComponent<InputField>().onEndEdit.RemoveAllListeners();
|
||||
input.GetComponent<InputField>().onEndEdit.AddListener((v) => inputCustomAction(input.transform, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<string, int> inputStatusDict = null;
|
||||
private void SetBgColor(PFUIInputField input, int v)
|
||||
{
|
||||
if (inputStatusDict == null)
|
||||
{
|
||||
inputStatusDict = new Dictionary<string, int>
|
||||
{
|
||||
{"CustomizeMin",3 },{"CustomizeS",3 }
|
||||
};
|
||||
}
|
||||
if (!inputStatusDict.ContainsKey(input.name)) return;
|
||||
//只要有一个select,enter 常亮 两个都exit,deselect 关掉
|
||||
inputStatusDict[input.name] = v;
|
||||
var bg = transform.Find("Main/Time/Inputbg").gameObject;
|
||||
if (inputStatusDict.Count(x=>x.Value == 1) > 0)
|
||||
{
|
||||
bg.GetComponent<Outline>().enabled = true;
|
||||
bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#6E6E7D");
|
||||
}
|
||||
else if (inputStatusDict.Count(x => x.Value == 2) > 0)
|
||||
{
|
||||
bg.GetComponent<Outline>().enabled = true;
|
||||
bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#f93086");
|
||||
}
|
||||
else if(inputStatusDict.Count(x => x.Value == 3) == 2)
|
||||
{
|
||||
bg.GetComponent<Outline>().enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitAll()
|
||||
{
|
||||
foreach (var item in formList)
|
||||
{
|
||||
if (item is Button)
|
||||
{
|
||||
SetButtonColor(item as Button, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var i = item as PFUIInputField;
|
||||
i.Text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ClickDistanceBtn(Button btn, IEnumerable<Button> list)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
SetButtonColor(item, false);
|
||||
}
|
||||
if (btn)
|
||||
{
|
||||
SetButtonColor(btn, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetButtonColor(Button btn, bool flag)
|
||||
{
|
||||
SetTextColor(btn.gameObject, flag);
|
||||
btn.gameObject.GetComponent<Image>().color = flag ? Utils.HexToColorHtml("#f93086") : Utils.HexToColorHtml("#23232d");
|
||||
}
|
||||
|
||||
private void SetTextColor(GameObject btn, bool flag)
|
||||
{
|
||||
if (btn.transform.Find("t1"))
|
||||
{
|
||||
btn.transform.Find("t1").GetComponent<Text>().color = flag ? Utils.HexToColorHtml("#ffffff") : Utils.HexToColorHtml("#9E9EAD");
|
||||
}
|
||||
|
||||
if (btn.transform.Find("t2"))
|
||||
{
|
||||
btn.transform.Find("t2").GetComponent<Text>().color = flag ? Utils.HexToColorHtml("#ffffff") : Utils.HexToColorHtml("#9E9EAD");
|
||||
}
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11dfa3e099daeb942b6e8e105572548c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,45 +8,131 @@ using UnityEngine.UI;
|
||||
|
||||
public class RowerWelldone : PFUIPanel
|
||||
{
|
||||
[SerializeField]
|
||||
GameObject AllRecord, Record,Rank;
|
||||
Dictionary<string, Texture> caches;
|
||||
Transform rankContent, gradeContent;
|
||||
|
||||
public string id { get; private set; }
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
Debug.Log("well done show");
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
protected override void Awake()
|
||||
{
|
||||
caches = new Dictionary<string, Texture>();
|
||||
rankContent = transform.Find("Container/Left/Scroll View").GetComponent<ScrollRect>().content;
|
||||
gradeContent = transform.Find("Container/Right/Scroll View").GetComponent<ScrollRect>().content;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
UIManager.AddEvent(transform.Find("BtnDefine").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
UIManager.AddEvent(transform.Find("Container/BtnDefine").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
startTime = false;
|
||||
Close();
|
||||
UIManager.ShowHomePanel();
|
||||
UIManager.ShowUserInfoPanel();
|
||||
//UIManager.ShowHomePanel();
|
||||
//UIManager.ShowUserInfoPanel();
|
||||
});
|
||||
UIManager.AddEvent(transform.Find("Container/BtnView").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
Close();
|
||||
Application.OpenURL($"{App.websiteDict[App.Host]}rower/record/{id}?Token={App.CurrentUser.cookie}");
|
||||
});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (startTime)
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
remainTime--;
|
||||
if (remainTime == 0)
|
||||
{
|
||||
startTime = false;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
transform.Find("Container/BtnDefine/Text").GetComponent<Text>().text = $"{"DEFINE"}({remainTime.ToString("#0")})";
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
RowerRecordModel model;
|
||||
public void Initial(RowerRecordModel model)
|
||||
|
||||
float timer = 1f, remainTime = 10f;
|
||||
bool startTime = false;
|
||||
public async void Initial(string id)
|
||||
{
|
||||
Debug.Log("Initial");
|
||||
if (model == null) return;
|
||||
this.model = model;
|
||||
transform.Find("Time/Value1").GetComponent<Text>().text = model.CreateTime.ToLocalTime().ToString("yyyy-MM-dd");
|
||||
transform.Find("Time/Value2").GetComponent<Text>().text = model.CreateTime.ToLocalTime().ToString("HH:mm:ss");
|
||||
transform.Find("RowingTime/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(model.TotalTime).ToString();
|
||||
transform.Find("Distance/Value").GetComponent<Text>().text = $"{model.TotalDistance.ToString()}M";
|
||||
var datas = transform.Find("Other/Datas");
|
||||
datas.Find("AvgRate/Value").GetComponent<Text>().text = $"{model.AvgRate.ToString("#0")}";
|
||||
datas.Find("MaxRate/Value").GetComponent<Text>().text = $"{model.MaxRate.ToString()}";
|
||||
datas.Find("AvgPower/Value").GetComponent<Text>().text = $"{model.AvgPower.ToString("#0")}";
|
||||
datas.Find("MaxPower/Value").GetComponent<Text>().text = $"{model.MaxPower.ToString()}";
|
||||
datas.Find("MaxPace/Value").GetComponent<Text>().text = $"{TimeSpan.FromSeconds(model.MaxPace).ToString(@"mm\:ss")}";
|
||||
datas.Find("AvgPace/Value").GetComponent<Text>().text = $"{TimeSpan.FromSeconds(model.AvgPace).ToString(@"mm\:ss")}";
|
||||
datas.Find("Calories/Value").GetComponent<Text>().text = $"{(model.Kj ?? 0).ToString("#0")}";
|
||||
datas.Find("StrokeCount/Value").GetComponent<Text>().text = $"{model.StrokeCount}";
|
||||
if (string.IsNullOrEmpty(id)) return;
|
||||
this.id = id;
|
||||
var res = await ConfigHelper.rowerApi.GetSegmentDataAndRanking(id);
|
||||
if (res.result)
|
||||
{
|
||||
DisplayData(res.data, caches);
|
||||
startTime = true;
|
||||
remainTime = 10f;
|
||||
timer = 1f;
|
||||
transform.Find("Container/BtnDefine/Text").GetComponent<Text>().text = $"{"DEFINE"}({remainTime.ToString("#0")})";
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayData(RowerSegmentData data, Dictionary<string, Texture> caches)
|
||||
{
|
||||
rankContent.DestroyChildren();
|
||||
gradeContent.DestroyChildren();
|
||||
for (int i = 0; i < data.ranks.Count; i++)
|
||||
{
|
||||
var item = data.ranks[i];
|
||||
var game = Instantiate<GameObject>(Rank);
|
||||
game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
|
||||
game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
|
||||
Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.WxHeadImg, caches);
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().text = data.info.Type == 1 ? TimeSpan.FromSeconds(item.Time).ToString() : item.TotalDistance.ToString("#0M");
|
||||
game.transform.SetParent(rankContent);
|
||||
game.transform.localScale = Vector3.one;
|
||||
game.SetActive(true);
|
||||
if (item.UserId == App.CurrentUser.Id)
|
||||
{
|
||||
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
|
||||
}
|
||||
else
|
||||
{
|
||||
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.segmentList.Count; i++)
|
||||
{
|
||||
var item = data.segmentList[i];
|
||||
var game = i == 0 ? Instantiate<GameObject>(AllRecord) : Instantiate<GameObject>(Record);
|
||||
var content = i != 0 ? game.transform.Find("Content") : game.transform;
|
||||
content.Find("Index").GetComponent<Text>().text = i == 0 ? "ALL" : i.ToString("00");
|
||||
content.Find("Time").GetComponent<Text>().text = TimeSpan.FromSeconds(item.Ticks).ToString();
|
||||
content.Find("Distance").GetComponent<Text>().text = item.Distance.ToString("#0");
|
||||
content.Find("500").GetComponent<Text>().text = TimeSpan.FromSeconds(item.Speed).ToString();
|
||||
content.Find("Power").GetComponent<Text>().text = item.Power.ToString("#0");
|
||||
content.Find("HR").GetComponent<Text>().text = item.HeartRate.ToString("#0");
|
||||
content.Find("Count").GetComponent<Text>().text = item.StrokeCount.ToString("#0");
|
||||
content.Find("Carlories").GetComponent<Text>().text = item.Energy.ToString("#0");
|
||||
//game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
|
||||
//game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
|
||||
//Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.WxHeadImg, caches);
|
||||
//game.transform.Find("Content/Time").GetComponent<Text>().text = data.info.Type == 1 ? TimeSpan.FromSeconds(item.Time).ToString() : item.TotalDistance.ToString("#0");
|
||||
game.transform.SetParent(gradeContent);
|
||||
game.transform.localScale = Vector3.one;
|
||||
game.SetActive(true);
|
||||
}
|
||||
transform.Find("Container/Left/MyRank").GetComponent<Text>().text = data.info.MyRank;
|
||||
transform.Find("Container/Right/Time").GetComponent<Text>().text = data.info.CreateTime;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user