void Start() { //var listClothes = dataController.GetClothesByType("Pants"); var listClothes = DataController.Instance.GetClothesByType("Pants"); //var listClothes = dataController.GetClothesByType("Shirts"); //var listClothes = dataController.GetClothesByType("Hats"); //var listClothes = dataController.GetClothesByType("Shoes"); //var listClothes = dataController.GetClothesByType("Overalls"); //var listClothes = dataController.GetClothesByType("Accesories"); foreach (var cloth in listClothes) { CarouselItemBlock clone = Instantiate(theBlock, transform.position, transform.rotation); clone.onItemUpdated = HandleOnItemUpdated; StartCoroutine(DataController.Instance.LoadClothSprite(cloth, clone)); //clone.SetSprite(sprite); blocks.Add(clone); Debug.Log("Cloth added: " + cloth.Name); } list.onItemLoaded = HandleOnItemLoadedHandler; // called when an item is recycled list.onItemSelected = HandleOnItemSelectedHandler; // called when the item is selected list.Create(blocks.Count, listItem); // create the list with a number and a prefab list.gameObject.SetActive(true); }
public IEnumerable <ValidationError> Validate(CarouselItemBlock instance) { if (!(ContentReference.IsNullOrEmpty(instance.ImageFile) ^ string.IsNullOrWhiteSpace(instance.YouTubeId))) { return(new[] { new ValidationError { ErrorMessage = "Either Youtube ID or Image but not both must be specified", PropertyName = instance.GetPropertyName(p => p.ImageFile), Severity = ValidationErrorSeverity.Error, RelatedProperties = new [] { instance.GetPropertyName(p => p.YouTubeId) } } }); } return(Enumerable.Empty <ValidationError>()); }
public IEnumerator LoadClothSprite(CollectionItemData cloth, CarouselItemBlock block) { string filePath = Application.streamingAssetsPath + currentCollection.Path + cloth.Id + ".png"; // Load a PNG or JPG image from disk to a Texture2D, assign this texture to a new sprite and return its reference Sprite newSprite = new Sprite(); float PixelsPerUnit = 100.0f; Texture2D spriteTexture = new Texture2D(2, 2); byte[] fileData = null; Debug.Log("UNITY: (Start LoadClothSprite) "); yield return(StartCoroutine(LoadTexture(filePath, result => spriteTexture = result))); newSprite = Sprite.Create(spriteTexture, new Rect(0, 0, spriteTexture.width, spriteTexture.height), new Vector2(0, 0), PixelsPerUnit); newSprite.name = "Loaded sprite"; block.SetSprite(newSprite); Debug.Log("UNITY: (End LoadClothSprite) "); }