90 lines
2.3 KiB
C#
90 lines
2.3 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class CreateRoomUI : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private List<Image> _crewImgs;
|
||
|
|
||
|
[SerializeField] private List<Button> _impostrCountButtons;
|
||
|
|
||
|
[SerializeField] private List<Button> _maxPlayerCountButtons;
|
||
|
|
||
|
private CreateGameRoomData _roomData;
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
for (int i = 0; i < _crewImgs.Count; i++)
|
||
|
{
|
||
|
Material mat = Instantiate(_crewImgs[i].material);
|
||
|
_crewImgs[i].material = mat;
|
||
|
}
|
||
|
_roomData = new CreateGameRoomData() { _imposterCount = 1, _maxPlayerCount = 10 };
|
||
|
UpdateCrewImages();
|
||
|
}
|
||
|
|
||
|
private void UpdateCrewImages()
|
||
|
{
|
||
|
for (int i = 0; i < _crewImgs.Count; i++)
|
||
|
{
|
||
|
_crewImgs[i].material.SetColor("_PlayerColor", Color.white);
|
||
|
}
|
||
|
int imposterCount = _roomData._imposterCount;
|
||
|
int idx = 0;
|
||
|
|
||
|
while(imposterCount != 0)
|
||
|
{
|
||
|
if (idx >= _roomData._maxPlayerCount)
|
||
|
{
|
||
|
idx = 0;
|
||
|
}
|
||
|
|
||
|
if(_crewImgs[idx].material.GetColor("_PlayerColor") != Color.red && Random.Range(0, 5) == 0)
|
||
|
{
|
||
|
_crewImgs[idx].material.SetColor("_PlayerColor", Color.red);
|
||
|
imposterCount--;
|
||
|
}
|
||
|
|
||
|
idx++;
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < _crewImgs.Count; i++)
|
||
|
{
|
||
|
if(i < _roomData._maxPlayerCount)
|
||
|
{
|
||
|
_crewImgs[i].gameObject.SetActive(true);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_crewImgs[i].gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void UpdateMaxPlayerCount(int count)
|
||
|
{
|
||
|
_roomData._maxPlayerCount = count;
|
||
|
|
||
|
for (int i = 0; i < _maxPlayerCountButtons.Count; i++)
|
||
|
{
|
||
|
if(i == count - 4)
|
||
|
{
|
||
|
_maxPlayerCountButtons[i].image.color = new Color(1f, 1f, 1f, 1f);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_maxPlayerCountButtons[i].image.color = new Color(1f, 1f, 1f, 0f);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
UpdateCrewImages();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class CreateGameRoomData
|
||
|
{
|
||
|
public int _imposterCount;
|
||
|
public int _maxPlayerCount;
|
||
|
}
|