Menu + Server List Done
This commit is contained in:
8
Assets/Scripts/Menu.meta
Normal file
8
Assets/Scripts/Menu.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 797723a43f410114ead22ea079859d61
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
116
Assets/Scripts/Menu/menuController.cs
Normal file
116
Assets/Scripts/Menu/menuController.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using LightReflectiveMirror;
|
||||
using Mirror;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class menuController : MonoBehaviour
|
||||
{
|
||||
public GameObject modSelectionPanel;
|
||||
public GameObject serverSelectionPanel;
|
||||
[Header("Server List")]
|
||||
public Transform scrollParent;
|
||||
public GameObject serverRow;
|
||||
public float heightPerRow = 30;
|
||||
public int curSelected = 0;
|
||||
private LightReflectiveMirrorTransport _LRM;
|
||||
public Toggle isPrivate;
|
||||
public InputField serverNameInput;
|
||||
void Start()
|
||||
{
|
||||
if (_LRM == null)
|
||||
{
|
||||
_LRM = (LightReflectiveMirrorTransport)Transport.activeTransport;
|
||||
_LRM.serverListUpdated.AddListener(ServerListUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (_LRM != null) { _LRM.serverListUpdated.RemoveListener(ServerListUpdate); }
|
||||
}
|
||||
|
||||
public void refreshServers()
|
||||
{
|
||||
_LRM.RequestServerList();
|
||||
}
|
||||
|
||||
public void ServerListUpdate()
|
||||
{
|
||||
//
|
||||
//clear all entries
|
||||
foreach(Transform t in scrollParent) { Destroy(t.gameObject); }
|
||||
bool b1 = false;
|
||||
for(int i =0; i < _LRM.relayServerList.Count; i++)
|
||||
{
|
||||
int mapId = int.Parse(_LRM.relayServerList[i].serverName.Substring(0, 1));
|
||||
|
||||
if(mapId == FindObjectOfType<modSelector>().currentSelectedId)
|
||||
{
|
||||
GameObject go = Instantiate(serverRow, scrollParent);
|
||||
go.transform.GetChild(0).GetComponent<Text>().text = _LRM.relayServerList[i].serverName;
|
||||
go.transform.GetChild(1).GetComponent<Text>().text = _LRM.relayServerList[i].currentPlayers + "/" + _LRM.relayServerList[i].maxPlayers;
|
||||
go.GetComponent<Button>().onClick.AddListener(() => { selectServer(i - 1); });
|
||||
if (!b1)
|
||||
{
|
||||
go.GetComponent<Image>().color = Color.grey;
|
||||
b1 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
scrollParent.GetComponent<RectTransform>().sizeDelta = new Vector2(scrollParent.GetComponent<RectTransform>().sizeDelta.x, heightPerRow *(_LRM.relayServerList.Count+1));
|
||||
}
|
||||
|
||||
public void selectServer(int id)
|
||||
{
|
||||
Debug.Log("Selected server :" + id);
|
||||
if(id < scrollParent.childCount-1) { return; }
|
||||
curSelected = id;
|
||||
foreach(Transform t in scrollParent.GetComponentsInChildren<Transform>())
|
||||
{
|
||||
if(t.GetComponent<Image>()!=null)t.GetComponent<Image>().color = serverRow.GetComponent<Image>().color;
|
||||
}
|
||||
scrollParent.GetChild(id).GetComponent<Image>().color = Color.grey;
|
||||
}
|
||||
|
||||
public void joinServer()
|
||||
{
|
||||
|
||||
NetworkManager.singleton.networkAddress= _LRM.relayServerList[curSelected].serverId.ToString();
|
||||
NetworkManager.singleton.StartClient();
|
||||
|
||||
}
|
||||
|
||||
public void hostClicked()
|
||||
{
|
||||
if (serverNameInput.text.Length > 3)
|
||||
{
|
||||
|
||||
_LRM.serverName = FindObjectOfType<modSelector>().currentSelectedId+serverNameInput.text;
|
||||
_LRM.isPublicServer = !isPrivate.isOn;
|
||||
|
||||
_LRM.ServerStart();
|
||||
NetworkManager.singleton.StartHost();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void selectMod(int modId)
|
||||
{
|
||||
modSelectionPanel.SetActive(false);
|
||||
serverSelectionPanel.SetActive(true);
|
||||
}
|
||||
|
||||
public void gotoModSelection()
|
||||
{
|
||||
modSelectionPanel.SetActive(true);
|
||||
serverSelectionPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Menu/menuController.cs.meta
Normal file
11
Assets/Scripts/Menu/menuController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcf660de59c795f4787ad902f91840cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
59
Assets/Scripts/Menu/modSelector.cs
Normal file
59
Assets/Scripts/Menu/modSelector.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Mirror;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class modSelector : MonoBehaviour
|
||||
{
|
||||
public Image Bg;
|
||||
public RectTransform[] mod_images;
|
||||
Vector2 defaultSize;
|
||||
public GameObject[] descriptions;
|
||||
[Scene]
|
||||
public string[] scenes;
|
||||
public int currentSelectedId = 0;
|
||||
public AudioClip selectionSfx;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (mod_images.Length != descriptions.Length)
|
||||
{
|
||||
Debug.LogError("WHAT THE FUCK ARE YOU DOING");
|
||||
}
|
||||
defaultSize = mod_images[0].sizeDelta;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
for (int i = 0; i < mod_images.Length; i++)
|
||||
{
|
||||
if(i == currentSelectedId)
|
||||
{
|
||||
mod_images[i].sizeDelta = Vector2.Lerp(mod_images[i].sizeDelta, defaultSize * 1.5f, 0.1f);
|
||||
descriptions[i].SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
mod_images[i].sizeDelta = Vector2.Lerp(mod_images[i].sizeDelta, defaultSize, 0.1f);
|
||||
descriptions[i].SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnPointerEnter(int value)
|
||||
{
|
||||
currentSelectedId = value;
|
||||
NetworkManager.singleton.onlineScene = scenes[value];
|
||||
Bg.sprite = mod_images[value].GetComponent<Image>().sprite;
|
||||
GetComponent<AudioSource>().PlayOneShot(selectionSfx);
|
||||
}
|
||||
public void OnPointerExit()
|
||||
{
|
||||
//currentSelectedId = -1;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Menu/modSelector.cs.meta
Normal file
11
Assets/Scripts/Menu/modSelector.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a20e9ea21510c1d41984febfdf26d0e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -18,6 +18,7 @@ public class netPlayer : NetworkBehaviour
|
||||
// public GameObject bloodPrefab;
|
||||
public GameObject BloodAttach;
|
||||
public GameObject[] BloodFX;
|
||||
public GameObject deadRagdoll;
|
||||
[HideInInspector]
|
||||
public int effectIdx;
|
||||
[Header("Weapons")]
|
||||
@@ -81,6 +82,9 @@ public class netPlayer : NetworkBehaviour
|
||||
|
||||
player.Run.AddStartListener(() => { callToggleAim(false); });
|
||||
|
||||
player.Death.AddListener(() => { callDeath(); });
|
||||
player.Respawn.AddListener(() => { callRespawn();});
|
||||
|
||||
toggleAim(false);
|
||||
}
|
||||
|
||||
@@ -529,6 +533,75 @@ public class netPlayer : NetworkBehaviour
|
||||
RpcDamage(dmg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void callDeath()
|
||||
{
|
||||
Debug.Log("Calling Death");
|
||||
if (isServer)
|
||||
{
|
||||
death();
|
||||
RpcDeath();
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdDeath();
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdDeath()
|
||||
{
|
||||
death();
|
||||
RpcDeath();
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcDeath()
|
||||
{
|
||||
death();
|
||||
}
|
||||
|
||||
void death()
|
||||
{
|
||||
// if (isLocalPlayer) { return; }
|
||||
|
||||
playerModelParent.gameObject.SetActive(false);
|
||||
Instantiate(deadRagdoll, transform.position, transform.rotation);
|
||||
}
|
||||
|
||||
public void callRespawn()
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
Respawn();
|
||||
RpcRespawn();
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdRespawn();
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdRespawn()
|
||||
{
|
||||
Respawn();
|
||||
RpcRespawn();
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcRespawn()
|
||||
{
|
||||
Respawn();
|
||||
}
|
||||
|
||||
void Respawn()
|
||||
{
|
||||
if (isLocalPlayer) { return; }
|
||||
|
||||
playerModelParent.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user