/// <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); }
private void OnEnable() { component = GetComponent <EnergyDeviceSlot>(); component.DeviceAttached += OnDeviceAttached; component.DeviceRemoved += OnDeviceRemoved; }
/// <summary> /// Changes the target of this device. The device effects are transferred to the new target. /// </summary> /// <param name="target">The new target.</param> public void SetTarget(EnergyDeviceSlot target) { if (targetForEffects != null) { targetForEffects.targetedBy = null; } targetForEffects = target; if (targetForEffects != null) { targetForEffects.targetedBy = this; } if (isActiveAndEnabled) { if (effectsSentTo != target) { if (effectsSentTo != null) { effectsSentTo.RemoveDeviceEffects(this); } effectsSentTo = target; if (effectsSentTo != null) { foreach (var ef in type.GetEffectsForTarget(effectsSentTo.acceptedType)) { effectsSentTo.AddDeviceEffect(this, ef); } } } } }
protected virtual void OnDisable() { if (type != null) { type.allDevices.Remove(this); } if (effectsSentTo != null) { effectsSentTo.RemoveDeviceEffects(this); effectsSentTo = null; } }
protected virtual void OnEnable() { if (grid == null) { grid = GetComponentInChildren <GridData>(); } if (type != null) { type.allDevices.Add(this); } Debug.Assert(effectsSentTo == null); effectsSentTo = targetForEffects; if (effectsSentTo != null) { foreach (var ef in type.GetEffectsForTarget(effectsSentTo.acceptedType)) { effectsSentTo.AddDeviceEffect(this, ef); } } }
private void AddHazard(EnergyDevice hazard, EnergyDeviceSlot target) { hazard.SetTarget(target); hazard.gameObject.SetActive(true); }