Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit b995ff0

Browse files
committed
use new Unity API in 2020.3.37 to create compatible external texture
1 parent 45813fd commit b995ff0

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Samples/UIWidgetsSamples_2019_4/Assets/Script/ModelViewHelper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using Unity.UIWidgets.engine;
34
using Unity.UIWidgets.foundation;
45
using UnityEngine;
56

@@ -81,7 +82,12 @@ public bool Load(int id, string path)
8182

8283
var gameObj = (GameObject) Instantiate(modelViewPrefab, Vector3.zero, Quaternion.identity);
8384

84-
var renderTexture = new RenderTexture(100, 100, 32);
85+
var renderTexture = UIWidgetsExternalTextureHelper.createCompatibleExternalTexture(new RenderTextureDescriptor(
86+
width: 100, height: 100
87+
)
88+
{
89+
depthBufferBits = 32
90+
});
8591

8692
gameObj.transform.Find("Camera").GetComponent<Camera>().targetTexture = renderTexture;
8793

Samples/UIWidgetsSamples_2019_4/Assets/Script/Scene3DTest1.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using UnityEngine;
99
using Color = Unity.UIWidgets.ui.Color;
1010
using Image = Unity.UIWidgets.widgets.Image;
11+
using TextStyle = Unity.UIWidgets.painting.TextStyle;
1112
using Texture = Unity.UIWidgets.widgets.Texture;
1213
using ui_ = Unity.UIWidgets.widgets.ui_;
1314

@@ -62,8 +63,8 @@ public override Widget build(BuildContext context)
6263
child: new Column(
6364
children: new List<Widget>
6465
{
65-
new Lottie("wine.json", size: new Size(100, 100)),
66-
new Container(width: 200, height: 200, color: Colors.red, child: new Center(child: new Container(width: 100, height: 100, child:new Texture(texture: text)))),
66+
new Text("External Texture is Only Available on OpenGLCore (Mac), OpenGLes(iOS and android) and D3d11(Windows)", style: new TextStyle(fontSize: 16f, decoration: TextDecoration.none, color: Colors.red)),
67+
new Container(width: 120, height: 120, color: Colors.red, child: new Center(child: new Container(width: 100, height: 100, child:new Texture(texture: text)))),
6768
/*new Container(
6869
width: 100,
6970
height: 100,

com.unity.uiwidgets/Runtime/engine/UIWidgetsExternalTextureRegistry.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
using System;
22
using System.Collections.Generic;
33
using Unity.UIWidgets.foundation;
4+
using UnityEngine;
45

56
namespace Unity.UIWidgets.engine {
7+
public static class UIWidgetsExternalTextureHelper {
8+
public static RenderTexture createCompatibleExternalTexture(RenderTextureDescriptor descriptor) {
9+
#if UNITY_2020_3_OR_NEWER && !UNITY_2020_3_1 && !UNITY_2020_3_2 && !UNITY_2020_3_3 && !UNITY_2020_3_4&& !UNITY_2020_3_5 && !UNITY_2020_3_6 && !UNITY_2020_3_7 && !UNITY_2020_3_8 && !UNITY_2020_3_9 && !UNITY_2020_3_10&& !UNITY_2020_3_11&& !UNITY_2020_3_12 && !UNITY_2020_3_13 && !UNITY_2020_3_14 && !UNITY_2020_3_15 && !UNITY_2020_3_16 && !UNITY_2020_3_17 && !UNITY_2020_3_18 && !UNITY_2020_3_19 && !UNITY_2020_3_20 && !UNITY_2020_3_21 && !UNITY_2020_3_22 && !UNITY_2020_3_23 && !UNITY_2020_3_24 && !UNITY_2020_3_25 && !UNITY_2020_3_26 && !UNITY_2020_3_27 && !UNITY_2020_3_28 && !UNITY_2020_3_29 && !UNITY_2020_3_30 && !UNITY_2020_3_31 && !UNITY_2020_3_32 && !UNITY_2020_3_33 && !UNITY_2020_3_34 && !UNITY_2020_3_35 && !UNITY_2020_3_36
10+
//this API is only available for 2020.3.37 and later Unity
11+
return UIWidgetsInternal.CreateBindableRenderTexture(descriptor);
12+
#else
13+
return new RenderTexture(descriptor);
14+
#endif
15+
}
16+
}
17+
618
public partial class UIWidgetsPanelWrapper {
719
readonly Dictionary<IntPtr, int> externalTextures = new Dictionary<IntPtr, int>();
820

0 commit comments

Comments
 (0)