骑行部分代码重构
This commit is contained in:
parent
21d54a8a1a
commit
fa5a9961a8
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cae07749732f9d4aa6831e43ea65d68
|
||||
guid: 04b83335f962c2745900aa55d8b8072c
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
22512
Assets/Resources/UI/Prefab/Match/onlinePlayerNoScriptNv.prefab
Normal file
22512
Assets/Resources/UI/Prefab/Match/onlinePlayerNoScriptNv.prefab
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94a353e3a43182d4c81a470b4765b1e0
|
||||
guid: 21aee99f3e4d49040837bc6b626cac95
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
File diff suppressed because it is too large
Load Diff
22537
Assets/Resources/UI/Prefab/Match/onlinePlayerNv.prefab
Normal file
22537
Assets/Resources/UI/Prefab/Match/onlinePlayerNv.prefab
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fe2d472537f7874797d676190b7255a
|
||||
guid: b1ca9edfdf2a0c14b9088b4d0c401294
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
File diff suppressed because it is too large
Load Diff
@ -51,6 +51,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
protected double power;
|
||||
protected double elevation;
|
||||
protected double cadance;
|
||||
public int Sex { get; set; }
|
||||
protected int? heartRate { get; set; }
|
||||
public int ticks { get; set; }
|
||||
protected double totalDistance;
|
||||
|
||||
@ -31,16 +31,106 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
public AbstractMap map;
|
||||
public GameObject player { get; set; }
|
||||
public GameObject UIObject;
|
||||
public GameObject minicamera;
|
||||
GameObject loadingcanvas;
|
||||
GameObject miniMap { get; set; }
|
||||
GameObject resultPanel;
|
||||
GameObject watcher;
|
||||
|
||||
GameObject uipanel { get; set; }
|
||||
GameObject onlineUserPrefab3d { get; set; }
|
||||
GameObject onlineUserPrefab3dNv { get; set; }
|
||||
GameObject OnlineHeadPanel { get; set; }
|
||||
|
||||
public GameObject GetOnlineheadPanel()
|
||||
{
|
||||
if (OnlineHeadPanel == null)
|
||||
{
|
||||
OnlineHeadPanel = Resources.Load<GameObject>("UI/Prefab/Ride/OnlineHeadPanel");
|
||||
}
|
||||
|
||||
return OnlineHeadPanel;
|
||||
}
|
||||
|
||||
Transform target;
|
||||
Transform uiParent;
|
||||
|
||||
Material Graph3d { get; set; }
|
||||
Material Graph4 { get; set; }
|
||||
Material Graph1 { get; set; }
|
||||
|
||||
public Material Get3dGraph2()
|
||||
{
|
||||
if (Graph3d == null)
|
||||
{
|
||||
Graph3d = Resources.Load<Material>("UI/Material/3dGraph2");
|
||||
}
|
||||
|
||||
return Graph3d;
|
||||
}
|
||||
|
||||
public Material GetMaterial4()
|
||||
{
|
||||
if (Graph4 == null)
|
||||
{
|
||||
Graph4 = Resources.Load<Material>("UI/Material/4");
|
||||
}
|
||||
|
||||
return Graph4;
|
||||
}
|
||||
|
||||
|
||||
public Material GetMaterial1()
|
||||
{
|
||||
if (Graph1 == null)
|
||||
{
|
||||
Graph1 = Resources.Load<Material>("UI/Material/1");
|
||||
}
|
||||
|
||||
return Graph1;
|
||||
}
|
||||
|
||||
Image CompetitionArrow { get; set; }
|
||||
|
||||
public Image GetCompetitionArrow()
|
||||
{
|
||||
if (CompetitionArrow == null)
|
||||
{
|
||||
CompetitionArrow = Resources.Load<Image>("UI/Prefab/Match/CompetitionArrow");
|
||||
}
|
||||
|
||||
return CompetitionArrow;
|
||||
}
|
||||
|
||||
Image CompetitionMobileArrow { get; set; }
|
||||
|
||||
public Image GetCompetitionMobileArrow()
|
||||
{
|
||||
if (CompetitionMobileArrow == null)
|
||||
{
|
||||
CompetitionMobileArrow = Resources.Load<Image>("UI/Prefab/Match/Mobile/CompetitionArrow");
|
||||
}
|
||||
|
||||
return CompetitionMobileArrow;
|
||||
}
|
||||
|
||||
public ChartDataSourceScript chartDataSourceScript { get; set; }
|
||||
public GraphChartBase graph { get; set; }
|
||||
public RouteResultParam selectParamModel;
|
||||
public RouteResult routeResult;
|
||||
|
||||
public GameObject minicamera;
|
||||
|
||||
public Dictionary<int, SeletedPlayerScript> selectPlayerDic { set; get; } = new Dictionary<int, SeletedPlayerScript>();
|
||||
public Dictionary<int, SeletedPlayerScript> selectPlayerDic { set; get; } =
|
||||
new Dictionary<int, SeletedPlayerScript>();
|
||||
|
||||
public int preticks { get; set; }
|
||||
private float activeSeconds { get; set; } //移动端用户进入骑行超过2min,界面进入沉浸状态
|
||||
public int RankingId;
|
||||
public string recordId;
|
||||
public bool RotateLock = true;
|
||||
private bool touchLock = true;
|
||||
|
||||
#region 参数
|
||||
|
||||
public MapRoute mapRoute { get; set; } //当前路书数据
|
||||
public MapCompetition competition { get; set; } //当前赛事数据
|
||||
private MapDataModel mapData { get; set; } //当前路书数据
|
||||
@ -59,8 +149,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
public DateTime endTime;
|
||||
public bool isQuit;
|
||||
public bool isPause;
|
||||
|
||||
#endregion
|
||||
GameObject loadingcanvas;
|
||||
|
||||
AbstratctLoadingController loadingController;
|
||||
|
||||
private async Task Login()
|
||||
@ -68,14 +159,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
var result = await new UserApi().Login("15261826280", "123456", "");
|
||||
App.CurrentUser = result.data;
|
||||
}
|
||||
GameObject miniMap { get; set; }
|
||||
GameObject resultPanel;
|
||||
public ChartDataSourceScript chartDataSourceScript { get; set; }
|
||||
public GraphChartBase graph { get; set; }
|
||||
|
||||
private float activeSeconds { get; set; }//移动端用户进入骑行超过2min,界面进入沉浸状态
|
||||
public int RankingId;
|
||||
public string recordId;
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@ -93,95 +177,26 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
roomId = App.gameRoomDetail?.RoomId ?? 0;
|
||||
App.CompetionId = 0; //清空比赛参数
|
||||
|
||||
HandleTempData();
|
||||
CreateCurrentPlayer();
|
||||
}
|
||||
|
||||
//处理异常中断的骑行
|
||||
if (App.tempRecordData != null)
|
||||
private void HandleTempData()
|
||||
{
|
||||
if (App.tempRecordData == null) return;
|
||||
selectParamModel = App.tempRecordData.selectParam;
|
||||
competitionId = App.tempRecordData.CompetitionId;
|
||||
routeId = App.tempRecordData.RouteId;
|
||||
}
|
||||
CreateCurrentPlayer();
|
||||
Resources.UnloadUnusedAssets();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
private void OnDestroy()
|
||||
{
|
||||
App.RouteIdParam = 0;
|
||||
App.tempRecordData = null;
|
||||
TouchKit.removeAllGestureRecognizers();
|
||||
Resources.UnloadUnusedAssets();
|
||||
}
|
||||
Transform target;
|
||||
GameObject watcher;
|
||||
Transform uiParent;
|
||||
|
||||
GameObject uipanel { get; set; }
|
||||
GameObject onlineUserPrefab3d { get; set; }
|
||||
|
||||
GameObject OnlineHeadPanel { get; set; }
|
||||
|
||||
public GameObject GetOnlineheadPanel()
|
||||
{
|
||||
if (OnlineHeadPanel == null)
|
||||
{
|
||||
OnlineHeadPanel = Resources.Load<GameObject>("UI/Prefab/Ride/OnlineHeadPanel");
|
||||
}
|
||||
return OnlineHeadPanel;
|
||||
}
|
||||
Material Graph3d { get; set; }
|
||||
Material Graph4 { get; set; }
|
||||
Material Graph1 { get; set; }
|
||||
public Material Get3dGraph2()
|
||||
{
|
||||
if (Graph3d == null)
|
||||
{
|
||||
Graph3d = Resources.Load<Material>("UI/Material/3dGraph2");
|
||||
}
|
||||
return Graph3d;
|
||||
}
|
||||
|
||||
public Material GetMaterial4()
|
||||
{
|
||||
if (Graph4 == null)
|
||||
{
|
||||
Graph4 = Resources.Load<Material>("UI/Material/4");
|
||||
}
|
||||
return Graph4;
|
||||
}
|
||||
|
||||
|
||||
public Material GetMaterial1()
|
||||
{
|
||||
if (Graph1 == null)
|
||||
{
|
||||
Graph1 = Resources.Load<Material>("UI/Material/1");
|
||||
}
|
||||
return Graph1;
|
||||
}
|
||||
|
||||
Image CompetitionArrow { get; set; }
|
||||
public Image GetCompetitionArrow()
|
||||
{
|
||||
if (CompetitionArrow == null)
|
||||
{
|
||||
CompetitionArrow = Resources.Load<Image>("UI/Prefab/Match/CompetitionArrow");
|
||||
}
|
||||
return CompetitionArrow;
|
||||
}
|
||||
|
||||
Image CompetitionMobileArrow { get; set; }
|
||||
public Image GetCompetitionMobileArrow()
|
||||
{
|
||||
if (CompetitionMobileArrow == null)
|
||||
{
|
||||
CompetitionMobileArrow = Resources.Load<Image>("UI/Prefab/Match/Mobile/CompetitionArrow");
|
||||
}
|
||||
return CompetitionMobileArrow;
|
||||
}
|
||||
|
||||
public bool RotateLock = true;
|
||||
|
||||
private bool touchLock = true;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@ -195,6 +210,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
uipanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Ride/Panel"), UIObject.transform);
|
||||
uicanvasScaler.referenceResolution = App.PcResolution;
|
||||
loadingcanvasScaler.referenceResolution = App.PcResolution;
|
||||
|
||||
var modalRect = transform.Find("UI/ModalPanel").GetComponent<RectTransform>();
|
||||
modalRect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
modalRect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
@ -213,8 +229,11 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
|
||||
UIManager.Instance.MainPanel = uipanel.GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("UI/ModalPanel").GetComponent<PFUIPanel>();
|
||||
|
||||
onlineUserPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/EmptyOnlinePlayer");
|
||||
onlineUserPrefab3d = Resources.Load<GameObject>("UI/Prefab/Match/onlinePlayerNoScript");
|
||||
onlineUserPrefab3dNv = Resources.Load<GameObject>("UI/Prefab/Match/onlinePlayerNoScriptNv");
|
||||
|
||||
miniMapPlayerPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/MiniMapPlayer");
|
||||
watcher = Resources.Load<GameObject>("UI/Prefab/Match/Watcher");
|
||||
target = transform.Find("Target");
|
||||
@ -222,8 +241,63 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
minicamera = transform.Find("MiniCamera").gameObject;
|
||||
//进入倒计时
|
||||
singleUIManager = UIObject.GetComponent<BaseUIManager>();
|
||||
SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
|
||||
|
||||
InitLoading();
|
||||
HandleTouchAndInput();
|
||||
StartCoroutine(Ping());
|
||||
HandleRideMode();
|
||||
}
|
||||
|
||||
|
||||
|
||||
float timer = 1f;
|
||||
bool clearLock = false;
|
||||
bool _dragStartedOnUI = false;
|
||||
float touchTimer = 0.1f;
|
||||
public bool isWatch { get; set; }
|
||||
private Vector3 currentCameraPos { get; set; }
|
||||
Vector3 far = new Vector3(-17, 52, -48);
|
||||
Vector3 medium = new Vector3(-14.5f, 45, -40);
|
||||
Vector3 plane = new Vector3(-10.5f, 35, -30); //new Vector3(-11.4f, 31, -30);
|
||||
Vector3 near = new Vector3(-7.3f, 24, -20);
|
||||
Vector3 neareast = new Vector3(-5.4f, 18, -15);
|
||||
List<Vector3> cameraList { get; set; }
|
||||
DateTime startTimpStamp = DateTime.Now;
|
||||
PlayerController playerController;
|
||||
public AbstractPlayer currentPlayer { get; set; }
|
||||
private GameObject onlinePlayer { get; set; }
|
||||
private Vector3 mapPos = Vector3.zero;
|
||||
Vector3 MAX_SIZE = new Vector3(3f, 3f, 3f);
|
||||
Vector3 MIN_SIZE = new Vector3(0.1f, 0.1f, 0.1f);
|
||||
public BaseUIManager singleUIManager;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
timer -= Time.deltaTime;
|
||||
|
||||
if (timer <= 0)
|
||||
{
|
||||
TcpHandler();
|
||||
App.CurrentScene = "Ride";
|
||||
if (competitionId == 0)
|
||||
{
|
||||
UIManager.SendCompetitionStartMessage("Ride");
|
||||
}
|
||||
|
||||
timer += 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
HandleTouch();
|
||||
HandleMouseScrollWheel();
|
||||
}
|
||||
|
||||
private void InitLoading()
|
||||
{
|
||||
if (competitionId > 0)
|
||||
{
|
||||
loadingController = transform.Find("LoadingCanvas").gameObject.AddComponent<CompetitionLoadingController>();
|
||||
@ -233,14 +307,14 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
loadingController = transform.Find("LoadingCanvas").gameObject.AddComponent<LoadingController>();
|
||||
}
|
||||
|
||||
//loadingController = FindObjectOfType<LoadingController>();
|
||||
//
|
||||
loadingController.InjectController(this);
|
||||
}
|
||||
|
||||
SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
|
||||
|
||||
HandleTouchAndInput();
|
||||
StartCoroutine(Ping());
|
||||
/// <summary>
|
||||
/// 设置当前骑行的模式
|
||||
/// </summary>
|
||||
private void HandleRideMode()
|
||||
{
|
||||
//进入对战房间
|
||||
if (App.gameRoomDetail != null)
|
||||
{
|
||||
@ -259,6 +333,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
StartCoroutine(Init());
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator Ping()
|
||||
{
|
||||
while (true)
|
||||
@ -268,14 +343,13 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
}
|
||||
}
|
||||
|
||||
float timer = 1f;
|
||||
bool clearLock = false;
|
||||
|
||||
private void SceneManager_activeSceneChanged(Scene arg0, Scene arg1)
|
||||
{
|
||||
ClearTempFile();
|
||||
}
|
||||
|
||||
#region 手势移动&PC鼠标的控制
|
||||
|
||||
private void HandleTouchAndInput()
|
||||
{
|
||||
var rotationRecognizer = new TKOneFingerRotationRecognizer
|
||||
@ -302,7 +376,8 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
timer.Stop();
|
||||
};
|
||||
|
||||
rotationRecognizer.gestureCompleteEvent += (r) => {
|
||||
rotationRecognizer.gestureCompleteEvent += (r) =>
|
||||
{
|
||||
UnityEngine.Debug.Log("gestureCompleteEvent");
|
||||
timer.Start();
|
||||
};
|
||||
@ -345,6 +420,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
cameraList.Add(medium);
|
||||
cameraList.Add(far);
|
||||
}
|
||||
|
||||
var prePos = Camera.main.transform.localPosition;
|
||||
var nextPos = Camera.main.transform.localPosition;
|
||||
if (r.deltaScale < 0)
|
||||
@ -354,6 +430,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
Camera.main.transform.DOLocalMove(nextPos, 0.5f);
|
||||
//StartCoroutine(MoveCamera(prePos, nextPos));
|
||||
}
|
||||
|
||||
if (r.deltaScale > 0)
|
||||
{
|
||||
nextPos = cameraList.Where(c => c.y < Camera.main.transform.localPosition.y).LastOrDefault();
|
||||
@ -365,6 +442,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
};
|
||||
TouchKit.addGestureRecognizer(PinchRecognizer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测是否点击UI
|
||||
/// </summary>
|
||||
@ -380,7 +458,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
EventSystem.current.RaycastAll(eventData, raycastResults);
|
||||
if (raycastResults.Count > 0)
|
||||
{
|
||||
return !raycastResults.Where(c => c.gameObject.name == "NearPanel" || c.gameObject.name == "ToolBarPanel" || c.gameObject.name == "SettingPanel" || c.gameObject.name == "QuitPanel").Any();
|
||||
return !raycastResults.Where(c =>
|
||||
c.gameObject.name == "NearPanel" || c.gameObject.name == "ToolBarPanel" ||
|
||||
c.gameObject.name == "SettingPanel" || c.gameObject.name == "QuitPanel").Any();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -389,52 +469,6 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
}
|
||||
|
||||
#endregion
|
||||
bool _dragStartedOnUI = false;
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
//CamControl();
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)//定时器 一秒执行一次
|
||||
{
|
||||
TcpHandler();
|
||||
App.CurrentScene = "Ride";
|
||||
if (competitionId == 0)
|
||||
{
|
||||
UIManager.SendCompetitionStartMessage("Ride");
|
||||
}
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
//if (isStart)
|
||||
//{
|
||||
// activeSeconds++;
|
||||
//}
|
||||
//if (activeSeconds >= App.autoClearTimes && !clearLock)
|
||||
//{
|
||||
// if (competitionId == 0)
|
||||
// {
|
||||
// clearLock = true;
|
||||
// singleUIManager?.ClearPanel(null);
|
||||
// }
|
||||
//}
|
||||
#endif
|
||||
timer += 1.0f;
|
||||
}
|
||||
}
|
||||
float touchTimer = 0.1f;
|
||||
private void FixedUpdate()
|
||||
{
|
||||
HandleTouch();
|
||||
HandleMouseScrollWheel();
|
||||
}
|
||||
public bool isWatch { get; set; }
|
||||
private Vector3 currentCameraPos { get; set; }
|
||||
|
||||
Vector3 far = new Vector3(-17, 52, -48);
|
||||
Vector3 medium = new Vector3(-14.5f, 45, -40);
|
||||
Vector3 plane = new Vector3(-10.5f, 35, -30); //new Vector3(-11.4f, 31, -30);
|
||||
Vector3 near = new Vector3(-7.3f, 24, -20);
|
||||
Vector3 neareast = new Vector3(-5.4f, 18, -15);
|
||||
List<Vector3> cameraList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 处理PC端
|
||||
@ -454,6 +488,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
cameraList.Add(medium);
|
||||
cameraList.Add(far);
|
||||
}
|
||||
|
||||
var prePos = Camera.main.transform.localPosition;
|
||||
var nextPos = Camera.main.transform.localPosition;
|
||||
if (scrollDelta < 0)
|
||||
@ -473,7 +508,6 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
}
|
||||
}
|
||||
|
||||
DateTime startTimpStamp = DateTime.Now;
|
||||
private void HandleTouch()
|
||||
{
|
||||
if (singleUIManager == null)
|
||||
@ -485,13 +519,15 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
UnityEngine.Debug.Log(Input.touches[0]);
|
||||
UnityEngine.Debug.Log($"{Input.touches[0]}{Input.touches[0].phase}");
|
||||
if (Input.touches[0].tapCount == 1 && Input.touches[0].phase == TouchPhase.Began && isStart && singleUIManager.clearLock && competitionId == 0)
|
||||
if (Input.touches[0].tapCount == 1 && Input.touches[0].phase == TouchPhase.Began && isStart &&
|
||||
singleUIManager.clearLock && competitionId == 0)
|
||||
{
|
||||
startTimpStamp = DateTime.Now;
|
||||
}
|
||||
|
||||
//单击切换极简模式
|
||||
if (Input.touches[0].tapCount==1 && Input.touches[0].phase == TouchPhase.Ended && isStart && singleUIManager.clearLock && competitionId == 0)
|
||||
if (Input.touches[0].tapCount == 1 && Input.touches[0].phase == TouchPhase.Ended && isStart &&
|
||||
singleUIManager.clearLock && competitionId == 0)
|
||||
{
|
||||
var interval = DateTime.Now - startTimpStamp;
|
||||
UnityEngine.Debug.Log(interval);
|
||||
@ -526,6 +562,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
cameraList.Add(plane);
|
||||
cameraList.Add(far);
|
||||
}
|
||||
|
||||
var prePos = Camera.main.transform.localPosition;
|
||||
var nextPos = Camera.main.transform.localPosition;
|
||||
if (offset < 0)
|
||||
@ -535,6 +572,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
Camera.main.transform.DOLocalMove(nextPos, 0.5f);
|
||||
//StartCoroutine(MoveCamera(prePos, nextPos));
|
||||
}
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
nextPos = cameraList.Where(c => c.y < Camera.main.transform.localPosition.y).LastOrDefault();
|
||||
@ -565,6 +603,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
App.tempRecordData = null; //清空
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator Init()
|
||||
{
|
||||
yield return null;
|
||||
@ -605,6 +644,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
//MapUDPService.Init(competitionId,isWatch);//初始化比赛TCP
|
||||
loadingController.AddProcess(10);
|
||||
}
|
||||
|
||||
public void InitTcp()
|
||||
{
|
||||
MapUDPService.Init(competitionId, isWatch); //初始化比赛TCP
|
||||
@ -616,7 +656,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
mapData = mapApi.GetData(routeId); //获取路书地理数据
|
||||
route = new Route(mapData, mapRoute);
|
||||
loadingController.AddProcess(10);
|
||||
|
||||
#region 其他场景传参处理
|
||||
|
||||
//骑行结果
|
||||
if (App.routeResult != null)
|
||||
{
|
||||
@ -659,7 +701,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
mapData = mapApi.GetData(routeId); //获取路书地理数据
|
||||
route = new Route(mapData, mapRoute);
|
||||
loadingController.AddProcess(10);
|
||||
|
||||
#region 其他场景传参处理
|
||||
|
||||
selectParamModel = new RouteResultParam
|
||||
{
|
||||
CompetitionId = 0,
|
||||
@ -673,6 +717,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
double endDistance = selectParamModel.EndDistance;
|
||||
//计算上次骑行距离调整地图中心点
|
||||
coordiantes = Along(endDistance);
|
||||
@ -683,7 +728,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
mapData = mapApi.GetData(routeId); //获取路书地理数据
|
||||
route = new Route(mapData, mapRoute);
|
||||
loadingController.AddProcess(10);
|
||||
|
||||
#region 其他场景传参处理
|
||||
|
||||
selectParamModel = new RouteResultParam
|
||||
{
|
||||
CompetitionId = competitionId,
|
||||
@ -697,12 +744,12 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
double endDistance = selectParamModel.EndDistance;
|
||||
//计算上次骑行距离调整地图中心点
|
||||
coordiantes = Along(endDistance);
|
||||
}
|
||||
|
||||
private Vector3 mapPos = Vector3.zero;
|
||||
//加载人物和地图以及UI界面
|
||||
private void InitGameObject()
|
||||
{
|
||||
@ -717,6 +764,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
map.OnTileFinished += Map_OnTileFinished;
|
||||
mapPos = map.transform.position;
|
||||
}
|
||||
|
||||
private void InitGameRoomObject()
|
||||
{
|
||||
#if !(UNITY_IOS || UNITY_ANDROID)
|
||||
@ -761,6 +809,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
map.SetExtent(MapExtentType.RangeAroundTransform, options);
|
||||
map.SetExtentOptions(options);
|
||||
}
|
||||
|
||||
//根据性别创建当前骑手
|
||||
private void CreateCurrentPlayer()
|
||||
{
|
||||
@ -772,6 +821,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
player = Instantiate<GameObject>(Resources.Load<GameObject>("UI/Prefab/Ride/Player_NV"), transform);
|
||||
}
|
||||
|
||||
TrailRenderer trail = player.GetComponent<TrailRenderer>();
|
||||
trail.Clear();
|
||||
playerController = player.GetComponent<PlayerController>();
|
||||
@ -797,16 +847,11 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
cyclingController = new GameModel(route, selectParamModel);
|
||||
break;
|
||||
}
|
||||
|
||||
GameStart();
|
||||
InitPlayer(); //初始化人物方向等
|
||||
}
|
||||
PlayerController playerController;
|
||||
public AbstractPlayer currentPlayer { get; set; }
|
||||
|
||||
private GameObject onlinePlayer { get; set; }
|
||||
|
||||
Vector3 MAX_SIZE = new Vector3(3f, 3f, 3f);
|
||||
Vector3 MIN_SIZE = new Vector3(0.1f, 0.1f, 0.1f);
|
||||
public void ChangeCurrentPlayer(int userId)
|
||||
{
|
||||
var coll = FindObjectsOfType<AbstractPlayer>();
|
||||
@ -821,7 +866,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
}
|
||||
}
|
||||
|
||||
var selectedPlayer = coll.Where(c => c.UserId == userId).FirstOrDefault();
|
||||
var selectedPlayer = coll.FirstOrDefault(c => c.UserId == userId);
|
||||
if (selectedPlayer != null)
|
||||
{
|
||||
currentPlayer = selectedPlayer;
|
||||
@ -832,17 +877,19 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
else
|
||||
{
|
||||
Utils.DestroyChildren(selectedPlayer.transform);
|
||||
var ss = Instantiate(onlineUserPrefab3d, selectedPlayer.transform);
|
||||
ss.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
var currentOnlinePrefab = selectedPlayer.Sex == 1 ? onlineUserPrefab3d : onlineUserPrefab3dNv;
|
||||
var onlineGameObject = Instantiate(currentOnlinePrefab, selectedPlayer.transform);
|
||||
onlineGameObject.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
selectedPlayer.transform.localScale = Is3dView ? MAX_SIZE : MIN_SIZE;
|
||||
selectedPlayer.UpdateAnimator();
|
||||
selectedPlayer.UserId = userId;
|
||||
}
|
||||
Vector2d nextLatLon = Along(selectedPlayer.TotalDistance + 0.1);
|
||||
|
||||
var nextLatLon = Along(selectedPlayer.TotalDistance + 0.1);
|
||||
//设定人物方向
|
||||
var s = map.GeoToWorldPosition(selectedPlayer.Currentlatlong);
|
||||
var e = map.GeoToWorldPosition(nextLatLon);
|
||||
Quaternion neededRotation = Quaternion.LookRotation(e - s);
|
||||
var neededRotation = Quaternion.LookRotation(e - s);
|
||||
selectedPlayer.transform.rotation = Quaternion.Euler(0, neededRotation.eulerAngles.y, 0);
|
||||
selectedPlayer.currentRotation = neededRotation;
|
||||
}
|
||||
@ -852,7 +899,6 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
graph.HorizontalScrolling = chartDataSourceScript.GetCurrentStart(currentIndex);
|
||||
}
|
||||
|
||||
//初始化人物位置角度
|
||||
private void InitPlayer()
|
||||
{
|
||||
TempFileHandler(); //处理中断骑行继续骑的逻辑
|
||||
@ -884,20 +930,21 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
tick = recorderData.RiderDatas.Last().Ticks;
|
||||
}
|
||||
|
||||
//对战模式重连秒数按照现在的日期减去对战开始的日期
|
||||
if (recorderData.RoomId > 0 && recorderData.RiderDatas.Count > 0)
|
||||
{
|
||||
tick = (int)(UIManager.Now.GetDateTime() - startTime).TotalSeconds;
|
||||
}
|
||||
|
||||
playerController.Init(index, recorderData.EndDistance, tick);
|
||||
}
|
||||
|
||||
public void InitGraph(int index)
|
||||
{
|
||||
chartDataSourceScript.InitHorizontalScrolling(index);
|
||||
}
|
||||
|
||||
//SingleUIManager singleUIManager;
|
||||
public BaseUIManager singleUIManager;
|
||||
public void GameStart()
|
||||
{
|
||||
Camera.main.transform.DOLocalMove(near, 1f);
|
||||
@ -917,15 +964,18 @@ public BaseUIManager singleUIManager;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = false;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = false;
|
||||
Utils.showToast(null, "Please connect the device!", duration: int.MaxValue, isLowest: true
|
||||
, stopFunc: () => isWatch || CheckAnt() || transform.Find("UI/Panel(Clone)/SelectPlayer").gameObject.activeInHierarchy
|
||||
, stopFunc: () =>
|
||||
isWatch || CheckAnt() || transform.Find("UI/Panel(Clone)/SelectPlayer").gameObject.activeInHierarchy
|
||||
, endCallback: () =>
|
||||
{
|
||||
if (!transform.Find("UI/Panel(Clone)/SelectPlayer").gameObject.activeInHierarchy)
|
||||
{
|
||||
UIManager.Instance.DevicePanel.Close();
|
||||
singleUIManager.StartRide();
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = true;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = true;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>()
|
||||
.enabled = true;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled =
|
||||
true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -938,26 +988,20 @@ public BaseUIManager singleUIManager;
|
||||
|
||||
#region TCP相关
|
||||
|
||||
public void TcpHandler()
|
||||
{
|
||||
if (cyclingController != null)
|
||||
{
|
||||
////tcp数据传输
|
||||
//if (competition != null && !cyclingController.recorderData.Saved)
|
||||
//{
|
||||
// cyclingController.recorderData.Saved = competition.HasRecord;
|
||||
//}
|
||||
cyclingController.Run(null);
|
||||
//在线人物或比赛人物渲染
|
||||
ShowOnlineUsers();
|
||||
}
|
||||
}
|
||||
|
||||
List<OnlinePlayerController> otherList = new List<OnlinePlayerController>();
|
||||
GameObject onlineUserPrefab;
|
||||
GameObject miniMapPlayerPrefab;
|
||||
|
||||
int messageIndex = 0;
|
||||
|
||||
private void TcpHandler()
|
||||
{
|
||||
if (cyclingController == null) return;
|
||||
|
||||
cyclingController.Run(null);
|
||||
|
||||
ShowOnlineUsers();
|
||||
}
|
||||
|
||||
private void ShowOnlineUsers()
|
||||
{
|
||||
var onlineRiders = cyclingController.riders;
|
||||
@ -966,71 +1010,111 @@ public BaseUIManager singleUIManager;
|
||||
foreach (var item in onlineRiders)
|
||||
{
|
||||
var onlineRider = item as OnlineRiderModel;
|
||||
var currentUser = currentOnlineUserList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
var currentUser = currentOnlineUserList.FirstOrDefault(c => c.UserId == item.UserId);
|
||||
var onlineDistance = onlineRider.EndDistance - onlineRider.PreDistance;
|
||||
var onlineTotalDistance = onlineRider.PreDistance;
|
||||
var index = GetCurrentIndex(onlineTotalDistance);
|
||||
|
||||
if (currentUser == null)
|
||||
{
|
||||
CreateOnlinePlayer(onlineRider,onlineTotalDistance,onlineDistance,index);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateOnlinePlayer(currentUser,onlineRider,onlineTotalDistance,onlineDistance,index);
|
||||
}
|
||||
|
||||
HandleWatcherView();
|
||||
}
|
||||
|
||||
if (onlineRiders.Count > 0)
|
||||
messageIndex++;
|
||||
|
||||
RemoveOfflineUsers();
|
||||
ShowNearPlayerInfo();
|
||||
}
|
||||
|
||||
private void CreateOnlinePlayer(OnlineRiderModel onlineRider,double onlineTotalDistance,double onlineDistance,int index)
|
||||
{
|
||||
//大地图人物
|
||||
GameObject otherPlayerObj = (GameObject)Instantiate(onlineUserPrefab, transform);
|
||||
var otherPlayerObj = (GameObject)Instantiate(onlineUserPrefab, transform);
|
||||
otherPlayerObj.transform.position = map.GeoToWorldPosition(Along(onlineTotalDistance));
|
||||
var onlinePlayerController = otherPlayerObj.GetComponent<OnlinePlayerController>();
|
||||
otherList.Add(onlinePlayerController);
|
||||
|
||||
onlinePlayerController.UserId = onlineRider.UserId;
|
||||
|
||||
onlinePlayerController.SetDataSource(onlineTotalDistance, onlineDistance, onlineRider.Power, onlineRider.HeartRate, onlineRider.Cadence, onlineRider.TotalTicks, onlineRider.NickName, onlineRider.WeightKg, new Vector2d(onlineRider.Point.Latitude, onlineRider.Point.Longitude), index);
|
||||
onlinePlayerController.SetDataSource(onlineTotalDistance, onlineDistance, onlineRider.Power,
|
||||
onlineRider.HeartRate, onlineRider.Cadence, onlineRider.TotalTicks, onlineRider.NickName,
|
||||
onlineRider.WeightKg, new Vector2d(onlineRider.Point.Latitude, onlineRider.Point.Longitude), index,
|
||||
onlineRider.Sex);
|
||||
onlinePlayerController.SetHead(onlineRider.WxHeadImg);
|
||||
|
||||
if (competitionId == 0)
|
||||
{
|
||||
//小地图人物
|
||||
GameObject miniPlayer = (GameObject)Instantiate(miniMapPlayerPrefab, transform);
|
||||
var miniPlayer = (GameObject)Instantiate(miniMapPlayerPrefab, transform);
|
||||
var miniController = miniPlayer.GetComponent<MiniMapPlayerController>();
|
||||
miniController.SetController(onlinePlayerController);
|
||||
}
|
||||
|
||||
//发消息xx进入路书
|
||||
if (messageIndex > 0)
|
||||
EventQueueSystem.QueueEvent(new JoinMessageEvent(onlineRider.NickName, onlineRider.WxHeadImg));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
currentUser.SetDataSource(onlineTotalDistance, onlineDistance, onlineRider.Power, onlineRider.HeartRate, onlineRider.Cadence, onlineRider.TotalTicks, onlineRider.NickName, onlineRider.WeightKg, new Vector2d(onlineRider.Point.Latitude, onlineRider.Point.Longitude), index);
|
||||
}
|
||||
|
||||
if (isWatch && (currentPlayer is PlayerController || currentPlayer == null))
|
||||
private void UpdateOnlinePlayer(OnlinePlayerController currentUser, OnlineRiderModel onlineRider,
|
||||
double onlineTotalDistance, double onlineDistance, int index)
|
||||
{
|
||||
var userId = onlineRiders.FirstOrDefault()?.UserId ?? 0;
|
||||
currentUser.SetDataSource(onlineTotalDistance, onlineDistance, onlineRider.Power, onlineRider.HeartRate,
|
||||
onlineRider.Cadence, onlineRider.TotalTicks, onlineRider.NickName, onlineRider.WeightKg,
|
||||
new Vector2d(onlineRider.Point.Latitude, onlineRider.Point.Longitude), index, onlineRider.Sex);
|
||||
}
|
||||
|
||||
private void HandleWatcherView()
|
||||
{
|
||||
var needChangeView = isWatch && (currentPlayer is PlayerController || currentPlayer == null);
|
||||
if (!needChangeView) return;
|
||||
|
||||
var userId = cyclingController.riders.FirstOrDefault()?.UserId ?? 0;
|
||||
ChangeCurrentPlayer(userId);
|
||||
|
||||
var competitionRankingFactory = FindObjectOfType<CompetitionRankingFactory>();
|
||||
if (competitionRankingFactory != null)
|
||||
{
|
||||
competitionRankingFactory.isInit = false;
|
||||
}
|
||||
}
|
||||
//显示观察者头像
|
||||
}
|
||||
if (onlineRiders.Count > 0)
|
||||
messageIndex++;
|
||||
//移除
|
||||
|
||||
private void RemoveOfflineUsers()
|
||||
{
|
||||
var currentOnlineUserList = FindObjectsOfType<OnlinePlayerController>();
|
||||
foreach (var item in currentOnlineUserList)
|
||||
{
|
||||
var currentItem = onlineRiders.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
var currentItem = cyclingController.riders.FirstOrDefault(c => c.UserId == item.UserId);
|
||||
if (currentItem == null)
|
||||
{
|
||||
item.RemoveSelf();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//显示面板信息
|
||||
private void ShowNearPlayerInfo()
|
||||
{
|
||||
var others = FindObjectsOfType<AbstractPlayer>();
|
||||
foreach (var item in others)
|
||||
{
|
||||
item.IsShowInfo = false;
|
||||
}
|
||||
var frontPlayer = others.Where(c => c.TotalDistance - currentPlayer.TotalDistance < 0.25 && c.TotalDistance - currentPlayer.TotalDistance >= 0 && c.UserId != currentPlayer.UserId).OrderBy(c => c.TotalDistance).FirstOrDefault();
|
||||
var bakePlayer = others.Where(c => c.TotalDistance - currentPlayer.TotalDistance > -0.25 && c.TotalDistance - currentPlayer.TotalDistance < 0 && c.UserId != currentPlayer.UserId).OrderByDescending(c => c.TotalDistance).FirstOrDefault();
|
||||
|
||||
var frontPlayer = others
|
||||
.Where(c => c.TotalDistance - currentPlayer.TotalDistance < 0.25 &&
|
||||
c.TotalDistance - currentPlayer.TotalDistance >= 0 && c.UserId != currentPlayer.UserId)
|
||||
.OrderBy(c => c.TotalDistance).FirstOrDefault();
|
||||
var bakePlayer = others
|
||||
.Where(c => c.TotalDistance - currentPlayer.TotalDistance > -0.25 &&
|
||||
c.TotalDistance - currentPlayer.TotalDistance < 0 && c.UserId != currentPlayer.UserId)
|
||||
.OrderByDescending(c => c.TotalDistance).FirstOrDefault();
|
||||
if (frontPlayer != null)
|
||||
frontPlayer.IsShowInfo = true;
|
||||
if (bakePlayer != null)
|
||||
|
||||
@ -21,6 +21,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
string nickName;
|
||||
string weightKgStr;
|
||||
double diff = 0;
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
@ -73,8 +74,9 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
diff = 0;
|
||||
}
|
||||
}
|
||||
double diff = 0;
|
||||
public void SetDataSource(double _totalDistance, double _distance, double _power, double _heartRate, double _cadence,int _totalTicks, string Name,double weightKg,Vector2d point,int index=0)
|
||||
|
||||
|
||||
public void SetDataSource(double _totalDistance, double _distance, double _power, double _heartRate, double _cadence,int _totalTicks, string Name,double weightKg,Vector2d point,int index=0,int sex=0)
|
||||
{
|
||||
totalDistance = _totalDistance;
|
||||
distance = _distance;
|
||||
@ -88,6 +90,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
power = Convert.ToInt32(_power);
|
||||
cadance = _cadence;
|
||||
ticks = _totalTicks;
|
||||
Sex = sex;
|
||||
}
|
||||
|
||||
public Vector2d Point { get; set; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user