static void ClickToAddPattern() { GameObject PatternObj = GameObject.Find("PatternManager"); if (PatternObj != null) { Patternmanager patternmanager = PatternObj.GetComponent <Patternmanager>(); if (Selection.gameObjects.Length == 1) { Transform currenChild = Selection.gameObjects[0].transform.Find("Root"); if (currenChild != null) { Pattern pattern = new Pattern(); foreach (Transform child in currenChild) { var prefab = UnityEditor.PrefabUtility.GetPrefabParent(child.gameObject); if (prefab != null) { PrefabItem prefabItem = new PrefabItem { name = prefab.name, pos = child.localPosition }; pattern.ItemList.Add(prefabItem); } } patternmanager.PatternList.Add(pattern); } } } }
public void CreatItem(Transform parent) { Patternmanager patternmanager = Patternmanager.Instance; Pattern pattern = patternmanager.PatternList[Random.Range(0, patternmanager.PatternList.Count)]; if (pattern != null && pattern.ItemList.Count > 0) { foreach (var item in pattern.ItemList) { GameObject go = GameSetting.Instance.objectPool.GetObject(item.name, parent); go.transform.parent = parent; go.transform.localPosition = item.pos; } } }