private IEnumerator TransitionToPresetCoroutine(FlockPreset targetPreset, float duration, Func <float, float, float, float> lerp) { float startTime = Time.time; float separationWeight = this.separationWeight; float alignmentWeight = this.alignmentWeight; float cohesionWeight = this.cohesionWeight; float headToOriginWeight = this.headToOriginWeight; float speed = this.speed; float currentHeadingWeight = this.currentHeadingWeight; float rotationSmooth = this.rotationSmooth; float nearRadius = this.nearRadius; float t = 0f; while (t < 1f) { this.separationWeight = lerp(separationWeight, targetPreset.separationWeight, t); this.alignmentWeight = lerp(alignmentWeight, targetPreset.alignmentWeight, t); this.cohesionWeight = lerp(cohesionWeight, targetPreset.cohesionWeight, t); this.headToOriginWeight = lerp(headToOriginWeight, targetPreset.headToOriginWeight, t); this.speed = lerp(speed, targetPreset.speed, t); this.currentHeadingWeight = lerp(currentHeadingWeight, targetPreset.currentHeadingWeight, t); this.rotationSmooth = lerp(rotationSmooth, targetPreset.rotationSmooth, t); this.nearRadius = lerp(nearRadius, targetPreset.nearRadius, t); t = (Time.time - startTime) / duration; yield return(new WaitForFixedUpdate()); } ApplyPreset(targetPreset); yield return(null); }
private void ApplyPreset(FlockPreset preset) { this.preset = preset; separationWeight = preset.separationWeight; alignmentWeight = preset.alignmentWeight; cohesionWeight = preset.cohesionWeight; headToOriginWeight = preset.headToOriginWeight; speed = preset.speed; currentHeadingWeight = preset.currentHeadingWeight; rotationSmooth = preset.rotationSmooth; nearRadius = preset.nearRadius; }
private void CreatePreset() { #if UNITY_EDITOR FlockPreset newPreset = ScriptableObject.CreateInstance <FlockPreset>(); newPreset.separationWeight = separationWeight; newPreset.alignmentWeight = alignmentWeight; newPreset.cohesionWeight = cohesionWeight; newPreset.headToOriginWeight = headToOriginWeight; newPreset.speed = speed; newPreset.currentHeadingWeight = currentHeadingWeight; newPreset.rotationSmooth = rotationSmooth; newPreset.nearRadius = nearRadius; string path = presetsPath + "/Presets"; if (!AssetDatabase.IsValidFolder(path)) { AssetDatabase.CreateFolder(presetsPath, "Presets"); } string newName = string.IsNullOrEmpty(newPresetName) ? "Flock" + DateTime.Now.Ticks : newPresetName; AssetDatabase.CreateAsset(newPreset, path + "/" + newName + ".asset"); #endif }
public void TransitionToPreset(FlockPreset targetPreset, float duration, Func <float, float, float, float> lerp = null) { StartCoroutine(TransitionToPresetCoroutine(targetPreset, duration, lerp != null ? lerp : Mathf.Lerp)); }