diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs index 3a63ba9..628fe1d 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs @@ -40,7 +40,9 @@ namespace GameCult.Eve.UnityScene private readonly HashSet _pendingCommandIds = new HashSet(StringComparer.Ordinal); private readonly HashSet _publishedReceiptIds = new HashSet(StringComparer.Ordinal); private readonly Dictionary _prefabs = new Dictionary(StringComparer.Ordinal); + private readonly Dictionary _nativeAssets = new Dictionary(StringComparer.Ordinal); private readonly List _assetBundles = new List(); + private readonly Dictionary _cameraCullingMasks = new Dictionary(StringComparer.Ordinal); private CultMeshNode? _node; private CultMeshSnapshotEndpoint? _snapshot; private CultMeshSnapshotSession? _assetSession; @@ -148,6 +150,7 @@ namespace GameCult.Eve.UnityScene foreach (var bundle in _assetBundles) bundle.Unload(unloadAllLoadedObjects: false); _assetBundles.Clear(); _prefabs.Clear(); + _nativeAssets.Clear(); _node?.Dispose(); _assetSession?.Dispose(); _node = null; @@ -165,6 +168,19 @@ namespace GameCult.Eve.UnityScene return _prefabs.TryGetValue(asset.AssetRef, out var prefab) ? prefab : null; } + public UnityEngine.Object? ResolveAsset(EveUnityPlayableWorldAssetBinding asset, Type assetType) + { + if (asset == null) throw new ArgumentNullException(nameof(asset)); + if (assetType == null) throw new ArgumentNullException(nameof(assetType)); + return _nativeAssets.TryGetValue(asset.AssetRef, out var value) && assetType.IsInstanceOfType(value) + ? value : null; + } + + public bool TryGetCameraCullingMask(string viewId, out int cullingMask) + { + return _cameraCullingMasks.TryGetValue(viewId ?? "", out cullingMask); + } + private void EnsureOpen() { if (_node != null) @@ -297,6 +313,8 @@ namespace GameCult.Eve.UnityScene foreach (var bundle in _assetBundles) bundle.Unload(unloadAllLoadedObjects: false); _assetBundles.Clear(); _prefabs.Clear(); + _nativeAssets.Clear(); + _cameraCullingMasks.Clear(); var selected = catalog.Assets .Select(asset => new { @@ -307,6 +325,7 @@ namespace GameCult.Eve.UnityScene }) .Where(selection => selection.Variant != null) .ToArray(); + ReadCameraPolicies(selected.Select(selection => selection.Variant!)); foreach (var group in selected.GroupBy(selection => selection.Variant!.Uri, StringComparer.Ordinal)) { var variant = group.First().Variant!; @@ -326,15 +345,47 @@ namespace GameCult.Eve.UnityScene _assetBundles.Add(bundle); foreach (var selection in group) { - var prefab = bundle.LoadAsset(selection.Variant!.AssetKey); - if (prefab != null) + var value = bundle.LoadAsset(selection.Variant!.AssetKey); + if (value == null) continue; + _nativeAssets[selection.Asset.AssetRef] = value; + if (selection.Asset.Metadata.TryGetValue("presentationRole", out var role) && + !string.IsNullOrWhiteSpace(role)) + _nativeAssets[role] = value; + if (value is GameObject prefab) + { _prefabs[selection.Asset.AssetRef] = prefab; + if (!string.IsNullOrWhiteSpace(role)) _prefabs[role] = prefab; + } } } CurrentAssetCatalogVersion = catalog.Version; } + private void ReadCameraPolicies(IEnumerable variants) + { + _cameraCullingMasks.Clear(); + foreach (var variant in variants) + { + foreach (var pair in variant.Metadata) + { + const string prefix = "view."; + const string suffix = ".excludeUnityLayers"; + if (!pair.Key.StartsWith(prefix, StringComparison.Ordinal) || + !pair.Key.EndsWith(suffix, StringComparison.Ordinal)) + continue; + var viewId = pair.Key.Substring(prefix.Length, pair.Key.Length - prefix.Length - suffix.Length); + var mask = -1; + foreach (var token in (pair.Value ?? "").Split(',')) + { + if (int.TryParse(token.Trim(), out var layer) && layer >= 0 && layer < 32) + mask &= ~(1 << layer); + } + _cameraCullingMasks[viewId] = mask; + } + } + } + private long CurrentAssetCatalogVersion { get; set; } = -1; private static string CurrentBundlePlatform() diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs index 612bb5e..2ea8570 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs @@ -14,7 +14,8 @@ namespace GameCult.Eve.UnityScene IEveUnitySceneCommandSink, IEveUnitySceneCommandReceiptSource, IEveUnityProviderRefreshSource, - IEveUnityGameObjectAssetProvider + IEveUnityCameraRenderPolicySource, + IEveUnityNativeAssetProvider { [SerializeField] private string rendezvousEndpoint = ""; [SerializeField] private string providerFilter = ""; @@ -93,6 +94,18 @@ namespace GameCult.Eve.UnityScene return _transport!.ResolvePrefab(asset); } + public UnityEngine.Object? ResolveAsset(EveUnityPlayableWorldAssetBinding asset, Type assetType) + { + EnsureTransport(); + return _transport!.ResolveAsset(asset, assetType); + } + + public bool TryGetCameraCullingMask(string viewId, out int cullingMask) + { + EnsureTransport(); + return _transport!.TryGetCameraCullingMask(viewId, out cullingMask); + } + private void OnDestroy() { _bridge?.Dispose(); diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityGameObjectPlayableWorldSceneSink.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityGameObjectPlayableWorldSceneSink.cs index 9238e73..75a9696 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityGameObjectPlayableWorldSceneSink.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityGameObjectPlayableWorldSceneSink.cs @@ -11,6 +11,11 @@ namespace GameCult.Eve.UnityScene GameObject? ResolvePrefab(EveUnityPlayableWorldAssetBinding asset); } + public interface IEveUnityNativeAssetProvider : IEveUnityGameObjectAssetProvider + { + UnityEngine.Object? ResolveAsset(EveUnityPlayableWorldAssetBinding asset, Type assetType); + } + public sealed class EveUnityGameObjectPlayableWorldSceneSink : IEveUnityPlayableWorldSceneSink { private readonly Transform _root; @@ -200,7 +205,7 @@ namespace GameCult.Eve.UnityScene private static float Positive(float value, float fallback) => value > 0f ? value : fallback; } - public sealed class EveUnityResourcesAssetProvider : IEveUnityGameObjectAssetProvider + public sealed class EveUnityResourcesAssetProvider : IEveUnityNativeAssetProvider { public GameObject? ResolvePrefab(EveUnityPlayableWorldAssetBinding asset) { @@ -210,6 +215,14 @@ namespace GameCult.Eve.UnityScene ? null : Resources.Load(resourcesPath); } + + public UnityEngine.Object? ResolveAsset(EveUnityPlayableWorldAssetBinding asset, Type assetType) + { + if (asset == null) throw new ArgumentNullException(nameof(asset)); + if (assetType == null) throw new ArgumentNullException(nameof(assetType)); + var resourcesPath = EveUnityPlayableWorldAssetManifestEntry.NormalizeResourcesPath(asset.AssetRef); + return string.IsNullOrWhiteSpace(resourcesPath) ? null : Resources.Load(resourcesPath, assetType); + } } public sealed class EveUnityPlayableWorldEntityMarker : MonoBehaviour diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldAssetManifest.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldAssetManifest.cs index 23653d4..cd858d0 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldAssetManifest.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldAssetManifest.cs @@ -314,7 +314,7 @@ namespace GameCult.Eve.UnityScene } } - public sealed class EveUnityManifestGameObjectAssetProvider : IEveUnityGameObjectAssetProvider + public sealed class EveUnityManifestGameObjectAssetProvider : IEveUnityNativeAssetProvider { private readonly EveUnityPlayableWorldAssetManifest _manifest; private readonly IEveUnityGameObjectAssetProvider? _fallback; @@ -343,5 +343,18 @@ namespace GameCult.Eve.UnityScene return _fallback?.ResolvePrefab(asset); } + + public UnityEngine.Object? ResolveAsset(EveUnityPlayableWorldAssetBinding asset, Type assetType) + { + if (asset == null) throw new ArgumentNullException(nameof(asset)); + if (assetType == null) throw new ArgumentNullException(nameof(assetType)); + var entry = _manifest.Find(asset) ?? _manifest.FindByPresentationRole(asset.AssetRef); + if (entry != null && !string.IsNullOrWhiteSpace(entry.ResourcesPath)) + { + var value = Resources.Load(entry.ResourcesPath, assetType); + if (value != null) return value; + } + return (_fallback as IEveUnityNativeAssetProvider)?.ResolveAsset(asset, assetType); + } } } diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldCameraRig.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldCameraRig.cs index 2394723..996c5bb 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldCameraRig.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldCameraRig.cs @@ -4,6 +4,11 @@ using UnityEngine; namespace GameCult.Eve.UnityScene { + public interface IEveUnityCameraRenderPolicySource + { + bool TryGetCameraCullingMask(string viewId, out int cullingMask); + } + public sealed class EveUnityPlayableWorldCameraRig : MonoBehaviour { [SerializeField] private EveUnityPlayableWorldClientHost? host; @@ -13,6 +18,7 @@ namespace GameCult.Eve.UnityScene [SerializeField] private float height = 6f; [SerializeField] private float yawDegrees = 35f; [SerializeField] private float followDamping = 12f; + private IEveUnityCameraRenderPolicySource? _renderPolicySource; public EveUnityPlayableWorldClientHost? Host { @@ -26,6 +32,12 @@ namespace GameCult.Eve.UnityScene set => cameraTransform = value; } + public IEveUnityCameraRenderPolicySource? RenderPolicySource + { + get => _renderPolicySource; + set => _renderPolicySource = value; + } + public bool ApplyRig(float deltaTime) { var resolvedHost = ResolveHost(); @@ -46,6 +58,12 @@ namespace GameCult.Eve.UnityScene return false; var cameraComponent = camera.GetComponent(); + if (cameraComponent != null && + _renderPolicySource != null && + _renderPolicySource.TryGetCameraCullingMask(activeWorld.ViewId, out var cullingMask)) + { + cameraComponent.cullingMask = cullingMask; + } var bounds = CalculateVisualBounds(player); var target = bounds?.center ?? player.transform.position; var radius = bounds?.extents.magnitude ?? 0f; diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientBootstrap.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientBootstrap.cs index 1883517..b5b6201 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientBootstrap.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientBootstrap.cs @@ -155,6 +155,7 @@ namespace GameCult.Eve.UnityScene rig.Host = resolvedHost; rig.CameraTransform = ResolveCameraTransform(); + rig.RenderPolicySource = provider as IEveUnityCameraRenderPolicySource; } private MonoBehaviour ResolveBehaviour( diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientHost.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientHost.cs index 7ec45de..93fdc0a 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientHost.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldClientHost.cs @@ -90,7 +90,7 @@ namespace GameCult.Eve.UnityScene feedbackEffects.Bind(this, Runtime.GameObjectAssetProvider); var thermal = GetComponent(); if (thermal == null) thermal = gameObject.AddComponent(); - thermal.Bind(this); + thermal.Bind(this, Runtime.GameObjectAssetProvider as IEveUnityNativeAssetProvider); return Runtime.Connect(); } diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldRuntime.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldRuntime.cs index 34d41bc..995eb49 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldRuntime.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityPlayableWorldRuntime.cs @@ -186,7 +186,7 @@ namespace GameCult.Eve.UnityScene } } - public sealed class EveUnityLivePlayableWorldAssetProvider : IEveUnityGameObjectAssetProvider + public sealed class EveUnityLivePlayableWorldAssetProvider : IEveUnityNativeAssetProvider { private readonly EveUnityPlayableWorldAssetManifestCache _assetManifests; private readonly Func _activeWorld; @@ -218,5 +218,20 @@ namespace GameCult.Eve.UnityScene return _fallback.ResolvePrefab(asset); } + + public UnityEngine.Object? ResolveAsset(EveUnityPlayableWorldAssetBinding asset, Type assetType) + { + if (asset == null) throw new ArgumentNullException(nameof(asset)); + if (assetType == null) throw new ArgumentNullException(nameof(assetType)); + var world = _activeWorld(); + var manifest = world == null ? null : _assetManifests.GetForWorld(world); + if (manifest != null) + { + var provider = new EveUnityManifestGameObjectAssetProvider(manifest, _fallback); + var value = provider.ResolveAsset(asset, assetType); + if (value != null) return value; + } + return (_fallback as IEveUnityNativeAssetProvider)?.ResolveAsset(asset, assetType); + } } } diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityThermalPresentation.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityThermalPresentation.cs index df9a526..e9deb76 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityThermalPresentation.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityThermalPresentation.cs @@ -13,6 +13,27 @@ namespace GameCult.Eve.UnityScene void ApplyThermalPresentation(EveUnityThermalPresentationFrame frame); } + public interface IEveUnityThermalPresentationAssetSink + { + void ConfigureThermalPresentationAssets(EveUnityThermalPresentationAssets assets); + } + + public sealed class EveUnityThermalPresentationAssets + { + public EveUnityThermalPresentationAssets(UnityEngine.Object? heatstroke, + UnityEngine.Object? severeHeatstroke, UnityEngine.Object? hypothermia, + UnityEngine.Object? severeHypothermia, UnityEngine.Object? death) + { + Heatstroke = heatstroke; SevereHeatstroke = severeHeatstroke; + Hypothermia = hypothermia; SevereHypothermia = severeHypothermia; Death = death; + } + public UnityEngine.Object? Heatstroke { get; } + public UnityEngine.Object? SevereHeatstroke { get; } + public UnityEngine.Object? Hypothermia { get; } + public UnityEngine.Object? SevereHypothermia { get; } + public UnityEngine.Object? Death { get; } + } + public readonly struct EveUnityThermalPresentationFrame { public EveUnityThermalPresentationFrame(string entityId, float cockpitTemperature, @@ -174,10 +195,18 @@ namespace GameCult.Eve.UnityScene public EveUnityThermalPresentationFrame LastFrame { get; private set; } - public void Bind(EveUnityPlayableWorldClientHost host) + public void Bind(EveUnityPlayableWorldClientHost host, IEveUnityNativeAssetProvider? assets = null) { _host = host != null ? host : throw new ArgumentNullException(nameof(host)); _sinks = GetComponents().OfType().ToArray(); + var resolved = new EveUnityThermalPresentationAssets( + Resolve(assets, "post.thermal.heatstroke"), + Resolve(assets, "post.thermal.severe-heatstroke"), + Resolve(assets, "post.thermal.hypothermia"), + Resolve(assets, "post.thermal.severe-hypothermia"), + Resolve(assets, "post.death")); + foreach (var sink in GetComponents().OfType()) + sink.ConfigureThermalPresentationAssets(resolved); ApplyAt(Time.unscaledTime); } @@ -188,5 +217,9 @@ namespace GameCult.Eve.UnityScene } private void Update() => ApplyAt(Time.unscaledTime); + + private static UnityEngine.Object? Resolve(IEveUnityNativeAssetProvider? assets, string role) => + assets?.ResolveAsset(new EveUnityPlayableWorldAssetBinding("", role, "provider-asset-ref"), + typeof(UnityEngine.Object)); } }