/// <summary> /// You need to check here if two keys are the same. /// You only need to compare your settings. The base /// class will do the comparison for the other settings /// and only call the Matches function if they do match. /// </summary> /// <param name="k">another key</param> /// <returns>If this key has the same settings as the other key</returns> protected override bool Matches(WaveSpectrumConditionKey k) { //Cast the key to your type. CustomSpectrumConditionKey key = k as CustomSpectrumConditionKey; //If the key is not of the same type return false if (key == null) return false; //If the key does not match your settings return false. if (WindSpeed != key.WindSpeed) return false; //else they have the same setting so would generate the same spectrum data so return true. return true; }
/// <summary> /// You need to create a class (see below) that implements the ISpectrum /// interface and is what will be used by the SpectrumTask script to generate the /// spectrum data. The task will call the Spectrum function from a separate /// thread as its being created so it need to be thread safe. /// </summary> public ISpectrum CreateSpectrum(WaveSpectrumConditionKey key) { //Cast from base class to your key type CustomSpectrumConditionKey k = key as CustomSpectrumConditionKey; //If this happens something has gone wrong. //Check what your returning in the CreateKey function. if (k == null) throw new InvalidCastException("Spectrum condition key is null or not the correct type"); //Get the settings the spectrum will be created from the key. float windSpeed = k.WindSpeed; float windDir = k.WindDir; //return a new spectrum. return new CustomSpectrum(windSpeed, windDir); }