/// <summary> /// 随机出一个木块 /// </summary> public void CreateOneBlock() { while (true) { int x = Random.Range(0, field.width); int y = Random.Range(0, field.height); if (field.GetSlot(x, y)) { int id = field.GetChip(x, y); if (id >= 0 && id != 9 && (field.blocks[x, y] == 0 || field.blocks[x, y] == 5)) { Slot s = SlotManager.Instance.FindSlot(x, y); if (s != null && s.GetChip() && !s.Block && !s.IsGenerator) { s.GetChip().HideChip(false); field.blocks[x, y] = 1; GameObject o = ResourceMgr.Instance.LoadAndInstanceGameObjectFromPreload(Block.prefabName); o.name = "Block_" + x + "x" + y; // o.transform.parent = s.transform; o.transform.SetParent(s.transform, false); o.transform.position = s.transform.position; Block b = o.GetComponent <Block>(); s.SetBlock(b); b.slot = s; b.level = field.blocks[x, y]; b.Initialize(); break; } } } } }
/// <summary> /// 生成两个无法消除木块 /// </summary> public void CreateNotDestroyableBlcok() { int createCount = 2; while (createCount > 0) { int x = Random.Range(0, field.width); int y = Random.Range(0, field.height); if (field.GetSlot(x, y)) { Slot s = SlotManager.Instance.FindSlot(x, y); if (s == null || s.IsGenerator) { continue; } int blockId = field.blocks[x, y]; if (blockId >= 6 && blockId <= 10) { //boss continue; } field.blocks[x, y] = 10; if (s.GetChip()) { s.GetChip().HideChip(false); } // else if(s.Block) // { // s.SetBlock(null); // s.gameObject.SetActive(false); // } s = SlotManager.Instance.FindSlot(x, y); GameObject o = ResourceMgr.Instance.LoadAndInstanceGameObjectFromPreload(FightDefine.SpecialBlock); o.transform.position = s.transform.position; o.name = "SpecialBlock_" + x + "x" + y; // o.transform.parent = s.transform; o.transform.SetParent(s.transform, false); o.transform.position = s.transform.position; SpecialBlock boss = o.GetComponent <SpecialBlock>(); s.SetBlock(boss); boss.slot = s; boss.Initialize(); s.gameObject.SetActive(false); createCount--; } } }
public static void Grow() { List <Slot> slots = new List <Slot> (); foreach (Weed weed in all) { foreach (Side side in Utils.straightSides) { if (weed.slot[side] && !weed.slot[side].Block && !(weed.slot[side].GetChip() && weed.slot[side].GetChip().chipType == "SugarChip")) { slots.Add(weed.slot[side]); } } } while (seed > 0) { if (slots.Count == 0) { return; } Slot target = slots[Random.Range(0, slots.Count)]; slots.Remove(target); if (target.GetChip()) { target.GetChip().HideChip(false); } Weed newWeed = ResourceMgr.Instance.LoadAndInstanceGameObjectFromPreload(prefabName).GetComponent <Weed>(); newWeed.transform.position = target.transform.position; newWeed.name = "New_Weed"; newWeed.transform.SetParent(target.transform, false); target.SetBlock(newWeed); newWeed.slot = target; // AudioAssistant.Shot("WeedCreate"); newWeed.Initialize(); seed--; } }