public void StartArcade(ArcadeConfiguration arcadeConfiguration, GameObject selectedArcadeModel)
        {
            Debug.Log("Loading Arcade Configuration " + arcadeConfiguration.id + " in ArcadeType " + arcadeConfiguration.arcadeType);
            if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString() || arcadeConfiguration.arcadeType == ArcadeType.CylArcade.ToString())
            {
                ArcadeManager.arcadeState = ArcadeStates.LoadingArcade;
            }

            // We are loading stuff...dont do these
            RigidbodyFirstPersonController arcadeRigidbodyFirstPersonController = ArcadeManager.arcadeControls[ArcadeType.FpsArcade].GetComponent <RigidbodyFirstPersonController>();

            if (arcadeRigidbodyFirstPersonController != null)
            {
                arcadeRigidbodyFirstPersonController.pause = true;
            }
            RigidbodyFirstPersonController menuRigidbodyFirstPersonController = ArcadeManager.arcadeControls[ArcadeType.FpsMenu].GetComponent <RigidbodyFirstPersonController>();

            if (menuRigidbodyFirstPersonController != null)
            {
                menuRigidbodyFirstPersonController.pause = true;
            }
            Rigidbody arcadeCameraRigidBody = ArcadeManager.arcadeControls[ArcadeType.FpsArcade].GetComponent <Rigidbody>();

            if (arcadeCameraRigidBody != null)
            {
                arcadeCameraRigidBody.isKinematic = true;
            }
            Rigidbody menuCameraRigidBody = ArcadeManager.arcadeControls[ArcadeType.FpsMenu].GetComponent <Rigidbody>();

            if (menuCameraRigidBody != null)
            {
                menuCameraRigidBody.isKinematic = true;
            }
            CapsuleCollider arcadeCapsuleCollider = ArcadeManager.arcadeControls[ArcadeType.FpsArcade].GetComponent <CapsuleCollider>();

            if (arcadeCapsuleCollider != null)
            {
                arcadeCapsuleCollider.enabled = false;
            }
            CapsuleCollider menuCapsuleCollider = ArcadeManager.arcadeControls[ArcadeType.FpsMenu].GetComponent <CapsuleCollider>();

            if (menuCapsuleCollider != null)
            {
                menuCapsuleCollider.enabled = false;
            }

            // Arcade
            if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString() || arcadeConfiguration.arcadeType == ArcadeType.CylArcade.ToString())
            {
                ArcadeManager.activeArcadeType = ArcadeType.None;
                ResetArcade(); // Reset current state to zero

                if (LoadArcade(arcadeConfiguration))
                {
                    UpdateController(ArcadeManager.activeArcadeType);
                    TriggerManager.SendEvent(Event.ArcadeStarted);
                    if (ArcadeManager.arcadeHistory.Count == 1)
                    {
                        TriggerManager.SendEvent(Event.MainMenuStarted);
                    }
                    if (ArcadeManager.activeArcadeType == ArcadeType.FpsArcade)
                    {
                        arcadeCameraRigidBody.isKinematic          = false;
                        arcadeCapsuleCollider.enabled              = true;
                        arcadeRigidbodyFirstPersonController.pause = false;
                    }
                    ArcadeManager.arcadeState = ArcadeStates.Running;
                    Cursor.lockState          = CursorLockMode.Locked;
                    Cursor.visible            = false;
                }
                else
                {
                    Debug.Log("Loading the Arcade Configuration of type " + arcadeConfiguration.arcadeType + " Failed!");
                    // TODO: Show an error dialog!
                }
            }
            // Menu
            if (arcadeConfiguration.arcadeType == ArcadeType.CylMenu.ToString() || arcadeConfiguration.arcadeType == ArcadeType.FpsMenu.ToString())
            {
                ArcadeManager.activeMenuType = ArcadeType.None;
                ResetMenu();

                if (LoadArcade(arcadeConfiguration))
                {
                    UpdateController(Application.isPlaying ? ArcadeManager.activeMenuType : ArcadeManager.activeArcadeType);
                    GameObject obj = ArcadeStateManager.selectedModel;
                    if (obj != null && obj.transform.childCount > 1)
                    {
                        ModelVideoSetup modelVideoSetup = obj.transform.GetChild(1).GetComponent <ModelVideoSetup>();
                        if (modelVideoSetup != null)
                        {
                            modelVideoSetup.ReleasePlayer();
                        }
                        ModelImageSetup modelImageSetup = obj.transform.GetChild(1).GetComponent <ModelImageSetup>();
                        if (modelImageSetup != null)
                        {
                            if (arcadeConfiguration.cylArcadeProperties.Count > 0)
                            {
                                if (arcadeConfiguration.cylArcadeProperties[0].cylArcadeOnScreenSelectedModel)
                                {
                                    modelImageSetup.SetMenuTexture();
                                }
                            }
                        }
                        ArcadeStateManager.savedArcadeModel      = ArcadeStateManager.selectedModel;
                        ArcadeStateManager.savedArcadeModelSetup = ArcadeStateManager.selectedModelSetup;
                    }
                    if (ArcadeManager.activeArcadeType == ArcadeType.FpsMenu)
                    {
                        arcadeCameraRigidBody.isKinematic          = false;
                        arcadeCapsuleCollider.enabled              = true;
                        arcadeRigidbodyFirstPersonController.pause = false;
                    }
                    ArcadeManager.activeMenuType = ArcadeType.CylMenu;
                    ArcadeManager.arcadeState    = ArcadeStates.ArcadeMenu;
                    TriggerManager.SendEvent(Event.MenuStarted);
                    Cursor.lockState = CursorLockMode.Locked;
                    Cursor.visible   = false;
                    return;
                }
                else
                {
                    Debug.Log("Loading the Arcade Configuration of type " + arcadeConfiguration.arcadeType + " Failed!");
                    // TODO: Show an error dialog!
                    ArcadeManager.activeMenuType = ArcadeType.None;
                }
                // If the menu setup fails go back to the regular arcade.
                ArcadeManager.arcadeState = ArcadeStates.Running;
                return;
            }

            void UpdateController(ArcadeType arcadeType)
            {
                ArcadeManager.arcadeControls[arcadeType].transform.position      = arcadeConfiguration.camera.position;
                ArcadeManager.arcadeControls[arcadeType].transform.rotation      = Quaternion.identity;
                ArcadeManager.arcadeControls[arcadeType].transform.localRotation = Quaternion.identity;
                ArcadeManager.arcadeControls[arcadeType].transform.GetChild(0).transform.rotation      = Quaternion.identity;
                ArcadeManager.arcadeControls[arcadeType].transform.GetChild(0).transform.localRotation = arcadeConfiguration.camera.rotation;
                ArcadeManager.arcadeControls[arcadeType].transform.GetChild(0).transform.position      = Vector3.zero;
                ArcadeManager.arcadeControls[arcadeType].transform.GetChild(0).transform.localPosition = new Vector3(0, arcadeConfiguration.camera.height, 0);
                RigidbodyFirstPersonController rigidbodyFirstPersonController = ArcadeManager.arcadeControls[arcadeType].GetComponent <RigidbodyFirstPersonController>();

                if (rigidbodyFirstPersonController != null)
                {
                    rigidbodyFirstPersonController.Setup();
                }
                ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].orthographic           = arcadeConfiguration.camera.orthographic;
                ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].fieldOfView            = arcadeConfiguration.camera.fieldOfView;
                ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].nearClipPlane          = arcadeConfiguration.camera.nearClipPlane;
                ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].farClipPlane           = arcadeConfiguration.camera.farClipPlane;
                ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].rect                   = arcadeConfiguration.camera.viewportRect;
                ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].allowDynamicResolution = arcadeConfiguration.camera.allowDynamicResolution;
                if (arcadeConfiguration.camera.aspectRatio != 0)
                {
                    ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].aspect = arcadeConfiguration.camera.aspectRatio;
                }
            }
        }
예제 #2
0
        public static void LoadGame(ModelSetup game, ModelSetup selected)
        {
            TriggerManager.SendEvent(Event.GameStarted);

            selectedModelSetup = selected; // The model not its dummy node
            gameModelSetup     = game;     // Different from selected when game was choosen in CylMenu or FpsMenu.

            if (gameModelSetup == null)
            {
                UnityEngine.Debug.Log("Launcher: model setup not found");
                return;
            }
            else
            {
                UnityEngine.Debug.Log("Launcher: launching " + gameModelSetup.id);
            }
            if (selectedModelSetup == null)
            {
                UnityEngine.Debug.Log("Launcher: selectedmodel setup not found");
                return;
            }
            else
            {
                UnityEngine.Debug.Log("Launcher: launchingselected " + selectedModelSetup.id);
            }
            List <EmulatorConfiguration> emulatorConfiguration = ArcadeManager.emulatorsConfigurationList.Where(x => x.emulator.id == gameModelSetup.emulator).ToList();

            if (emulatorConfiguration.Count < 1)
            {
                UnityEngine.Debug.Log("Launcher: no emulator configuration found");
                return;
            }
            selectedModelSetup.isPlaying = true;
            var launcherMethod = GameLauncherMethod.None;

            launcherMethod = gameModelSetup.gameLauncherMethod;
            if (launcherMethod == GameLauncherMethod.None)
            {
                System.Enum.TryParse(emulatorConfiguration[0].emulator.gameLauncherMethod, true, out launcherMethod);
            }
            if (launcherMethod == GameLauncherMethod.None)
            {
                System.Enum.TryParse(selectedModelSetup == gameModelSetup ? ArcadeManager.arcadeConfiguration.gameLauncherMethod : ArcadeManager.menuConfiguration.gameLauncherMethod, true, out launcherMethod);
            }
            switch (launcherMethod)
            {
            case GameLauncherMethod.Internal:
                LoadInternalGame(emulatorConfiguration[0].emulator);
                break;

            case GameLauncherMethod.External:
                LoadExternalGame(emulatorConfiguration[0].emulator);
                break;

            case GameLauncherMethod.URL:
                LoadURLGame(emulatorConfiguration[0].emulator);
                break;

            default:
                UnityEngine.Debug.Log("Launcher: no launcher method found");
                break;
            }

            void LoadExternalGame(EmulatorProperties emulator)
            {
                // Application.OpenURL("mameios://");
                // TODO: Damn this works, but ugly! You know better!
                string path       = ArcadeManager.applicationPath;
                string executable = emulator.executable.Trim();
                string extension  = emulator.extension != null?emulator.extension.Trim() : "";

                // TODO: Implement commandline arguments
                //string arguments = emulator.arguments.Trim();
                string options      = emulator.options.TrimStart();
                string emulatorPath = FileManager.CorrectFilePath(emulator.emulatorPath);

                if (emulatorPath != "")
                {
                    emulatorPath = path + emulatorPath;
                }
                string gamePath = FileManager.CorrectFilePath(emulator.gamePath);

                if (gamePath != "")
                {
                    gamePath = path + gamePath;
                }
                string workingDir = FileManager.CorrectFilePath(emulator.workingDir);

                if (workingDir != "")
                {
                    workingDir = path + workingDir;
                }

                ProcessStartInfo startInfo = new ProcessStartInfo();

                startInfo.FileName  = emulatorPath + executable;
                startInfo.Arguments = options + gamePath + gameModelSetup.id.Trim() + extension; // space char after -File
                if (workingDir != "")
                {
                    startInfo.WorkingDirectory = workingDir;
                }
                startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                startInfo.CreateNoWindow  = true;
                startInfo.UseShellExecute = false;
                bool    started = false;
                Process process = new Process();

                process.StartInfo = startInfo;
                started           = process.Start();
                try
                {
                    int procId = process.Id;
                }
                catch (InvalidOperationException)
                {
                    started = false;
                }
                catch (Exception ex)
                {
                    UnityEngine.Debug.Log("Error: " + ex.Message + "  " + ex.InnerException);
                    started = false;
                }
                if (started)
                {
                    UnityEngine.Debug.Log("game started");
                    ArcadeManager.arcadeState = ArcadeStates.Game;
                }
            }

            void LoadInternalGame(EmulatorProperties emulator)
            {
                UnityEngine.Debug.Log("Launcher: start internal launcher " + selectedModelSetup.transform.gameObject.name);

                GameObject screen = selectedModelSetup.transform.GetChild(0).GetChild(1).gameObject;

                UnityEngine.Debug.Log("selected obj " + selectedModelSetup.name);
                ModelVideoSetup video = screen.GetComponent <ModelVideoSetup>();

                video.ReleasePlayer(false);
                UnityEngine.Debug.Log("selected video " + video);

                RigidbodyFirstPersonController arcadeRigidbodyFirstPersonController = ArcadeManager.arcadeControls[ArcadeType.FpsArcade].GetComponent <RigidbodyFirstPersonController>();

                if (arcadeRigidbodyFirstPersonController != null)
                {
                    arcadeRigidbodyFirstPersonController.pause = true;
                }

                // TODO: Damn this works, but ugly!
                string path       = ArcadeManager.applicationPath;
                string executable = emulator.libretroCore.Trim();
                string extension  = emulator.extension != null?emulator.extension.Trim() : "";

                string arguments    = emulator.arguments.Trim();
                string options      = emulator.options.TrimStart();
                string emulatorPath = FileManager.CorrectFilePath(emulator.emulatorPath);

                if (emulatorPath != "")
                {
                    emulatorPath = Path.Combine(path + emulatorPath);
                }
                string gamePath = FileManager.CorrectFilePath(emulator.gamePath);

                if (gamePath != "")
                {
                    gamePath = Path.Combine(path + gamePath);
                }
                string workingDir = FileManager.CorrectFilePath(emulator.workingDir);

                if (workingDir != "")
                {
                    workingDir = Path.Combine(path + workingDir);
                }

                //UnityEngine.Debug.Log("is path" + gamePath );
                //UnityEngine.Debug.Log("is game" + gameModelSetup.id);
                ModelLibretroGameSetup libretroGame;

                libretroGame = selectedModelSetup.gameObject.GetComponent <ModelLibretroGameSetup>();
                if (libretroGame == null)
                {
                    libretroGame = selectedModelSetup.gameObject.AddComponent <ModelLibretroGameSetup>();
                    modelLibretroGameSetupsList.Add(libretroGame);
                    libretroGame.StartGame(executable, gamePath, gameModelSetup.id);
                }
                else
                {
                    libretroGame.ResumeGame();
                }
                // Increase 1 to support more then one game at once
                if (modelLibretroGameSetupsList.Count > 1)
                {
                    libretroGame = modelLibretroGameSetupsList[0];
                    if (libretroGame != null)
                    {
                        libretroGame.StopGame();
                        modelLibretroGameSetupsList.RemoveAt(0);
                    }
                }
                ArcadeManager.arcadeState = ArcadeStates.Game;
            }

            void LoadURLGame(EmulatorProperties emulator)
            {
                Application.OpenURL(emulator.executable.Trim() + emulator.options.Trim() + gameModelSetup.id.Trim() + emulator.arguments.Trim());
                ArcadeManager.arcadeState = ArcadeStates.Game;
            }
        }