Пример #1
0
 void Start()
 {
     UIMgr        = GameManager.Instance.UIMgr;
     SelectionMgr = GameManager.Instance.SelectionMgr;
     TaskMgr      = GameManager.Instance.TaskMgr;
 }
Пример #2
0
        public AudioSource GeneralAudioSource;      //The audio source where audio will be played generally unless the audio is local. In that case, it will be played

        void Awake()
        {
            //set the instance:
            if (Instance == null)
            {
                Instance = this;
            }
            else if (Instance != this)
            {
                Destroy(gameObject);
            }

            Time.timeScale = 1.0f;    //unfreeze game if it was frozen from a previous game.

            allFactionsReady = false; //faction stats are not ready, yet

            //Randomize player controlled faction:
            RandomizePlayerFaction();

            //Get components:
            CamMov      = FindObjectOfType(typeof(CameraMovement)) as CameraMovement;   //Find the camera movement script.
            ResourceMgr = FindObjectOfType(typeof(ResourceManager)) as ResourceManager; //Find the resource manager script.
            if (ResourceMgr != null)
            {
                ResourceMgr.gameMgr = this;
            }
            UIMgr        = FindObjectOfType(typeof(UIManager)) as UIManager; //Find the UI manager script.
            BuildingMgr  = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            Events       = FindObjectOfType(typeof(CustomEvents)) as CustomEvents;
            TaskMgr      = FindObjectOfType(typeof(TaskManager)) as TaskManager;
            UnitMgr      = FindObjectOfType(typeof(UnitManager)) as UnitManager;
            SelectionMgr = FindObjectOfType(typeof(SelectionManager)) as SelectionManager;
            PlacementMgr = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            TerrainMgr   = FindObjectOfType(typeof(TerrainManager)) as TerrainManager;
            MvtMgr       = FindObjectOfType(typeof(MovementManager)) as MovementManager;

            MultiplayerGame = false;            //We start by assuming it's a single player game.

            InitFactionMgrs();                  //create the faction managers components for the faction slots.

            InitMultiplayerGame();              //to initialize a multiplayer game.

            InitSinglePlayerGame();             //to initialize a single player game.

            SetPlayerFactionID();               //pick the player faction ID.

            InitFactionCapitals();              //init the faction capitals.

            ResourceMgr.InitFactionResources(); //init resources for factions.

            InitFactions();                     //init the faction types.

            //In order to avoid having buildings that are being placed by AI players and units collide, we will ignore physics between their two layers:
            Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Hidden"), LayerMask.NameToLayer("Unit"));

            //Set the amount of the active factions:
            activeFactionsAmount = Factions.Count;

            GameState = GameStates.Running; //the game state is now set to running

            //reaching this point means that all faction info/stats in the game manager are ready:
            allFactionsReady = true;
        }