// Callback used by the visibility system for objects on a host. // Objects on a host (with a local client) cannot be disabled or // destroyed when they are not visible to the local client. So this // function is called to allow custom code to hide these objects. A // typical implementation will disable renderer components on the // object. This is only called on local clients on a host. // => need the function in here and virtual so people can overwrite! // => not everyone wants to hide renderers! public virtual void SetHostVisibility(NetworkIdentity identity, bool visible) { foreach (Renderer rend in identity.GetComponentsInChildren <Renderer>()) { rend.enabled = visible; } }
/// <summary> /// Valids Prefab then adds it to prefabs dictionary /// </summary> /// <param name="prefab">NetworkIdentity on Prefab GameObject</param> static void RegisterPrefabIdentity(NetworkIdentity prefab) { if (prefab.assetId == Guid.Empty) { logger.LogError($"Can not Register '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead"); return; } if (prefab.sceneId != 0) { logger.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene."); return; } NetworkIdentity[] identities = prefab.GetComponentsInChildren <NetworkIdentity>(); if (identities.Length > 1) { logger.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object."); } if (prefabs.ContainsKey(prefab.assetId)) { GameObject existingPrefab = prefabs[prefab.assetId]; logger.LogWarning($"Replacing existing prefab with assetId '{prefab.assetId}'. Old prefab '{existingPrefab.name}', New prefab '{prefab.name}'"); } if (spawnHandlers.ContainsKey(prefab.assetId) || unspawnHandlers.ContainsKey(prefab.assetId)) { logger.LogWarning($"Adding prefab '{prefab.name}' with assetId '{prefab.assetId}' when spawnHandlers with same assetId already exists."); } if (logger.LogEnabled()) { logger.Log($"Registering prefab '{prefab.name}' as asset:{prefab.assetId}"); } prefabs[prefab.assetId] = prefab.gameObject; }