summaryrefslogtreecommitdiff
path: root/Runtime/Export/UserAuthorizationDialog.cs
blob: c2cb0116f5427a8e79746ea96f242ad4cee98eb7 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using UnityEngine;
namespace UnityEngine 
{

[AddComponentMenu("")]
class UserAuthorizationDialog : MonoBehaviour
{
#if !UNITY_FLASH && !UNITY_WEBGL && !UNITY_WINRT
	private Rect windowRect;
	private const int width = 385;
	private const int height = 155;
	
	private Texture warningIcon;
#endif
		
	private void Start ()
	{
#if !UNITY_FLASH && !UNITY_WEBGL && !UNITY_WINRT
		warningIcon = Resources.GetBuiltinResource(typeof (Texture2D), "WarningSign.psd") as Texture2D;
		if (Screen.width < width || Screen.height < height)
		{
			Debug.LogError ("Screen is to small to display authorization dialog. Authorization denied.");
			Application.ReplyToUserAuthorizationRequest (false);
		}
		
		windowRect = new Rect (Screen.width / 2 - width/2, Screen.height / 2 - height/2, width, height);
#endif
	}
		
	private void OnGUI () {
#if !UNITY_FLASH && !UNITY_WEBGL && !UNITY_WINRT
		GUISkin oldSkin = GUI.skin;
		
		// Create a custom GUISkin from scratch so users cannot change 
		// the look of the security dialog by changing the default GUI skins.
		GUISkin skin = ScriptableObject.CreateInstance ("GUISkin") as GUISkin;
		
		skin.box.normal.background = (Texture2D)Resources.GetBuiltinResource(typeof(Texture2D), "GameSkin/box.png");
		skin.box.normal.textColor = new Color (0.9f, 0.9f, 0.9f, 1.0f);
		skin.box.padding.left = 6;
		skin.box.padding.right = 6;
		skin.box.padding.top = 4;
		skin.box.padding.bottom = 4;
		skin.box.border.left = 6;
		skin.box.border.right = 6;
		skin.box.border.top = 6;
		skin.box.border.bottom = 6;
		skin.box.margin.left = 4;
		skin.box.margin.right = 4;
		skin.box.margin.top = 4;
		skin.box.margin.bottom = 4;
		
		skin.button.normal.background = (Texture2D)Resources.GetBuiltinResource(typeof(Texture2D), "GameSkin/button.png");
		skin.button.normal.textColor = new Color (0.9f, 0.9f, 0.9f, 1.0f);
		skin.button.hover.background = (Texture2D)Resources.GetBuiltinResource(typeof(Texture2D), "GameSkin/button hover.png");
		skin.button.hover.textColor = Color.white;
		skin.button.active.background = (Texture2D)Resources.GetBuiltinResource(typeof(Texture2D), "GameSkin/button active.png");
		skin.button.active.textColor = new Color (0.9f, 0.9f, 0.9f, 1.0f);
		skin.button.border.left = 6;
		skin.button.border.right = 6;
		skin.button.border.top = 6;
		skin.button.border.bottom = 6;
		skin.button.padding.left = 8;
		skin.button.padding.right = 8;
		skin.button.padding.top = 4;
		skin.button.padding.bottom = 4;
		skin.button.margin.left = 4;
		skin.button.margin.right = 4;
		skin.button.margin.top = 4;
		skin.button.margin.bottom = 4;
		
		skin.label.normal.textColor = new Color (0.9f, 0.9f, 0.9f, 1.0f);
		skin.label.padding.left = 6;
		skin.label.padding.right = 6;
		skin.label.padding.top = 4;
		skin.label.padding.bottom = 4;
		skin.label.margin.left = 4;
		skin.label.margin.right = 4;
		skin.label.margin.top = 4;
		skin.label.margin.bottom = 4;
		skin.label.alignment = TextAnchor.UpperLeft;

		skin.window.normal.background = (Texture2D)Resources.GetBuiltinResource(typeof(Texture2D), "GameSkin/window.png");
		skin.window.normal.textColor = Color.white;
		skin.window.border.left = 8;
		skin.window.border.right = 8;
		skin.window.border.top = 18;
		skin.window.border.bottom = 8;
		skin.window.padding.left = 8;
		skin.window.padding.right = 8;
		skin.window.padding.top = 20;
		skin.window.padding.bottom = 5;
		skin.window.alignment = TextAnchor.UpperCenter;
		skin.window.contentOffset = new Vector2 (0, -18);

		GUI.skin = skin;
	    windowRect = GUI.Window (0, windowRect, DoUserAuthorizationDialog, "Unity Web Player Authorization Request");
		GUI.skin = oldSkin;
#endif
	}
	
	// Make the contents of the window
	private void DoUserAuthorizationDialog (int windowID) {
#if !UNITY_FLASH && !UNITY_WEBGL && !UNITY_WINRT
		UserAuthorization auth = Application.GetUserAuthorizationRequestMode();

		GUILayout.FlexibleSpace ();
		
		GUI.backgroundColor = new Color (0.9f, 0.9f, 0.9f, 0.7f);
		GUILayout.BeginHorizontal ("box");
		GUILayout.FlexibleSpace ();
		
		GUILayout.BeginVertical();
		GUILayout.FlexibleSpace ();
		
		GUILayout.Label(warningIcon);
		
		GUILayout.FlexibleSpace ();
		GUILayout.EndVertical();
			
		GUILayout.FlexibleSpace ();
		
		GUILayout.BeginVertical();
		GUILayout.FlexibleSpace ();
		
		if (auth == (UserAuthorization.WebCam | UserAuthorization.Microphone))
			GUILayout.Label ("The content on this site would like to use your\ncomputer's web camera and microphone.\nThese images and sounds may be recorded.");
		else
		if (auth == UserAuthorization.WebCam)
			GUILayout.Label ("The content on this site would like to use\nyour computer's web camera. The images\nfrom your web camera may be recorded.");
		else
		if (auth == UserAuthorization.Microphone)
			GUILayout.Label ("The content on this site would like to use\nyour computer's microphone. The sounds\nfrom your microphone may be recorded.");
		else
			return;	
		
		GUILayout.FlexibleSpace ();
		GUILayout.EndVertical();
		
		GUILayout.FlexibleSpace ();
		GUILayout.EndHorizontal ();	
		
		GUILayout.FlexibleSpace ();
		
		GUI.backgroundColor = Color.white;
		GUILayout.BeginHorizontal ();
		
		if (GUILayout.Button ("Deny"))
			Application.ReplyToUserAuthorizationRequest (false);
			
		GUILayout.FlexibleSpace ();
		
		if (GUILayout.Button ("Always Allow for this Site"))
			Application.ReplyToUserAuthorizationRequest (true, true);
		
		GUILayout.Space (5);
		
		if (GUILayout.Button ("Allow"))
			Application.ReplyToUserAuthorizationRequest (true);
		
		GUILayout.EndHorizontal ();
		GUILayout.FlexibleSpace ();
#endif
	}
}
}