对战初步完成
This commit is contained in:
1 parent
b0c0890ca3
commit
509c309252
55 files changed
+7079
-6748
No files matched your search
@@ -9,6 +9,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
|
||||
public class GameRoomCell : MonoBehaviour, ICell, IBeginDragHandler, IDragHandler, IEndDragHandler,IScrollHandler
|
||||
{
|
||||
@@ -39,18 +40,21 @@ public class GameRoomCell : MonoBehaviour, ICell, IBeginDragHandler, IDragHandle
|
||||
|
||||
public RawImage AltitudeGraphImg;
|
||||
|
||||
public RawImage Owner;
|
||||
public RawImage Head1;
|
||||
public RawImage Head2;
|
||||
public RawImage Head3;
|
||||
public RawImage Head4;
|
||||
public RawImage Head5;
|
||||
|
||||
public GameObject IconOwnerLight;
|
||||
public RawImage HeadPrefab;
|
||||
public Transform Content;
|
||||
|
||||
public GameObject JoinBtn;
|
||||
public GameObject CycingBtn;
|
||||
public GameObject ResultBtn;
|
||||
public GameObject Lock;
|
||||
public GameObject LockL;
|
||||
public GameObject D2;
|
||||
public GameObject D3;
|
||||
public GameObject AR;
|
||||
public GameObject D2L;
|
||||
public GameObject D3L;
|
||||
public GameObject ARL;
|
||||
|
||||
private ScrollRect Scroll;
|
||||
|
||||
private bool IsLock;
|
||||
@@ -70,11 +74,42 @@ public class GameRoomCell : MonoBehaviour, ICell, IBeginDragHandler, IDragHandle
|
||||
{
|
||||
LockL.SetActive(IsLock);
|
||||
Lock.SetActive(false);
|
||||
|
||||
D2.SetActive(false);
|
||||
D2L.SetActive(Enable2d);
|
||||
|
||||
D3.SetActive(false);
|
||||
D3L.SetActive(Enable3d);
|
||||
|
||||
AR.SetActive(false);
|
||||
ARL.SetActive(EnableAR);
|
||||
|
||||
|
||||
var list = GetComponentsInChildren<GameRoomHead>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.ShowLight();
|
||||
}
|
||||
});
|
||||
UIManager.AddEvent(gameObject, EventTriggerType.PointerExit, (e) =>
|
||||
{
|
||||
LockL.SetActive(false);
|
||||
Lock.SetActive(IsLock);
|
||||
|
||||
D2.SetActive(Enable2d);
|
||||
D2L.SetActive(false);
|
||||
|
||||
D3.SetActive(Enable3d);
|
||||
D3L.SetActive(false);
|
||||
|
||||
AR.SetActive(EnableAR);
|
||||
ARL.SetActive(false);
|
||||
|
||||
var list = GetComponentsInChildren<GameRoomHead>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.ShowShadow();
|
||||
}
|
||||
});
|
||||
UIManager.AddEvent(JoinBtn, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
@@ -88,6 +123,16 @@ public class GameRoomCell : MonoBehaviour, ICell, IBeginDragHandler, IDragHandle
|
||||
manager.ShowDownLoadConfirm();
|
||||
}
|
||||
});
|
||||
//对战正在进行
|
||||
UIManager.AddEvent(CycingBtn, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
manager.ShowCycingPanel(gameRoom);
|
||||
});
|
||||
//对战已经结束
|
||||
UIManager.AddEvent(ResultBtn, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
manager.ShowDonePanel(gameRoom.RoomId);
|
||||
});
|
||||
}
|
||||
private float timer = 1f;
|
||||
private void Update()
|
||||
@@ -98,7 +143,9 @@ public class GameRoomCell : MonoBehaviour, ICell, IBeginDragHandler, IDragHandle
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
|
||||
private bool Enable2d { get; set; }
|
||||
private bool Enable3d { get; set; }
|
||||
private bool EnableAR { get; set; }
|
||||
//This is called from the SetCell method in DataSource
|
||||
public void ConfigureCell(GameRoomModel cell, int cellIndex)
|
||||
{
|
||||
@@ -119,15 +166,39 @@ public class GameRoomCell : MonoBehaviour, ICell, IBeginDragHandler, IDragHandle
|
||||
|
||||
RouteNameTxt.text = cell.MapRouteName;
|
||||
RouteNameLightTxt.text = cell.MapRouteName;
|
||||
IdTxt.text = cell.Id.ToString().PadLeft(7,'0');
|
||||
IdTxt.text = cell.RoomId.ToString().PadLeft(7,'0');
|
||||
|
||||
IsLock = cell.IsLock;
|
||||
Id = cell.Id;
|
||||
Id = cell.RoomId;
|
||||
//房间状态
|
||||
JoinBtn.SetActive(cell.Status == 0);
|
||||
CycingBtn.SetActive(cell.Status == 1);
|
||||
ResultBtn.SetActive(cell.Status == 2);
|
||||
|
||||
Enable2d = !cell.Enable3D && !cell.EnableAR;
|
||||
Enable3d = cell.Enable3D && !cell.EnableAR;
|
||||
EnableAR = cell.EnableAR;
|
||||
|
||||
D2.SetActive(Enable2d);
|
||||
D3.SetActive(Enable3d);
|
||||
AR.SetActive(EnableAR);
|
||||
|
||||
Lock.SetActive(IsLock);
|
||||
LockL.SetActive(false);
|
||||
Utils.DisplayImage(AltitudeGraphImg, cell.AltitudeGraph);
|
||||
Utils.DisplayImage(Owner, cell.WxHeadImg);
|
||||
|
||||
var playerList = cell.RoomPlayerList;
|
||||
if (playerList != null)
|
||||
{
|
||||
MembersTxt.text = $"{playerList.Count}/{cell.MaxMembers}";
|
||||
var s = playerList.Select(c => c.UserId);
|
||||
var user = ConfigHelper.mapApi.GetOnlineUserInfo(s);
|
||||
foreach (var item in playerList)
|
||||
{
|
||||
var obj = Instantiate(HeadPrefab, Content);
|
||||
obj.GetComponent<GameRoomHead>().Set(item.WxHeadImage,item.IsOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void UpdateItem(string name, string gender, string id)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameRoomHead : MonoBehaviour
|
||||
{
|
||||
public Image IconOwnerLightImg;
|
||||
public Image IconOwnerImg;
|
||||
public RawImage Head;
|
||||
|
||||
private bool IsOwner { get; set; }
|
||||
|
||||
private float timer = 1f;
|
||||
private void Update()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
while (timer < 0)
|
||||
{
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(string headUrl,bool isOwner)
|
||||
{
|
||||
Utils.DisplayImage(Head, headUrl);
|
||||
IsOwner = isOwner;
|
||||
IconOwnerImg.gameObject.SetActive(isOwner);
|
||||
}
|
||||
|
||||
public void ShowLight()
|
||||
{
|
||||
IconOwnerImg.gameObject.SetActive(false);
|
||||
IconOwnerLightImg.gameObject.SetActive(IsOwner);
|
||||
}
|
||||
|
||||
public void ShowShadow()
|
||||
{
|
||||
IconOwnerImg.gameObject.SetActive(IsOwner);
|
||||
IconOwnerLightImg.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7fd898b102fbad479f0d0037b505976
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,7 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scripts.UI.Control;
|
||||
using PolyAndCode.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,11 +12,8 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
class GameRoomList : MonoBehaviour, IRecyclableScrollRectDataSource
|
||||
class GameRoomList : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
RecyclableScrollRect _recyclableScrollRect;
|
||||
|
||||
[SerializeField]
|
||||
RectTransform _rectTransform;
|
||||
|
||||
@@ -29,18 +27,33 @@ class GameRoomList : MonoBehaviour, IRecyclableScrollRectDataSource
|
||||
private int _dataLength;
|
||||
private bool _isInit;
|
||||
|
||||
private GameObject RoomCell { get; set; }
|
||||
|
||||
//Dummy data List
|
||||
private List<GameRoomModel> _list = new List<GameRoomModel>();
|
||||
|
||||
private string seachName = "";
|
||||
PFUIPageHelper pageHelper;
|
||||
|
||||
//Recyclable scroll rect's data source must be assigned in Awake.
|
||||
private void Awake()
|
||||
{
|
||||
_recyclableScrollRect.DataSource = this;
|
||||
RoomCell = Resources.Load<GameObject>("UI/Prefab/GameRoom/Room");
|
||||
//分页
|
||||
pageHelper = FindObjectOfType<PFUIPageHelper>();
|
||||
pageHelper.PageIndex = 0;
|
||||
pageHelper.PageSize = 6;
|
||||
pageHelper.Register((e) =>
|
||||
{
|
||||
_ = GetDataAsync();
|
||||
});
|
||||
|
||||
_ = GetDataAsync();
|
||||
_searchInputField.onValueChanged.AddListener((e) => {
|
||||
if (!string.IsNullOrEmpty(e))
|
||||
_searchInputField.onValueChanged.AddListener((e) => { seachName = e; });
|
||||
_searchInputField.onEndEdit.AddListener((e) => {
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
_ = GetDataAsync(Convert.ToInt32(e));
|
||||
_ = GetDataAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -53,14 +66,23 @@ class GameRoomList : MonoBehaviour, IRecyclableScrollRectDataSource
|
||||
{
|
||||
_ = GetDataAsync();
|
||||
}
|
||||
private async Task GetDataAsync(int? id =null)
|
||||
private async Task GetDataAsync()
|
||||
{
|
||||
if (_list != null) _list.Clear();
|
||||
var result = await ConfigHelper.GameRoomApi.GetList(0, 1000, id);
|
||||
var result = await ConfigHelper.GameRoomApi.GetList(pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
if (result.result)
|
||||
{
|
||||
_list = result.data;
|
||||
_recyclableScrollRect.ReloadData();
|
||||
Utils.DestroyChildren(_rectTransform);
|
||||
_list = result.data.List;
|
||||
int index = 0;
|
||||
foreach (var item in _list)
|
||||
{
|
||||
index++;
|
||||
var g = Instantiate(RoomCell, _rectTransform);
|
||||
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
||||
}
|
||||
pageHelper.Total = result.data.Total;
|
||||
pageHelper.Build();
|
||||
}
|
||||
}
|
||||
float timer = 1f;
|
||||
@@ -72,28 +94,5 @@ class GameRoomList : MonoBehaviour, IRecyclableScrollRectDataSource
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
|
||||
#region DATA-SOURCE
|
||||
|
||||
/// <summary>
|
||||
/// Data source method. return the list length.
|
||||
/// </summary>
|
||||
public int GetItemCount()
|
||||
{
|
||||
return _list.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data source method. Called for a cell every time it is recycled.
|
||||
/// Implement this method to do the necessary cell configuration.
|
||||
/// </summary>
|
||||
public void SetCell(ICell cell, int index)
|
||||
{
|
||||
//Casting to the implemented Cell
|
||||
var item = cell as GameRoomCell;
|
||||
item.ConfigureCell(_list[index], index);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
var fileName = map.FileName;
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + "/" + fileName;
|
||||
if ((map.EnableAR && !File.Exists(filepath) )|| !map.EnableAR)
|
||||
//if ((map.EnableAR && !File.Exists(filepath) )|| !map.EnableAR)
|
||||
{
|
||||
var list = FindObjectsOfType<GameRoomMapItem>();
|
||||
foreach (var item in list)
|
||||
|
||||
@@ -28,20 +28,26 @@ class GameRoomPassword : MonoBehaviour
|
||||
passwordInput.text = "";
|
||||
}
|
||||
|
||||
private async void ConfirmClick(BaseEventData baseEventData)
|
||||
private void ConfirmClick(BaseEventData baseEventData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Password))
|
||||
{
|
||||
Utils.showToast(gameObject, App.GetLocalString("room password can not be empty"));
|
||||
return;
|
||||
}
|
||||
var RoomId = manager.GetRoomId();
|
||||
var result = await ConfigHelper.GameRoomApi.ConfirmRoomPwd(RoomId, Password);
|
||||
if (!result.result)
|
||||
var room = manager.GetCurrentRoom();
|
||||
if (room != null && !room.Password.Equals(Password))
|
||||
{
|
||||
Utils.showToast(gameObject, result.errMsg);
|
||||
Utils.showToast(gameObject, App.GetLocalString("Wrong password"));
|
||||
return;
|
||||
}
|
||||
//var RoomId = manager.GetRoomId();
|
||||
//var result = await ConfigHelper.GameRoomApi.ConfirmRoomPwd(RoomId, Password);
|
||||
//if (!result.result)
|
||||
//{
|
||||
// Utils.showToast(gameObject, result.errMsg);
|
||||
// return;
|
||||
//}
|
||||
Refresh();
|
||||
gameObject.SetActive(false);
|
||||
manager.ShowDownLoadConfirm();
|
||||
|
||||
@@ -27,12 +27,14 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public bool NotUse { get; private set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var manager = FindObjectOfType<GameRoomDetailController>();
|
||||
var inviteBtn = inviteModal.transform.Find("InviteBtn").gameObject;
|
||||
UIManager.AddEvent(inviteBtn,EventTriggerType.PointerClick,(e)=> {
|
||||
Utils.CopyToClipboard($"GameRoom/{manager.GameRoom.Id}");
|
||||
Utils.CopyToClipboard($"GameRoom/{manager.GameRoom.RoomId}");
|
||||
Utils.showToast(transform.parent.gameObject, App.GetLocalString("copy to clipboard successfully!"));
|
||||
});
|
||||
UIManager.AddEvent(gameObject, EventTriggerType.PointerClick, (e) =>
|
||||
@@ -45,11 +47,11 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
});
|
||||
UIManager.AddEvent(kickBtn, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
MapUDPService.SendGameRoomKick(App.gameRoomDetail.Id, UserId, App.CurrentUser.Id);
|
||||
MapUDPService.SendGameRoomKick(App.gameRoomDetail.RoomId, UserId, App.CurrentUser.Id);
|
||||
});
|
||||
}
|
||||
|
||||
public void Init(int userId, string userName,string headUrl,double weight, float ftp,bool isOwner,int Status)
|
||||
public void Init(int userId, string userName,string headUrl,double weight, float ftp,bool isOwner,int Status,int sex)
|
||||
{
|
||||
UserId = userId;
|
||||
inviteModal.SetActive(false);
|
||||
@@ -65,7 +67,7 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
ready.SetActive(!isOwner && Status == 1);
|
||||
}
|
||||
|
||||
public void UpdatePlayer(int userId, string userName, string headUrl, double weight, float ftp, bool isOwner, int Status)
|
||||
public void UpdatePlayer(int userId, string userName, string headUrl, double weight, float ftp, bool isOwner, int Status,int sex)
|
||||
{
|
||||
UserId = userId;
|
||||
inviteModal.SetActive(false);
|
||||
@@ -91,22 +93,20 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
{
|
||||
ready.SetActive(false);
|
||||
}
|
||||
public void ForceQuit()
|
||||
{
|
||||
//TODO:踢人
|
||||
NotInUse();
|
||||
}
|
||||
public void ShowQuitModal()
|
||||
{
|
||||
kickModal.SetActive(true);
|
||||
}
|
||||
public void ShowInviteModal()
|
||||
{
|
||||
NotUse = false;
|
||||
UserId = 0;
|
||||
notInUseModal.SetActive(false);
|
||||
inviteModal.SetActive(true);
|
||||
}
|
||||
public void NotInUse()
|
||||
{
|
||||
NotUse = true;
|
||||
UserId = 0;
|
||||
notInUseModal.SetActive(true);
|
||||
}
|
||||
@@ -115,5 +115,10 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
{
|
||||
me.SetActive(true);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ShowInviteModal();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user