/// <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 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); } } }