-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainManager.cs
904 lines (825 loc) · 24.2 KB
/
MainManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class MainManager : MonoBehaviour {
public static List<MeshRenderer> meshManager = new List<MeshRenderer> ();
public AudioSource source;
public SongGenre getGenre;
public SongID backupGenre;
public static AudioClip song;
public AudioClip debugSong;
public ShaderManager shaderManager;
public GameObject loading;
private Text text;
private SpectrumAnalyzer sa;
public SongGenre.Genre genre;
private float sampleTime; //time of each sample (for charPitches and volumes)
private SortedDictionary <float, float> [] bandBeats; //hashes beat time to power for each band
private float [] beatTotalPower; //total power for each band during beats, use to rate "matching"
private float [] charPitches; //list of characteristic pitches for each sample
private float [] volumes; //list of voumes for each sample
private bool done = false;
public static String pathName;
private SortedDictionary<float,float> bpm;
//private float hueRange;
//private float baseHue;
//private float minSat;
//private float maxSat;
private float minVal;
private float maxVal;
//Scale of 1 to 5 as this is multiplied later on by cube size
private int treeMax;
private int treeSize;
private float leaf_density;
private int buildingMax;
private int buildingSize;
private int buildingHeight;
private float expandChance;
private float windows;
private bool dome;
private float domeRat;
private int numChild;
private float childRadius;
private float childHeight;
private bool treeLeaves;
private bool caves = false;
private float equilibrium = 1;
private float min = 0 ;
private float max = 15;
public GameObject waterTop;
public GameObject waterBottom;
private float waterLevel= .7f;
public GameObject camera;
public GameObject marchingCube;
public GameObject clouds;
private CloudsToy.TypePreset cloudScene = CloudsToy.TypePreset.Sunrise;
private Color cloudColor;
private int numClouds;
public GameObject CubeGenerator;
//private Color baseCubeColor;
private GameObject treeParent;
public GameObject trees;
//private Color baseTreeColor;
private GameObject buildingParent;
public GameObject buildings;
//private Color baseBuildingColor;
public GameObject RainObject;
private bool rain;
// Use this for initialization
void Start () {
shaderManager.enabled = true;
StartCoroutine ("Spectrum");
}
IEnumerator Spectrum(){
text = loading.GetComponent<Text> ();
text.text = "Analyzing Song";
if (song == null) song = debugSong;
float [] data = new float [song.samples * song.channels];
song.GetData (data, 0);
sa = new SpectrumAnalyzer (data, song.length);
sa.Run ();
while(sa.done == false)
yield return new WaitForSeconds (.05f);
sampleTime = sa.sampleTime;
bandBeats = sa.bandBeats;
beatTotalPower = sa.beatTotalPower;
charPitches = sa.charPitches;
volumes = sa.volumes;
yield return StartCoroutine("findGenre");
}
IEnumerator Generate(){
text.text = "Generating Terrain, Buildings and Trees";
CubeGenerator = Instantiate (CubeGenerator);
CubeManager g = CubeGenerator.GetComponent<CubeManager>() as CubeManager;
g.buildingDensity = buildingMax;
g.treeDensity = treeMax;
g.treeLeaves = true;
g.treeSize = treeSize;
g.buildingSize = buildingSize;
g.caves = caves;
//This needs to have an object prefab that has a marching cubes script sent in
g.object_prefab = marchingCube;
//Fixed
g.cubeSize = 20;
//Fix this but the equilibrium needs to be barren for certain songs not others
g.equilibrium = equilibrium;
//Set the surface here
g.surface = 1;
//Set size to 10
g.size = 10;
g.leaf_density = leaf_density;
g.Begin ();
//Set if the terrain turns to cave or flat and where it happens within the range next
//mod 1 is in x direction mod 2 is z mod 3 is x as well
while (g.done == false)
yield return new WaitForSeconds(.02f);
foreach (MeshRenderer mr in meshManager) {
mr.enabled = true;
}
yield return StartCoroutine("cloudInitializer");
}
IEnumerator cloudInitializer(){
text.text = "Setting Clouds";
yield return new WaitForSeconds (1.0f);
clouds.GetComponent<CloudsToy> ().CloudPreset = cloudScene;
clouds.GetComponent<CloudsToy> ().NumberClouds = 2 * numClouds;
Debug.Log ("Clouds");
clouds.GetComponent<CloudsToy> ().EditorRepaintClouds ();
clouds.SetActive(true);
yield return StartCoroutine (startSong ());
}
IEnumerator waterInitializer(){
GameObject top = Instantiate (waterTop);
//GameObject bottom = Instantiate (waterBottom);
text.text = "Setting Water";
yield return new WaitForSeconds (1.0f);
//Vector3 curr = top.transform.position;
float cube_size = CubeGenerator.GetComponent<CubeManager> ().cubeSize;
waterLevel = (max - min)*cube_size* waterLevel;
top.transform.localScale = new Vector3 (4000, 1, 4000);
top.transform.position = new Vector3 (500, waterLevel, 500);
//bottom.transform.position = new Vector3 (curr.x, waterLevel, curr.y);
}
IEnumerator startSong(){
text.text = "Making it Rain";
yield return new WaitForSeconds (1.0f);
MeshParticleEmitter e = null;
//rain = false;
GameObject rainMain = null;
if (rain == true){
rainMain = Instantiate (RainObject);
e = rainMain.GetComponent<MeshParticleEmitter>();
rainMain.SetActive(true);
}
float avg = 0;
int count = 0;
float maxVol = 0;
foreach(float f in volumes){
if (f > maxVol){
maxVol = f;
}
avg += f;
count++;
}
avg = avg / count;
float min = 0;
float max = 0;
if(rain == true){
min = e.minEmission;
max = e.maxEmission;
}
GameObject cam = Instantiate (camera);
cam.GetComponent<UnderWater> ().water_level = waterLevel;
Vector3 down = transform.TransformDirection(Vector3.down);
RaycastHit hit;
Physics.Raycast(new Vector3(500,500f,500),down,out hit);
cam.transform.position = new Vector3 (hit.point.x, hit.point.y + 5, hit.point.z);
text.text = "Setting Fog";
FogControl fg = cam.GetComponent<FogControl> () as FogControl;
GameObject p = Instantiate (new GameObject ());
source = p.AddComponent<AudioSource> ();
source.clip = song;
p.SetActive (true);
float songTime = source.clip.length;
float timerStart = Time.time;
float currTime = Time.time;
source.Play ();
shaderManager.Begin (genre, sa, rainMain, fg);
text.text = "";
yield return new WaitForSeconds (sampleTime / 2);
foreach (float f in volumes ) {
if(rain){
e.minEmission = min * (f/maxVol);
e.maxEmission = max * (f/maxVol);
}
currTime = Time.time;
if(currTime - timerStart >= songTime- 10){
Debug.Log ("TIME");
break;
}
Debug.Log("Rain");
yield return new WaitForSeconds (sampleTime);
}
Debug.Log ("HERE");
float dens = RenderSettings.fogDensity;
shaderManager.enabled = false;
cam.GetComponent<FogControl> ().fog_color= Color.white;
while (Time.time - timerStart <= songTime-2) {
RenderSettings.fogColor = Color.white;
dens *= 1.1f;
cam.GetComponent<FogControl>().fog_density = dens;
RenderSettings.fogDensity = dens;
yield return new WaitForSeconds(.01f);
}
Application.LoadLevel (0);
yield return null;
}
void Alternative(){
//hueRange = 90
//minSat = .3f;
//maxSat = .7f;
minVal = .5f;
maxVal = .75f;
treeMax = 2;
treeSize = 2;
buildingMax = 2;
buildingSize = 2;
treeLeaves = true;
leaf_density = .5f;
rain = false;
equilibrium = 2.5f;
TreeAndBuilding.buildingHeight = 2;
TreeAndBuilding.expandChance = .4f;
TreeAndBuilding.windows = .5f;
TreeAndBuilding.dome = true;
TreeAndBuilding.domeRat = .3f;
TreeAndBuilding.numChild = 0;
TreeAndBuilding.childRadius = new float[]{0,0};
TreeAndBuilding.childHeight = new float[]{0,0};
TreeAndBuilding.segments = new int[]{10,2};
TreeAndBuilding.segmentLength = new float[]{2,0};
TreeAndBuilding.upCurve = new float[]{.9f,0};
TreeAndBuilding.maxTurn = new float[]{20,0};
TreeAndBuilding.branchChance = new float[]{.45f,0};
TreeAndBuilding.branchDeviation = new float[]{10,0};
TreeAndBuilding.leafDensity = new int[]{4,7};
numClouds = 75;
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
}
void Ambient(){
//hueRange = 30;
//baseHue = 240;
//minSat = TreeAndBuilding.1f;
//maxSat = TreeAndBuilding.3f;
minVal = .5f;
maxVal = .8f;
treeMax = 3;
treeSize = 5;
buildingMax = 1;
buildingSize = 5;
treeLeaves = true;
leaf_density = .1f;
rain = true;
equilibrium = 1;
buildingHeight = 2;
TreeAndBuilding.expandChance = .2f;
TreeAndBuilding.windows = .1f;
TreeAndBuilding.dome = false;
TreeAndBuilding.domeRat = 0;
TreeAndBuilding.numChild = 6;
TreeAndBuilding.childRadius = new float[]{.5f,.6f};
TreeAndBuilding.childHeight = new float[] {1,1.5f};
TreeAndBuilding.segments = new int[]{20,4};
TreeAndBuilding.segmentLength = new float[]{3.0f,0};
TreeAndBuilding.upCurve = new float[]{.9f,0};
TreeAndBuilding.maxTurn = new float[]{10,0};
TreeAndBuilding.branchChance = new float[]{.6f,0};
TreeAndBuilding.branchDeviation = new float[]{0,0};
TreeAndBuilding.leafDensity = new int[]{8,12};
cloudScene = CloudsToy.TypePreset.Fantasy;
numClouds = 50;
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
}
void Country(){
// hueRange = 45;
// baseHue = 60;
// minSat = .7f;
// maxSat = .9f;
minVal = .8f;
maxVal = 1;
treeMax = 3;
treeSize = 3;
buildingMax = 1;
buildingSize = 1;
treeLeaves = true;
leaf_density = 1;
rain = false;
equilibrium = 1;
TreeAndBuilding.buildingHeight = 1;
TreeAndBuilding.expandChance = .5f;
TreeAndBuilding.windows = .7f;
TreeAndBuilding.dome = true;
TreeAndBuilding.domeRat = .5f;
TreeAndBuilding.numChild = 0;
TreeAndBuilding.childRadius = new float[]{0,0};
TreeAndBuilding.childHeight = new float[]{0,0};
TreeAndBuilding.segments = new int[]{12,3};
TreeAndBuilding.segmentLength = new float[]{2.0f,0};
TreeAndBuilding.upCurve = new float[]{.9f,0};
TreeAndBuilding.maxTurn = new float[]{10,0};
TreeAndBuilding.branchChance = new float[]{.75f,0};
TreeAndBuilding.branchDeviation = new float[]{0,0};
TreeAndBuilding.leafDensity = new int[]{8,10};
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
numClouds = 50;
}
void Electronic(){
// hueRange = 360;
// minSat = .7f;
// maxSat = 1;
minVal = .8f;
maxVal = 1;
treeMax = 4;
treeSize = 4;
buildingMax = 2;
buildingSize = 4;
treeLeaves = false;
leaf_density = .8f;
rain = true;
equilibrium = 2;
TreeAndBuilding.buildingHeight = 3;
TreeAndBuilding.expandChance = .2f;
TreeAndBuilding.windows = .5f;
TreeAndBuilding.dome = false;
TreeAndBuilding.domeRat = 0;
TreeAndBuilding.numChild = 4;
TreeAndBuilding.childRadius = new float[] {.2f,.4f};
TreeAndBuilding.childHeight = new float[]{.2f,.4f};
TreeAndBuilding.segments = new int[]{18,4};
TreeAndBuilding.segmentLength = new float[]{3.0f,0};
TreeAndBuilding.upCurve = new float[]{20,0};
TreeAndBuilding.maxTurn = new float[]{10,0};
TreeAndBuilding.branchChance = new float[]{.6f,0};
TreeAndBuilding.branchDeviation = new float[]{20,0};
TreeAndBuilding.leafDensity = new int[]{4,7};
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
numClouds = 100;
}
void Dubstep(){
// hueRange= 120;
// minSat = .5f;
// maxSat = .9f;
minVal = .7f;
maxVal = .9f;
treeMax = 1;
treeSize = 1;
buildingMax = 4;
buildingSize = 4;
treeLeaves = false;
leaf_density = .9f;
rain = true;
equilibrium = 2;
TreeAndBuilding.buildingHeight = 1;
TreeAndBuilding.expandChance = .1f;
TreeAndBuilding.windows = .5f;
TreeAndBuilding.dome = true;
TreeAndBuilding.domeRat = .4f;
TreeAndBuilding.numChild = 4;
TreeAndBuilding.childRadius = new float[]{.6f,1};
TreeAndBuilding.childHeight = new float[]{.2f,.3f};
TreeAndBuilding.segments = new int[]{14,4};
TreeAndBuilding.segmentLength = new float[]{1.25f,0};
TreeAndBuilding.upCurve = new float[]{.8f,.3f};
TreeAndBuilding.maxTurn = new float[]{10,0};
TreeAndBuilding.branchChance = new float[]{.5f,0};
TreeAndBuilding.branchDeviation = new float[]{12,0};
TreeAndBuilding.leafDensity = new int[]{4,7};
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
cloudScene = CloudsToy.TypePreset.Sunrise;
numClouds = 100;
}
void House(){
// hueRange= 120;
// minSat = .7f;
// maxSat = 1;
minVal = .4f;
maxVal = 1;
treeMax = 1;
treeSize = 5;
buildingMax = 2;
buildingSize = 2;
treeLeaves = true;
leaf_density = .5f;
rain = false;
equilibrium = 1.5f;
TreeAndBuilding.buildingHeight = 1;
TreeAndBuilding.expandChance = .2f;
TreeAndBuilding.windows = .5f;
TreeAndBuilding.dome = false;
TreeAndBuilding.domeRat = 0;
TreeAndBuilding.numChild = 0;
TreeAndBuilding.childRadius = new float[]{0,0};
TreeAndBuilding.childHeight = new float[]{0,0};
TreeAndBuilding.segments = new int[]{14,4};
TreeAndBuilding.segmentLength = new float[]{3.0f,0};
TreeAndBuilding.upCurve = new float[]{.75f,.3f};
TreeAndBuilding.maxTurn = new float[]{10,0};
TreeAndBuilding.branchChance = new float[]{.7f,0};
TreeAndBuilding.branchDeviation = new float[]{0,0};
TreeAndBuilding.leafDensity = new int[]{4,7};
numClouds = 100;
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
}
void Metal(){
// hueRange= 20;
// minSat = .3f;
// maxSat = .4f;
minVal = 0;
maxVal = .2f;
treeMax = 3;
treeSize = 5;
buildingMax = 5;
buildingSize = 3;
treeLeaves = false;
leaf_density = 0;
rain = true;
equilibrium = 2.5f;
TreeAndBuilding.buildingHeight = 5;
TreeAndBuilding.expandChance = .1f;
TreeAndBuilding.windows = .01f;
TreeAndBuilding.dome = false;
TreeAndBuilding.domeRat = 0;
TreeAndBuilding.numChild = 0;
TreeAndBuilding.childRadius = new float[]{0,0};
TreeAndBuilding.childHeight = new float[]{0,0};
TreeAndBuilding.segments = new int[]{25,4};
TreeAndBuilding.segmentLength = new float[]{2.0f,0};
TreeAndBuilding.upCurve = new float[]{.99f,0};
TreeAndBuilding.maxTurn = new float[]{10,0};
TreeAndBuilding.branchChance = new float[]{.3f,0};
TreeAndBuilding.branchDeviation = new float[]{0,0};
TreeAndBuilding.leafDensity = new int[]{0,0};
cloudScene = CloudsToy.TypePreset.Stormy;
numClouds = 210;
waterLevel = .7f;
clouds.GetComponent<CloudsToy> ().CloudColor = Color.black;
}
void Rap(){
// hueRange = 10;
// minSat = 0;
// maxSat = .2f;
minVal = 0;
maxVal = .2f;
treeMax = 0;
treeSize = 0;
buildingMax = 4;
buildingSize = 4;
treeLeaves = false;
caves = true;
leaf_density = 0;
rain = false;
equilibrium = 1;
waterLevel = .8f;
TreeAndBuilding.buildingHeight = 3;
TreeAndBuilding.expandChance = .05f;
TreeAndBuilding.windows = .3f;
TreeAndBuilding.dome = false;
TreeAndBuilding.domeRat = 0;
TreeAndBuilding.numChild = 0;
TreeAndBuilding.childRadius = new float[]{0,0};
TreeAndBuilding.childHeight = new float[] {0,0};
TreeAndBuilding.segments = new int[]{20,4};
TreeAndBuilding.segmentLength = new float[]{2.0f,0};
TreeAndBuilding.upCurve = new float[]{.9f,0};
TreeAndBuilding.maxTurn = new float[]{0,0};
TreeAndBuilding.branchChance = new float[]{.3f,0};
TreeAndBuilding.branchDeviation = new float[]{0,0};
TreeAndBuilding.leafDensity = new int[]{4,7};
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
numClouds =150;
}
void Reggae(){
// hueRange = 10;
// minSat = .5f;
// maxSat = .7f;
minVal = .7f;
maxVal = .8f;
treeMax = 5;
treeSize = 3;
buildingMax = 1;
buildingSize = 2;
treeLeaves = true;
leaf_density = 1;
rain = false;
TreeAndBuilding.buildingHeight = 1;
TreeAndBuilding.expandChance = .4f;
TreeAndBuilding.windows = .1f;
TreeAndBuilding.dome = true;
TreeAndBuilding.domeRat = .4f;
TreeAndBuilding.numChild = 0;
TreeAndBuilding.childRadius = new float[]{0,0};
TreeAndBuilding.childHeight = new float[] {0,0};
TreeAndBuilding.segments = new int[]{20,6};
TreeAndBuilding.segmentLength = new float[]{2.0f,0};
TreeAndBuilding.upCurve = new float[]{.75f,0};
TreeAndBuilding.maxTurn = new float[]{25,0};
TreeAndBuilding.branchChance = new float[]{.8f,0};
TreeAndBuilding.branchDeviation = new float[]{25,0};
TreeAndBuilding.leafDensity = new int[]{8,9};
numClouds = 25;
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
}
void Rock () {
minVal = .7f;
maxVal = .8f;
treeMax = 5;
treeSize = 3;
buildingMax = 1;
buildingSize = 2;
treeLeaves = true;
leaf_density = 1;
rain = false;
equilibrium = 2.5f;
CubeThreader.rockiness = 2.5f;
TreeAndBuilding.buildingHeight = 2;
TreeAndBuilding.expandChance = .15f;
TreeAndBuilding.windows = .2f;
TreeAndBuilding.dome = true;
TreeAndBuilding.domeRat = .2f;
TreeAndBuilding.numChild = 0;
TreeAndBuilding.childRadius = new float[] {0,0};
TreeAndBuilding.childHeight = new float[] {0,0};
TreeAndBuilding.segments = new int[]{10,3};
TreeAndBuilding.segmentLength = new float[]{3.0f,0};
TreeAndBuilding.upCurve = new float[]{.9f,0};
TreeAndBuilding.maxTurn = new float[]{2,0};
TreeAndBuilding.branchChance = new float[]{.3f,0};
TreeAndBuilding.branchDeviation = new float[]{0,0};
TreeAndBuilding.leafDensity = new int[]{4,7};
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
numClouds = 75;
}
void Trance(){
// hueRange= 90;
// minSat = .4f;
// maxSat = .8f;
minVal = .4f;
maxVal = .8f;
treeMax = 5;
treeSize = 2;
buildingMax = 1;
buildingSize = 1;
treeLeaves = true;
leaf_density = .7f;
rain = true;
equilibrium = 1.5f;
TreeAndBuilding.buildingHeight = 1;
TreeAndBuilding.expandChance = 0;
TreeAndBuilding.windows = .5f;
TreeAndBuilding.dome = false;
TreeAndBuilding.domeRat = 0;
TreeAndBuilding.numChild = 2;
TreeAndBuilding.childRadius = new float[]{.1f,.2f};
TreeAndBuilding.childHeight = new float[] {1.5f,2f};
TreeAndBuilding.segments = new int[]{10,3};
TreeAndBuilding.segmentLength = new float[]{2.0f,0};
TreeAndBuilding.upCurve = new float[]{.6f,0};
TreeAndBuilding.maxTurn = new float[]{25,0};
TreeAndBuilding.branchChance = new float[]{.4f,0};
TreeAndBuilding.branchDeviation = new float[]{15,0};
TreeAndBuilding.leafDensity = new int[]{4,7};
clouds.GetComponent<CloudsToy> ().CloudColor = Color.white;
numClouds = 100;
}
IEnumerator findGenre(){
text.text = "Analyzing Genre";
if (pathName != null) {
yield return StartCoroutine (getGenre.Request(pathName));
genre = getGenre.genre;
}
if (genre == SongGenre.Genre.Unknown) {
Debug.Log ("backup");
yield return StartCoroutine(backupGenre.Request(pathName));
genre = backupGenre.genre;
}
switch (genre)
{
case SongGenre.Genre.Alternative:
Alternative();
break;
case SongGenre.Genre.Ambient:
Ambient();
break;
case SongGenre.Genre.Classical:
Ambient();
break;
case SongGenre.Genre.Folk:
Country();
break;
case SongGenre.Genre.Electronic:
Electronic();
break;
case SongGenre.Genre.House:
House();
break;
case SongGenre.Genre.Dubstep:
Dubstep();
break;
case SongGenre.Genre.Rap:
Rap();
break;
case SongGenre.Genre.Reggae:
Reggae ();
break;
case SongGenre.Genre.Metal:
Metal();
break;
case SongGenre.Genre.Trance:
Trance();
break;
case SongGenre.Genre.Rock:
Alternative();
break;
case SongGenre.Genre.Unknown:
Rock ();
break;
default:
Electronic();
break;
}
StartCoroutine(waterInitializer());
yield return StartCoroutine("Generate");
}
IEnumerator SetInitial(){
setWater ();
fogSet();
yield return null;
}
void setWater(){
//Set the initial water Color and the initial water fog color
Color color = Color.blue;
float height = 20f;
Color color_under = Color.blue;
GameObject water = Instantiate (waterTop);
GameObject water_B = Instantiate (waterBottom);
water.transform.position = new Vector3(water.transform.position.x, height, water.transform.position.z);
water_B.transform.position = new Vector3(water.transform.position.x, height, water.transform.position.z);
float fog_density = .03f;
float water_height = -10f;
waterTop.GetComponent<MeshRenderer> ().sharedMaterial.SetColor ("_Color", color);
UnderWater under = new UnderWater(color_under,fog_density,water_height);
}
void fogSet(){
FogControl f = camera.GetComponent<FogControl> () as FogControl;
//Set whether there is fog and the color and such, can update the color if there is fog
f.fog = false;
f.fog_color = Color.gray;
f.fog_density = 0;
}
/*
IEnumerator VolumeBased(){
int every = 1;
source.clip = song;
source.Play ();
float zeroTime = Time.time;
float num = 0;
foreach (float f in volumes) {
StartCoroutine (LandColor(f));
StartCoroutine(TreeColor (f));
StartCoroutine(BuildingColor(f));
yield return new WaitForSeconds (sampleTime);
num++;
}
yield return null;
}
*/
/*
IEnumerator LandColor(float f){
Color color = basicChange (f, baseCubeColor);
CubeGenerator.GetComponent<MeshRenderer> ().sharedMaterial.SetColor ("_Color", color);
yield return new WaitForSeconds (.05f);
}
IEnumerator TreeColor(float f){
Color color= basicChange(f, baseTreeColor);
trees.GetComponent<MeshRenderer> ().sharedMaterial.SetColor ("_Color", color);
yield return new WaitForSeconds (.05f);
}
IEnumerator BuildingColor(float f){
Color color = basicChange (f, baseBuildingColor);
buildings.GetComponent<MeshRenderer> ().sharedMaterial.SetColor ("_Color", color);
yield return new WaitForSeconds (.05f);
}
*/
/* These methods are used to change the colors based on the volume*/
// Color basicChange(float vol, float ch,Color c){
// Color color = c;
// float incr = 1;
// float h = 1;
// float s = 1;
// float v = 1;
// //HSV colors allow you to keep the brightness the same while changing the color
// ColorToHSV (color, out h, out s, out v);
// s = vol / maxVol;
// color = ColorFromHSV(h,s,v,1);
// return color;
// }
//
// Color rainbowChange(float vol,float ch, Color c){
// Color color = c;
// float h = 1;
// float s = 1;
// float v = 1;
// //HSV colors allow you to keep the brightness the same while changing the color
// ColorToHSV (color,out h, out s, out v);
//
// c = ColorFromHSV (h, s, v,1);
// return c;
}
// public static Color ColorFromHSV(float h, float s, float v, float a = 1)
// {
// // no saturation, we can return the value across the board (grayscale)
// if (s == 0)
// return new Color(v, v, v, a);
//
// // which chunk of the rainbow are we in?
// float sector = h / 60;
//
// // split across the decimal (ie 3.87 into 3 and 0.87)
// int i = (int)sector;
// float f = sector - i;
//
// float p = v * (1 - s);
// float q = v * (1 - s * f);
// float t = v * (1 - s * (1 - f));
//
// // build our rgb color
// Color color = new Color(0, 0, 0, a);
//
// switch(i)
// {
// case 0:
// color.r = v;
// color.g = t;
// color.b = p;
// break;
//
// case 1:
// color.r = q;
// color.g = v;
// color.b = p;
// break;
//
// case 2:
// color.r = p;
// color.g = v;
// color.b = t;
// break;
//
// case 3:
// color.r = p;
// color.g = q;
// color.b = v;
// break;
//
// case 4:
// color.r = t;
// color.g = p;
// color.b = v;
// break;
//
// default:
// color.r = v;
// color.g = p;
// color.b = q;
// break;
// }
//
// return color;
// }
//
// public static void ColorToHSV(Color color, out float h, out float s, out float v)
// {
// float min = Mathf.Min(Mathf.Min(color.r, color.g), color.b);
// float max = Mathf.Max(Mathf.Max(color.r, color.g), color.b);
// float delta = max - min;
//
// // value is our max color
// v = max;
//
// // saturation is percent of max
// if (!Mathf.Approximately(max, 0))
// s = delta / max;
// else
// {
// // all colors are zero, no saturation and hue is undefined
// s = 0;
// h = -1;
// return;
// }
//
// // grayscale image if min and max are the same
// if (Mathf.Approximately(min, max))
// {
// v = max;
// s = 0;
// h = -1;
// return;
// }
//
// // hue depends which color is max (this creates a rainbow effect)
// if (color.r == max)
// h = (color.g - color.b) / delta; // between yellow & magenta
// else if (color.g == max)
// h = 2 + (color.b - color.r) / delta; // between cyan & yellow
// else
// h = 4 + (color.r - color.g) / delta; // between magenta & cyan
//
// // turn hue into 0-360 degrees
// h *= 60;
// if (h < 0 )
// h += 360;
// }
//}