Пример #1
0
 //whenever a building is added or removed, this method will be called to add/remove it to the lists in the spawn units:
 public void UpdateUnitCreatorList(TaskLauncher taskLauncher, bool add)
 {
     //Make sure that this task launcher can actually create units and that there units to spawn
     if (taskLauncher.UnitCreationTasks.Count > 0)
     {
         //loop through the unit creation tasks
         foreach (int taskID in taskLauncher.UnitCreationTasks)
         {
             if (add == false) //if this task launcher is getting removed.
             {
                 int i = 0;
                 //go through all registerd task launchers in this component
                 while (i < unitCreatorList.Count)
                 {
                     if (unitCreatorList[i].taskLauncher == taskLauncher) //if the task launcher matches:
                     {
                         //remove it:
                         unitCreatorList.RemoveAt(i);
                     }
                     else
                     {
                         i++; //go to the next register unit creator
                     }
                 }
             }
             else //if we are adding this task launcher
             {
                 //if there are valid prefab(s) assigned to this unit creation task
                 if (taskLauncher.TasksList[taskID].UnitCreationSettings.Prefabs.Length > 0)
                 {
                     string prefabCode = taskLauncher.TasksList[taskID].UnitCreationSettings.Prefabs[0].Code;
                     //if the unit code is included in the list => that unit is managed by this regulator
                     if (prefabCode == code)
                     {
                         //go ahead and add it:
                         UnitCreatorInfo newUnitCreator = new UnitCreatorInfo
                         {
                             //set the unit creator info:
                             taskLauncher = taskLauncher,
                             taskID       = taskID
                         };
                         //add it to the list:
                         unitCreatorList.Add(newUnitCreator);
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 //whenever a building is added or removed, this method will be called to add/remove it to the lists in the spawn units:
 public void UpdateUnitCreatorList(TaskLauncher taskLauncher, bool add)
 {
     if (add == false) //if this task launcher is getting removed.
     {
         int i = 0;
         //go through all registerd task launchers in this component
         while (i < unitCreatorList.Count)
         {
             if (unitCreatorList[i].taskLauncher == taskLauncher) //if the task launcher matches:
             //remove it:
             {
                 unitCreatorList.RemoveAt(i);
             }
             else
             {
                 i++; //move on
             }
         }
     }
     //Make sure that this task launcher can actually create units and that there units to spawn
     else if (taskLauncher.GetTasksCount() > 0) //if we're adding tasks and this task launcher has tasks.
     {
         //loop through the task launcher's tasks
         for (int taskID = 0; taskID < taskLauncher.GetTasksCount(); taskID++)
         {
             //if this is a unit creation task:
             if (taskLauncher.GetTask(taskID).GetTaskType() == TaskTypes.createUnit && taskLauncher.GetTask(taskID).UnitCode == code)
             {
                 //if the unit code is included in the list => that unit is managed by this regulator
                 //go ahead and add it:
                 UnitCreatorInfo newUnitCreator = new UnitCreatorInfo
                 {
                     //set the unit creator info:
                     taskLauncher = taskLauncher,
                     taskID       = taskID
                 };
                 //add it to the list:
                 unitCreatorList.Add(newUnitCreator);
             }
         }
     }
 }