Esempio n. 1
0
        public static void SetImage(int id, string key)
        {
            var go    = ObjectBuilder.Get(id);
            var image = go.GetComponentInChildren <Image>();

            if (image == null)
            {
                image = go.AddComponent <Image>();
            }
            if (key == null)
            {
                image.sprite = null;
            }
            else
            {
                var texture = StreamingAssetsDatabase.GetTexture(key);
                image.sprite = Sprite.Create(
                    texture,
                    new Rect(0, 0, texture.width, texture.height),
                    new Vector2(0.5f, 0.5f)
                    );
            }
        }
Esempio n. 2
0
        public static void SetTexture(int id, string textureKey)
        {
            var go = Get(id);
            var sr = go.GetComponentInChildren <SpriteRenderer>();

            if (sr == null)
            {
                sr = go.AddComponent <SpriteRenderer>();
            }
            if (textureKey == null)
            {
                sr.sprite = null;
            }
            else
            {
                var texture = StreamingAssetsDatabase.GetTexture(textureKey);
                sr.sprite = Sprite.Create(
                    texture,
                    new Rect(0, 0, texture.width, texture.height),
                    new Vector2(0.5f, 0.5f)
                    );
            }
        }