private void OnCreateButtonClick() { SceneItem[] AllItems = scene.GetComponentsInChildren <SceneItem>(); List <SceneItem> AllItemList = new List <SceneItem>(AllItems); foreach (SceneItem item in AllItemList) { if (item.transform == scene) { continue; } Transform[] placeHolders = item.GetComponentsInChildren <Transform>(); int counter = placeHolders.Length + 1; for (int i = 0; i < 10; i++) { foreach (Transform placeHolder in placeHolders) { if (placeHolder == item.transform || placeHolder.parent != item.transform) { continue; } GameObject newPlaceHolder = Instantiate(placeHolder.gameObject, item.transform) as GameObject; newPlaceHolder.name = item.name + "_" + counter; SpriteRenderer[] images = newPlaceHolder.GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer image in images) { string resourceName = SceneDescriptorsHelper.GetResourceName(AssetDatabase.GetAssetPath(image.sprite)) + UnityEngine.Random.Range(2, 21); Sprite[] spritesAll = Resources.LoadAll <Sprite>(resourceName); Sprite sprite = spritesAll.FirstOrDefault(x => x.name == image.sprite.name); image.sprite = sprite; } counter++; } } } for (int i = 0; i < 10; i++) { foreach (SceneItem item in AllItemList) { if (item.transform == scene) { continue; } GameObject newitem = Instantiate(item.gameObject, scene.transform) as GameObject; newitem.name = item.name + i; } } }
public Sprite Get(string assetPath, string spriteName) { string resourceName = SceneDescriptorsHelper.GetResourceName(assetPath); if (StringHelper.IsNullOrWhitespace(resourceName) || StringHelper.IsNullOrWhitespace(spriteName)) { return(null); } if (!dictionary.ContainsKey(resourceName)) { Put(resourceName); } Sprite sprite = dictionary[resourceName].FirstOrDefault(x => x.name == spriteName); if (sprite == null) { Debug.LogError("Error sprite in asset : " + spriteName + " does not exist!"); return(null); } return(sprite); }