コード例 #1
0
ファイル: BoidsFlock.cs プロジェクト: chadiik/PCG-MCT
        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);
        }
コード例 #2
0
ファイル: BoidsFlock.cs プロジェクト: chadiik/PCG-MCT
        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;
        }
コード例 #3
0
ファイル: BoidsFlock.cs プロジェクト: chadiik/PCG-MCT
        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
        }
コード例 #4
0
ファイル: BoidsFlock.cs プロジェクト: chadiik/PCG-MCT
 public void TransitionToPreset(FlockPreset targetPreset, float duration, Func <float, float, float, float> lerp = null)
 {
     StartCoroutine(TransitionToPresetCoroutine(targetPreset, duration, lerp != null ? lerp : Mathf.Lerp));
 }