mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-22 02:14:30 -05:00
Add initial file for Networking Model
This commit is contained in:
8
Assets/Scripts/PlayerScripts/Network.meta
Normal file
8
Assets/Scripts/PlayerScripts/Network.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f28e7652a4fb34f4e839bc58fb1bc546
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/Scripts/PlayerScripts/Network/ModelSwapping.cs
Normal file
58
Assets/Scripts/PlayerScripts/Network/ModelSwapping.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using MLAPI;
|
||||
using MLAPI.Messaging;
|
||||
using System.Linq;
|
||||
|
||||
public class ModelSwapping : NetworkBehaviour {
|
||||
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
// If game scene & Local Player
|
||||
if (SceneManager.GetActiveScene().buildIndex == 3 && IsLocalPlayer) {
|
||||
StartCoroutine(WaitSwapModel());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator WaitSwapModel() {
|
||||
yield return new WaitForSecondsRealtime(3f);
|
||||
|
||||
SwapModelServerRPC(gameObject.transform.root.GetComponent<NetworkObject>().OwnerClientId);
|
||||
}
|
||||
|
||||
[ServerRpc(RequireOwnership = false)]
|
||||
private void SwapModelServerRPC(ulong playerID) {
|
||||
// Spawn the player
|
||||
if (ServerGameNetPortal.Instance.clientIdToGuid.TryGetValue(playerID, out string clientGuid)) {
|
||||
if (ServerGameNetPortal.Instance.clientData.TryGetValue(clientGuid, out PlayerData playerData)) {
|
||||
// Get the players item list
|
||||
string itemsAsString = string.Join(",", playerData.pInv.NetworkItemList);
|
||||
|
||||
// Apply to each client
|
||||
SwapModelClientRPC(playerID, itemsAsString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void SwapModelClientRPC(ulong playerID, string itemList) {
|
||||
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
|
||||
|
||||
foreach (GameObject player in players) {
|
||||
if (player.GetComponent<NetworkObject>().OwnerClientId == playerID) {
|
||||
// Player to Update found
|
||||
player.GetComponentInChildren<ModelSwapping>().SwapModels(itemList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SwapModels(string itemsAsString) {
|
||||
List<string> itemList = itemsAsString.Split(',').ToList();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/PlayerScripts/Network/ModelSwapping.cs.meta
Normal file
11
Assets/Scripts/PlayerScripts/Network/ModelSwapping.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac4390dd337a1474fb5cd03906cfe44a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user