-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExample_CustomHTML.cs
More file actions
62 lines (48 loc) · 1.74 KB
/
Example_CustomHTML.cs
File metadata and controls
62 lines (48 loc) · 1.74 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
using UnityEngine;
using System.Collections;
using AwesomiumMono;
public class Example_CustomHTML : WebTexture
{
new void Start()
{
base.initialURL = "about:blank";
base.Start();
CreateJSObject("App");
SetJSObjectProperty("App", "unityVersion", new JSValue(Application.unityVersion));
SetJSObjectProperty("App", "unityPlatform", new JSValue(Application.platform.ToString()));
SetJSObjectProperty("App", "insideEditor", new JSValue(Application.isEditor));
BindJSObjectCallback("App", "quit", OnQuitPressed);
LoadHTML(@"
<html>
<body style='font-family: Helvetica, Arial, sans-serif;'>
<h1>Awesomium Rocks!</h1>
<p>This web-page was loaded with HTML directly from within Unity3D.</p>
<h2>Environment Info</h2>
<dl>
<dt>Unity Version</dt><dd id='stat1'></dd>
<dt>Unity Platform</dt><dd id='stat2'></dd>
<dt>Inside Editor?</dt><dd id='stat3'></dd>
</dl>
<script type='text/javascript'>
document.getElementById('stat1').innerText = App.unityVersion;
document.getElementById('stat2').innerText = App.unityPlatform;
document.getElementById('stat3').innerText = App.insideEditor;
</script>
<p>The above info was passed to the web-page via a shared JS object.</p>
<h2>Callback Example</h2>
<input type='button' value='Quit App' onclick='App.quit()' />
<p>The above button is hooked up to a Unity script via a shared JS callback.</p>
</body>
</html>
");
}
public void OnQuitPressed(object sender, JSCallbackEventArgs e)
{
#if UNITY_EDITOR
UnityEditor.EditorUtility.DisplayDialog("Quit Requested",
"If you ran this in an actual player, it would quit. :-)", "Ok");
#else
Application.Quit();
#endif
}
}