Пример #1
0
        protected virtual void Awake()
        {
            Time.timeScale = 1.0f; //unfreeze game if it was frozen from a previous game.

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

            //Get components:
            CamMgr           = FindObjectOfType(typeof(CameraController)) as CameraController; //Find the camera movement script.
            ResourceMgr      = FindObjectOfType(typeof(ResourceManager)) as ResourceManager;   //Find the resource manager script.
            BuildingMgr      = FindObjectOfType(typeof(BuildingManager)) as BuildingManager;
            TaskMgr          = FindObjectOfType(typeof(TaskManager)) as TaskManager;
            UnitMgr          = FindObjectOfType(typeof(UnitManager)) as UnitManager;
            SelectionMgr     = FindObjectOfType(typeof(SelectionManager)) as SelectionManager;
            GroupSelection   = FindObjectOfType(typeof(UnitGroupSelection)) as UnitGroupSelection;
            PlacementMgr     = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            TerrainMgr       = FindObjectOfType(typeof(TerrainManager)) as TerrainManager;
            MvtMgr           = FindObjectOfType(typeof(MovementManager)) as MovementManager;
            UIMgr            = FindObjectOfType(typeof(UIManager)) as UIManager; //Find the UI manager script.
            ErrorMessageMgr  = FindObjectOfType(typeof(ErrorMessageHandler)) as ErrorMessageHandler;
            MinimapIconMgr   = FindObjectOfType(typeof(MinimapIconManager)) as MinimapIconManager;
            AttackWarningMgr = FindObjectOfType(typeof(AttackWarningManager)) as AttackWarningManager;
            AttackMgr        = FindObjectOfType(typeof(AttackManager)) as AttackManager;
            EffectPool       = FindObjectOfType(typeof(EffectObjPool)) as EffectObjPool;
            UpgradeMgr       = FindObjectOfType(typeof(UpgradeManager)) as UpgradeManager;
            InputMgr         = FindObjectOfType(typeof(InputManager)) as InputManager;
#if RTSENGINE_FOW
            FoWMgr = FindObjectOfType(typeof(FogOfWarRTSManager)) as FogOfWarRTSManager;
#endif

#if RTSENGINE_FOW
            if (FoWMgr) //only if there's a fog of war manager in the scene
            {
                FoWMgr.Init(this);
            }
#endif

            CamMgr.Init(this);
            MinimapIconMgr?.Init(this);
            MvtMgr.Init(this);
            TaskMgr.Init(this);
            SelectionMgr.Init(this);
            GroupSelection.Init(this);
            PlacementMgr.Init(this);
            TerrainMgr.Init(this);
            UIMgr.Init(this); //initialize the UI manager.
            ErrorMessageMgr.Init(this);
            AttackWarningMgr?.Init(this);
            AttackMgr.Init(this);
            EffectPool.Init(this);
            UpgradeMgr.Init(this);
            ResourceMgr.Init(this);
            BuildingMgr.Init(this);
            UnitMgr.Init(this);
            InputMgr.Init(this);

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

            if (!InitMultiplayerGame() && !InitSinglePlayerGame()) //if it's not neither a multiplayer nor a single player game
            {
                InitFactions();                                    //we're starting the game directly from the editor in the map scene, init factions directly
            }

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

            InitCampaignGame();                       //initialise a game where the player is coming from the campaign menu to play a mission
            SetPlayerFaction();                       //pick the player faction ID.
            InitDefaultEntities();                    //initialise the pre-spawned faction units and factions

            ResourceMgr.InitResources();              //init the pre-spawned resources.

            UnitMgr.OnFactionSlotsInitialized();      //init free units
            BuildingMgr.OnFactionSlotsInitialized();  //init free buildings
            if (MultiplayerGame)                      //if this is a multiplayer game
            {
                InputMgr.OnFactionSlotsInitialized(); //init spawnable prefabs and default entities in a multiplayer game
            }
            //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;

            SetGameState(GameState.running);          //the game state is now set to running

            UIMgr.PeaceTime.Toggle(peaceTime > 0.0f); //enable the peace time panel if there's actual peace time assigned

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