示例#1
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         TABSSceneManager.LoadMainMenu();
     }
 }
示例#2
0
 public static void LoadUnitPreviewScene()
 {
     CampaignPlayerDataHolder.BackToMenu();
     CampaignHandler.ResetLoadedLevel();
     TABSSceneManager.LoadScene("WebTabsUnitPreview", false);
 }
示例#3
0
        public static void Tick()     // A thread safe repeating method
        {
            if (Time.time > waitTime) // Wait until the interval has passed (~60tps)
            {
                waitTime += interval;
                SocketConnection.SetCulture();

                if (SocketConnection.getUIClient().Connected)
                {
                    ScreenshareSender.SetWinHandle(); // Send the unity window handle for receiving images
                }

                if (SocketConnection.switchScene)
                {
                    SocketConnection.switchScene = false;
                    TABSSceneManager.LoadScene(SocketConnection.newScene, true); // Instantly load the new scene
                }

                if (SocketConnection.switchMap)
                {
                    //SocketConnection.WriteToUI("SHOWMSG|Loading a map!"); // Debug
                    SocketConnection.switchMap = false;
                    CampaignPlayerDataHolder.StartedPlayingSandbox();          // Change the game state
                    TABSSceneManager.LoadMap(GetMap(SocketConnection.newMap)); // Load the new map
                }

                if (SocketConnection.updateBudget) // Refresh the UI's budget
                {
                    SocketConnection.updateBudget = false;
                    UpdateUIBudget();
                }


                while (SocketConnection.tickCommands.TryDequeue(out string newData))
                {
                    if (newData.StartsWith("SPAWNUNIT"))
                    {
                        string[] split   = newData.Split('|');
                        string   entName = split[1];
                        Team     team    = (Team)Enum.Parse(typeof(Team), split[2]);
                        Vector3  pos     = StrToVec3(split[3]);

                        UnitBlueprint blueprint = GetUnitBlueprint(entName);
                        GetBrushBehaviorOfUnitBrush(GameObject.FindObjectOfType <UnitBrush>()).Place(blueprint, team, pos); // Add the unit with the brush

                        ServiceLocator.GetService <BattleBudget>().SpendAmount(team, (int)blueprint.UnitCost);              // Update the budget
                        UpdateUIBudget();
                    }
                    else if (newData.StartsWith("REMOVEUNIT"))
                    {
                        string[] split = newData.Split('|');
                        Vector3  pos   = StrToVec3(split[1]);
                        Team     team  = (Team)Enum.Parse(typeof(Team), split[2]);

                        Unit unit = FindClosestUnit(pos); // Get the nearest unit of the pos
                        if (unit != null && unit.Team == team)
                        {
                            GetBrushBehaviorOfUnitBrush(GameObject.FindObjectOfType <UnitBrush>()).Remove(unit, team);       // Remove the unit with the brush

                            ServiceLocator.GetService <BattleBudget>().ReturnAmount(team, (int)unit.unitBlueprint.UnitCost); // Update the budget
                            UpdateUIBudget();
                        }
                    }
                    else if (newData.StartsWith("CLEAR"))
                    {
                        bool        red  = bool.Parse(newData.Split('|')[1]);
                        Team        team = red ? Team.Red : Team.Blue;
                        PlacementUI pui  = GameObject.FindObjectOfType <PlacementUI>(); // Get the placement UI

                        // Clear the right area without triggering an echo
                        UnitLayoutManager.ClearTeam(team);
                        GetClearButtonDelegate(pui)(team);
                    }
                    else if (newData.StartsWith("AUDIO"))
                    {
                        string[] split = newData.Split('|');

                        string  soundRef = split[1];
                        float   volMulti = float.Parse(split[2]);
                        Vector3 relPos   = StrToVec3(split[3]);
                        SoundEffectVariations.MaterialType matType = (SoundEffectVariations.MaterialType)Enum.
                                                                     Parse(typeof(SoundEffectVariations.MaterialType), split[4]);
                        Vector3 worldPos = Camera.main.transform.position + relPos; // Get the world pos from the relative one

                        ServiceLocator.GetService <SoundPlayer>().PlaySoundEffect(soundRef, volMulti, worldPos, matType);
                    }
                }
            }
        }