/// <summary> /// 取得空的遊戲內套裝 /// </summary> /// <returns></returns> public MeatBallSet GetSetObject(SetType _setName) { MeatBallSet set = null; //確認資料池中是否已經有該套裝 if (dataPool.ContainsKey(_setName)) { //確認散件是否在使用中 for (int i = 0; i < objectPool[_setName].Count; i++) { if (objectPool[_setName][i].IsPartUsing) { continue; } //如果沒有任何一個在使用中的話在初始化函式後直接回傳 objectPool[_setName][i].ReuseAllParts(); return(objectPool[_setName][i]); } } set = GameObject.Instantiate(GetSet(_setName)); set.FindPartsSection(); set.InstantiateParts(); set.ReuseAllParts(); objectPool[_setName].Add(set); return(set); }
/// <summary> /// 取得套裝散件 /// </summary> /// <param name="_setName"></param> /// <param name="_type"></param> /// <returns></returns> protected MBSetPart GetPartGameObject(SetType _setName, MeatBall.SetPartType _type) { //如果原資料就沒有該部位了就回傳null if (dataPool[_setName].GetPartByEnum(_type) == null) { return(null); } Debug.Log("Search Suit"); MBSetPart part = null; //尋找該Dictionary for (int i = 0; i < objectPool[_setName].Count; i++) { //找出該套裝 part = objectPool[_setName][i].GetPartByEnum(_type); //如果此物件的該部位正在被使用就繼續找別的 if (part.IsThisUsing) { part = null; continue; } //沒在使用就指定該物件 break; } //整場物件都沒有空的部位就造新的套裝再取其物件 if (part == null) { MeatBallSet newSet = GameObject.Instantiate(GetSet(_setName)) as MeatBallSet; objectPool[_setName].Add(newSet); newSet.InstantiateParts(); part = newSet.GetPartByEnum(_type); } Debug.Log(part.name); //事前準備 part.ReuseGameObject(); //回傳該物件 return(part); }