Esempio n. 1
0
        // Set the static arcadeConfiguration property and update the properties that can be changed in the editor.
        public void SetArcadeConfiguration(ArcadeConfiguration arcadeConfiguration)
        {
            descriptiveName = arcadeConfiguration.descriptiveName;
            id = arcadeConfiguration.id;
            System.Enum.TryParse(arcadeConfiguration.arcadeType, true, out arcadeType);
            System.Enum.TryParse(arcadeConfiguration.gameLauncherMethod, true, out gameLauncherMethod);
            externalModels = arcadeConfiguration.externalModels;
            showFPS        = arcadeConfiguration.showFPS;

            // TODO: Transforms setup not here
            arcadeControl.transform.position      = arcadeConfiguration.camera.position;
            arcadeControl.transform.rotation      = Quaternion.identity;
            arcadeControl.transform.localRotation = Quaternion.identity;
            arcadeControl.transform.GetChild(0).transform.rotation      = Quaternion.identity;
            arcadeControl.transform.GetChild(0).transform.localRotation = arcadeConfiguration.camera.rotation;
            arcadeControl.transform.GetChild(0).transform.position      = Vector3.zero;
            arcadeControl.transform.GetChild(0).transform.localPosition = new Vector3(0, arcadeConfiguration.camera.height, 0);
            RigidbodyFirstPersonController rigidbodyFirstPersonController = arcadeControl.GetComponent <RigidbodyFirstPersonController>();

            if (rigidbodyFirstPersonController != null)
            {
                rigidbodyFirstPersonController.Setup();
            }
            fpsArcadeProperties   = arcadeConfiguration.fpsArcadeProperties;
            cylArcadeProperties   = arcadeConfiguration.cylArcadeProperties;
            modelSharedProperties = arcadeConfiguration.modelSharedProperties;
            zones = arcadeConfiguration.zones;
            UnityEngine.RenderSettings.ambientIntensity = modelSharedProperties.renderSettings.ambientIntensity; // TODO: not here

            ArcadeManager.arcadeConfiguration = arcadeConfiguration;
        }
        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;
                }
            }
        }