// Use this for initialization public override void Init() { go = GameObject.Find("Pinball(Clone)"); if(go == null) { go = GameObject.Instantiate(Resources.Load("Prefabs/States/Pinball")) as GameObject; thisChapter = StateChapterSelect.Instance.Chapters[ID]; m_PinballMono = go.GetComponent<PinballMono>(); for (int i = 0; i < m_PinballMono.Levels.Length; i++) { m_PinballMono.Levels[i].SetActive(i == StateChapterSelect.Instance.Chapters[ID].LevelNumber); } if(thisChapter.Completed) return; if(ID == 0) { SetBucketPositions(); } else { RandomizeBucketPosition(); } m_PinballMono.SetFrameParent(true); m_PinballMono.SetCannonState(true); } }
public void StartPinball() { if(m_challenge_go != null) { UnityEngine.GameObject.Destroy(m_challenge_go); StatePinball.Instance.Init(); m_pinball_go = GameObject.Find("Pinball(Clone)"); pm = StatePinball.Instance.m_PinballMono; pm.SetCannonState(false); pm.SetFrameParent(false); pm.ActivateAnimationIn(); } }
// Use this for initialization public override void Init() { GameObject go = GameObject.Find("Pinball(Clone)"); if(go == null) { go = GameObject.Instantiate(Resources.Load("Prefabs/States/Pinball")) as GameObject; Chapter thisChapter = StateChapterSelect.Instance.Chapters[ID]; m_PinballMono = go.GetComponent<PinballMono>(); for (int i = 0; i < m_PinballMono.Levels.Length; i++) { m_PinballMono.Levels[i].SetActive(i == StateChapterSelect.Instance.Chapters[ID].LevelNumber); } List<int> intList = new List<int>(); for (int i = 0; i < thisChapter.JigsawPeicesUnlocked.Length; i++) { if (thisChapter.JigsawPeicesUnlocked[i] != 1) { intList.Add(i); } } while (intList.Count > 5) { intList.RemoveAt(Random.Range(0, intList.Count - 1)); } //intList now ordered list of 5 elements or less int[] BucketsShuffled; { List<int> BucketIs = new List<int>(new int[] { 0, 1, 2, 3, 4 }); BucketsShuffled = new int[BucketIs.Count]; int count = BucketIs.Count; for (int i = 0; i < count; i++) { int iToRemove = Random.Range(0, BucketIs.Count); Debug.Log("Removed : [" + iToRemove + "|"+BucketIs[iToRemove]+"];"); BucketsShuffled[i] = BucketIs[iToRemove]; BucketIs.RemoveAt(iToRemove); } } //BucketsShuffled now randomised array of 1 through 5 for (int i = 0; i < intList.Count; i++) { //m_PinballMono.Buckets[BucketsShuffled[i]].JigsawPeiceToUnlock = intList[i]; //m_PinballMono.Buckets[BucketsShuffled[i]].LevelToUnlock = ID + 1; m_PinballMono.Buckets[BucketsShuffled[i]] .Init(intList[i], StateChapterSelect.Instance.Chapters[ID].JigsawPeicesUnlocked[intList[i]], ID + 1); int div = intList[i] / 4; int mod = intList[i] % 4; string prefabstring = "Prefabs/JigsawPieces/" + mod + "_" + div; Debug.Log(i + "| Shuffle : [" + BucketsShuffled[i] + "]; Piece : [" + intList[i] + "]; Jigsaw Prefab Path : [" + prefabstring + "];"); GameObject jigsawPieceGO = GameObject.Instantiate(Resources.Load(prefabstring)) as GameObject; RectTransform jigsawPieceTransform = jigsawPieceGO.GetComponent<RectTransform>(); if (jigsawPieceTransform.childCount != 0) { Image img = jigsawPieceTransform.GetChild(0).GetComponent<Image>(); if (img != null) { img.sprite = Resources.Load<Sprite>("PinballBackgrounds/" + StateChapterSelect.Instance.Chapters[ID].nextLvlPictureName); } } jigsawPieceTransform.SetParent(m_PinballMono.JigsawParents[BucketsShuffled[i]].transform,false); //jigsawPieceTransform.parent = m_PinballMono.JigsawParents[BucketsShuffled[i]].transform; jigsawPieceTransform.localPosition = Vector2.zero;//m_PinballMono.JigsawParents[BucketsShuffled[i]].GetComponent<RectTransform>().localPosition; jigsawPieceTransform.localScale = Vector2.one * 0.015f; m_PinballMono.SetFrameParent(true); m_PinballMono.SetCannonState(true); } } }