네트워크 동기화 문제 해결
몬스터와 크립에 네트워크 관련 컴포넌트가 없는 문제 수정 포탈/캠프와 몬스터/크립 간의 계층 구조 해제 - 네트워크 오브젝트끼리 계층 구조로 둘 수 없음
This commit is contained in:
@@ -116,7 +116,6 @@ namespace Northbound
|
||||
private List<Vector3> _spawnedPositions = new List<Vector3>();
|
||||
private List<Vector3> _creepCampPositions = new List<Vector3>();
|
||||
private List<GameObject> _creepPrefabs = new List<GameObject>();
|
||||
private Transform _objectsParent;
|
||||
|
||||
[System.Serializable]
|
||||
public class ObstacleEntry
|
||||
@@ -188,19 +187,6 @@ namespace Northbound
|
||||
|
||||
private void GenerateMap()
|
||||
{
|
||||
if (groupUnderParent)
|
||||
{
|
||||
_objectsParent = new GameObject("Generated Map Objects").transform;
|
||||
_objectsParent.SetParent(transform);
|
||||
|
||||
NetworkObject parentNetworkObj = _objectsParent.gameObject.GetComponent<NetworkObject>();
|
||||
if (parentNetworkObj == null)
|
||||
{
|
||||
parentNetworkObj = _objectsParent.gameObject.AddComponent<NetworkObject>();
|
||||
}
|
||||
parentNetworkObj.Spawn();
|
||||
}
|
||||
|
||||
_spawnedPositions.Clear();
|
||||
_creepCampPositions.Clear();
|
||||
|
||||
@@ -412,7 +398,7 @@ namespace Northbound
|
||||
for (int i = 0; i < _generatedResources.Length; i++)
|
||||
{
|
||||
GameObject resourceObj = Instantiate(resourcePrefab, new Vector3(_generatedResources[i].position.x, 1f, _generatedResources[i].position.y), Quaternion.identity);
|
||||
|
||||
|
||||
Resource resource = resourceObj.GetComponent<Resource>();
|
||||
if (resource == null)
|
||||
{
|
||||
@@ -422,15 +408,11 @@ namespace Northbound
|
||||
}
|
||||
|
||||
resource.InitializeQuality(_generatedResources[i].qualityModifier);
|
||||
|
||||
|
||||
NetworkObject networkObj = resourceObj.GetComponent<NetworkObject>();
|
||||
if (networkObj != null)
|
||||
{
|
||||
networkObj.Spawn();
|
||||
if (groupUnderParent && _objectsParent != null)
|
||||
{
|
||||
resourceObj.transform.SetParent(_objectsParent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -557,11 +539,6 @@ namespace Northbound
|
||||
|
||||
networkObj.Spawn();
|
||||
|
||||
if (groupUnderParent && _objectsParent != null)
|
||||
{
|
||||
obstacle.transform.SetParent(_objectsParent);
|
||||
}
|
||||
|
||||
if (obstacle.GetComponent<FogOfWarVisibility>() == null)
|
||||
{
|
||||
var visibility = obstacle.AddComponent<FogOfWarVisibility>();
|
||||
@@ -657,18 +634,7 @@ namespace Northbound
|
||||
|
||||
private int CountObstacleType(GameObject prefab)
|
||||
{
|
||||
int count = 0;
|
||||
if (_objectsParent != null)
|
||||
{
|
||||
foreach (Transform child in _objectsParent)
|
||||
{
|
||||
if (child.name.StartsWith(prefab.name))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -860,6 +826,13 @@ namespace Northbound
|
||||
{
|
||||
GameObject campObj = Instantiate(creepCampPrefab, position, Quaternion.identity);
|
||||
|
||||
if (campObj.GetComponent<FogOfWarVisibility>() == null)
|
||||
{
|
||||
var visibility = campObj.AddComponent<FogOfWarVisibility>();
|
||||
visibility.showInExploredAreas = false;
|
||||
visibility.updateInterval = 0.2f;
|
||||
}
|
||||
|
||||
CreepCamp creepCamp = campObj.GetComponent<CreepCamp>();
|
||||
if (creepCamp == null)
|
||||
{
|
||||
@@ -879,18 +852,6 @@ namespace Northbound
|
||||
}
|
||||
|
||||
networkObj.Spawn();
|
||||
|
||||
if (groupUnderParent && _objectsParent != null)
|
||||
{
|
||||
campObj.transform.SetParent(_objectsParent);
|
||||
}
|
||||
|
||||
if (campObj.GetComponent<FogOfWarVisibility>() == null)
|
||||
{
|
||||
var visibility = campObj.AddComponent<FogOfWarVisibility>();
|
||||
visibility.showInExploredAreas = false;
|
||||
visibility.updateInterval = 0.2f;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -912,34 +873,6 @@ namespace Northbound
|
||||
|
||||
public void ClearGeneratedObjects()
|
||||
{
|
||||
if (_objectsParent != null)
|
||||
{
|
||||
NetworkObject parentNetworkObj = _objectsParent.GetComponent<NetworkObject>();
|
||||
if (parentNetworkObj != null && parentNetworkObj.IsSpawned)
|
||||
{
|
||||
parentNetworkObj.Despawn(true);
|
||||
}
|
||||
|
||||
foreach (Transform child in _objectsParent)
|
||||
{
|
||||
NetworkObject networkObj = child.GetComponent<NetworkObject>();
|
||||
if (networkObj != null && networkObj.IsSpawned)
|
||||
{
|
||||
networkObj.Despawn(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
Destroy(_objectsParent.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyImmediate(_objectsParent.gameObject);
|
||||
}
|
||||
_objectsParent = null;
|
||||
}
|
||||
|
||||
_spawnedPositions.Clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user