Enemy now spawns and is transform synced
This commit is contained in:
parent
8b60e45bab
commit
d8f8cdc37a
|
@ -114,7 +114,6 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
flipTrans: {fileID: 0}
|
flipTrans: {fileID: 0}
|
||||||
body: {fileID: 0}
|
body: {fileID: 0}
|
||||||
--- !u!114 &7159876145595507269
|
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: af7974227ca2b6c4eb332e658d94fc34, type: 3}
|
||||||
|
m_Name: EnemyList
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
List:
|
||||||
|
- prefabs:
|
||||||
|
- {fileID: 4934207185621008411, guid: 854e7815477416848ba19ede927d8601, type: 3}
|
||||||
|
Difficulty: 1
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b5be1b6a03ce1d74ebd3f721d1332eca
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,21 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e651dbb3fbac04af2b8f5abf007ddc23, type: 3}
|
||||||
|
m_Name: NetworkedEnemies
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
IsDefault: 0
|
||||||
|
List:
|
||||||
|
- Override: 0
|
||||||
|
Prefab: {fileID: 4934207185621008411, guid: 854e7815477416848ba19ede927d8601, type: 3}
|
||||||
|
SourcePrefabToOverride: {fileID: 0}
|
||||||
|
SourceHashToOverride: 0
|
||||||
|
OverridingTargetPrefab: {fileID: 0}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 64355e81cc3d52c4d8e2f01f078efcc4
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -29,8 +29,3 @@ MonoBehaviour:
|
||||||
SourcePrefabToOverride: {fileID: 0}
|
SourcePrefabToOverride: {fileID: 0}
|
||||||
SourceHashToOverride: 0
|
SourceHashToOverride: 0
|
||||||
OverridingTargetPrefab: {fileID: 0}
|
OverridingTargetPrefab: {fileID: 0}
|
||||||
- Override: 0
|
|
||||||
Prefab: {fileID: 7065654593080984807, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
|
|
||||||
SourcePrefabToOverride: {fileID: 0}
|
|
||||||
SourceHashToOverride: 0
|
|
||||||
OverridingTargetPrefab: {fileID: 0}
|
|
||||||
|
|
|
@ -3725,14 +3725,10 @@ MonoBehaviour:
|
||||||
enemyDifficulties: []
|
enemyDifficulties: []
|
||||||
SpawnRadius: 22.6
|
SpawnRadius: 22.6
|
||||||
NumEnemies: 6
|
NumEnemies: 6
|
||||||
players: []
|
|
||||||
initialSpawnDelay: 5
|
initialSpawnDelay: 5
|
||||||
SpawnCenter: {fileID: 5796191506433166635}
|
SpawnCenter: {fileID: 5796191506433166635}
|
||||||
timer: 0
|
timer: 0
|
||||||
enemyList:
|
enemyList: {fileID: 11400000, guid: b5be1b6a03ce1d74ebd3f721d1332eca, type: 2}
|
||||||
- prefabs:
|
|
||||||
- {fileID: 7065654593080984807, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
|
|
||||||
Difficulty: 0
|
|
||||||
--- !u!1001 &4158834148864819266
|
--- !u!1001 &4158834148864819266
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -1213,6 +1213,7 @@ MonoBehaviour:
|
||||||
Prefabs:
|
Prefabs:
|
||||||
NetworkPrefabsLists:
|
NetworkPrefabsLists:
|
||||||
- {fileID: 11400000, guid: 3ca514815d13ed84bae5371c002442c4, type: 2}
|
- {fileID: 11400000, guid: 3ca514815d13ed84bae5371c002442c4, type: 2}
|
||||||
|
- {fileID: 11400000, guid: 64355e81cc3d52c4d8e2f01f078efcc4, type: 2}
|
||||||
TickRate: 30
|
TickRate: 30
|
||||||
ClientConnectionBufferTimeout: 10
|
ClientConnectionBufferTimeout: 10
|
||||||
ConnectionApproval: 0
|
ConnectionApproval: 0
|
||||||
|
|
|
@ -20,10 +20,9 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
// Inspector
|
// Inspector
|
||||||
[SerializeField] private float difficultyIncreasePerWave = 1f;
|
[SerializeField] private float difficultyIncreasePerWave = 1f;
|
||||||
[SerializeField] public float WaveTime = 20f;
|
[SerializeField] public float WaveTime = 20f;
|
||||||
[SerializeField] private List<float> enemyDifficulties;
|
|
||||||
[SerializeField] private float SpawnRadius = 10;
|
[SerializeField] private float SpawnRadius = 10;
|
||||||
[SerializeField] private int NumEnemies = 6;
|
[SerializeField] private int NumEnemies = 6;
|
||||||
[SerializeField] public GameObject[] players;
|
private GameObject[] players;
|
||||||
[SerializeField] private float initialSpawnDelay = 5;
|
[SerializeField] private float initialSpawnDelay = 5;
|
||||||
[Space(10)]
|
[Space(10)]
|
||||||
[SerializeField] private Transform SpawnCenter;
|
[SerializeField] private Transform SpawnCenter;
|
||||||
|
@ -32,12 +31,22 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
private bool nextWaveRequested = false;
|
private bool nextWaveRequested = false;
|
||||||
public float timer = 0f;
|
public float timer = 0f;
|
||||||
private GameObject SpawnedEnenmyHolder;
|
private GameObject SpawnedEnenmyHolder;
|
||||||
[SerializeField] private List<EnemyPrefabInfo> enemyList;
|
[SerializeField] private EnemyList enemyList;
|
||||||
|
|
||||||
private bool SpawnerStarted = false;
|
private bool SpawnerStarted = false;
|
||||||
|
|
||||||
public static EnemySpawner instance;
|
public static EnemySpawner instance;
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
GameManager.OnPlayersReady += OnPlayersReady;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayersReady(GameObject[] players)
|
||||||
|
{
|
||||||
|
this.players = players;
|
||||||
|
}
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
|
@ -54,11 +63,6 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
{
|
{
|
||||||
SpawnedEnenmyHolder = new GameObject("SpawnedEnenmyHolder");
|
SpawnedEnenmyHolder = new GameObject("SpawnedEnenmyHolder");
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
enemyList.Add(new EnemyPrefabInfo() { Difficulty = i+1, prefabs = Resources.LoadAll<GameObject>("Enemies/" + (i+1)) });
|
|
||||||
}
|
|
||||||
|
|
||||||
timer = WaveTime - initialSpawnDelay;
|
timer = WaveTime - initialSpawnDelay;
|
||||||
|
|
||||||
if (IsServer || IsHost) // If server then start spawning
|
if (IsServer || IsHost) // If server then start spawning
|
||||||
|
@ -87,7 +91,11 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
|
|
||||||
void SpawnWave(float difficulty)
|
void SpawnWave(float difficulty)
|
||||||
{
|
{
|
||||||
//SpawnStrongestFirst(difficulty);
|
if (enemyList.List.Any(x=>x.Difficulty < 0.1f))
|
||||||
|
{
|
||||||
|
Debug.LogError("Difficulty on prefab too low!", enemyList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Wave != 0 && Wave % 10 == 0)
|
if (Wave != 0 && Wave % 10 == 0)
|
||||||
SpawnStrongestFirst(difficulty);
|
SpawnStrongestFirst(difficulty);
|
||||||
|
@ -97,16 +105,15 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
|
|
||||||
void SpawnStrongestFirst(float difficulty)
|
void SpawnStrongestFirst(float difficulty)
|
||||||
{
|
{
|
||||||
var decendingList = enemyList.Where(x => x.Difficulty < difficulty).OrderByDescending(x => x.Difficulty).ToArray();
|
var decendingList = enemyList.List.Where(x => x.Difficulty < difficulty).OrderByDescending(x => x.Difficulty).ToArray();
|
||||||
for (int i = 0; i < decendingList.Length; i++)
|
for (int i = 0; i < decendingList.Length; i++)
|
||||||
{
|
{
|
||||||
while (difficulty > decendingList[i].Difficulty)
|
while (difficulty > decendingList[i].Difficulty)
|
||||||
{
|
{
|
||||||
GameObject enemy = Instantiate(decendingList[i].prefabs[UnityEngine.Random.Range(0, decendingList[i].prefabs.Length)], GetRandomPointOnCircle(SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform);
|
GameObject enemyToSpawn = decendingList[i].prefabs[UnityEngine.Random.Range(0, decendingList[i].prefabs.Length)];
|
||||||
difficulty -= decendingList[i].Difficulty;
|
SpawnEnemy(enemyToSpawn);
|
||||||
enemy.GetComponent<NetworkObject>().Spawn();
|
|
||||||
|
|
||||||
enemy.GetComponent<EnemyPathFinding>().targets = players.Select(x=>x.transform).ToArray();
|
difficulty -= decendingList[i].Difficulty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +123,7 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
difficulty *= 1.1f;
|
difficulty *= 1.1f;
|
||||||
while (difficulty > 1f) // Spawn until difficulty is less than 0.5f
|
while (difficulty > 1f) // Spawn until difficulty is less than 0.5f
|
||||||
{
|
{
|
||||||
var validEnemies = enemyList.Where(x => x.Difficulty <= difficulty).ToArray();
|
var validEnemies = enemyList.List.Where(x => x.Difficulty <= difficulty).ToArray();
|
||||||
int enemyIndex = UnityEngine.Random.Range(0, validEnemies.Length);
|
int enemyIndex = UnityEngine.Random.Range(0, validEnemies.Length);
|
||||||
var enemyToSpawn = validEnemies[enemyIndex];
|
var enemyToSpawn = validEnemies[enemyIndex];
|
||||||
difficulty -= enemyToSpawn.Difficulty;
|
difficulty -= enemyToSpawn.Difficulty;
|
||||||
|
@ -124,12 +131,18 @@ public class EnemySpawner : NetworkBehaviour
|
||||||
int variant = UnityEngine.Random.Range(0, enemyToSpawn.prefabs.Length);
|
int variant = UnityEngine.Random.Range(0, enemyToSpawn.prefabs.Length);
|
||||||
GameObject variantToSpawn = enemyToSpawn.prefabs[variant];
|
GameObject variantToSpawn = enemyToSpawn.prefabs[variant];
|
||||||
|
|
||||||
GameObject enemy = Instantiate(variantToSpawn, GetRandomPointOnCircle(SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform);
|
SpawnEnemy(variantToSpawn);
|
||||||
|
|
||||||
enemy.GetComponent<EnemyPathFinding>().targets = players.Select(x => x.transform).ToArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpawnEnemy(GameObject enemyPrefab)
|
||||||
|
{
|
||||||
|
GameObject enemy = Instantiate(enemyPrefab, GetRandomPointOnCircle(SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform);
|
||||||
|
enemy.GetComponent<NetworkObject>().Spawn();
|
||||||
|
|
||||||
|
enemy.GetComponent<EnemyPathFinding>().targets = players.Select(x => x.transform).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
// Centrum is SpawnCenter
|
// Centrum is SpawnCenter
|
||||||
public Vector3 GetRandomPointOnCircle(float radius)
|
public Vector3 GetRandomPointOnCircle(float radius)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"GUID:055e16077a1232f4780a04598b3bfe00",
|
"GUID:055e16077a1232f4780a04598b3bfe00",
|
||||||
"GUID:1031dfc67c8f1a645b71d679ac3bf7db",
|
"GUID:1031dfc67c8f1a645b71d679ac3bf7db",
|
||||||
"GUID:0ba5c175a7b2c8345a4e996560a9d0ab",
|
"GUID:0ba5c175a7b2c8345a4e996560a9d0ab",
|
||||||
"GUID:1491147abca9d7d4bb7105af628b223e"
|
"GUID:1491147abca9d7d4bb7105af628b223e",
|
||||||
|
"GUID:c0e1b40f519e6e84b8f4af9930403ecb"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|
|
@ -37,30 +37,6 @@ public class NetworkedGameSetup : NetworkBehaviour
|
||||||
GameObject[] players;
|
GameObject[] players;
|
||||||
if (isServer)
|
if (isServer)
|
||||||
players = SpawnPlayers(playerIds);
|
players = SpawnPlayers(playerIds);
|
||||||
else
|
|
||||||
players = GetPlayers(playerIds);
|
|
||||||
|
|
||||||
//StartCoroutine(LateSetupProcedue(players));
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator LateSetupProcedue(GameObject[] players)
|
|
||||||
{
|
|
||||||
yield return new WaitForSecondsRealtime(0.01f);
|
|
||||||
|
|
||||||
InitRope(players);
|
|
||||||
|
|
||||||
InitUpgrader(players);
|
|
||||||
|
|
||||||
InitBlood(players);
|
|
||||||
|
|
||||||
InitSpawner(players);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GameObject[] GetPlayers(List<ulong> playerIds)
|
|
||||||
{
|
|
||||||
GameObject[] players = NetworkManager.SpawnManager.SpawnedObjects.Where(x => playerIds.Contains(x.Value.NetworkObjectId)).Select(x => x.Value.gameObject).ToArray();
|
|
||||||
|
|
||||||
return players;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private GameObject[] SpawnPlayers(List<ulong> playerIds)
|
private GameObject[] SpawnPlayers(List<ulong> playerIds)
|
||||||
|
@ -76,58 +52,4 @@ public class NetworkedGameSetup : NetworkBehaviour
|
||||||
|
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitRope(GameObject[] players)
|
|
||||||
{
|
|
||||||
if (players.Length == 1)
|
|
||||||
{
|
|
||||||
RopeSimulator.instance.BuildRope(players[0].GetComponent<RopeJoint>(), players[0].GetComponent<RopeJoint>());
|
|
||||||
}
|
|
||||||
else // 2 players
|
|
||||||
{
|
|
||||||
RopeSimulator.instance.BuildRope(players[0].GetComponent<RopeJoint>(), players[1].GetComponent<RopeJoint>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitUpgrader(GameObject[] players)
|
|
||||||
{
|
|
||||||
return; // fuck this upgrade system
|
|
||||||
|
|
||||||
Upgrader upgradeSystem = Upgrader.instance;
|
|
||||||
|
|
||||||
if (players.Length == 1)
|
|
||||||
{
|
|
||||||
upgradeSystem.player1 = players[0];
|
|
||||||
upgradeSystem.player2 = players[0];
|
|
||||||
}
|
|
||||||
else // 2 players
|
|
||||||
{
|
|
||||||
upgradeSystem.player1 = players[0];
|
|
||||||
upgradeSystem.player2 = players[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitBlood(GameObject[] players)
|
|
||||||
{
|
|
||||||
BloodComputeShader bloodScript = BloodComputeShader.Instance;
|
|
||||||
|
|
||||||
if (players.Length == 1)
|
|
||||||
{
|
|
||||||
bloodScript.mop1 = players[0].GetComponent<Mop>();
|
|
||||||
bloodScript.mop2 = players[0].GetComponent<Mop>();
|
|
||||||
}
|
|
||||||
else // 2 players
|
|
||||||
{
|
|
||||||
bloodScript.mop1 = players[0].GetComponent<Mop>();
|
|
||||||
bloodScript.mop2 = players[1].GetComponent<Mop>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitSpawner(GameObject[] players)
|
|
||||||
{
|
|
||||||
EnemySpawner spawner = EnemySpawner.instance;
|
|
||||||
|
|
||||||
spawner.players = players;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Unity.Netcode;
|
using Unity.Netcode;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.AI;
|
||||||
|
|
||||||
public class ZDisablerV2 : NetworkBehaviour
|
public class ZDisablerV2 : NetworkBehaviour
|
||||||
{
|
{
|
||||||
|
@ -25,7 +26,7 @@ public class ZDisablerV2 : NetworkBehaviour
|
||||||
|
|
||||||
switch (objectType)
|
switch (objectType)
|
||||||
{
|
{
|
||||||
case MonoBehaviour monoBehaviour:
|
case Behaviour monoBehaviour:
|
||||||
monoBehaviour.enabled = false;
|
monoBehaviour.enabled = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue