Skip to content

Commit caa17f3

Browse files
author
SG
committed
v7.3update
1 parent 3e93b35 commit caa17f3

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

Assets/UnityChatDemo(Can be deleted)/Scripts/Holo/HoloCaptureManager.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
using System.Collections.Generic;
55
using System;
66
using UnityEngine;
7-
public class HoloCaptureManager : MonoBehaviour {
7+
8+
#if UNITY_2020_1_OR_NEWER
9+
10+
#endif
11+
12+
public class HoloCaptureManager : MonoBehaviour
13+
{
814

915
public static HoloCaptureManager Instance;
1016
private void Awake()
@@ -25,13 +31,13 @@ public enum HoloResolution
2531
Holo_1280x720,
2632
}
2733
//public HoloType holoType;
28-
public HoloResolution holoResolution;
34+
public HoloResolution holoResolution;
2935
public HoloCamFrame holoFrame;
3036
HoloCapture.Resolution resolution;
3137
public bool EnableHolograms = true;
3238

33-
[Range(0,1)]
34-
public float Opacity=0.9f;
39+
[Range(0, 1)]
40+
public float Opacity = 0.9f;
3541

3642

3743
public Texture2D _videoTexture { get; set; }
@@ -49,7 +55,7 @@ public void Init()
4955
resolution = new HoloCapture.Resolution(896, 504);
5056
break;
5157
case HoloResolution.Holo_1280x720:
52-
resolution = new HoloCapture.Resolution(1280,720);
58+
resolution = new HoloCapture.Resolution(1280, 720);
5359
break;
5460
}
5561
int frame;
@@ -65,8 +71,21 @@ public void Init()
6571
frame = 15;
6672
break;
6773
}
74+
#if UNITY_WSA
75+
76+
#if UNITY_2020_1_OR_NEWER
77+
//Note:
78+
//please add those packages on PackageManager
79+
//1.XR Plugin Management 4.x
80+
//2.Windows XR Plugin 4.x
81+
HoloCaptureHelper.Instance.Init(resolution, frame, true, EnableHolograms, Opacity, false,
82+
UnityEngine.XR.WindowsMR.WindowsMREnvironment.OriginSpatialCoordinateSystem, OnFrameSampleCallback);
83+
#else
6884
HoloCaptureHelper.Instance.Init(resolution, frame, true, EnableHolograms, Opacity, false,
6985
UnityEngine.XR.WSA.WorldManager.GetNativeISpatialCoordinateSystemPtr(), OnFrameSampleCallback);
86+
#endif
87+
88+
#endif
7089

7190
_videoTexture = new Texture2D(resolution.width, resolution.height, TextureFormat.BGRA32, false);
7291
}
@@ -111,7 +130,7 @@ void OnFrameSampleCallback(VideoCaptureSample sample)
111130

112131
UnityEngine.WSA.Application.InvokeOnAppThread(() =>
113132
{
114-
if (Application.platform==RuntimePlatform.WSAPlayerX86)
133+
if (Application.platform == RuntimePlatform.WSAPlayerX86)
115134
{
116135
ImageHorizontalMirror(imageBytes);
117136
}
@@ -152,11 +171,11 @@ void ImageVerticalMirror(byte[] imageBytes)
152171
int height = resolution.height;
153172
int Line = width * PixelSize;
154173

155-
for (int i = 0; i< width; i ++)
174+
for (int i = 0; i < width; i++)
156175
{
157176
for (int j = 0; j < height / 2; j++)
158177
{
159-
Swap<byte>(ref imageBytes[Line * j + i * PixelSize], ref imageBytes[Line * (height-j-1)+ i * PixelSize]);
178+
Swap<byte>(ref imageBytes[Line * j + i * PixelSize], ref imageBytes[Line * (height - j - 1) + i * PixelSize]);
160179
Swap<byte>(ref imageBytes[Line * j + i * PixelSize + 1], ref imageBytes[Line * (height - j - 1) + i * PixelSize + 1]);
161180
Swap<byte>(ref imageBytes[Line * j + i * PixelSize + 2], ref imageBytes[Line * (height - j - 1) + i * PixelSize + 2]);
162181
Swap<byte>(ref imageBytes[Line * j + i * PixelSize + 3], ref imageBytes[Line * (height - j - 1) + i * PixelSize + 3]);

0 commit comments

Comments
 (0)