Lower provider-native rendering assets
This commit is contained in:
parent
580af5328d
commit
b112acb34d
9 changed files with 165 additions and 8 deletions
|
|
@ -40,7 +40,9 @@ namespace GameCult.Eve.UnityScene
|
|||
private readonly HashSet<string> _pendingCommandIds = new HashSet<string>(StringComparer.Ordinal);
|
||||
private readonly HashSet<string> _publishedReceiptIds = new HashSet<string>(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, GameObject> _prefabs = new Dictionary<string, GameObject>(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, UnityEngine.Object> _nativeAssets = new Dictionary<string, UnityEngine.Object>(StringComparer.Ordinal);
|
||||
private readonly List<AssetBundle> _assetBundles = new List<AssetBundle>();
|
||||
private readonly Dictionary<string, int> _cameraCullingMasks = new Dictionary<string, int>(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<GameObject>(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<EveAssetVariant> 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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<GameObject>(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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Camera>();
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ namespace GameCult.Eve.UnityScene
|
|||
|
||||
rig.Host = resolvedHost;
|
||||
rig.CameraTransform = ResolveCameraTransform();
|
||||
rig.RenderPolicySource = provider as IEveUnityCameraRenderPolicySource;
|
||||
}
|
||||
|
||||
private MonoBehaviour ResolveBehaviour<T>(
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ namespace GameCult.Eve.UnityScene
|
|||
feedbackEffects.Bind(this, Runtime.GameObjectAssetProvider);
|
||||
var thermal = GetComponent<EveUnityThermalPresenter>();
|
||||
if (thermal == null) thermal = gameObject.AddComponent<EveUnityThermalPresenter>();
|
||||
thermal.Bind(this);
|
||||
thermal.Bind(this, Runtime.GameObjectAssetProvider as IEveUnityNativeAssetProvider);
|
||||
|
||||
return Runtime.Connect();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<EveUnityPlayableWorldProjection?> _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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<MonoBehaviour>().OfType<IEveUnityThermalPresentationSink>().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<MonoBehaviour>().OfType<IEveUnityThermalPresentationAssetSink>())
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue