Browse files

uninformative commit message

  • Loading branch information...
1 parent e67fa82 commit db2c3f2450ac4b262dbfe6505027a716001d31ab @v21 committed Sep 14, 2011
View
149 Assets/KeyboardHook.cs
@@ -0,0 +1,149 @@
+using System;
+using System.Windows.Forms;
+using System.Runtime.InteropServices;
+using UnityEngine;
+
+public sealed class KeyboardHook : IDisposable
+{
+ // Registers a hot key with Windows.
+ [DllImport("user32.dll", SetLastError = true)]
+ private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
+ // Unregisters the hot key with Windows.
+ [DllImport("user32.dll", SetLastError = true)]
+ private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
+ /// <summary>
+ /// Represents the window that is used internally to get the messages.
+ /// </summary>
+ private class Window : NativeWindow, IDisposable
+ {
+ private static int WM_HOTKEY = 0x0312;
+
+ public Window()
+ {
+ // create the handle for the window.
+ this.CreateHandle(new CreateParams());
+ }
+
+ /// <summary>
+ /// Overridden to get the notifications.
+ /// </summary>
+ /// <param name="m"></param>
+ protected override void WndProc(ref Message m)
+ {
+ base.WndProc(ref m);
+
+ // check if we got a hot key pressed.
+ if (m.Msg == WM_HOTKEY)
+ {
+ // get the keys.
+ Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
+ ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF);
+
+ // invoke the event to notify the parent.
+ if (KeyPressed != null)
+ KeyPressed(this, new KeyPressedEventArgs(modifier, key));
+ }
+ }
+
+ public event EventHandler<KeyPressedEventArgs> KeyPressed;
+
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ this.DestroyHandle();
+ }
+
+ #endregion
+ }
+
+ private Window _window = new Window();
+ private int _currentId;
+
+ public KeyboardHook()
+ {
+ // register the event of the inner native window.
+ _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args)
+ {
+ if (KeyPressed != null)
+ KeyPressed(this, args);
+ };
+ }
+
+ /// <summary>
+ /// Registers a hot key in the system.
+ /// </summary>
+ /// <param name="modifier">The modifiers that are associated with the hot key.</param>
+ /// <param name="key">The key itself that is associated with the hot key.</param>
+ public void RegisterHotKey(ModifierKeys modifier, Keys key)
+ {
+ // increment the counter.
+ _currentId = _currentId + 1;
+
+ Debug.Log(_window.Handle);
+ // register the hot key.
+ if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key)){
+ //throw new InvalidOperationException("Couldn’t register the hot key.");
+ //Debug.Log(Marshal.GetLastWin32Error());
+ }
+ }
+
+ /// <summary>
+ /// A hot key has been pressed.
+ /// </summary>
+ public event EventHandler<KeyPressedEventArgs> KeyPressed;
+
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ // unregister all the registered hot keys.
+ for (int i = _currentId; i > 0; i--)
+ {
+ UnregisterHotKey(_window.Handle, i);
+ }
+
+ // dispose the inner native window.
+ _window.Dispose();
+ }
+
+ #endregion
+}
+
+/// <summary>
+/// Event Args for the event that is fired after the hot key has been pressed.
+/// </summary>
+public class KeyPressedEventArgs : EventArgs
+{
+ private ModifierKeys _modifier;
+ private Keys _key;
+
+ internal KeyPressedEventArgs(ModifierKeys modifier, Keys key)
+ {
+ _modifier = modifier;
+ _key = key;
+ }
+
+ public ModifierKeys Modifier
+ {
+ get { return _modifier; }
+ }
+
+ public Keys Key
+ {
+ get { return _key; }
+ }
+}
+
+/// <summary>
+/// The enumeration of possible modifiers.
+/// </summary>
+[Flags]
+public enum ModifierKeys : uint
+{
+ None = 0,
+ Alt = 1,
+ Control = 2,
+ Shift = 4,
+ Win = 8
+}
View
2 Assets/KeyboardHook.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 1
+guid: 551075a86642d2542b3a6bf28d4a7d59
View
111 Assets/Launcher.cs
@@ -5,13 +5,17 @@
using System.IO;
using System;
using LitJson;
+using System.Windows.Forms;
+
+
public class Launcher : MonoBehaviour {
public bool currentlyVideo;
public Process launched = null;
+ KeyboardHook hook;
public class Game{
public string author;
@@ -22,37 +26,45 @@ public class Game{
public MovieTexture splashVideo = null;
public bool splashIsVideo = false;
- public Process process = new Process();
+ public Process process = null;
public IEnumerator LoadTexture(){
+ splashScreenPath = "file://" + splashScreenPath;
+
if (splashIsVideo){
WWW www = new WWW(splashScreenPath);
yield return www;
- splashVideo = www.movie;
+ if (www.error == null){
+ splashVideo = www.movie;
+ }
}
else {
WWW www = new WWW(splashScreenPath);
yield return www;
- splashScreen = www.texture;
+ if (www.error == null){
+ splashScreen = www.texture;
+ }
}
+
}
public void LaunchGame () {
UnityEngine.Debug.Log("game launching");
+ process = new Process();
process.StartInfo.FileName = filePath;
process.Start();
//how do Events work in c#? - trigger on process.Exited , assuming Unity is happy to run in the backround.
- Screen.fullScreen = false;
+ UnityEngine.Screen.fullScreen = false;
}
public void OnGameExited(){
UnityEngine.Debug.Log("game exited");
- Screen.fullScreen = true;
+ UnityEngine.Screen.fullScreen = true;
}
}
@@ -70,11 +82,25 @@ public class ConfigFile {
public int currentGameI = 0;
+ public Texture2D errorTex;
+ public GUIText errorGUIText;
+
+ public Texture2D imgMissing;
+
+ public bool firstImageLoaded = false;
+
public string localJsonPath;
// Use this for initialization
void Start () {
-
- configFile = ReadJson(localJsonPath);
+ UnityEngine.Screen.showCursor = false;
+ try{
+ configFile = ReadJson(localJsonPath);
+ } catch (Exception e){
+
+
+ guiTexture.texture = errorTex;
+ errorGUIText.text = e.Message;
+ }
foreach (Game game in configFile.games) {
@@ -83,22 +109,27 @@ public class ConfigFile {
currentGameI = 0;
+ hook = new KeyboardHook();
+ // register the event that is fired after the key press.
+ hook.KeyPressed +=
+ new EventHandler<KeyPressedEventArgs>(hook_KeyPressed);
+ // register the control + alt + F12 combination as hot key.
+ hook.RegisterHotKey(ModifierKeys.None,
+ Keys.F11);
//LaunchFile( "C:\\Windows\\system32\\calc.exe");
}
// Update is called once per frame
void Update () {
- try {
+ try {
if (configFile.games[currentGameI].process.HasExited){ //believe me, i know this isn't the way to do this - but i just want this to work and go to bed
configFile.games[currentGameI].OnGameExited();
}
- } catch (Exception) {
-
- }
-
+ } catch (Exception) {
+ }
- if (guiTexture.texture == null){ //to handle rendering once it's loaded
+ if (!firstImageLoaded && (configFile.games[currentGameI].splashScreen != null || configFile.games[currentGameI].splashVideo != null)){ //to handle rendering once it's loaded
ChangeTexture();
}
@@ -136,11 +167,19 @@ public class ConfigFile {
}
void ChangeTexture(){
+
+
+
Game game = configFile.games[currentGameI];
if (currentlyVideo){
- MovieTexture guiMovieTex = (MovieTexture)guiTexture.texture;
- guiMovieTex.Stop();
+ try {
+ MovieTexture guiMovieTex = (MovieTexture)guiTexture.texture;
+ guiMovieTex.Stop();
+ }
+ catch (Exception){
+
+ }
}
if (game.splashIsVideo){
@@ -151,19 +190,34 @@ public class ConfigFile {
guiTexture.texture = game.splashVideo;
MovieTexture guiMovieTex = (MovieTexture)guiTexture.texture;
guiMovieTex.Play();
+ errorGUIText.text = "";
+
guiMovieTex.loop = true;
+ firstImageLoaded = true;
+ }
+ else {
+ guiTexture.texture = imgMissing;
+ errorGUIText.text = game.name + "\n" + game.author;
+
}
}
else {
- if (game.splashScreen != null){
-
+ if (game.splashScreen != null){
+
currentlyVideo = false;
guiTexture.texture = game.splashScreen;
- }
+ errorGUIText.text = "";
+ firstImageLoaded = true;
+ }
+ else {
+ guiTexture.texture = imgMissing;
+ errorGUIText.text = game.name + "\n" + game.author;
+ }
}
+
}
@@ -175,7 +229,26 @@ public class ConfigFile {
}
-
+ void hook_KeyPressed(object sender, KeyPressedEventArgs e)
+ {
+ // show the keys pressed in a label.
+ print("hotkey pressed");
+ try {
+ if (configFile.games[currentGameI].process != null){
+ if (!configFile.games[currentGameI].process.CloseMainWindow()){
+ configFile.games[currentGameI].process.Kill();
+
+ }
+
+ configFile.games[currentGameI].process.Close();
+ configFile.games[currentGameI].OnGameExited();
+
+ }
+ } catch (Exception err) {
+
+ }
+
+ }
}
View
2 Assets/Plugins.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 1
+guid: 5dd2150deae459742b44ec49d2834994
View
BIN Assets/Plugins/System.Deployment.dll
Binary file not shown.
View
2 Assets/Plugins/System.Deployment.dll.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 1
+guid: e50737ed1d3df0444b92cb600d9a7dd6
View
BIN Assets/Plugins/System.Windows.Forms.dll
Binary file not shown.
View
2 Assets/Plugins/System.Windows.Forms.dll.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 1
+guid: a58298b4df88259468d5d35267f2d4be
View
BIN Assets/error.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
28 Assets/error.psd.meta
@@ -0,0 +1,28 @@
+fileFormatVersion: 1
+guid: daf988f667b15f8418cc451bc820eef0
+TextureImporter:
+ importerVersion: 2
+ maxTextureSize: 1024
+ textureFormat: -1
+ grayscaleToAlpha: 0
+ npotScale: 1
+ generateCubemap: 0
+ isReadable: 0
+ textureType: 5
+ mipmaps:
+ generation: 0
+ correctGamma: 0
+ border: 0
+ filter: 0
+ fadeout: 0
+ fadeoutStart: 1
+ fadeoutEnd: 3
+ bumpmap:
+ generation: 0
+ bumpyness: 0.25
+ filter: 0
+ textureSettings:
+ filterMode: 0
+ anisoLevel: 1
+ mipmapBias: -1
+ wrapMode: 1
View
BIN Assets/img_missing.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
28 Assets/img_missing.psd.meta
@@ -0,0 +1,28 @@
+fileFormatVersion: 1
+guid: 8f7dc628ff8e01e46ad351c532c80167
+TextureImporter:
+ importerVersion: 2
+ maxTextureSize: 1024
+ textureFormat: -1
+ grayscaleToAlpha: 0
+ npotScale: 1
+ generateCubemap: 0
+ isReadable: 0
+ textureType: 5
+ mipmaps:
+ generation: 0
+ correctGamma: 0
+ border: 0
+ filter: 0
+ fadeout: 0
+ fadeoutStart: 1
+ fadeoutEnd: 3
+ bumpmap:
+ generation: 0
+ bumpyness: 0.25
+ filter: 0
+ textureSettings:
+ filterMode: 0
+ anisoLevel: 1
+ mipmapBias: -1
+ wrapMode: 1
View
BIN Assets/loading.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
28 Assets/loading.psd.meta
@@ -0,0 +1,28 @@
+fileFormatVersion: 1
+guid: f1cbbaa3860a1414db872c9a5396e75d
+TextureImporter:
+ importerVersion: 2
+ maxTextureSize: 1024
+ textureFormat: -1
+ grayscaleToAlpha: 0
+ npotScale: 1
+ generateCubemap: 0
+ isReadable: 0
+ textureType: 5
+ mipmaps:
+ generation: 0
+ correctGamma: 0
+ border: 0
+ filter: 0
+ fadeout: 0
+ fadeoutStart: 1
+ fadeoutEnd: 3
+ bumpmap:
+ generation: 0
+ bumpyness: 0.25
+ filter: 0
+ textureSettings:
+ filterMode: 0
+ anisoLevel: 1
+ mipmapBias: -1
+ wrapMode: 0
View
37 Assets/local.json
@@ -3,23 +3,42 @@
[
{
- "name" : "my super awesome game",
+ "name" : "Brute and Flaps",
"author" : "me" ,
- "filePath" : "C:/Users/v21/Desktop/arcade games/Hot Cross Bunions (Arcade) v1/build_arcade_1/HOT CROSS BUNIONS.exe",
- "splashScreenPath" : "file://C:/Users/v21/Documents/My Dropbox/Launcher/Assets/vid1.ogg",
+ "filePath" : "bruteAndFlaps.exe",
+ "splashScreenPath" : "bruteandflaps.png",
"splashIsVideo" : true
},
{
- "name" : "game2",
+ "name" : "sky tank",
+ "author" : "v21" ,
+ "filePath" : "sky tank/SkyTank.exe",
+ "splashScreenPath" : "file://skytank.png"
+ },
+ {
+ "name" : "cubes",
+ "author" : "me" ,
+ "filePath" : "cubes_arcade.exe",
+ "splashScreenPath" : "file://cubes_arcade.png",
+ "splashIsVideo" : true
+ },
+ {
+ "name" : "it's my birthday",
+ "author" : "me" ,
+ "filePath" : "itsMyBirthdayICanDieIfIWantTo.exe",
+ "splashScreenPath" : "file://itsMyBirthdayICanDieIfIWantTo.png"
+ },
+ {
+ "name" : "sumo boss race",
"author" : "me" ,
- "filePath" : "C:/Users/v21/Desktop/arcade games/bruteAndFlaps.exe",
- "splashScreenPath" : "file://C:/Users/v21/Documents/My Dropbox/Launcher/Assets/tex2.png"
+ "filePath" : "SumoBOSSRace.exe",
+ "splashScreenPath" : "file://sumobossrace.png"
},
{
- "name" : "game3",
+ "name" : "big boss",
"author" : "me" ,
- "filePath" : "C:/Windows/system32/calc.exe",
- "splashScreenPath" : "file://C:/Users/v21/Documents/My Dropbox/Launcher/Assets/tex3.png"
+ "filePath" : "bigboss.exe",
+ "splashScreenPath" : "file://big boss.png"
}
]
}
View
BIN Assets/main.unity
Binary file not shown.
View
BIN Library/ProjectSettings.asset
Binary file not shown.
View
0 README
No changes.
View
13 local.json
@@ -2,6 +2,13 @@
{"games" :
[
+
+ {
+ "name" : "game2",
+ "author" : "me" ,
+ "filePath" : "C:/Users/Public/arcade games/SumoBOSSRace.exe",
+ "splashScreenPath" : "file://C:/Users/v21/Documents/My Dropbox/Launcher/Assets/tex2.png"
+ },
{
"name" : "my super awesome game",
"author" : "me" ,
@@ -10,12 +17,6 @@
"splashIsVideo" : true
},
{
- "name" : "game2",
- "author" : "me" ,
- "filePath" : "C:/Users/v21/Desktop/arcade games/bruteAndFlaps.exe",
- "splashScreenPath" : "file://C:/Users/v21/Documents/My Dropbox/Launcher/Assets/tex2.png"
- },
- {
"name" : "game3",
"author" : "me" ,
"filePath" : "C:/Windows/system32/calc.exe",

0 comments on commit db2c3f2

Please sign in to comment.