AR以及对战房间部分代码重构

This commit is contained in:
lishuo committed 2023-03-10 14:22:41 +08:00
1 parent fb4da81ce2
commit a149a7c08e
13 files changed
+280 -262

No files matched your search

@@ -10,67 +10,48 @@ public class GameRoomCountDownController : PFUIPanel
public Text endCount;
private int Seconds { get; set; }
public GameRoomModel GameRoom { get; set; }
private Action Callback { get; set; }
protected override void Awake()
private bool simple { get; set; }
public void Init(int seconds,Action action,bool isEnd = false,bool simple = false)
{
base.Awake();
}
public override void Show()
{
base.Show();
}
private bool isSimple { get; set; }
public void Init(int seconds,Action action,bool isEnd = false,bool isSimple = false)
{
stopped = false;
_stopped = false;
Seconds = seconds;
Callback = action;
this.simple = simple;
endCount.gameObject.SetActive(false);
this.isSimple = isSimple;
}
public override void Close()
{
base.Close();
}
private bool stopped;
private bool _stopped;
public void Stop()
{
this.stopped = true;
this._stopped = true;
}
float timer = 0f;
private float _timer = 0f;
private void Update()
{
timer -= Time.deltaTime;
while (timer < 0)
_timer -= Time.deltaTime;
while (_timer < 0)
{
if (Seconds == 0)
{
Callback?.Invoke();
}
if (Seconds < 0 || stopped)
if (Seconds <= 0 || _stopped)
{
gameObject.SetActive(false);
}
else
{
if (isSimple)
{
count.text = Seconds.ToString();
}
else
{
count.text = Helper.FormatTicks(Seconds);
}
endCount.text = Helper.FormatTicks(Seconds);
}
count.gameObject.SetActive(Seconds >0);
count.text = simple ? Seconds.ToString() : Helper.FormatTicks(Seconds);
endCount.text = Helper.FormatTicks(Seconds);
Seconds--;
timer += 1f;
_timer += 1f;
}
}
}
@@ -105,30 +105,24 @@ public class GameRoomDetailController : PFUIPanel
private void ListenerHandler(List<ReceiveMsgModel> message)
{
var detail = message.FirstOrDefault();
if (detail != null)
if (detail == null || message.Count > 1) return;
if (detail.RoomList == null)
{
if (detail.RoomList == null)
{
DataSourceChanged = true;
GameRoom = null;
return;
}
GameRoom = detail.RoomList.Where(c => c.RoomId == GameRoom.RoomId).FirstOrDefault();
if (GameRoom != null)
{
DataSourceChanged = true;
}
DataSourceChanged = true;
GameRoom = null;
return;
}
GameRoom = detail.RoomList.Where(c => c.RoomId == GameRoom.RoomId).FirstOrDefault();
if (GameRoom != null)
{
DataSourceChanged = true;
}
}
float timer = 0f;
private void Update()
{
TcpHandler();
timer -= Time.deltaTime;
while (timer < 0)
{
timer += 1f;
}
}
private void Init()
{