Example #1
0
        public List <GameObject> SpawnDrones(IDrone drone, int droneCount = 1, bool isAdded = false, Area area = new Area(), StartPositionDelegate posDelegate = null)
        {
            var drones     = new List <GameObject>();
            var droneDatas = new List <SpawnDroneData>();

            for (var i = 0; i < droneCount; i++)
            {
                var newDrone = drone.CreateDroneInstance(this, isAdded, area, posDelegate);
                newDrone.AddComponent <DroneManager>();

                if (IsServer)
                {
                    var data = AddDroneData(newDrone);
                    drone.ConfigureDrone(newDrone, this);
                    droneDatas.Add(new SpawnDroneData(
                                       new DroneState(data.Id, newDrone.transform.position.x, newDrone.transform.position.z),
                                       drone.Speed, drone.Size, drone.Color, drone.DroneType));
                }
                else
                {
                    drone.ConfigureDrone(newDrone, this);
                }
                drones.Add(newDrone);
            }

            if (IsServer)
            {
                SyncDroneServer.SpawnDrones(droneDatas);
            }
            return(drones);
        }