Give enemies networked synced id
required for reconciliation
This commit is contained in:
parent
9887ee0266
commit
b037d5077b
|
@ -17,6 +17,7 @@ GameObject:
|
||||||
- component: {fileID: -3563373198581541198}
|
- component: {fileID: -3563373198581541198}
|
||||||
- component: {fileID: 5669020798899338457}
|
- component: {fileID: 5669020798899338457}
|
||||||
- component: {fileID: 7025838755278696983}
|
- component: {fileID: 7025838755278696983}
|
||||||
|
- component: {fileID: 3458620527668384477}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: EnemyBase
|
m_Name: EnemyBase
|
||||||
m_TagString: Enemy
|
m_TagString: Enemy
|
||||||
|
@ -154,6 +155,7 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
targets: []
|
targets: []
|
||||||
ropeDistCheck: 1
|
ropeDistCheck: 1
|
||||||
|
stopBeforeTargetOffset: 1
|
||||||
ropeCheckMask:
|
ropeCheckMask:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 0
|
m_Bits: 0
|
||||||
|
@ -239,3 +241,16 @@ MonoBehaviour:
|
||||||
objectsToDisable:
|
objectsToDisable:
|
||||||
- {fileID: -2259174063119120971}
|
- {fileID: -2259174063119120971}
|
||||||
- {fileID: 5063378671874793948}
|
- {fileID: 5063378671874793948}
|
||||||
|
--- !u!114 &3458620527668384477
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7065654593080984807}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e071dd818c5a905209e31c2d66ea6390, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
spawnedId: -1
|
||||||
|
|
|
@ -30,6 +30,8 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
|
|
||||||
public static EnemySpawner instance;
|
public static EnemySpawner instance;
|
||||||
|
|
||||||
|
private static int idCounter = 0;
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
GameManager.OnPlayersReady += OnPlayersReady;
|
GameManager.OnPlayersReady += OnPlayersReady;
|
||||||
|
@ -131,6 +133,7 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
void SpawnEnemy(GameObject enemyPrefab)
|
void SpawnEnemy(GameObject enemyPrefab)
|
||||||
{
|
{
|
||||||
GameObject enemy = Instantiate(enemyPrefab, GetRandomPointOnCircle(SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform);
|
GameObject enemy = Instantiate(enemyPrefab, GetRandomPointOnCircle(SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform);
|
||||||
|
enemy.GetComponent<NetworkID>().InitialID = idCounter++;
|
||||||
enemy.GetComponent<NetworkObject>().Spawn();
|
enemy.GetComponent<NetworkObject>().Spawn();
|
||||||
|
|
||||||
enemy.GetComponent<EnemyPathFinding>().targets = players.Select(x => x.transform).ToArray();
|
enemy.GetComponent<EnemyPathFinding>().targets = players.Select(x => x.transform).ToArray();
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using Unity.Netcode;
|
||||||
|
|
||||||
|
public class NetworkID : NetworkBehaviour
|
||||||
|
{
|
||||||
|
// Set from enemy spawner
|
||||||
|
public int InitialID = -1;
|
||||||
|
|
||||||
|
private NetworkVariable<int> nID = new();
|
||||||
|
|
||||||
|
public int ID => nID.Value;
|
||||||
|
|
||||||
|
public override void OnNetworkSpawn()
|
||||||
|
{
|
||||||
|
if (IsServer)
|
||||||
|
nID.Value = InitialID;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e071dd818c5a905209e31c2d66ea6390
|
|
@ -0,0 +1,16 @@
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
[CustomEditor(typeof(NetworkID))]
|
||||||
|
public class NetworkID_Inspector : Editor
|
||||||
|
{
|
||||||
|
public override void OnInspectorGUI()
|
||||||
|
{
|
||||||
|
base.OnInspectorGUI();
|
||||||
|
|
||||||
|
EditorGUILayout.LabelField($"ID: {(target as NetworkID).ID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,2 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e70a0a80d88c1620c955d7bdc1efe3ee
|
|
@ -1,3 +1,16 @@
|
||||||
{
|
{
|
||||||
"name": "Project.Scripts.Utilities"
|
"name": "Project.Scripts.Utilities",
|
||||||
}
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"GUID:1491147abca9d7d4bb7105af628b223e"
|
||||||
|
],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
Loading…
Reference in New Issue