Ejemplo n.º 1
0
        public NPCBuildingRegulator ActivateBuildingRegulator(NPCBuildingRegulator buildingRegulator, BuildingCenterRegulator centerRegulator)
        {
            BuildingCenterRegulator.ActiveBuildingRegulator abr = IsRegulatorActive(buildingRegulator, centerRegulator);
            if (abr != null)          //regulator is already active
            {
                return(abr.instance); //return the instance.
            }

            //we will be activating the building regulator for the input center only
            BuildingCenterRegulator.ActiveBuildingRegulator newBuildingRegulator = new BuildingCenterRegulator.ActiveBuildingRegulator()
            {
                //create new instance
                instance = Instantiate(buildingRegulator),
                source   = buildingRegulator, //assign the source/prefab.
                //initial spawning timer: regular spawn reload + start creating after value
                spawnTimer = buildingRegulator.spawnReloadRange.getRandomValue() + buildingRegulator.startCreatingAfter.getRandomValue()
            };

            //add it to the active building regulators list:
            centerRegulator.activeBuildingRegulators.Add(newBuildingRegulator);

            newBuildingRegulator.instance.Init(npcMgr, this, centerRegulator.buildingCenter); //initialize the building regulator.

            //whenever a new regulator is added to the active regulators list, then move the building creator into the active state
            isActive = true;

            //return the new created instance:
            return(newBuildingRegulator.instance);
        }
Ejemplo n.º 2
0
 //a method to remove an active instance of a building regulator by providing its source/prefab regulator:
 public void DestroyActiveRegulator(NPCBuildingRegulator nbr)
 {
     foreach (BuildingCenterRegulator bcr in buildingCenterRegulators) //go through the active regulators
     {
         for (int i = 0; i < bcr.activeBuildingRegulators.Count; i++)
         {
             //if this is the building regulator we're looking for:
             BuildingCenterRegulator.ActiveBuildingRegulator abr = bcr.activeBuildingRegulators[i];
             if (nbr == abr.source)
             {
                 //destroy the active instance:
                 Destroy(abr.instance);
                 //remove from list:
                 bcr.activeBuildingRegulators.RemoveAt(i);
                 break;
             }
         }
     }
 }