-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBrowserWindowSample.cs
More file actions
75 lines (68 loc) · 2.76 KB
/
BrowserWindowSample.cs
File metadata and controls
75 lines (68 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using NT.Android;
using UnityEngine;
using UnityEngine.UI;
namespace NT.Samples {
public class BrowserWindowSample : MonoBehaviour {
public InputField URLField;
public Button OpenButton;
public Button AdvancedSettingsOpener;
public Button OpenColoredButton;
public Button OpenSlideButton;
void Start() {
// Add some listeners
URLField.onValueChanged.AddListener(InputValueChanged);
OpenButton.onClick.AddListener(Open);
OpenColoredButton.onClick.AddListener(OpenColored);
OpenSlideButton.onClick.AddListener(OpenSlide);
}
// This is the main function that calls BrowserWindow.
void Open() {
// Get the text
string url = URLField.text;
// If there is no "http" in the start, add it
if (!url.StartsWith("http")) url = "http://" + url;
// Open browser window
BrowserWindow.Open(url);
}
// This is a simple function that disables the input field
// if there is no URL.
void InputValueChanged(string text) {
OpenButton.interactable = text.Length > 0;
}
#region Advanced settings
// This is a function that calls BrowserWindow with a config.
void OpenColored() {
// Get the text
string url = URLField.text;
// If there is no "http" in the start, add it
if (!url.StartsWith("http")) url = "http://" + url;
// Create a config
BWAndroidConfig androidConfig = new BWAndroidConfig();
androidConfig.SetColor(Color.blue);
// Create a BrowserWindow instance
BrowserWindow window = new BrowserWindow();
window.SetAndroidConfig(androidConfig);
// Open browser window
window.CustomOpen(url);
}
// This is a function that calls BrowserWindow with a config
// telling it that the window has to slide in from the left.
void OpenSlide() {
// Get the text
string url = URLField.text;
// If there is no "http" in the start, add it
if (!url.StartsWith("http")) url = "http://" + url;
// Create a config
BWAndroidConfig androidConfig = new BWAndroidConfig();
// Set the animations
androidConfig.SetStartAnimations(BWAndroidAnimations.SlideLeft);
androidConfig.SetExitAnimations(BWAndroidAnimations.SlideLeft);
// Create a BrowserWindow instance
BrowserWindow window = new BrowserWindow();
window.SetAndroidConfig(androidConfig);
// Open browser window
window.CustomOpen(url);
}
#endregion
}
}