/// <summary>
        /// Spawns a hazard with the specified <paramref name="type"/> and sets it's target to <paramref name="target"/>.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="target"></param>
        public void SpawnHazardOnTarget(EnergyDeviceType type, EnergyDeviceSlot target)
        {
            GameObject hazardGo;

            if (type.model != null)
            {
                var modelActive = type.model.activeSelf;
                type.model.SetActive(false);

                hazardGo = Instantiate(type.model);

                type.model.SetActive(modelActive);
            }
            else
            {
                hazardGo = new GameObject(type.name);
                hazardGo.SetActive(false);
            }

            var hazard = hazardGo.GetOrAddComponent <EnergyDevice>();

            hazardGo.transform.position = target.transform.position + new Vector3(0, 60, 0);
            hazard.type = type;

            AddHazard(hazard, target);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns all suitable effects this type has for the targetType.
 /// </summary>
 /// <param name="targetType"></param>
 /// <returns></returns>
 public IEnumerable <DeviceEffect> GetEffectsForTarget(EnergyDeviceType targetType)
 {
     for (int i = 0; i < deviceEffects.Count; ++i)
     {
         if (deviceEffects[i].targetType == targetType)
         {
             yield return(deviceEffects[i]);
         }
     }
 }
        /// <summary>
        /// If a random target can be found, spawns a hazard with the specified <paramref name="type"/>.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool TrySpawnHazardOnRandomTarget(EnergyDeviceType type)
        {
            var target = GetValidTarget();

            if (target == null)
            {
                return(false);
            }
            SpawnHazardOnTarget(type, target);
            return(true);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns an effect if this type has a suitable effect for the targetType.
 /// </summary>
 /// <param name="targetType"></param>
 /// <returns></returns>
 public DeviceEffect GetEffectForTarget(EnergyDeviceType targetType)
 {
     for (int i = 0; i < deviceEffects.Count; ++i)
     {
         if (deviceEffects[i].targetType == targetType)
         {
             return(deviceEffects[i]);
         }
     }
     return(null);
 }
        private List <HazardConfiguration.DeviceHazard> FilterHazards(EnergyDeviceType targetType, List <HazardConfiguration.DeviceHazard> hazards)
        {
            var filtered = new List <HazardConfiguration.DeviceHazard>();

            for (int i = 0; i < hazards.Count; ++i)
            {
                if (hazards[i].type.enabled &&
                    (hazards[i].maxCount < 0 || hazards[i].type.allDevices.Count < hazards[i].maxCount) &&
                    hazards[i].type.GetEffectForTarget(targetType) != null)
                {
                    filtered.Add(hazards[i]);
                }
            }
            return(filtered);
        }