/// <summary> /// Get an inactive BallContainerController object. /// </summary> /// <returns></returns> public BallContainerController GetBallContainerControl() { //Find in the list BallContainerController ballContainerControl = listBallContainerControl.Where(a => !a.gameObject.activeInHierarchy).FirstOrDefault(); if (ballContainerControl == null) { //Did not find one -> create new one ballContainerControl = Instantiate(ballContainerControlPrefab, Vector3.zero, Quaternion.identity); ballContainerControl.gameObject.SetActive(false); listBallContainerControl.Add(ballContainerControl); } return(ballContainerControl); }
// Use this for initialization private void Start() { Application.targetFrameRate = 60; ViewManager.Instance.OnLoadingSceneDone(SceneManager.GetActiveScene().name); //Setup variables IsRevived = false; ForceTurn = 1; ballContainerSizeY = PoolManager.Instance.GetBallContainerControl().GetSizeY(); completedLevelEffectsTrans.gameObject.SetActive(false); //Set current level if (!PlayerPrefs.HasKey(PlayerPrefsKey.SAVED_LEVEL_PPK)) { PlayerPrefs.SetInt(PlayerPrefsKey.SAVED_LEVEL_PPK, 1); } //Load parameters CurrentLevel = (testingLevel != 0) ? testingLevel : PlayerPrefs.GetInt(PlayerPrefsKey.SAVED_LEVEL_PPK); foreach (LevelConfig o in listLevelConfig) { if (CurrentLevel == o.LevelNumber) { background = o.MusicClip; backgroundMaterial.SetColor("_TopColor", o.BackgroundTopColor); backgroundMaterial.SetColor("_BottomColor", o.BackgroundBottomColor); Vector3 currentstagePos = Vector3.zero; Material blockerMat = new Material(Shader.Find("EasyShader/Self Illumin Diffuse")); blockerMat.SetColor("_Color", o.BlockerColor); Material duplicatorMat = new Material(Shader.Find("EasyShader/Self Illumin Diffuse")); duplicatorMat.SetColor("_Color", o.DuplicatorColor); Material lockerMat = new Material(Shader.Find("EasyShader/Self Illumin Diffuse")); lockerMat.SetColor("_Color", o.LockerColor); Material ballContainerMat = new Material(Shader.Find("EasyShader/Self Illumin Diffuse")); ballContainerMat.SetColor("_Color", o.LockerColor); for (int i = 0; i < o.ListStageControlPrefab.Count; i++) { //Create the stage Quaternion quaternion = (i % 2 == 0) ? Quaternion.identity : Quaternion.Euler(new Vector3(0, 180f, 0)); StageController stageControl = Instantiate(o.ListStageControlPrefab[i], currentstagePos, quaternion); stageControl.transform.position = currentstagePos; stageControl.gameObject.SetActive(true); listStageControl.Add(stageControl); //Create the ball container object Vector3 ballContainerPos = stageControl.GetBottomPosition(); BallContainerController ballContainerControl = PoolManager.Instance.GetBallContainerControl(); ballContainerControl.transform.position = ballContainerPos; ballContainerControl.gameObject.SetActive(true); ballContainerControl.SetMaterial(ballContainerMat); listBallContainerControl.Add(ballContainerControl); //Set the position for complete level effects if (i == o.ListStageControlPrefab.Count - 1) { completedLevelEffectsTrans.position = ballContainerPos; } //Update stage position currentstagePos = stageControl.GetBottomPosition() + Vector3.down * (ballContainerSizeY + stageControl.GetSize().y / 2f); stageControl.SetBlockerMaterial(blockerMat); stageControl.SetDuplicatorMaterial(duplicatorMat); stageControl.SetLockerMaterial(lockerMat); } break; } } listStageControl[0].CreateBall(); previousStageControl = listStageControl[0]; listStageControl.RemoveAt(0); previousStageControl.OnSetup(); cRCheckingGameOver = StartCoroutine(CRCheckingGameOver()); PlayingGame(); }