@@ -21,17 +21,29 @@ public void Spawn()
21
21
Delete ( ) ;
22
22
UiValues = new Dictionary < string , float > ( ) ;
23
23
sliders . ForEach ( slider => UiValues . Add ( slider . name , slider . value ) ) ;
24
- root = new TreeNode ( 50 , new Vector3 ( - UiValues [ "GalaxyRadius" ] * 3 / 2f , - UiValues [ "GalaxyRadius" ] * 3 / 2f ) , UiValues [ "GalaxyRadius" ] * 3f ) ;
24
+
25
+ float galaxyRadius = UiValues [ "GalaxyRadius" ] ;
26
+ float galaxyThickness = UiValues [ "GalaxyThickness" ] ;
27
+ float starInitialVelocity = UiValues [ "StarInitialVelocity" ] ;
28
+ int starCount = ( int ) UiValues [ "StarCount" ] ;
29
+
30
+ root = new TreeNode ( 50 , new Vector3 ( - galaxyRadius * 3 / 2f , - galaxyRadius * 3 / 2f ) , galaxyRadius * 3f ) ;
25
31
List < Star > stars = new List < Star > ( ) ;
26
- for ( int i = 0 ; i < UiValues [ "StarCount" ] ; i ++ )
32
+
33
+ for ( int i = 0 ; i < starCount ; i ++ )
27
34
{
28
- stars . Add ( Instantiate ( starPrefab , DiscPos ( Random . Range ( 0f , 360f ) , Random . Range ( - UiValues [ "GalaxyThickness" ] , UiValues [ "GalaxyThickness" ] ) , Random . Range ( - UiValues [ "GalaxyRadius" ] , UiValues [ "GalaxyRadius" ] ) ) , starPrefab . transform . rotation , transform ) ) ;
29
- stars [ i ] . velocity = new Vector3 ( ( stars [ i ] . transform . position . x * Mathf . Cos ( 90f ) ) - ( stars [ i ] . transform . position . z * Mathf . Sin ( 90f ) ) , 0f , ( stars [ i ] . transform . position . z * Mathf . Cos ( 90f ) ) + ( stars [ i ] . transform . position . x * Mathf . Sin ( 90f ) ) ) . normalized * UiValues [ "StarInitialVelocity" ] ;
30
- root . InsertToNode ( stars [ i ] ) ;
35
+ Vector3 randomPosition = DiscPos ( Random . Range ( 0f , 360f ) , Random . Range ( - galaxyThickness , galaxyThickness ) , Random . Range ( - galaxyRadius , galaxyRadius ) ) ;
36
+ Quaternion rotation = starPrefab . transform . rotation ;
37
+
38
+ Star star = Instantiate ( starPrefab , randomPosition , rotation , transform ) ;
39
+ star . velocity = new Vector3 ( ( star . transform . position . x * Mathf . Cos ( 90f ) ) - ( star . transform . position . z * Mathf . Sin ( 90f ) ) , Random . Range ( - 1f , 1f ) , ( star . transform . position . z * Mathf . Cos ( 90f ) ) + ( star . transform . position . x * Mathf . Sin ( 90f ) ) ) . normalized * starInitialVelocity ;
40
+
41
+ stars . Add ( star ) ;
42
+ root . InsertToNode ( star ) ;
31
43
}
32
- galaxy = new Galaxy ( stars , UiValues [ "GalaxyRadius" ] , UiValues [ "GalaxyRadius" ] , UiValues [ "StarInitialVelocity" ] ) ;
33
- simulationStarted = true ;
34
44
45
+ galaxy = new Galaxy ( stars , galaxyRadius , galaxyRadius , starInitialVelocity ) ;
46
+ simulationStarted = true ;
35
47
}
36
48
public void Delete ( )
37
49
{
@@ -60,7 +72,7 @@ public void Update()
60
72
setStarColor ( star ) ;
61
73
}
62
74
root . ComputeMassDistribution ( UiValues [ "BlackHoleMass" ] ) ;
63
- // center_galaxy();
75
+ // center_galaxy();
64
76
displayInfoCount ( ) ;
65
77
66
78
}
0 commit comments