上传YomovSDK

This commit is contained in:
Sora丶kong
2026-03-03 03:15:46 +08:00
parent 9096da7e6c
commit eb97f31065
6477 changed files with 1932208 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
{
"name": "CustomCompositionLayerFeature",
"rootNamespace": "",
"references": [
"Unity.XR.OpenXR",
"Unity.XR.CompositionLayers"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.xr.compositionlayers",
"expression": "",
"define": "XR_COMPOSITION_LAYERS"
}
],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 761ff1028970883469d1bae03390ccb9
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
#if XR_COMPOSITION_LAYERS
using System.Runtime.CompilerServices;
using Unity.XR.CompositionLayers.Layers;
using UnityEditor;
using UnityEngine.XR.OpenXR.CompositionLayers;
using UnityEngine.XR.OpenXR.Features;
#if UNITY_EDITOR
[UnityEditor.XR.OpenXR.Features.OpenXRFeature(UiName = "OpenXR Custom Layer Handler Example",
BuildTargetGroups = new[] { BuildTargetGroup.Standalone, BuildTargetGroup.WSA, BuildTargetGroup.Android },
Company = "Unity",
Desc = "An example to demonstrate how to enable a handler for a customized composition layer type.",
DocumentationLink = "",
FeatureId = "com.unity.openxr.features.customlayerexample",
OpenxrExtensionStrings = "",
Version = "1")]
#endif
public class CustomFeature : OpenXRFeature
{
bool isSubscribed;
protected override void OnEnable()
{
if (OpenXRLayerProvider.isStarted)
CreateAndRegisterLayerHandler();
else
{
OpenXRLayerProvider.Started += CreateAndRegisterLayerHandler;
isSubscribed = true;
}
}
protected override void OnDisable()
{
if (isSubscribed)
{
OpenXRLayerProvider.Started -= CreateAndRegisterLayerHandler;
isSubscribed = false;
}
}
protected void CreateAndRegisterLayerHandler()
{
if (enabled)
{
var layerHandler = new CustomLayerHandler();
OpenXRLayerProvider.RegisterLayerHandler(typeof(CustomQuadLayerData), layerHandler);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6de7ce2a0dc75043b4669d09d7fd6c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,160 @@
#if XR_COMPOSITION_LAYERS
using Unity.XR.CompositionLayers.Extensions;
using Unity.XR.CompositionLayers.Services;
using Unity.XR.CompositionLayers;
using Unity.XR.CompositionLayers.Layers;
using UnityEngine.XR.OpenXR.NativeTypes;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.OpenXR.CompositionLayers
{
/// <summary>
/// Demonstrates custom handler for the custom quad layer.
/// </summary>
public class CustomLayerHandler : OpenXRCustomLayerHandler<CustomNativeCompositionLayerQuad>
{
protected override bool CreateSwapchain(CompositionLayerManager.LayerInfo layer, out SwapchainCreateInfo swapchainCreateInfo)
{
unsafe
{
var texturesExtension = layer.Layer.GetComponent<TexturesExtension>();
if (texturesExtension == null || texturesExtension.enabled == false)
{
swapchainCreateInfo = default;
return false;
}
if (texturesExtension.sourceTexture == TexturesExtension.SourceTextureEnum.LocalTexture && texturesExtension.LeftTexture != null)
{
var xrCreateInfo = new XrSwapchainCreateInfo()
{
Type = (uint)XrStructureType.XR_TYPE_SWAPCHAIN_CREATE_INFO,
Next = OpenXRLayerUtility.GetExtensionsChain(layer, CompositionLayerExtension.ExtensionTarget.Swapchain),
CreateFlags = 0,
UsageFlags = (ulong)(XrSwapchainUsageFlags.XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XrSwapchainUsageFlags.XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT),
Format = OpenXRLayerUtility.GetDefaultColorFormat(),
SampleCount = 1,
Width = (uint)texturesExtension.LeftTexture.width,
Height = (uint)texturesExtension.LeftTexture.height,
FaceCount = 1,
ArraySize = 1,
MipCount = (uint)texturesExtension.LeftTexture.mipmapCount,
};
swapchainCreateInfo = new SwapchainCreateInfo(xrCreateInfo, isExternalSurface: false);
return true;
}
swapchainCreateInfo = default;
return false;
}
}
protected override bool CreateNativeLayer(CompositionLayerManager.LayerInfo layer, SwapchainCreatedOutput swapchainOutput, out CustomNativeCompositionLayerQuad nativeLayer)
{
unsafe
{
var texturesExtension = layer.Layer.GetComponent<TexturesExtension>();
if (texturesExtension == null || texturesExtension.enabled == false)
{
nativeLayer = default;
return false;
}
var data = layer.Layer.LayerData as CustomQuadLayerData;
var transform = layer.Layer.GetComponent<Transform>();
int subImageWidth = 0;
int subImageHeight = 0;
if (texturesExtension.sourceTexture == TexturesExtension.SourceTextureEnum.LocalTexture && texturesExtension.LeftTexture != null)
{
subImageWidth = texturesExtension.LeftTexture.width;
subImageHeight = texturesExtension.LeftTexture.height;
}
var size = data.GetScaledSize(transform.lossyScale);
nativeLayer = new CustomNativeCompositionLayerQuad()
{
Type = (uint)XrStructureType.XR_TYPE_COMPOSITION_LAYER_QUAD,
Next = OpenXRLayerUtility.GetExtensionsChain(layer, CompositionLayerExtension.ExtensionTarget.Layer),
LayerFlags = data.BlendType == BlendType.Premultiply ? XrCompositionLayerFlags.SourceAlpha : XrCompositionLayerFlags.SourceAlpha | XrCompositionLayerFlags.UnPremultipliedAlpha,
Space = OpenXRLayerUtility.GetCurrentAppSpace(),
EyeVisibility = 0,
SubImage = new XrSwapchainSubImage()
{
Swapchain = swapchainOutput.handle,
ImageRect = new XrRect2Di()
{
Offset = new XrOffset2Di() { X = 0, Y = 0 },
Extent = new XrExtent2Di()
{
Width = subImageWidth,
Height = subImageHeight
}
},
ImageArrayIndex = 0
},
Pose = new XrPosef(OpenXRUtility.ComputePoseToWorldSpace(transform, CompositionLayerManager.mainCameraCache).position, OpenXRUtility.ComputePoseToWorldSpace(transform, CompositionLayerManager.mainCameraCache).rotation),
Size = new XrExtent2Df()
{
Width = size.x,
Height = size.y
}
};
return true;
}
}
protected override bool ModifyNativeLayer(CompositionLayerManager.LayerInfo layerInfo, ref CustomNativeCompositionLayerQuad nativeLayer)
{
var texturesExtension = layerInfo.Layer.GetComponent<TexturesExtension>();
if (texturesExtension == null || texturesExtension.enabled == false)
return false;
var data = layerInfo.Layer.LayerData as CustomQuadLayerData;
var transform = layerInfo.Layer.GetComponent<Transform>();
nativeLayer.Pose = new XrPosef(OpenXRUtility.ComputePoseToWorldSpace(transform, CompositionLayerManager.mainCameraCache).position, OpenXRUtility.ComputePoseToWorldSpace(transform, CompositionLayerManager.mainCameraCache).rotation);
nativeLayer.Size = new XrExtent2Df()
{
Width = data.GetScaledSize(transform.lossyScale).x,
Height = data.GetScaledSize(transform.lossyScale).y
};
unsafe
{
nativeLayer.Next = OpenXRLayerUtility.GetExtensionsChain(layerInfo, CompositionLayerExtension.ExtensionTarget.Layer);
}
return true;
}
protected override bool ActiveNativeLayer(CompositionLayerManager.LayerInfo layerInfo, ref CustomNativeCompositionLayerQuad nativeLayer)
{
var texturesExtension = layerInfo.Layer.GetComponent<TexturesExtension>();
if (texturesExtension == null || texturesExtension.enabled == false)
return false;
var transform = layerInfo.Layer.GetComponent<Transform>();
nativeLayer.Pose = new XrPosef(OpenXRUtility.ComputePoseToWorldSpace(transform, CompositionLayerManager.mainCameraCache).position, OpenXRUtility.ComputePoseToWorldSpace(transform, CompositionLayerManager.mainCameraCache).rotation);
nativeLayer.Space = OpenXRLayerUtility.GetCurrentAppSpace();
return base.ActiveNativeLayer(layerInfo, ref nativeLayer);
}
}
}
namespace UnityEngine.XR.OpenXR.NativeTypes
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct CustomNativeCompositionLayerQuad
{
public uint Type;
public void* Next;
public XrCompositionLayerFlags LayerFlags;
public ulong Space;
public uint EyeVisibility;
public XrSwapchainSubImage SubImage;
public XrPosef Pose;
public XrExtent2Df Size;
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46b75e7ee6eb88d49bbf7ac40fbb2dfc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
#if XR_COMPOSITION_LAYERS
using System;
using UnityEngine;
using Unity.XR.CompositionLayers.Extensions;
using Unity.XR.CompositionLayers.Layers;
/// <summary>
/// Example of defining a layer data script for a custom shape.
/// In this case, we are just creating a custom quad shape.
/// This composition layer type will appear in the type dropdown of the CompositionLayer component with what the Name is defined as.
/// </summary>
[Serializable]
[CompositionLayerData(
Provider = "Unity",
Name = "Custom Quad",
IconPath = "",
InspectorIcon = "",
ListViewIcon = "",
Description = "Custom shape example.",
SuggestedExtenstionTypes = new[] { typeof(TexturesExtension) }
)]
public class CustomQuadLayerData : LayerData
{
[SerializeField]
Vector2 m_Size = Vector2.one;
[SerializeField]
bool m_ApplyTransformScale = true;
public Vector2 Size
{
get => m_Size;
set => m_Size = UpdateValue(m_Size, value);
}
public bool ApplyTransformScale
{
get => m_ApplyTransformScale;
set => m_ApplyTransformScale = UpdateValue(m_ApplyTransformScale, value);
}
public Vector2 GetScaledSize(Vector3 scale)
{
return m_ApplyTransformScale ? scale * m_Size : m_Size;
}
public override void CopyFrom(LayerData layerData)
{
if (layerData is CustomQuadLayerData customQuadLayerData)
{
m_Size = customQuadLayerData.Size;
m_ApplyTransformScale = customQuadLayerData.ApplyTransformScale;
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
# Composition Layer Feature Sample
Demonstrates how to add support for customized composition layer types using OpenXR Feature [OpenXRFeature](https://docs.unity3d.com/Packages/com.unity.xr.openxr@1.6/manual/features.html).

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4a82d7e62db68ce469c8f7c859731ad7
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: