/// <summary> /// たまをキャッシュ /// </summary> public void InitTamaCache(PlayFieldSetting setting, Transform transform) { if (tamaCache != null) { return; } var count = setting.columnsCount * setting.rowsCount + 4; tamaCache = new Stack <TamaData>(count); for (int i = 0; i < count; ++i) { var s = GameObject.Instantiate <SpriteRenderer>(tamaPrefab); //s.sprite = atlas.GetSprite("l01"); s.transform.parent = transform; s.transform.localPosition = Vector3.zero; s.transform.localScale = Vector3.one; s.enabled = false; var e = s.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>(); var tama = new TamaData() { Sprite = s, Spark = e }; tamaCache.Push(tama); } }
/// <summary> /// たまのペアを生成 /// </summary> public void GenerateTamaPair(PlayFieldSetting setting, TamaData[] pair) { // たまをキャッシュから取得し色を決める pair[0] = GenerateTama(); pair[1] = GenerateTama(); // たまの組み合わせを決める TamaStateType mt, st; GenerateTamaPairType(setting, out mt, out st); pair[0].State = mt; pair[1].State = st; // たまのスプライトを設定する SetupTamaSprite(pair[0]); SetupTamaSprite(pair[1]); // たま生成数カウント ++generatedCount; }
/// <summary> /// たまの組み合わせを決める /// </summary> /// <returns></returns> private void GenerateTamaPairType(PlayFieldSetting setting, out TamaStateType mainState, out TamaStateType subState) { int sum = setting.tamaPairRate.Sum(); int r = tamaRand.Next(sum); TamaPairType pair = TamaPairType.LL; for (int i = 0; i < setting.tamaPairRate.Length; ++i) { int rate = setting.tamaPairRate[i]; if (r < rate) { pair = (TamaPairType)i; break; } r -= rate; } switch (pair) { case TamaPairType.LL: mainState = TamaStateType.Large; subState = TamaStateType.Large; break; case TamaPairType.LS: mainState = TamaStateType.Large; subState = TamaStateType.Small; break; case TamaPairType.SS: mainState = TamaStateType.Small; subState = TamaStateType.Small; break; default: throw new System.ArgumentException(); } }
/// <summary> /// スプライトをキャッシュ /// </summary> public void InitTamaSpriteCache(PlayFieldSetting setting) { tamaSprites = CreateSpriteCache(setting.tamaSpriteNames); tamaSparkSprites = CreateSpriteCache(setting.sparkSpriteNames); }
/// <summary> /// たま生成乱数の初期化 /// </summary> public void InitTamaRandom(PlayFieldSetting setting) { InitTamaRandom(setting.tamaRandomSeed); }