From 1aa65ce615b2619e378e7135fb3d27b2b3598523 Mon Sep 17 00:00:00 2001 From: dal4segno Date: Fri, 13 Feb 2026 15:18:05 +0900 Subject: [PATCH] =?UTF-8?q?EnemyPortal=EC=9D=B4=20=EC=9E=91=EB=8F=99?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Network 환경 대응 --- Assets/DefaultNetworkPrefabs.asset | 5 ++ Assets/Prefabs/EnemyPortal.prefab | 32 ++++++++++- Assets/Scenes/GameMain.unity | 26 ++++++++- Assets/Scripts/EnemyPortal.cs | 89 +++++++++++++++++------------- 4 files changed, 110 insertions(+), 42 deletions(-) diff --git a/Assets/DefaultNetworkPrefabs.asset b/Assets/DefaultNetworkPrefabs.asset index 6a746f9..5045d66 100644 --- a/Assets/DefaultNetworkPrefabs.asset +++ b/Assets/DefaultNetworkPrefabs.asset @@ -154,3 +154,8 @@ MonoBehaviour: SourcePrefabToOverride: {fileID: 0} SourceHashToOverride: 0 OverridingTargetPrefab: {fileID: 0} + - Override: 0 + Prefab: {fileID: 3432047510330746227, guid: 11e3760dda2c0164abf759c18d918893, type: 3} + SourcePrefabToOverride: {fileID: 0} + SourceHashToOverride: 0 + OverridingTargetPrefab: {fileID: 0} diff --git a/Assets/Prefabs/EnemyPortal.prefab b/Assets/Prefabs/EnemyPortal.prefab index 744ca03..98bbbd4 100644 --- a/Assets/Prefabs/EnemyPortal.prefab +++ b/Assets/Prefabs/EnemyPortal.prefab @@ -9,6 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 228462577495887354} + - component: {fileID: 8411098988276399395} - component: {fileID: 6859825394817103090} m_Layer: 0 m_Name: EnemyPortal @@ -33,6 +34,31 @@ Transform: - {fileID: 1144932316349886388} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &8411098988276399395 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3432047510330746227} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: Unity.Netcode.Runtime::Unity.Netcode.NetworkObject + GlobalObjectIdHash: 2651171896 + InScenePlacedSourceGlobalObjectIdHash: 0 + DeferredDespawnTick: 0 + Ownership: 1 + AlwaysReplicateAsRoot: 0 + SynchronizeTransform: 1 + ActiveSceneSynchronization: 0 + SceneMigrationSynchronization: 1 + SpawnWithObservers: 1 + DontDestroyWithOwner: 0 + AutoObjectParentSync: 1 + SyncOwnerTransformWhenParented: 1 + AllowOwnerToParent: 0 --- !u!114 &6859825394817103090 MonoBehaviour: m_ObjectHideFlags: 0 @@ -45,8 +71,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cb91abd3aae74d941a739a48aefb74a1, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::EnemyPortal - Enemies: - - {fileID: 5176576196123937037, guid: 951b69041a2ace947afd721fefb3eaba, type: 3} + ShowTopMostFoldoutHeaderGroup: 1 + monsterEntries: [] + initialCost: 4 + costIncreaseRate: 10 --- !u!1001 &606055883085645919 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/GameMain.unity b/Assets/Scenes/GameMain.unity index 7cce8e2..8705aa1 100644 --- a/Assets/Scenes/GameMain.unity +++ b/Assets/Scenes/GameMain.unity @@ -1762,6 +1762,18 @@ PrefabInstance: propertyPath: monsterEntries.Array.data[1].monsterData value: objectReference: {fileID: 0} + - target: {fileID: 8411098988276399395, guid: 11e3760dda2c0164abf759c18d918893, type: 3} + propertyPath: GlobalObjectIdHash + value: 3475466684 + objectReference: {fileID: 0} + - target: {fileID: 8411098988276399395, guid: 11e3760dda2c0164abf759c18d918893, type: 3} + propertyPath: SceneMigrationSynchronization + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8411098988276399395, guid: 11e3760dda2c0164abf759c18d918893, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 2651171896 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] @@ -2231,7 +2243,7 @@ MonoBehaviour: cycleLength: 90 autoStart: 1 pauseOnZero: 0 - exceptionalFirstCycleLength: 0 + exceptionalFirstCycleLength: 10 showDebugLogs: 1 --- !u!4 &1442785555 Transform: @@ -2989,6 +3001,18 @@ PrefabInstance: propertyPath: monsterEntries.Array.data[1].monsterData value: objectReference: {fileID: 0} + - target: {fileID: 8411098988276399395, guid: 11e3760dda2c0164abf759c18d918893, type: 3} + propertyPath: GlobalObjectIdHash + value: 4252027324 + objectReference: {fileID: 0} + - target: {fileID: 8411098988276399395, guid: 11e3760dda2c0164abf759c18d918893, type: 3} + propertyPath: SceneMigrationSynchronization + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8411098988276399395, guid: 11e3760dda2c0164abf759c18d918893, type: 3} + propertyPath: InScenePlacedSourceGlobalObjectIdHash + value: 2651171896 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] diff --git a/Assets/Scripts/EnemyPortal.cs b/Assets/Scripts/EnemyPortal.cs index 7870874..347647d 100644 --- a/Assets/Scripts/EnemyPortal.cs +++ b/Assets/Scripts/EnemyPortal.cs @@ -4,42 +4,53 @@ using System.Collections.Generic; using Unity.Netcode; using UnityEngine; -public class EnemyPortal : NetworkBehaviour -{ - [System.Serializable] - public class MonsterEntry + public class EnemyPortal : NetworkBehaviour { - public GameObject prefab; - } + [System.Serializable] + public class MonsterEntry + { + public GameObject prefab; + } - [Header("Spawn Settings")] - [Tooltip("몬스터 프리팹 목록 (Editor에서 자동 로드 가능)")] - [SerializeField] private List monsterEntries = new(); + [Header("Spawn Settings")] + [Tooltip("몬스터 프리팹 목록 (Editor에서 자동 로드 가능)")] + [SerializeField] private List monsterEntries = new(); - [Header("Cost Settings")] - [Tooltip("시간당 코스트 시작 값")] - [SerializeField] private float initialCost = 4f; - [Tooltip("사이클마다 코스트 증가율 (%)")] - [SerializeField] private float costIncreaseRate = 10f; + [Header("Cost Settings")] + [Tooltip("시간당 코스트 시작 값")] + [SerializeField] private float initialCost = 4f; + [Tooltip("사이클마다 코스트 증가율 (%)")] + [SerializeField] private float costIncreaseRate = 10f; - private float currentCost; + private float currentCost; - void Start() + public override void OnNetworkSpawn() { - currentCost = initialCost; + base.OnNetworkSpawn(); GlobalTimer.Instance.OnCycleStart += OnCycleStart; } - private void OnCycleStart(int cycleNumber) - { - SpawnMonsters(); - IncreaseCost(); - } + public override void OnNetworkDespawn() + { + GlobalTimer.Instance.OnCycleStart -= OnCycleStart; + base.OnNetworkDespawn(); + } - private void SpawnMonsters() - { - float remainingCost = currentCost; - int spawnedCount = 0; + void Start() + { + currentCost = initialCost; + } + + private void OnCycleStart(int cycleNumber) + { + SpawnMonsters(); + IncreaseCost(); + } + + private void SpawnMonsters() + { + float remainingCost = currentCost; + int spawnedCount = 0; while (remainingCost > 0 && monsterEntries.Count > 0) { @@ -129,21 +140,21 @@ public class EnemyPortal : NetworkBehaviour return null; } - private void SpawnEnemy(GameObject prefab) - { - if (!IsServer) return; - - GameObject enemy = Instantiate(prefab, transform); - - if (enemy.GetComponent() == null) + private void SpawnEnemy(GameObject prefab) { - var visibility = enemy.AddComponent(); - visibility.showInExploredAreas = false; - visibility.updateInterval = 0.2f; - } + if (!IsServer) return; - enemy.GetComponent().SpawnWithOwnership(NetworkManager.Singleton.LocalClientId); - } + GameObject enemy = Instantiate(prefab, transform); + + if (enemy.GetComponent() == null) + { + var visibility = enemy.AddComponent(); + visibility.showInExploredAreas = false; + visibility.updateInterval = 0.2f; + } + + enemy.GetComponent().SpawnWithOwnership(NetworkManager.Singleton.LocalClientId); + } private void IncreaseCost() {