コード例 #1
0
        //a method that initializes a single player game:
        private bool InitSinglePlayerGame()
        {
            //if there's no single player manager then
            if (LobbyManager.instance == null)
            {
                return(false); //do not proceed.
            }
            //If there's a map manager script in the scene, it means that we just came from the single player menu, so we need to set the NPC players settings!

            //randomzie the faction slots
            List <int> factionSlots = RTSHelper.GenerateIndexList(factions.Count);

            RTSHelper.ShuffleList <int>(factionSlots); //randomize the faction slots indexes list IDs by shuffling it.
            RandomizeFactionSlots(factionSlots.ToArray());

            //This where we will set the NPC settings using the info from the single player manager:
            //First check if we have enough faction slots available:
            if (LobbyManager.instance.LobbyFactions.Count <= factions.Count)
            {
                defeatCondition = LobbyManager.instance.UIMgr.defeatConditionMenu.GetValue(); //set defeat condition
                speedModifier   = LobbyManager.instance.UIMgr.speedModifierMenu.GetValue();   //set speed modifier

                //loop through the factions slots of this map:
                for (int i = 0; i < LobbyManager.instance.LobbyFactions.Count; i++)
                {
                    factions[i].Init(
                        LobbyManager.instance.LobbyFactions[i].GetFactionName(),
                        LobbyManager.instance.LobbyFactions[i].GetFactionType(),
                        LobbyManager.instance.LobbyFactions[i].GetFactionColor(),
                        LobbyManager.instance.LobbyFactions[i].PlayerControlled,
                        LobbyManager.instance.GetCurrentMap().GetInitialPopulation(),
                        LobbyManager.instance.LobbyFactions[i].GetNPCType(),
                        gameObject.AddComponent <FactionManager>(), i, this);
                }

                //if there are more slots than required.
                while (LobbyManager.instance.LobbyFactions.Count < factions.Count)
                {
                    //remove the extra slots:
                    factions[factions.Count - 1].InitDestroy();
                    factions.RemoveAt(factions.Count - 1);
                }

                //Destroy the map manager script because we don't really need it anymore:
                DestroyImmediate(LobbyManager.instance.gameObject);

                return(true);
            }
            else
            {
                Debug.LogError("[Game Manager]: Not enough slots available for all the factions coming from the single player menu.");
                return(false);
            }
        }
        //called by the server when the game is about to start:
        public void OnStartGame()
        {
            if (isLocalPlayer == false || manager.IsHost == false) //the host must be the only one able to start the game
            {
                return;
            }

            List <int> factionSlots = RTSHelper.GenerateIndexList(manager.maxConnections);

            RTSHelper.ShuffleList <int>(factionSlots); //randomize the faction slots list IDs by shuffling it

            RpcOnGameStart(factionSlots.ToArray());    //let all clients know that the game is starting
        }
コード例 #3
0
        //called to activate the border
        public void ActivateBorder()
        {
            //make sure to get the game manager and resource manager components
            GameMgr     = GameManager.Instance;
            ResourceMgr = GameMgr.ResourceMgr;

            //if the border is not active yet
            if (IsActive == false)
            {
                //shuffle building defs list:
                RTSHelper.ShuffleList <BuildingsInsideBorderVars>(BuildingsInsideBorder);

                //if we're allowed to spawn the border object
                if (SpawnBorderObj == true)
                {
                    //create and spawn it
                    BorderObj = (GameObject)Instantiate(BorderObj, new Vector3(transform.position.x, BorderHeight, transform.position.z), Quaternion.identity);
                    BorderObj.transform.localScale = new Vector3(Size * BorderSizeMultiplier, BorderObj.transform.localScale.y, Size * BorderSizeMultiplier);
                    BorderObj.transform.SetParent(transform, true);

                    //Set the border's color to the faction it belongs to:
                    Color FactionColor = GameMgr.Factions[MainBuilding.FactionID].FactionColor;
                    BorderObj.GetComponent <MeshRenderer>().material.color = new Color(FactionColor.r, FactionColor.g, FactionColor.b, BorderColorTransparency);
                    //Set the border's sorting order:
                    BorderObj.GetComponent <MeshRenderer>().sortingOrder = GameMgr.LastBorderSortingOrder;
                    GameMgr.LastBorderSortingOrder--;
                }


                //Add the border to all borders list:
                GameMgr.AllBorders.Add(this);

                CheckBorderResources(); //check the resources around the border

                IsActive = true;        //mark the border as active

                //Custom Event:
                if (GameMgr.Events)
                {
                    GameMgr.Events.OnBorderActivated(this);
                }
            }

            //set the faction manager
            FactionMgr = GameMgr.Factions[MainBuilding.FactionID].FactionMgr;

            //check the buildings in the border
            CheckBuildingsInBorder();
        }