Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 321eba7

Browse files
committed
Merge branch 'master' into hook1.5.4
2 parents 21601cb + cd9e1d2 commit 321eba7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3692
-1608
lines changed

Runtime/Plugins/platform/android/editing/TextInputPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public TextInputPlugin() {
4343
ViewGroup contentView = (ViewGroup)UnityPlayer.currentActivity.findViewById(android.R.id.content);
4444
mView = new TextInputView(UnityPlayer.currentActivity);
4545
mView.requestFocus();
46-
contentView.addView(mView, 0, 0);
46+
contentView.addView(mView, 1, 1);
4747
mImm = (InputMethodManager) mView.getContext().getSystemService(
4848
Context.INPUT_METHOD_SERVICE);
4949
}

Runtime/Plugins/platform/android/view/UIWidgetsViewController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,29 @@ public static UIWidgetsViewController getInstance() {
3434
private UIWidgetsViewMetrics viewMetrics;
3535
private boolean keyboardOpen;
3636

37+
private float statusHeight;
38+
private float navigationBarHeight;
39+
3740
private void setup() {
3841
//Log.i("tag", "On Setup 2");
3942

4043
keyboardOpen = false;
4144
viewMetrics = new UIWidgetsViewMetrics();
42-
45+
setupHeights();
4346
updateViewMetrics();
4447

4548
setupViewMetricsChangedListener();
4649
}
4750

51+
private void setupHeights() {
52+
final View unityView = ((ViewGroup)UnityPlayer.currentActivity.findViewById(android.R.id.content)).getChildAt(0);
53+
Rect rect = new Rect();
54+
unityView.getWindowVisibleDisplayFrame(rect);
55+
56+
statusHeight = rect.top;
57+
navigationBarHeight = unityView.getRootView().getHeight() - rect.bottom;
58+
}
59+
4860
public static UIWidgetsViewMetrics getMetrics() {
4961
UIWidgetsViewController controller = getInstance();
5062
return controller.viewMetrics;
@@ -143,6 +155,10 @@ public void updateViewMetrics() {
143155
viewMetrics.insets_bottom = navigationBarHidden? calculateBottomKeyboardInset(rect) : rect.bottom;
144156
viewMetrics.insets_left = 0;
145157

158+
//adjust
159+
viewMetrics.insets_bottom -= navigationBarHeight;
160+
viewMetrics.padding_top -= statusHeight;
161+
146162
//Log.i("UIWidgetsDebug", "checks: " + navigationBarHidden + " " + rect.bottom);
147163
//Log.i("UIWidgetsDebug", " padding: " + viewMetrics.padding_top + " " + viewMetrics.padding_right + " " + viewMetrics.padding_bottom + " " + viewMetrics.padding_left);
148164
//Log.i("UIWidgetsDebug", " insets: " + viewMetrics.insets_top + " " + viewMetrics.insets_right + " " + viewMetrics.insets_bottom + " " + viewMetrics.insets_left);

Runtime/Resources/UIWidgets_canvas.cginc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ float _mat[9];
33

44
half4 _color;
55
fixed _alpha;
6+
fixed _strokeMult;
67
half4x4 _shaderMat;
78
sampler2D _shaderTex;
89
half4 _leftColor;
@@ -178,3 +179,11 @@ fixed4 frag_mf (v2f i) : SV_Target {
178179

179180
return color;
180181
}
182+
183+
float strokeMask(float u, float v) {
184+
return min(1.0, (1.0 - abs(u * 2.0 - 1.0)) * 1.0) * min(1.0, v);
185+
}
186+
187+
fixed4 frag_stroke_alpha(v2f i) : SV_Target {
188+
return prealpha(shader_color(i)) * strokeMask(i.ftcoord.x, i.ftcoord.y);
189+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Shader "UIWidgets/ShadowBox"
2+
{
3+
//originally from http://madebyevan.com/shaders/fast-rounded-rectangle-shadows/
4+
Properties
5+
{
6+
_SrcBlend("_SrcBlend", Int) = 1 // One
7+
_DstBlend("_DstBlend", Int) = 10 // OneMinusSrcAlpha
8+
_StencilComp("_StencilComp", Float) = 8 // - Equal, 8 - Always
9+
}
10+
SubShader
11+
{
12+
ZTest Always
13+
ZWrite Off
14+
Blend [_SrcBlend] [_DstBlend]
15+
16+
Stencil {
17+
Ref 128
18+
Comp [_StencilComp]
19+
}
20+
21+
Pass {
22+
CGPROGRAM
23+
24+
float4 _sb_box;
25+
float4 _viewport;
26+
float _sb_sigma;
27+
float4 _sb_color;
28+
float _mat[9];
29+
30+
struct appdata
31+
{
32+
float4 vertex : POSITION;
33+
};
34+
35+
struct v2f
36+
{
37+
float4 vertex : SV_POSITION;
38+
float2 coord : TEXCOORD0;
39+
};
40+
41+
float4 erf(float4 x)
42+
{
43+
float4 s = sign(x);
44+
float4 a = abs(x);
45+
x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a;
46+
x = x * x;
47+
return s - s / (x * x);
48+
return s;
49+
}
50+
51+
float boxShadow(float2 lower, float2 upper, float2 pnt, float sigma)
52+
{
53+
float4 query = float4(pnt - lower, pnt - upper);
54+
float4 integral = 0.5 + 0.5 * erf(query * (sqrt(0.5) / sigma));
55+
return (integral.z - integral.x) * (integral.w - integral.y);
56+
}
57+
58+
v2f vert(appdata v){
59+
v2f o;
60+
float padding = 3.0 * _sb_sigma;
61+
o.coord = lerp(_sb_box.xy - padding, _sb_box.zw + padding, v.vertex.xy);
62+
float3x3 mat = float3x3(_mat[0], _mat[1], _mat[2], _mat[3], _mat[4], _mat[5], 0, 0, 1);
63+
float2 p = mul(mat, float3(o.coord.xy, 1.0)).xy - _viewport.xy;
64+
65+
#if UNITY_UV_STARTS_AT_TOP
66+
o.vertex = float4(2.0 * p.x / _viewport.z - 1.0, 2.0 * p.y / _viewport.w - 1.0, 0, 1);
67+
#else
68+
o.vertex = float4(2.0 * p.x / _viewport.z - 1.0, 1.0 - 2.0 * p.y / _viewport.w, 0, 1);
69+
#endif
70+
return o;
71+
}
72+
73+
float4 frag(v2f i) : SV_TARGET {
74+
float4 fragColor = _sb_color;
75+
fragColor.a = fragColor.a * boxShadow(_sb_box.xy, _sb_box.zw, i.coord, _sb_sigma);
76+
return fragColor;
77+
}
78+
79+
#pragma vertex vert
80+
#pragma fragment frag
81+
82+
ENDCG
83+
}
84+
}
85+
}

Runtime/Resources/UIWidgets_canvas_shadowBox.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Shader "UIWidgets/ShadowRBox"
2+
{
3+
//originally from http://madebyevan.com/shaders/fast-rounded-rectangle-shadows/
4+
Properties
5+
{
6+
_SrcBlend("_SrcBlend", Int) = 1 // One
7+
_DstBlend("_DstBlend", Int) = 10 // OneMinusSrcAlpha
8+
_StencilComp("_StencilComp", Float) = 8 // - Equal, 8 - Always
9+
}
10+
SubShader
11+
{
12+
ZTest Always
13+
ZWrite Off
14+
Blend [_SrcBlend] [_DstBlend]
15+
16+
Stencil {
17+
Ref 128
18+
Comp [_StencilComp]
19+
}
20+
21+
Pass {
22+
CGPROGRAM
23+
24+
float4 _sb_box;
25+
float4 _viewport;
26+
float _sb_sigma;
27+
float4 _sb_color;
28+
float _sb_corner;
29+
float _mat[9];
30+
31+
struct appdata
32+
{
33+
float4 vertex : POSITION;
34+
};
35+
36+
struct v2f
37+
{
38+
float4 vertex : SV_POSITION;
39+
float2 coord : TEXCOORD0;
40+
};
41+
42+
float gaussian(float x, float sigma)
43+
{
44+
float pi = 3.141592653589793;
45+
return exp(-(x*x) / (2.0 * sigma * sigma)) / (sqrt(2.0 * pi) * sigma);
46+
}
47+
48+
float2 erf(float2 x)
49+
{
50+
float2 s = sign(x);
51+
float2 a = abs(x);
52+
x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a;
53+
x = x * x;
54+
return s - s / (x * x);
55+
return s;
56+
}
57+
58+
float roundedBoxShadowX(float x, float y, float sigma, float corner, float2 halfSize)
59+
{
60+
float delta = min(halfSize.y - corner - abs(y), 0.0);
61+
float curved = halfSize.x - corner + sqrt(max(0.0, corner * corner - delta * delta));
62+
float2 integral = 0.5 + 0.5 * erf((x + float2(-curved, curved)) * (sqrt(0.5)/sigma));
63+
return integral.y - integral.x;
64+
}
65+
66+
float roundedBoxShadow(float2 lower, float2 upper, float2 pnt, float sigma, float corner)
67+
{
68+
float2 center = (lower + upper) * 0.5;
69+
float2 halfSize = (upper - lower) * 0.5;
70+
pnt -= center;
71+
72+
float low = pnt.y - halfSize.y;
73+
float high = pnt.y + halfSize.y;
74+
float start = clamp(-3.0 * sigma, low, high);
75+
float end = clamp(3.0 * sigma, low, high);
76+
77+
float step = (end - start) / 4.0;
78+
float y = start + step * 0.5;
79+
float value = 0.0;
80+
81+
for(int i=0; i<4;i++)
82+
{
83+
value += roundedBoxShadowX(pnt.x, pnt.y - y, sigma, corner, halfSize) * gaussian(y, sigma) * step;
84+
y += step;
85+
}
86+
87+
return value;
88+
}
89+
90+
v2f vert(appdata v){
91+
v2f o;
92+
float padding = 3.0 * _sb_sigma;
93+
o.coord = lerp(_sb_box.xy - padding, _sb_box.zw + padding, v.vertex.xy);
94+
float3x3 mat = float3x3(_mat[0], _mat[1], _mat[2], _mat[3], _mat[4], _mat[5], 0, 0, 1);
95+
float2 p = mul(mat, float3(o.coord.xy, 1.0)).xy - _viewport.xy;
96+
97+
#if UNITY_UV_STARTS_AT_TOP
98+
o.vertex = float4(2.0 * p.x / _viewport.z - 1.0, 2.0 * p.y / _viewport.w - 1.0, 0, 1);
99+
#else
100+
o.vertex = float4(2.0 * p.x / _viewport.z - 1.0, 1.0 - 2.0 * p.y / _viewport.w, 0, 1);
101+
#endif
102+
return o;
103+
}
104+
105+
float4 frag(v2f i) : SV_TARGET {
106+
float4 fragColor = _sb_color;
107+
fragColor.a = fragColor.a * roundedBoxShadow(_sb_box.xy, _sb_box.zw, i.coord, _sb_sigma, _sb_corner);
108+
return fragColor;
109+
}
110+
111+
#pragma vertex vert
112+
#pragma fragment frag
113+
114+
ENDCG
115+
}
116+
}
117+
}

Runtime/Resources/UIWidgets_canvas_shadowRBox.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Shader "UIWidgets/canvas_strokeAlpha"
2+
{
3+
Properties {
4+
_SrcBlend("_SrcBlend", Int) = 1 // One
5+
_DstBlend("_DstBlend", Int) = 10 // OneMinusSrcAlpha
6+
_StencilComp("_StencilComp", Float) = 3 // - Equal, 8 - Always
7+
}
8+
9+
SubShader {
10+
ZTest Always
11+
ZWrite Off
12+
Blend [_SrcBlend] [_DstBlend]
13+
14+
Stencil {
15+
Ref 128
16+
Comp [_StencilComp]
17+
Pass IncrSat
18+
}
19+
20+
Pass { // 0, color
21+
CGPROGRAM
22+
#define UIWIDGETS_COLOR
23+
#include "UIWidgets_canvas.cginc"
24+
#pragma vertex vert
25+
#pragma fragment frag_stroke_alpha
26+
ENDCG
27+
}
28+
29+
Pass { // 1, linear
30+
CGPROGRAM
31+
#define UIWIDGETS_LINEAR
32+
#include "UIWidgets_canvas.cginc"
33+
#pragma vertex vert
34+
#pragma fragment frag_stroke_alpha
35+
ENDCG
36+
}
37+
38+
Pass { // 2, radial
39+
CGPROGRAM
40+
#define UIWIDGETS_RADIAL
41+
#include "UIWidgets_canvas.cginc"
42+
#pragma vertex vert
43+
#pragma fragment frag_stroke_alpha
44+
ENDCG
45+
}
46+
47+
Pass { // 3, sweep
48+
CGPROGRAM
49+
#define UIWIDGETS_SWEEP
50+
#include "UIWidgets_canvas.cginc"
51+
#pragma vertex vert
52+
#pragma fragment frag_stroke_alpha
53+
ENDCG
54+
}
55+
56+
Pass { // 4, image
57+
CGPROGRAM
58+
#define UIWIDGETS_IMAGE
59+
#include "UIWidgets_canvas.cginc"
60+
#pragma vertex vert
61+
#pragma fragment frag_stroke_alpha
62+
ENDCG
63+
}
64+
}
65+
}

Runtime/Resources/UIWidgets_canvas_strokeAlpha.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)