// Use this for initialization void Start() { // Try Find our Moga Manager Game Object mogaManagerObject = GameObject.Find("MogaControllerManager"); // If it exists.. if (mogaManagerObject != null) { // Check the Moga Manager Script is correctly attached to the Moga Manager Game Object mogaManagerScript = mogaManagerObject.GetComponent <Moga_ControllerManager>(); // If it is attached... if (mogaManagerScript != null) { // Register MOGA Controller Input.RegisterMogaController(); // Get our mapped KeyCode Values and assign them. aButtonKeyCode = mogaManagerScript.p1ButtonA; bButtonKeyCode = mogaManagerScript.p1ButtonB; xButtonKeyCode = mogaManagerScript.p1ButtonX; yButtonKeyCode = mogaManagerScript.p1ButtonY; mogaFound = true; } } }
void OnGUI() { if (btnTexture == null) { if (GUILayout.Button("\nMOGA\n")) { Application.OpenURL("http://www.mogaanywhere.com/"); } } else { if (GUILayout.Button(btnTexture, GUIStyle.none)) { Application.OpenURL("http://www.mogaanywhere.com/"); } } EditorGUILayout.HelpBox("Controller Mappings are automatically assigned by Default, you can re-assign the KeyCodes here if required.", MessageType.Info); if (GameObject.Find("MogaControllerManager") != null) { controllerManagerExists = true; mogaControllerManger = GameObject.Find("MogaControllerManager").GetComponent <Moga_ControllerManager>(); } if (controllerManagerExists) { GUILayout.Label("Controller Mappings", EditorStyles.boldLabel); mogaControllerManger.p1ButtonA = (KeyCode)EditorGUILayout.EnumPopup("Button A ", mogaControllerManger.p1ButtonA); mogaControllerManger.p1ButtonB = (KeyCode)EditorGUILayout.EnumPopup("Button B ", mogaControllerManger.p1ButtonB); mogaControllerManger.p1ButtonX = (KeyCode)EditorGUILayout.EnumPopup("Button X ", mogaControllerManger.p1ButtonX); mogaControllerManger.p1ButtonY = (KeyCode)EditorGUILayout.EnumPopup("Button Y ", mogaControllerManger.p1ButtonY); mogaControllerManger.p1ButtonL1 = (KeyCode)EditorGUILayout.EnumPopup("Button L1 ", mogaControllerManger.p1ButtonL1); mogaControllerManger.p1ButtonL2 = (KeyCode)EditorGUILayout.EnumPopup("Button L2 ", mogaControllerManger.p1ButtonL2); mogaControllerManger.p1ButtonL3 = (KeyCode)EditorGUILayout.EnumPopup("Button L3 ", mogaControllerManger.p1ButtonL3); mogaControllerManger.p1ButtonR1 = (KeyCode)EditorGUILayout.EnumPopup("Button R1 ", mogaControllerManger.p1ButtonR1); mogaControllerManger.p1ButtonR2 = (KeyCode)EditorGUILayout.EnumPopup("Button R2 ", mogaControllerManger.p1ButtonR2); mogaControllerManger.p1ButtonR3 = (KeyCode)EditorGUILayout.EnumPopup("Button R3 ", mogaControllerManger.p1ButtonR3); mogaControllerManger.p1ButtonStart = (KeyCode)EditorGUILayout.EnumPopup("Button Start ", mogaControllerManger.p1ButtonStart); mogaControllerManger.p1ButtonSelect = (KeyCode)EditorGUILayout.EnumPopup("Button Select ", mogaControllerManger.p1ButtonSelect); mogaControllerManger.p1ButtonDPadUp = (KeyCode)EditorGUILayout.EnumPopup("Button DPad Up ", mogaControllerManger.p1ButtonDPadUp); mogaControllerManger.p1ButtonDPadDown = (KeyCode)EditorGUILayout.EnumPopup("Button DPad Down ", mogaControllerManger.p1ButtonDPadDown); mogaControllerManger.p1ButtonDPadLeft = (KeyCode)EditorGUILayout.EnumPopup("Button DPad Left ", mogaControllerManger.p1ButtonDPadLeft); mogaControllerManger.p1ButtonDPadRight = (KeyCode)EditorGUILayout.EnumPopup("Button DPad Right ", mogaControllerManger.p1ButtonDPadRight); mogaControllerManger.p1AxisHorizontal = EditorGUILayout.TextField("Left Nub Horizontal: ", mogaControllerManger.p1AxisHorizontal); mogaControllerManger.p1AxisVertical = EditorGUILayout.TextField("Left Nub Vertical: ", mogaControllerManger.p1AxisVertical); mogaControllerManger.p1AxisLookHorizontal = EditorGUILayout.TextField("Right Nub Horizontal: ", mogaControllerManger.p1AxisLookHorizontal); mogaControllerManger.p1AxisLookVertical = EditorGUILayout.TextField("Right Nub Vertical: ", mogaControllerManger.p1AxisLookVertical); mogaControllerManger.p1AxisL2 = EditorGUILayout.TextField("Left Trigger: ", mogaControllerManger.p1AxisL2); mogaControllerManger.p1AxisR2 = EditorGUILayout.TextField("Right Trigger: ", mogaControllerManger.p1AxisR2); } else { EditorGUILayout.HelpBox("You need to create the Controller Manager first!", MessageType.Warning); } }
void Start() { #if UNITY_EDITOR debug = false; #else debug = false; #endif if (Grid.mogaManagerObject != null) { // Check the Moga Manager Script is correctly attached to the Moga Manager Game Object mogaManagerScript = Grid.mogaManagerObject.GetComponent <Moga_ControllerManager>(); if (mogaManagerScript != null) { Input.RegisterMogaController(); } } }
// ENDREGION public static void RegisterMogaController() { mogaManager = GameObject.Find("MogaControllerManager"); if (mogaManager != null) { mogaControllerManager = mogaManager.GetComponent <Moga_ControllerManager>(); } if (mogaControllerManager == null) { Debug.Log("MOGA Controller Manager could not be found. Access the MOGA Menu to create one!"); } else { MapController(); } }
void OnGUI() { if (btnTexture == null) { if (GUILayout.Button("\nMOGA\n")) { Application.OpenURL("http://www.mogaanywhere.com/"); } } else { if (GUILayout.Button(btnTexture, GUIStyle.none)) { Application.OpenURL("http://www.mogaanywhere.com/"); } } if (GameObject.Find("MogaControllerManager") != null) { controllerManagerExists = true; mogaControllerManger = GameObject.Find("MogaControllerManager").GetComponent <Moga_ControllerManager>(); } if (GameObject.Find("MogaControllerManager") != null) { GUILayout.BeginVertical("box"); GUILayout.Space(3); GUILayout.Label("Controller Manager", EditorStyles.boldLabel); GUILayout.Space(4); GUILayout.EndHorizontal(); if (GUILayout.Button("\nDelete Moga Controller Manager\n")) { DestroyImmediate(GameObject.Find("MogaControllerManager")); } } else { GUILayout.BeginVertical("box"); GUILayout.Space(3); GUILayout.Label("Controller Manager", EditorStyles.boldLabel); GUILayout.Space(4); GUILayout.EndHorizontal(); if (GUILayout.Button("\nCreate Moga Controller Manager\n")) { GameObject mogaControllerObject = new GameObject("MogaControllerManager"); mogaControllerObject.AddComponent <Moga_ControllerManager>(); } } GUILayout.Space(12); GUILayout.BeginVertical("box"); GUILayout.Space(3); GUILayout.Label("Input Scripts", EditorStyles.boldLabel); GUILayout.Space(4); GUILayout.EndHorizontal(); if (Selection.activeTransform != null) { inputScripts = Selection.activeTransform.gameObject.GetComponents <Moga_Input>(); GUILayout.Label("Add Input Script to " + Selection.activeTransform.gameObject.name + "?"); GUILayout.BeginHorizontal(); if (getInputScript() != null) { if (GUILayout.Button("\nRemove Moga_Input Script\n")) { DestroyImmediate(getInputScript()); } } else { if (GUILayout.Button("\nAttach Moga_Input Script\n")) { Selection.activeTransform.gameObject.AddComponent <Moga_Input>(); } } GUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("Select a GameObject to attach the Script to...", MessageType.Info); } #endif #if UNITY_WP8 if (GameObject.Find("MogaControllerManager") != null) { mogaControllerManger = GameObject.Find("MogaControllerManager").GetComponent <Moga_ControllerManager>(); // Additional Settings GUILayout.BeginVertical("box"); GUILayout.Space(3); GUILayout.BeginHorizontal(); GUILayout.Label("Additional Settings", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUILayout.Label("optional", EditorStyles.miniLabel); GUILayout.EndHorizontal(); GUILayout.Space(4); GUILayout.EndVertical(); if (!mogaControllerManger.wp8poll) { EditorGUILayout.HelpBox("Listening Mode Enabled", MessageType.Info); } else { EditorGUILayout.HelpBox("Polling Mode Enabled", MessageType.Info); } mogaControllerManger.wp8poll = EditorGUILayout.Toggle("Polling Mode", mogaControllerManger.wp8poll); if (!mogaControllerManger.armlib) { EditorGUILayout.HelpBox("Building for x86 - The x86 library should be used when targeting a 32-bit Windows Emulator", MessageType.Info); } else { EditorGUILayout.HelpBox("Building for ARM - The ARM library should be used when targeting a physical Windows Phone device.", MessageType.Info); } mogaControllerManger.armlib = EditorGUILayout.Toggle("Build Architecture", mogaControllerManger.armlib); } #endif #if UNITY_WP8 || UNITY_ANDROID }
public static void updateVisualStudioProject(string visualstudioPath, string applicationName) { // STEP 1 : We open up the file generated by Unity and read into memory as a list of lines for processing string project = visualstudioPath + "Properties/WMAppManifest.xml"; string[] lines = System.IO.File.ReadAllLines(project); // STEP 2 : We check if file has already been processed and only proceed if it hasn't, we'll do this by looping // through the build files and see if ID_CAP_IDENTITY_PROXIMITY int i = 0; bool bFound = false; bool bEnd = false; while (!bFound && !bEnd) { if (i == lines.Length - 1) { bEnd = true; } bFound = lines[i].Contains("ID_CAP_IDENTITY_PROXIMITY"); ++i; } if (bFound) { Debug.Log("MOGA WP8 -> ERROR: AppManifest has already been updated"); Debug.Log("MOGA WP8 - Finished OnPostProcessBuild"); } else { // --------------------------------------------------------------------------- // Update WMAppManifest.xaml.cs ---------------------------------------------- // --------------------------------------------------------------------------- FileStream filestr = new FileStream(project, FileMode.Create); //Create new file and open it for read and write, if the file exists overwrite it. filestr.Close(); StreamWriter fCurrentManifestFile = new StreamWriter(project); // will be used for writing int iNbBuildConfigSet = 0; // can't be > 2 i = 0; foreach (string line in lines) { fCurrentManifestFile.WriteLine(line); if (line.StartsWith(" <Capabilities>") && iNbBuildConfigSet < 1) { fCurrentManifestFile.Write("\t <Capability Name=\"ID_CAP_PROXIMITY\" />\n"); Debug.Log("MOGA WP8 -> Step 1: Added \"Proximity\" to WMAppManifest.xml"); ++iNbBuildConfigSet; } ++i; } fCurrentManifestFile.Close(); // --------------------------------------------------------------------------- // Update MainPage.xaml.cs --------------------------------------------------- // --------------------------------------------------------------------------- Array.Clear(lines, 0, lines.Length); project = visualstudioPath + "MainPage.xaml.cs"; lines = System.IO.File.ReadAllLines(project); FileStream filestrMainPage = new FileStream(project, FileMode.Create); filestrMainPage.Close(); StreamWriter fCurrentMainPageFile = new StreamWriter(project); iNbBuildConfigSet = 0; // can't be > 2 i = 0; bool nextLine = false; foreach (string line in lines) { fCurrentMainPageFile.WriteLine(line); // Add using Moga.Windows.Phone.Unity; if (line.StartsWith("using Microsoft.Phone.Controls;") && iNbBuildConfigSet < 2) { fCurrentMainPageFile.Write("using Moga.Windows.Phone.Unity;\n"); Debug.Log("MOGA WP8 -> Step 2: Added \"MOGA namespace\" to MainPage.xaml.cs"); ++iNbBuildConfigSet; } // Add Controller Connect on Unity Loaded if (line.StartsWith(" private void Unity_Loaded()") && iNbBuildConfigSet < 2 || nextLine) { if (nextLine) { nextLine = false; // Check to see if the MogaControllerManager exists if (GameObject.Find("MogaControllerManager") != null) { Moga_ControllerManager mogaControllerManger = GameObject.Find("MogaControllerManager").GetComponent <Moga_ControllerManager>(); if (mogaControllerManger.wp8poll) { fCurrentMainPageFile.Write("\t\t\tControllerUnity.Connect(ControllerMode.Poll);\n"); Debug.Log("MOGA WP8 -> Step 3: Added \"Connect in Polling Mode\" to MainPage.xaml.cs"); } else { fCurrentMainPageFile.Write("\t\t\tControllerUnity.Connect(ControllerMode.Listen);\n"); Debug.Log("MOGA WP8 -> Step 3: Added \"Connect in Listener Mode\" to MainPage.xaml.cs"); } ++iNbBuildConfigSet; } // Use Polling mode by default else { fCurrentMainPageFile.Write("\t\t\tControllerUnity.Connect(ControllerMode.Poll);\n"); ++iNbBuildConfigSet; Debug.Log("MOGA WP8 -> Step 3: Added \"Connect\" to MainPage.xaml.cs"); } } else { nextLine = true; } } ++i; } fCurrentMainPageFile.Close(); // --------------------------------------------------------------------------- // Update App.xaml.cs -------------------------------------------------------- // --------------------------------------------------------------------------- Array.Clear(lines, 0, lines.Length); project = visualstudioPath + "App.xaml.cs"; lines = System.IO.File.ReadAllLines(project); FileStream filestrApp = new FileStream(project, FileMode.Create); filestrApp.Close(); StreamWriter fCurrentAppFile = new StreamWriter(project); iNbBuildConfigSet = 0; i = 0; nextLine = false; bool alreadyRan = false; foreach (string line in lines) { if (line.StartsWith("using Moga.Windows.Phone.Unity;")) { alreadyRan = true; Debug.Log("MOGA WP8 -> Project already MOGA Enabled (Skip 5-8).\n"); } else { fCurrentAppFile.WriteLine(line); } // Add using Moga.Windows.Phone.Unity; if (line.StartsWith("using Microsoft.Phone.Shell;") && iNbBuildConfigSet < 4) { fCurrentAppFile.Write("using Moga.Windows.Phone.Unity;\n"); Debug.Log("MOGA WP8 -> Step 4: Added \"MOGA namespace\" to App.xaml.cs"); ++iNbBuildConfigSet; } // Add ControllerUnity.Activated() to Application_Activated() if (line.StartsWith(" private void Application_Activated") && !alreadyRan && iNbBuildConfigSet < 4 || nextLine) { if (nextLine) { nextLine = false; fCurrentAppFile.Write("\t\t\tControllerUnity.Activated();\n"); Debug.Log("MOGA WP8 -> Step 5: Added \"ControllerUnity.Actived\" to App.xaml.cs"); ++iNbBuildConfigSet; } else { nextLine = true; } } // Add ControllerUnity.Deactivated() to Application_Deactivate() if (line.StartsWith(" UnityPlayer.UnityApp.Deactivate();") && !alreadyRan && iNbBuildConfigSet < 4) { fCurrentAppFile.Write("\t\t\tControllerUnity.Deactivated();\n"); Debug.Log("MOGA WP8 -> Step 6: Added \"ControllerUnity.Deactived\" to App.xaml.cs"); ++iNbBuildConfigSet; } ++i; } fCurrentAppFile.Close(); // --------------------------------------------------------------------------- // Update AppName.csproj ----------------------------------------------------- // --------------------------------------------------------------------------- Array.Clear(lines, 0, lines.Length); project = visualstudioPath + applicationName + ".csproj"; lines = System.IO.File.ReadAllLines(project); FileStream filestrCsProj = new FileStream(project, FileMode.Create); filestrCsProj.Close(); StreamWriter fCurrentCsProjFile = new StreamWriter(project); iNbBuildConfigSet = 0; i = 0; nextLine = false; bool armLibrary = true; foreach (string line in lines) { fCurrentCsProjFile.WriteLine(line); // Add Controller.UnityPlugin.cs to Visual Studio CSPROJ file if (line.StartsWith(" <Compile Include=\"LocalizedStrings.cs") && !alreadyRan && iNbBuildConfigSet < 2) { fCurrentCsProjFile.Write("\t<Compile Include=\"Controller.UnityPlugin.cs\" />\n"); Debug.Log("MOGA WP8 -> Step 7: Added \"Controller.UnityPlugin.cs\" to Visual Studio CSProj file."); ++iNbBuildConfigSet; } // Add Moga.Windows.Phone Library to Project if (line.StartsWith(" <HintPath>Assembly-CSharp-firstpass.dll</HintPath>") && !alreadyRan && iNbBuildConfigSet < 2 || nextLine) { if (nextLine) { nextLine = false; // Check to see if the MogaControllerManager exists if (GameObject.Find("MogaControllerManager") != null) { Moga_ControllerManager mogaControllerManger = GameObject.Find("MogaControllerManager").GetComponent <Moga_ControllerManager>(); if (mogaControllerManger.armlib) { fCurrentCsProjFile.Write("\t<Reference Include=\"Moga.Windows.Phone\">\n"); fCurrentCsProjFile.Write("\t\t<HintPath>ARM\\Moga.Windows.Phone.winmd</HintPath>\n"); fCurrentCsProjFile.Write("\t</Reference>\n"); Debug.Log("MOGA WP8 -> Step 8: Added \"ARM Library\" to Visual Studio Project"); } else { fCurrentCsProjFile.Write("\t<Reference Include=\"Moga.Windows.Phone\">\n"); fCurrentCsProjFile.Write("\t\t<HintPath>x86\\Moga.Windows.Phone.winmd</HintPath>\n"); fCurrentCsProjFile.Write("\t</Reference>\n"); armLibrary = false; Debug.Log("MOGA WP8 -> Step 8: Added \"x86 Library\" to Visual Studio Project"); } ++iNbBuildConfigSet; } // Use Arm library by default else { fCurrentCsProjFile.Write("\t<Reference Include=\"Moga.Windows.Phone\">\n"); fCurrentCsProjFile.Write("\t\t<HintPath>ARM\\Moga.Windows.Phone.winmd</HintPath>\n"); fCurrentCsProjFile.Write("\t</Reference>\n"); Debug.Log("MOGA WP8 -> Step 8: Added \"ARM Library\" to Visual Studio Project"); ++iNbBuildConfigSet; } } else { nextLine = true; } } ++i; } fCurrentCsProjFile.Close(); // --------------------------------------------------------------------------------- // Move Controller.UnityPlugin.cs and Moga.Windows.Phone.dll to Project Directory // --------------------------------------------------------------------------------- // TODO if (Directory.Exists(Application.dataPath + "/Plugins/winphone8")) { string[] pluginPath = Directory.GetFiles(Application.dataPath + "/Plugins/winphone8/", "Controller.UnityPlugin.cs", SearchOption.AllDirectories); string[] libraryPath; // Check to see if the MogaControllerManager exists if (armLibrary) { libraryPath = Directory.GetFiles(Application.dataPath + "/Plugins/winphone8/ARM", "Moga.Windows.Phone.dll", SearchOption.AllDirectories); } else { libraryPath = Directory.GetFiles(Application.dataPath + "/Plugins/winphone8/x86", "Moga.Windows.Phone.dll", SearchOption.AllDirectories); } // Move Plugin to Visual Studio Build directory. if (pluginPath.Length == 0) { Debug.Log("MOGA WP8 -> ERROR: winphone8/Controller.UnityPlugin.cs is missing"); } else { if (!System.IO.File.Exists(visualstudioPath + "Controller.UnityPlugin.cs")) { File.Copy("Assets/Plugins/winphone8/Controller.UnityPlugin.cs", visualstudioPath + "Controller.UnityPlugin.cs"); Debug.Log("MOGA WP8 -> Step 9: Copied \"Controller.UnityPlugin.cs\" to Visual Studio Directory"); } else { Debug.Log("MOGA WP8 -> Step 9: Skipped \"Controller.UnityPlugin.cs\" already present"); } } // Move Library to Visual Studio Build Directory if (libraryPath.Length == 0) { Debug.Log("MOGA WP8 -> ERROR: winphone8/Moga.Windows.Phone.dll is missing"); } else { if (armLibrary) { if (!System.IO.File.Exists(visualstudioPath + "ARM")) { CopyDirectory("Assets/Plugins/winphone8/ARM", visualstudioPath + "ARM"); Debug.Log("MOGA WP8 -> Step 10: Copied \"ARM\" to Visual Studio Directory"); } else { Debug.Log("MOGA WP8 -> Step 10: Skipped \"ARM\" already present"); } } else { if (!System.IO.File.Exists(visualstudioPath + "x86")) { CopyDirectory("Assets/Plugins/winphone8/x86", visualstudioPath + "x86"); Debug.Log("MOGA WP8 -> Step 10: Copied \"x86\" to Visual Studio Directory"); } else { Debug.Log("MOGA WP8 -> Step 10: Skipped \"x86\" already present"); } } } } else { Debug.Log("MOGA WP8 -> ERROR: winphone8 Plugin directory is missing"); } // --------------------------------------------------------------------------- // Add Namespaces to Controller.UnityPlugin.cs ------------------------------- // --------------------------------------------------------------------------- Array.Clear(lines, 0, lines.Length); project = visualstudioPath + "Controller.UnityPlugin.cs"; lines = System.IO.File.ReadAllLines(project); FileStream filestrUnityPlugin = new FileStream(project, FileMode.Create); filestrUnityPlugin.Close(); StreamWriter fCurrentPluginFile = new StreamWriter(project); iNbBuildConfigSet = 0; i = 0; foreach (string line in lines) { if (line.StartsWith("/* REMOVE ME") || line.StartsWith("REMOVE ME */")) { // Unity disliked having this file in the Assets folder, so we had to comment out // the code, we need to strip these comments out. } else { fCurrentPluginFile.WriteLine(line); } ++i; } fCurrentPluginFile.Close(); Debug.Log("MOGA WP8 -> Step 11: Stripped Comment Tags from Controller.UnityPlugin.cs"); Debug.Log("MOGA WP8 - Finished OnPostProcessBuild"); } }