@@ -15,6 +15,7 @@ public class GameManager : MonoBehaviour
1515 private static GameObject _cubePrefab ;
1616 private static GameObject _codeLinePanel ;
1717 private static GameObject _menu ;
18+ private static Material _defaultMat ;
1819 private static GameManager _instance ;
1920 public Slider min ;
2021 public Slider max ;
@@ -30,6 +31,7 @@ private void Awake()
3031 _cubePrefab = Resources . Load < GameObject > ( "Prefabs/CubeContainer" ) ;
3132 _codeLinePanel = GameObject . FindWithTag ( "CodeLinePanel" ) ;
3233 _menu = GameObject . Find ( "SliderMenu" ) ;
34+ _defaultMat = Resources . Load < Material > ( "Materials/Cube" ) ;
3335 _instance = this ;
3436 }
3537
@@ -48,11 +50,18 @@ private void Update()
4850 public void GenObjects ( )
4951 {
5052 Rest ( ) ;
51- GenObjectsFromArray ( GetUniqueRandomArray ( ( int ) min . value , ( int ) max . value , ( int ) count . value ) ) ;
53+ CompleteBinaryTree . ClearTree ( ) ;
54+ GenObjectsFromArray ( GetUniqueRandomArray ( ( int ) min . value , ( int ) max . value , ( int ) count . value ) , false ) ;
5255 }
5356
54- public static void GenObjectsFromArray ( int [ ] arr )
57+ public static void GenObjectsFromArray ( int [ ] arr , bool reuse = true )
5558 {
59+ if ( reuse )
60+ {
61+ Reuse ( arr ) ;
62+ return ;
63+ }
64+
5665 Destroy ( _space ) ;
5766 _space = Instantiate ( _spacePrefab ) ;
5867
@@ -69,6 +78,17 @@ public static void GenObjectsFromArray( int[] arr )
6978 }
7079 }
7180
81+ private static void Reuse ( int [ ] arr )
82+ {
83+ Numbers = arr ;
84+ for ( var i = 0 ; i < Numbers . Length ; i ++ )
85+ {
86+ Cubes [ i ] . transform . position = new Vector3 ( i * Config . HorizontalGap , 0f , 0f ) ;
87+ Cubes [ i ] . GetComponent < CubeController > ( ) . SetValue ( Numbers [ i ] ) ;
88+ CubeController . SetPillarMaterial ( Cubes [ i ] , _defaultMat ) ;
89+ }
90+ }
91+
7292 private static int [ ] GetUniqueRandomArray ( int minNum , int maxNum , int count )
7393 {
7494 if ( maxNum - minNum < count )
@@ -100,7 +120,6 @@ public static void EnableButtons( bool enable )
100120
101121 public static void Rest ( )
102122 {
103- CompleteBinaryTree . ClearTree ( ) ;
104123 PerformanceQueue . Course . Clear ( ) ;
105124 PerformanceQueue . Rewind . Clear ( ) ;
106125 CubeController . courseIndex = 0 ;
0 commit comments