네트워크 멀티플레이 대응
This commit is contained in:
55
Assets/Scripts/NetworkSpawnHelper.cs
Normal file
55
Assets/Scripts/NetworkSpawnHelper.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
public static class NetworkSpawnHelper
|
||||
{
|
||||
public static void AddFogOfWarVisibility(GameObject obj, bool showInExploredAreas = true, float updateInterval = 0.2f)
|
||||
{
|
||||
if (obj.GetComponent<FogOfWarVisibility>() == null)
|
||||
{
|
||||
var visibility = obj.AddComponent<FogOfWarVisibility>();
|
||||
visibility.showInExploredAreas = showInExploredAreas;
|
||||
visibility.updateInterval = updateInterval;
|
||||
}
|
||||
}
|
||||
|
||||
public static void PreparePreviewForRendering(GameObject preview)
|
||||
{
|
||||
NetworkObject netObj = preview.GetComponent<NetworkObject>();
|
||||
if (netObj != null)
|
||||
{
|
||||
Object.DestroyImmediate(netObj);
|
||||
}
|
||||
|
||||
Building building = preview.GetComponent<Building>();
|
||||
if (building != null)
|
||||
{
|
||||
Object.DestroyImmediate(building);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyMaterialToPreview(GameObject preview, Material material)
|
||||
{
|
||||
Renderer[] renderers = preview.GetComponentsInChildren<Renderer>();
|
||||
foreach (var renderer in renderers)
|
||||
{
|
||||
Material[] mats = new Material[renderer.materials.Length];
|
||||
for (int i = 0; i < mats.Length; i++)
|
||||
{
|
||||
mats[i] = material;
|
||||
}
|
||||
renderer.materials = mats;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DisableColliders(GameObject obj)
|
||||
{
|
||||
foreach (var collider in obj.GetComponentsInChildren<Collider>())
|
||||
{
|
||||
collider.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user