protected virtual void TrySelectOption(int option, int player)
    {
        // Check if he was playing online or not...
        if (!UFE.isConnected)
        {
            // If it's a local game, go to the selected screen immediately...
            this.SelectOption(option, player);
        }
        else
        {
            // If it's an online game, we need to inform the other client about the screen we want to go...
            int localPlayer = UFE.GetLocalPlayer();
            if (localPlayer == player)
            {
                UFEController controller = UFE.GetController(localPlayer);

                // We don't invoke the OnstageSelected() method immediately because we are using the frame-delay
                // algorithm to keep players synchronized, so we can't invoke the OnstageSelected() method
                // until the other player has received the message with our choice.
                controller.GetType().GetMethod(
                    "RequestOptionSelection",
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                    null,
                    new Type[] { typeof(int) },
                    null
                    ).Invoke(controller, new object[] { option });
            }
        }
    }
Exemple #2
0
    public void TrySelectStage(int stageIndex)
    {
        // Check if he was playing online or not...
        if (!UFE.isConnected)
        {
            // If it's a local game, update the corresponding stage immediately...
            this.OnStageSelectionAllowed(stageIndex);
        }
        else
        {
            // If it's an online game, we only select the stage if it has been requested by Player 1...
            // But if player 2 wants to come back to character selection screen, we also allow that...
            int localPlayer = UFE.GetLocalPlayer();
            if (localPlayer == 1 || stageIndex < 0)
            {
                UFEController controller = UFE.GetController(localPlayer);

                // We don't invoke the OnstageSelected() method immediately because we are using the frame-delay
                // algorithm to keep players synchronized, so we can't invoke the OnstageSelected() method
                // until the other player has received the message with our choice.
                controller.GetType().GetMethod(
                    "RequestOptionSelection",
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                    null,
                    new Type[] { typeof(int) },
                    null
                    ).Invoke(controller, new object[] { stageIndex });
            }
        }
    }
    public virtual void TrySelectCharacter(int characterIndex, int player)
    {
        // Check if he was playing online or not...
        if (!UFE.isConnected)
        {
            // If it's a local game, update the corresponding character immediately...
            this.OnCharacterSelectionAllowed(characterIndex, player);
        }
        else
        {
            // If it's an online game, find out if the requesting player is the local player
            // because we will only accept requests for the local player...
            int localPlayer = UFE.GetLocalPlayer();
            if (player == localPlayer)
            {
                UFEController controller = UFE.GetController(localPlayer);

                // We don't invoke the OnCharacterSelected() method immediately because we are using the frame-delay
                // algorithm to keep players synchronized, so we can't invoke the OnCharacterSelected() method
                // until the other player has received the message with our choice.
                controller.GetType().GetMethod(
                    "RequestOptionSelection",
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                    null,
                    new Type[] { typeof(int) },
                    null
                    ).Invoke(controller, new object[] { characterIndex });
            }
        }
    }
    // Output the blackboard as a string
    public IEnumerator BlackBoardLog(string player)
    {
        bool ai = false;

        // Check if player is AI
        if (player == Constants.p1Key)
        {
            UFEController p1Control = UFE.GetPlayer1Controller();
            if (p1Control.isCPU)
            {
                ai = true;
            }
        }
        if (player == Constants.p2Key)
        {
            UFEController p2Control = UFE.GetPlayer2Controller();
            if (p2Control.isCPU)
            {
                ai = true;
            }
        }

        // Record data for this player
        // Append _AI to all AI players
        KeyData data;

        if (ai)
        {
            data = new KeyData(UFE.GetTimer(), "BlackBoard Update", (flags[player][Constants.playerName] == "" ? player + "_AI" : flags[player][Constants.playerName] + "_AI"), BlackBoardToString());
        }
        else
        {
            data = new KeyData(UFE.GetTimer(), "BlackBoard Update", (flags[player][Constants.playerName] == "" ? player : flags[player][Constants.playerName]), BlackBoardToString());
        }

        string write_to = Constants.addLogUrl + data.AsUrlParams() + "&hash=" + data.Md5Sum(Constants.notSoSecretKey);

        //Debug.Log("Write to: " + write_to);
        // Enqueue for POSTing to server

        if (player == Constants.p1Key)
        {
            PostDataToServer.postQueueP1.Add(new WWW(write_to));
        }
        else if (player == Constants.p2Key)
        {
            PostDataToServer.postQueueP2.Add(new WWW(write_to));
        }
        else
        {
            Debug.Log("Error: 3 Players");
        }
        yield return(null);
    }
Exemple #5
0
    protected void Awake()
    {
        // TODO: it would be cool to load/save the user settings from/to disk (PlayerPrefs)
        UFE.config = UFE_Config;

        // Check which characters have been unlocked
        UFE.LoadUnlockedCharacters();

        // Check the installed Addons and supported 3rd party products
        UFE.isCInputInstalled = UFE.IsInstalled("cInput");
        UFE.isAiAddonInstalled = UFE.IsInstalled("RuleBasedAI");
        UFE.isNetworkAddonInstalled = UFE.IsInstalled("NetworkController");

        #if !UFE_BASIC
        UFE.isControlFreakInstalled = UFE.IsInstalled("TouchController");
        #else
        UFE.isControlFreakInstalled = false;
        #endif

        // Check if we should run the application in background
        Application.runInBackground = UFE.config.runInBackground;

        // Check if cInput is installed and initialize the cInput GUI
        if (UFE.isCInputInstalled){
            Type t = UFE.SearchClass("cGUI");
            if (t != null) t.GetField("cSkin").SetValue(null, UFE.config.inputOptions.cInputSkin);
        }

        #if !UFE_BASIC
        // Check if "Control Freak Virtual Controller" is installed and instantiate the prefab
        if (
            UFE.isControlFreakInstalled &&
            UFE.config.inputOptions.inputManagerType == InputManagerType.ControlFreak &&
            UFE.config.inputOptions.controlFreakPrefab != null
        ){
            UFE.controlFreakPrefab = (GameObject) Instantiate(UFE.config.inputOptions.controlFreakPrefab);
        }
        #endif

        // Check if the "network addon" is installed
        if (UFE.isNetworkAddonInstalled){
            NetworkView network = this.gameObject.AddComponent<NetworkView>();
            network.stateSynchronization = NetworkStateSynchronization.Off;
            Network.sendRate = 1f / (float)UFE.config.fps;

            UFE.localPlayerController = this.gameObject.AddComponent(UFE.SearchClass("LocalPlayerController")) as UFEController;
            UFE.remotePlayerController = this.gameObject.AddComponent(UFE.SearchClass("RemotePlayerController")) as UFEController;
            network.observed = UFE.remotePlayerController;
        }

        UFE.InitializeAudioSystem();

        // Initialize the input systems
        p1Controller = gameObject.AddComponent<UFEController> ();
        if (Input.multiTouchEnabled){
            p1Controller.humanController = gameObject.AddComponent<InputTouchController>();
        }else{
            p1Controller.humanController = gameObject.AddComponent<InputController>();
        }
        if (UFE.isAiAddonInstalled){
            p1Controller.cpuController = (AbstractInputController)gameObject.AddComponent<RuleBasedAI>();
        }else{
            p1Controller.cpuController = gameObject.AddComponent<RandomAI>();
        }
        p1Controller.isCPU = config.p1CPUControl;
        p1Controller.player = 1;

        p2Controller = gameObject.AddComponent<UFEController> ();
        p2Controller.humanController = gameObject.AddComponent<InputController>();
        if (UFE.isAiAddonInstalled){
            p2Controller.cpuController = (AbstractInputController )gameObject.AddComponent<RuleBasedAI>();
        }else{
            p2Controller.cpuController = gameObject.AddComponent<RandomAI>();
        }
        p2Controller.isCPU = config.p2CPUControl;
        p2Controller.player = 2;

        p1Controller.Initialize(config.player1_Inputs);
        p2Controller.Initialize(config.player2_Inputs);

        if (config.fps > 0) {
            Time.timeScale = config.gameSpeed;
            Application.targetFrameRate = config.fps;
        }

        SetLanguage();

        //-------------------------------------------------------------------------------------------------------------
        // Initialize the GUI
        //-------------------------------------------------------------------------------------------------------------
        GameObject goGroup = new GameObject("CanvasGroup");
        UFE.canvasGroup = goGroup.AddComponent<CanvasGroup>();

        GameObject go = new GameObject("Canvas");
        go.transform.SetParent(goGroup.transform);

        UFE.canvas = go.AddComponent<Canvas>();
        UFE.canvas.renderMode = RenderMode.ScreenSpaceOverlay;

        UFE.eventSystem = go.AddComponent<EventSystem>();
        UFE.graphicRaycaster = go.AddComponent<GraphicRaycaster>();

        UFE.touchInputModule = go.AddComponent<TouchInputModule>();
        UFE.touchInputModule.allowActivationOnStandalone = true;
        UFE.touchInputModule.ActivateModule();

        //UFE.standaloneInputModule = go.AddComponent<StandaloneInputModule>();
        //UFE.standaloneInputModule.verticalAxis = "P1KeyboardVertical";
        //UFE.standaloneInputModule.horizontalAxis = "P1KeyboardHorizontal";
        //UFE.standaloneInputModule.allowActivationOnMobileDevice = true;

        if (UFE.config.gameGUI.useCanvasScaler){
            CanvasScaler cs = go.AddComponent<CanvasScaler>();
            cs.defaultSpriteDPI = UFE.config.gameGUI.canvasScaler.defaultSpriteDPI;
            cs.fallbackScreenDPI = UFE.config.gameGUI.canvasScaler.fallbackScreenDPI;
            cs.matchWidthOrHeight = UFE.config.gameGUI.canvasScaler.matchWidthOrHeight;
            cs.physicalUnit = UFE.config.gameGUI.canvasScaler.physicalUnit;
            cs.referencePixelsPerUnit = UFE.config.gameGUI.canvasScaler.referencePixelsPerUnit;
            cs.referenceResolution = UFE.config.gameGUI.canvasScaler.referenceResolution;
            cs.scaleFactor = UFE.config.gameGUI.canvasScaler.scaleFactor;
            cs.screenMatchMode = UFE.config.gameGUI.canvasScaler.screenMatchMode;
            cs.uiScaleMode = UFE.config.gameGUI.canvasScaler.scaleMode;

            //---------------------------------------------------------------------------------------------------------
            // We use comment the next line because we use a "Screen Space - Overlay" canvas
            // and the "dynaicPixelsPerUnit" property is only used in "World Space" Canvas.
            //---------------------------------------------------------------------------------------------------------
            //cs.dynamicPixelsPerUnit = UFE.config.gameGUI.canvasScaler.dynamicPixelsPerUnit;
        }

        // DEBUGGER
        GameObject debuggerGO = new GameObject("Debugger1");
        UFE.debugger1 = debuggerGO.AddComponent<GUIText>();
        UFE.debugger1.pixelOffset = new Vector2(55 * ((float)Screen.width/1280), 570f * ((float)Screen.height/720));
        UFE.debugger1.text = "Debug mode";
        UFE.debugger1.anchor = TextAnchor.UpperLeft;
        UFE.debugger1.color = Color.black;
        UFE.debugger1.richText = true;
        debugger1.enabled = false;

        GameObject debuggerGO2 = new GameObject("Debugger2");
        UFE.debugger2 = debuggerGO2.AddComponent<GUIText>();
        UFE.debugger2.pixelOffset = new Vector2(1225 * ((float)Screen.width/1280), 570f * ((float)Screen.height/720));
        UFE.debugger2.text = "Debug mode";
        UFE.debugger2.alignment = TextAlignment.Right;
        UFE.debugger2.anchor = TextAnchor.UpperRight;
        UFE.debugger2.color = Color.black;
        UFE.debugger2.richText = true;
        debugger2.enabled = false;
        //-------------------------------------------------------------------------------------------------------------

        // Load the player settings from disk
        UFE.SetMusic(PlayerPrefs.GetInt(UFE.MusicEnabledKey, 1) > 0);
        UFE.SetMusicVolume(PlayerPrefs.GetFloat(UFE.MusicVolumeKey, 1f));
        UFE.SetSoundFX(PlayerPrefs.GetInt(UFE.SoundsEnabledKey, 1) > 0);
        UFE.SetSoundFXVolume(PlayerPrefs.GetFloat(UFE.SoundsVolumeKey, 1f));
        UFE.SetDebugMode(config.debugOptions.debugMode);

        // Set default difficulty level
        /*int difficultyIndex = PlayerPrefs.GetInt(UFE.DifficultyLevelKey, -1);
        if (difficultyIndex >= 0 && difficultyIndex < UFE.config.aiOptions.difficultySettings.Length){
            UFE.SetAIDifficulty(UFE.config.aiOptions.difficultySettings[difficultyIndex]);
        }else{*/

        UFE.SetAIDifficulty(UFE.config.aiOptions.selectedDifficultyLevel);
        //}

        // Load the intro screen or the combat, depending on the UFE Config settings
        if (UFE.config.debugOptions.startGameImmediately){
            if (UFE.config.debugOptions.trainingMode) {
                UFE.gameMode = GameMode.TrainingRoom;
            } else {
                UFE.gameMode = GameMode.VersusMode;
            }
            UFE.config.player1Character = config.p1CharStorage;
            UFE.config.player2Character = config.p2CharStorage;
            UFE.SetCPU(1, config.p1CPUControl);
            UFE.SetCPU(2, config.p2CPUControl);
            //UFE.StartGame(0);
            UFE._StartLoadingBattleScreen(0);
        }else{
            UFE.StartIntroScreen(0f);
        }
    }