125 lines
4.1 KiB
C#
125 lines
4.1 KiB
C#
using Assets.Scenes.Ride.Scripts.Model;
|
|
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
using ChartAndGraph;
|
|
using DG.Tweening;
|
|
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Linq;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
public class OnlinePlayerController : AbstractPlayer
|
|
{
|
|
public PlayerController _playerController;
|
|
RawImage head;
|
|
GameObject headPanel;
|
|
|
|
Image arrowImage;
|
|
GameObject reviewInfoPanel;
|
|
Transform uiObject;
|
|
|
|
GraphChartBase graph;
|
|
ChartDataSourceScript chartDataSourceScript;
|
|
|
|
protected override void Init()
|
|
{
|
|
base.Init();
|
|
currentlatlong = mainController.GetCenterCoordinate();
|
|
_playerController = FindObjectOfType<PlayerController>();
|
|
graph = transform.parent.Find("SingleUI/Panel/GraphChart").GetComponent<GraphChartBase>();
|
|
chartDataSourceScript = transform.parent.Find("SingleUI/Panel/GraphChart").GetComponent<ChartDataSourceScript>();
|
|
|
|
//创建UI
|
|
uiObject = transform.parent.Find("SingleUI/Panel/ArrowList");
|
|
arrowImage = Instantiate(Resources.Load<Image>("UI/Prefab/Ride/ReviewArrow"), uiObject);
|
|
arrowImage.color = new Color(0.1529412f, 0.8745098f, 0.8901961f);
|
|
|
|
|
|
}
|
|
protected override bool GetStart()
|
|
{
|
|
return true;
|
|
}
|
|
protected override void Compute()
|
|
{
|
|
currentlatlong = mainController.Along(totalDistance);//下一个坐标
|
|
//var currentUser = cyclingExcutor.riders.Where(c => c.UserId == UserId).FirstOrDefault();
|
|
//if (currentUser == null)
|
|
//{
|
|
// RemoveSelf();
|
|
//}
|
|
}
|
|
|
|
public void SetDistance(double _distance)
|
|
{
|
|
}
|
|
|
|
public void SetTotalDistance(double _totalDistance, double _distance)
|
|
{
|
|
totalDistance = _totalDistance;
|
|
distance = _distance;
|
|
}
|
|
|
|
public int GetCurrentIndex(double endistance,MapDataModel mapDataModel)
|
|
{
|
|
var pointList = mapDataModel.List;
|
|
int onIndex = 0;
|
|
var sumDistance = 0D;
|
|
for (int i = 0; i < pointList.Count; i++)
|
|
{
|
|
sumDistance += pointList[i].Distance;
|
|
if (endistance * 1000 <= sumDistance)
|
|
{
|
|
onIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
return onIndex;
|
|
}
|
|
|
|
private string headUrl;
|
|
public void SetHead(string url )
|
|
{
|
|
headUrl = url;
|
|
}
|
|
public void MoveHead(Transform parent)
|
|
{
|
|
var itemIndex = chartDataSourceScript.GetViewIndex(GetCurrentIndex(TotalDistance, mainController.GetMapData())) + 1;
|
|
var m = graph.DataSource.GetPoint("Player 2", itemIndex);
|
|
graph.PointToWorldSpace(out Vector3 itemPosition, m.x, m.y, "Player 2");
|
|
itemPosition.x -= 12f;
|
|
itemPosition.y += 5f;
|
|
|
|
if (headPanel == null)
|
|
{
|
|
headPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Ride/OnlineHeadPanel"));
|
|
headPanel.transform.SetParent(parent);
|
|
headPanel.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
|
|
headPanel.transform.position = itemPosition;
|
|
}
|
|
if (head == null)
|
|
{
|
|
head = headPanel.GetComponentInChildren<RawImage>();
|
|
if (!string.IsNullOrEmpty(headUrl))
|
|
{
|
|
Utils.DisplayImage(head, headUrl, true);
|
|
}
|
|
}
|
|
|
|
headPanel.transform.DOMove(new Vector3(itemPosition.x, itemPosition.y, 0), 1);
|
|
}
|
|
|
|
public void RemoveSelf()
|
|
{
|
|
transform.gameObject.Destroy();
|
|
headPanel.Destroy();
|
|
}
|
|
protected override void AfterExcute()
|
|
{
|
|
((RectTransform)arrowImage.transform).position = Camera.main.WorldToScreenPoint(transform.position);
|
|
MoveHead(graph.transform);
|
|
}
|
|
}
|
|
} |