mirror of
https://github.com/Kaveinator/NetickProForUnity.git
synced 2025-10-27 02:09:06 -07:00
auto
This commit is contained in:
49
Samples~/Bomberman/Scripts/UI/UIServerBroweser.cs
Normal file
49
Samples~/Bomberman/Scripts/UI/UIServerBroweser.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Netick;
|
||||
using Netick.Unity;
|
||||
public class UIServerBroweser : NetworkEventsListener
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject _UIServerElementPrefab;
|
||||
[SerializeField]
|
||||
private Vector3 _startPosition;
|
||||
[SerializeField]
|
||||
private float _stepSize = 50;
|
||||
|
||||
[SerializeField]
|
||||
private List<GameObject> _servers = new List<GameObject>();
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
Sandbox?.RefreshMatchList();
|
||||
}
|
||||
|
||||
public override void OnStartup(NetworkSandbox sandbox)
|
||||
{
|
||||
if (sandbox.IsServer)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public override void OnConnectedToServer(NetworkSandbox sandbox, NetworkConnection server)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public override void OnMatchListUpdate(NetworkSandbox sandbox, List<Session> sessions)
|
||||
{
|
||||
foreach (var server in _servers)
|
||||
Destroy(server);
|
||||
|
||||
_servers.Clear();
|
||||
|
||||
for (int i = 0; i < sessions.Count; i++)
|
||||
{
|
||||
var session = sessions[i];
|
||||
var newElement = Instantiate(_UIServerElementPrefab, gameObject.transform).GetComponent<UIServerElement>();
|
||||
newElement.Init(Sandbox,session.Name, session.IP, session.Port, _startPosition - (Vector3.up * i * _stepSize));
|
||||
_servers.Add(newElement.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Samples~/Bomberman/Scripts/UI/UIServerBroweser.cs.meta
Normal file
11
Samples~/Bomberman/Scripts/UI/UIServerBroweser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8e8276de5223424c801fbb31d5ccbf9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Samples~/Bomberman/Scripts/UI/UIServerElement.cs
Normal file
39
Samples~/Bomberman/Scripts/UI/UIServerElement.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Netick;
|
||||
using Netick.Unity;
|
||||
|
||||
public class UIServerElement : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Text _nameText;
|
||||
|
||||
[SerializeField]
|
||||
private Text _ipText;
|
||||
|
||||
[SerializeField]
|
||||
private string _ip;
|
||||
[SerializeField]
|
||||
private int _Port;
|
||||
|
||||
private NetworkSandbox _sandbox;
|
||||
|
||||
public void Init(NetworkSandbox sandbox, string name, string ip, int port, Vector3 position)
|
||||
{
|
||||
_sandbox = sandbox;
|
||||
|
||||
_ip = ip;
|
||||
_Port = port;
|
||||
_nameText.text = name;
|
||||
_ipText.text = ip;
|
||||
GetComponent<RectTransform>().anchoredPosition3D = position;
|
||||
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
_sandbox.Connect(_Port, _ip);
|
||||
}
|
||||
}
|
||||
11
Samples~/Bomberman/Scripts/UI/UIServerElement.cs.meta
Normal file
11
Samples~/Bomberman/Scripts/UI/UIServerElement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 742d47201bd4e0e47b3460de2b0f17c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user