D
D
Dmitry Korolev2018-07-17 18:11:35
Unity
Dmitry Korolev, 2018-07-17 18:11:35

How to get a sprite from a texture?

I had an array of sprites and I freely dragged the image asset into it, it was accepted as a sprite,
and now I rendered the collection in the inspector and specified in the objectfield
n.Obj = EditorGUILayout.ObjectField(n.Obj, typeof(UnityEngine.Object), false) as sprite;
and in this box I can't insert an image, but only a nested sprite in the image. as the project window shows a triangle on the asset, you press it and the image has a sprite there.
It turns out that to drag the sprites, you need to expand each image. I can of course accept the texture, but again, the nested sprite in the texture field is not accepted. sprite is not a texture, is it? and this object is sent to the spriterenderer that the sprite specifically requires. How can I specify a sprite in the field of the object, regardless of whether I specify the texture itself or its nested sprite, as it was before when I used a simple array of sprites?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2018-07-17
@adressmoeistranici

A sprite is not a texture, it is somewhat similar to a mini-Mesh , it has its own list of vertices and a link to the texture to which it is attached.
I suspect that the problem will solve itself if you use EditorGUILayout.PropertyField . If this option is not suitable, then you can try to look in the SpriteUtility.GetSpriteFromPathsOrObjects area . In this class, the dragging of sprites to the stage is handled, I think that dragging to the inspector should be somewhere nearby.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question