public void ResetArcade()
        {
            TriggerManager.SendEvent(Event.ArcadeEnded);
            TriggerManager.triggersActive = new Dictionary <Event, List <ModelTriggerSetup> >();

            ResetMenu();

            // Destroy the models attached to the camera
            GameObject        tobj        = ArcadeManager.arcadeCameras[ArcadeType.FpsArcade].transform.gameObject;
            List <GameObject> gameObjects = tobj.GetChildren();

            foreach (GameObject child in gameObjects)
            {
                ModelSetup modelSetup = child.GetComponent <ModelSetup>();
                if (modelSetup != null)
                {
                    DestroyModel(child);
                }
            }

            // Reset external assets.
            AssetBundle.UnloadAllAssetBundles(true);
            ArcadeManager.modelAssets.Clear();
            GameObject obj = GameObject.Find("EditorModelCache");

            if (obj != null)
            {
                foreach (Transform child in obj.transform)
                {
                    DestroyModel(child.gameObject);
                }
                DestroyModel(obj);
            }

            obj = GameObject.Find("Arcade/GameModels");
            if (obj == null)
            {
                Debug.Log("no game models found");
                return;
            }
            var transform = obj.transform;

            for (int i = transform.childCount - 1; i >= 0; --i)
            {
                DestroyModel(transform.GetChild(i).gameObject);
            }
            transform.DetachChildren();

            obj = GameObject.Find("Arcade/ArcadeModels");
            if (obj == null)
            {
                Debug.Log("no arcade models found");
                return;
            }
            transform = obj.transform;
            for (int i = transform.childCount - 1; i >= 0; --i)
            {
                DestroyModel(transform.GetChild(i).gameObject);
            }
            transform.DetachChildren();

            obj = GameObject.Find("Arcade/PropModels");
            if (obj == null)
            {
                Debug.Log("no prop models found");
                return;
            }
            transform = obj.transform;
            for (int i = transform.childCount - 1; i >= 0; --i)
            {
                DestroyModel(transform.GetChild(i).gameObject);
            }
            transform.DetachChildren();
            void DestroyModel(GameObject child)
            {
                if (Application.isPlaying)
                {
                    Object.Destroy(child);
                }
                else
                {
                    Object.DestroyImmediate(child);
                }
            }

            Resources.UnloadUnusedAssets();
            TriggerManager.UnLoadTriggers();
        }
        public GameObject AddModelToArcade(ModelType modelType, ModelProperties modelProperties, ArcadeType arcadeType, bool addTrigger)
        {
            AssetBundle tAsset;
            GameObject  tObj;

            tAsset = GetExternalModel(modelProperties.model);
            if (tAsset != null)
            {
                return(addExternalModel(tAsset));
            }
            tObj = GetInternalModel(modelProperties.model);
            if (tObj != null)
            {
                return(AddInternalModel(tObj));
            }
            tAsset = GetExternalModel(modelProperties.id);
            if (tAsset != null)
            {
                return(addExternalModel(tAsset));
            }
            tObj = GetInternalModel(modelProperties.id);
            if (tObj != null)
            {
                return(AddInternalModel(tObj));
            }
            tAsset = GetExternalModel(modelProperties.idParent);
            if (tAsset != null)
            {
                return(addExternalModel(tAsset));
            }
            tObj = GetInternalModel(modelProperties.idParent);
            if (tObj != null)
            {
                return(AddInternalModel(tObj));
            }

            // Now check for defaultmodels
            // First defaultmodel filters in the emulator
            List <EmulatorConfiguration> emulatorConfiguration = ArcadeManager.emulatorsConfigurationList.Where(x => x.emulator.id == modelProperties.emulator).ToList();

            if (emulatorConfiguration.Count > 1)
            {
                List <DefaultModelFilter> defaultModelFilters = emulatorConfiguration[0].emulator.defaultModelFilters;
                foreach (DefaultModelFilter defaultModel in defaultModelFilters)
                {
                    bool success = true;
                    foreach (ModelFilter filter in defaultModel.modelFilters)
                    {
                        success &= FilterModel(filter, modelProperties);
                    }
                    if (success)
                    {
                        tAsset = GetExternalModel(defaultModel.model);
                        if (tAsset != null)
                        {
                            return(addExternalModel(tAsset));
                        }
                        tObj = GetInternalModel(defaultModel.model);
                        if (tObj != null)
                        {
                            return(AddInternalModel(tObj));
                        }
                    }
                }
            }

            // Generic defaultmodel filters
            if (arcadeManager.generalConfiguration != null)
            {
                List <DefaultModelFilter> defaultModelFilters = arcadeManager.generalConfiguration.defaultModelFilters;
                foreach (DefaultModelFilter defaultModel in defaultModelFilters)
                {
                    bool success = true;
                    foreach (ModelFilter filter in defaultModel.modelFilters)
                    {
                        success &= FilterModel(filter, modelProperties);
                    }
                    if (success)
                    {
                        tAsset = GetExternalModel(defaultModel.model);
                        if (tAsset != null)
                        {
                            return(addExternalModel(tAsset));
                        }
                        tObj = GetInternalModel(defaultModel.model);
                        if (tObj != null)
                        {
                            return(AddInternalModel(tObj));
                        }
                    }
                }
            }

            // defaultmodel
            string[]      defaultModels = { "default70hor", "default70vert", "default80hor", "default80vert", "default90hor", "default90vert" };
            System.Random rnd           = new System.Random();
            tObj = GetInternalModel(defaultModels[rnd.Next(defaultModels.Length)]);
            if (tObj != null)
            {
                return(AddInternalModel(tObj));
            }

            return(null);

            AssetBundle GetExternalModel(string modelName)
            {
                List <AssetBundle> prefab = ArcadeManager.modelAssets.Where(x => x.name == modelName).ToList();

                if (prefab.Count < 1)
                {
                    var file = FileManager.FileExists(ArcadeManager.applicationPath + "/3darcade~/Configuration/Assets/" + ArcadeManager.currentOS.ToString() + "/" + modelType.ToString() + "s/", modelName + ".unity3d");
                    if (file != null)
                    {
                        var asset = AssetBundle.LoadFromFile(file);
                        if (asset != null && asset.name != null && asset.name != "")
                        {
                            ArcadeManager.modelAssets.Add(asset);
                            prefab.Add(asset);
                            return(asset);
                        }
                    }
                }
                return(prefab.Count == 1 ? prefab[0] : null);
            }

            GameObject addExternalModel(AssetBundle asset)
            {
                GameObject me    = asset.LoadAsset(asset.name) as GameObject;
                GameObject child = UnityEngine.Object.Instantiate(me);

                return(AddModel(child, modelProperties));
            }

            GameObject GetInternalModel(string modelName)
            {
                GameObject obj = (UnityEngine.GameObject)Resources.Load(modelType.ToString() + "s/" + modelName, typeof(GameObject));

                // TODO: NBNB remove this hack to be able to use gamelist models as prop models
                if (obj == null)
                {
                    obj = (UnityEngine.GameObject)Resources.Load(ModelType.Game.ToString() + "s/" + modelName, typeof(GameObject));
                }
                return(obj == null ? null : obj);
            }

            GameObject AddInternalModel(GameObject obj)
            {
                GameObject child = UnityEngine.Object.Instantiate(obj);

                return(AddModel(child, modelProperties));
            }

            GameObject AddModel(GameObject obj, ModelProperties model)
            {
                GameObject dummyNode;

                if (Application.isPlaying)
                {
                    dummyNode = new GameObject("dummy");
                    obj.transform.SetParent(dummyNode.transform);
                }
                else
                {
                    dummyNode = obj;
                }

                var modelSetup = dummyNode.GetComponent <ModelSetup>();

                if (modelSetup == null)
                {
                    dummyNode.AddComponent <ModelSetup>();
                    modelSetup = dummyNode.GetComponent <ModelSetup>();
                }
                //Rigidbody rigidbody = obj.GetComponent<Rigidbody>();
                //if (rigidbody != null)
                //{
                //    rigidbody.isKinematic = true;
                //}
                dummyNode.transform.position   = model.position; // model is redundant you aleady have access to modelProperties
                dummyNode.transform.rotation   = model.rotation;
                dummyNode.transform.localScale = model.scale;
                if (modelType == ModelType.Arcade)
                {
                    dummyNode.tag = "arcademodel";
                }
                if (modelType == ModelType.Game)
                {
                    dummyNode.tag = "gamemodel";
                }
                if (modelType == ModelType.Prop)
                {
                    dummyNode.tag = "propmodel";
                }
                bool   isArcadeLayer = arcadeType == ArcadeType.FpsArcade || arcadeType == ArcadeType.CylArcade || arcadeType == ArcadeType.None ? true : false;
                string layer         = (isArcadeLayer ? "Arcade/" : "Menu/") + modelType.ToString() + "Models";

                dummyNode.layer = LayerMask.NameToLayer(layer);
                dummyNode.RunOnChildrenRecursive(tChild => tChild.layer = LayerMask.NameToLayer(layer));

                GameObject node = null;

                if (isArcadeLayer)
                {
                    node = GameObject.Find("Arcade/" + modelType.ToString() + "Models");
                }
                else
                {
                    node = GameObject.Find("Menu/" + modelType.ToString() + "Models");
                }

                if (node != null)
                {
                    dummyNode.transform.SetParent(node.transform);
                }
                else
                {
                    Debug.Log("Error: Could not find the models parent node...");
                }

                // Zoning
                if (arcadeType == ArcadeType.FpsArcade || arcadeType == ArcadeType.FpsMenu)
                {
                    if (!ArcadeManager.visibleZones[arcadeType].ContainsKey(modelProperties.zone))
                    {
                        ArcadeManager.visibleZones[arcadeType][modelProperties.zone] = new List <GameObject>();
                    }

                    if (modelProperties.zone != 0)
                    {
                        ArcadeManager.visibleZones[arcadeType][modelProperties.zone].Add(dummyNode);
                    }
                    else
                    {
                        if (Physics.Raycast(dummyNode.transform.position, -dummyNode.transform.up, out RaycastHit vision, 100.0f))
                        {
                            GameObject objectHit = vision.transform.gameObject;
                            if (objectHit != null)
                            {
                                ModelSetup hitModelSetup = objectHit.transform.parent.gameObject.GetComponent <ModelSetup>();
                                if (hitModelSetup != null)
                                {
                                    //Debug.Log("zonemodel " + modelSetup.descriptiveName);
                                    ArcadeManager.visibleZones[arcadeType][hitModelSetup.zone].Add(dummyNode);
                                }
                            }
                        }
                    }
                }

                ArcadeConfiguration arcadeConfiguration = isArcadeLayer ? ArcadeManager.arcadeConfiguration : ArcadeManager.menuConfiguration;

                modelSetup.Setup(model, arcadeConfiguration.modelSharedProperties);
                if (addTrigger && modelSetup.triggers.Count > 0 && Application.isPlaying)
                {
                    TriggerManager.Add(modelSetup, arcadeType);
                }
                return(dummyNode);
            }
        }
        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;
                }
            }
        }
        public bool LoadArcade(ArcadeConfiguration arcadeConfiguration)
        {
            if (arcadeManager == null)
            {
                Debug.Log("No ArcadeManager reference found, create one...");
                return(false);
            }
            if (arcadeConfiguration == null)
            {
                return(false);
            }
            if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString() || arcadeConfiguration.arcadeType == ArcadeType.CylArcade.ToString() || !Application.isPlaying)
            {
                arcadeManager.SetArcadeConfiguration(arcadeConfiguration);
            }
            else
            {
                ArcadeManager.menuConfiguration = arcadeConfiguration;
            }
            System.Enum.TryParse(arcadeConfiguration.arcadeType, true, out ArcadeType arcadeType);
            if (arcadeType == ArcadeType.FpsArcade || arcadeType == ArcadeType.FpsMenu)
            {
                ArcadeManager.allZones[arcadeType]     = new Dictionary <int, List <int> >();
                ArcadeManager.visibleZones[arcadeType] = new Dictionary <int, List <GameObject> >();
                foreach (Zone zone in arcadeConfiguration.zones)
                {
                    ArcadeManager.allZones[arcadeType][zone.zone] = zone.visibleZones;
                }
            }

            SetListOfModelProperties(ModelType.Arcade, arcadeConfiguration.arcadeModelList, "Arcades");
            if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString() || !Application.isPlaying)
            {
                SetListOfModelProperties(ModelType.Game, arcadeConfiguration.gameModelList, "Games");
            }
            SetListOfModelProperties(ModelType.Prop, arcadeConfiguration.propModelList, "Props");

            if (!Application.isPlaying)
            {
                return(true);
            }                                            // TODO: Why true?

            if (arcadeConfiguration.arcadeType == ArcadeType.CylArcade.ToString())
            {
                ArcadeManager.activeArcadeType = ArcadeType.CylArcade;
                ArcadeManager.arcadeHistory.Add(arcadeConfiguration.id);
                CylController cylController = ArcadeManager.arcadeControls[ArcadeType.CylArcade].GetComponentInChildren <CylController>();
                cylController.SetupCylArcade(arcadeConfiguration);
            }
            if (arcadeConfiguration.arcadeType == ArcadeType.FpsArcade.ToString())
            {
                ArcadeManager.activeArcadeType = ArcadeType.FpsArcade;
                ArcadeManager.arcadeHistory.Add(arcadeConfiguration.id);
            }
            if (arcadeConfiguration.arcadeType == ArcadeType.CylMenu.ToString())
            {
                ArcadeManager.activeMenuType = ArcadeType.CylMenu;
                CylController cylController = ArcadeManager.arcadeControls[ArcadeType.CylMenu].GetComponentInChildren <CylController>();
                cylController.SetupCylArcade(arcadeConfiguration);
            }
            if (arcadeConfiguration.arcadeType == ArcadeType.FpsMenu.ToString())
            {
                ArcadeManager.activeMenuType = ArcadeType.FpsMenu;
            }
            TriggerManager.Setup(arcadeType);

            return(true);

            void SetListOfModelProperties(ModelType modelType, List <ModelProperties> list, string resourceFolder)
            {
                ArcadeType tempArcadeType = !Application.isPlaying ? ArcadeType.None : arcadeType;
                int        count          = list.Count;

                for (int i = 0; i < count; i++)
                {
                    ModelProperties modelProperties = list[i];
                    AddModelToArcade(modelType, modelProperties, tempArcadeType, false);
                }
            }
        }
Ejemplo n.º 5
0
        public static void UnLoadGame()
        {
            TriggerManager.SendEvent(Event.GameEnded);

            if (selectedModelSetup == null)
            {
                UnityEngine.Debug.Log("Launcher:  model setup not found");
                if (selectedModelSetup == null)
                {
                    UnityEngine.Debug.Log("Launcher: selected model setup not found");
                }
                return;
            }
            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 = false;
            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:
                UnLoadInternalGame();
                break;

            case GameLauncherMethod.External:
                UnLoadExternalGame();
                break;

            case GameLauncherMethod.URL:
                UnLoadExternalGame();
                break;

            default:
                UnityEngine.Debug.Log("Launcher: no launcher method found");
                break;
            }
            void UnLoadExternalGame()
            {
                // Stop Game
                ArcadeManager.arcadeState = ArcadeStates.Running;
            }

            void UnLoadInternalGame()
            {
                // Stop Game
                ModelLibretroGameSetup libretroGame = selectedModelSetup.gameObject.GetComponent <ModelLibretroGameSetup>();

                if (libretroGame != null)
                {
                    libretroGame.PauseGame(false, true, true);
                }
                Cursor.lockState          = CursorLockMode.Locked;
                Cursor.visible            = false;
                ArcadeManager.arcadeState = ArcadeStates.Running;
                if (ArcadeManager.activeMenuType != ArcadeType.None || (ArcadeManager.activeMenuType == ArcadeType.None && ArcadeManager.activeArcadeType == ArcadeType.FpsArcade))
                {
                    UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController arcadeRigidbodyFirstPersonController = ArcadeManager.arcadeControls[ArcadeType.FpsArcade].GetComponent <RigidbodyFirstPersonController>();
                    if (arcadeRigidbodyFirstPersonController != null)
                    {
                        arcadeRigidbodyFirstPersonController.pause = false;
                    }
                }
            }
        }
Ejemplo n.º 6
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;
            }
        }