You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
209 lines
6.5 KiB
209 lines
6.5 KiB
using AX.NetworkSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Text.RegularExpressions; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using AX.DrillOnlineServer; |
|
/// <summary> |
|
/// 进入房间校验类 |
|
/// </summary> |
|
public class EnterRoomPair |
|
{ |
|
public UserData UserData; |
|
public long RoomId; |
|
public string PassWord; |
|
public GoTo TargetScene; |
|
} |
|
|
|
public class LobbyDataManager : MonoBehaviour |
|
{ |
|
public static LobbyDataManager GetInstance; |
|
#region 头像相关 |
|
public Image HeadImg; |
|
public Text SoliderName; |
|
public Text RoleName; |
|
#endregion |
|
#region 房间相关 |
|
public long NowRoomId = -1; |
|
public Image MapImg; |
|
public Text MapName; |
|
public Text DisasterIntro; |
|
public Text RoomOwner; |
|
public Text RoomType; |
|
public Text RoomPeopleNum; |
|
private Sprite MapSpritDefaut; |
|
#endregion |
|
#region 密码相关 |
|
public GameObject PassWordParent; |
|
public InputField PassWordInput; |
|
public Text PassWordErrorText; |
|
public Text PassWordErrorType; |
|
private int prevRoomId; |
|
#endregion |
|
public Text ModeText; |
|
public Button EnterRoom; |
|
public Button CreateRoom; |
|
public Text ErrorText; |
|
|
|
|
|
|
|
private GameObject roomParent; |
|
private GameObject createRoom; |
|
|
|
private string HeadSpritName = "HeadDefaut.png"; |
|
void Awake() |
|
{ |
|
GetInstance = this; |
|
MapSpritDefaut = MapImg.sprite; |
|
roomParent = transform.Find("RoomParent").gameObject; |
|
createRoom = transform.Find("CreateRoom").gameObject; |
|
ModeText.text = GameSettings.othersSettings.mode == Mode.manoeuvre ? "演习模式" : "练习模式"; |
|
PassWordInput.onValueChanged.AddListener(PassWordInputChanged); |
|
if (CurrentUserInfo.role != Role.导调组) |
|
{ |
|
//EnterRoom.gameObject.SetActive(true); |
|
CreateRoom.gameObject.SetActive(false); |
|
} |
|
else |
|
{ |
|
//EnterRoom.gameObject.SetActive(false); |
|
CreateRoom.gameObject.SetActive(true); |
|
} |
|
EnterRoom.onClick.AddListener(EnterRoomClick); |
|
CreateRoom.onClick.AddListener(CreateRoomClick); |
|
|
|
//BindHeadMessage("zhandouban.jpg", "laskflsaf", "战斗班1"); |
|
} |
|
|
|
private void PassWordInputChanged(string value) |
|
{ |
|
Regex rex = new Regex("^[1-9]\\d{2,5}$"); |
|
if (rex.IsMatch(value)) |
|
{ |
|
PassWordErrorType.gameObject.SetActive(false); |
|
} |
|
else |
|
{ |
|
PassWordErrorType.gameObject.SetActive(true); |
|
} |
|
} |
|
|
|
private void CreateRoomClick() |
|
{ |
|
roomParent.SetActive(false); |
|
createRoom.SetActive(true); |
|
} |
|
|
|
private void EnterRoomClick() |
|
{ |
|
if (PassWordErrorType.gameObject.activeSelf) |
|
return; |
|
if (CurrentUserInfo.room != null) |
|
{ |
|
if (CurrentUserInfo.room.IsDrillStart) |
|
{ |
|
ErrorText.text = "已经开始演练的房间无法加入"; |
|
NowRoomId = -1; |
|
CurrentUserInfo.room = null; |
|
return; |
|
} |
|
string password = ""; |
|
if (PassWordParent.activeSelf) |
|
{ |
|
if (PassWordInput.text == null || PassWordInput.text == "") |
|
{ |
|
ErrorText.text = "请输入房间密码"; |
|
} |
|
else |
|
{ |
|
password = SHA256HashAlgorithmHelper.GetSHA256hash(PassWordInput.text); |
|
} |
|
|
|
} |
|
else |
|
{ |
|
password = ""; |
|
} |
|
UserData data = new UserData() |
|
{ |
|
UserInfo = CurrentUserInfo.mySelf, |
|
Role = CurrentUserInfo.role, |
|
Org = CurrentUserInfo.organization, |
|
IsReady = false |
|
}; |
|
EnterRoomPair pair = new EnterRoomPair() |
|
{ |
|
UserData = data, |
|
RoomId = CurrentUserInfo.room.Id, |
|
PassWord = password, |
|
TargetScene = GoTo.DongYouLiQing |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("ROOM_ENTER_SYNC", pair); |
|
} |
|
else |
|
{ |
|
ErrorText.text = "请选择您要进入的房间"; |
|
} |
|
|
|
} |
|
|
|
public void BindRoomMessage(RoomManager RoomManager) |
|
{ |
|
ErrorText.text = ""; |
|
if (RoomManager != null) |
|
{ |
|
switch (RoomManager.MyRoom.Map.unit) |
|
{ |
|
case Unit.DongYouLiQing: |
|
string imgPath = "Common/" + RoomManager.MyRoom.Map.unit; |
|
Texture2D texture = (Texture2D)Resources.Load(imgPath); |
|
MapImg.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); |
|
break; |
|
default: |
|
|
|
break; |
|
} |
|
MapName.text = RoomManager.MyRoom.Map.name; |
|
DisasterIntro.text = RoomManager.MyRoom.Map.introduction; |
|
RoomOwner.text = RoomManager.MyRoom.Owner.UserInfo.Username; |
|
RoomPeopleNum.text = RoomManager.MyRoom.UserList.Count + "/" + RoomManager.MyRoom.MaxPersons; |
|
NowRoomId = RoomManager.MyRoom.Id; |
|
RoomType.text = RoomManager.MyRoom.Map.sceneType.ToString(); |
|
if (RoomManager.MyRoom.IsDrillStart) |
|
{ |
|
if (EnterRoom.interactable) |
|
EnterRoom.interactable = false; |
|
if (PassWordParent.gameObject.activeSelf) |
|
PassWordParent.gameObject.SetActive(false); |
|
return; |
|
} |
|
else |
|
{ |
|
if (!EnterRoom.interactable) |
|
EnterRoom.interactable = true; |
|
if (!PassWordParent.gameObject.activeSelf) |
|
PassWordParent.gameObject.SetActive(true); |
|
} |
|
PassWordParent.gameObject.SetActive(RoomManager.HasPassWord); |
|
if (RoomManager.HasPassWord) |
|
PassWordParent.GetComponentInChildren<InputField>().text = ""; |
|
} |
|
else |
|
{ |
|
MapImg.sprite = MapSpritDefaut; |
|
MapName.text = "地图名称"; |
|
DisasterIntro.text = ""; |
|
RoomOwner.text = ""; |
|
RoomPeopleNum.text = ""; |
|
RoomType.text = ""; |
|
NowRoomId = -1; |
|
PassWordParent.gameObject.SetActive(false); |
|
PassWordParent.GetComponentInChildren<InputField>().text = ""; |
|
if (EnterRoom.interactable) |
|
EnterRoom.interactable = false; |
|
} |
|
} |
|
}
|
|
|