Как получить/изменить имя источника изображения с кодом в Unity?

мы сделали скрипт и нам нужно получить имя изображения, мы реализуем эту задачу корявым способом ниже, но мы все еще хотим знать, есть ли способ получить имя изображения напрямую?

введите здесь описание изображения

public class CubeManager
{
    static public Dictionary<CubeType, string> cubeTypeDict = new Dictionary<CubeType, string>();
    static private Dictionary<string, GameObject> cubeDict = new Dictionary<string, GameObject>();
    static CubeManager()
    {
        cubeTypeDict.Add(CubeType.Wall01, "Wall01");
        cubeTypeDict.Add(CubeType.Wall02, "Wall02");
        cubeTypeDict.Add(CubeType.Wall03, "Wall03");
        cubeTypeDict.Add(CubeType.Wall04, "Wall04");
        cubeTypeDict.Add(CubeType.Wall05, "Wall05");
        cubeTypeDict.Add(CubeType.Wall06, "Wall06");
        cubeTypeDict.Add(CubeType.Wall07, "Wall07");
        cubeTypeDict.Add(CubeType.Wall08, "Wall08");
        cubeTypeDict.Add(CubeType.Wall09, "Wall09");
        cubeTypeDict.Add(CubeType.Wall10, "Wall10");
        cubeTypeDict.Add(CubeType.Wall11, "Wall11");
        cubeTypeDict.Add(CubeType.Wall12, "Wall12");
        cubeTypeDict.Add(CubeType.Wall13, "Wall13");
        cubeTypeDict.Add(CubeType.Wall14, "Wall14");
        cubeTypeDict.Add(CubeType.Wall15, "Wall15");
        cubeTypeDict.Add(CubeType.Wall16, "Wall16");
        cubeTypeDict.Add(CubeType.Wall17, "Wall17");
        cubeTypeDict.Add(CubeType.Wall18, "Wall18");
        cubeTypeDict.Add(CubeType.Wall19, "Wall19");
        cubeTypeDict.Add(CubeType.Wall20, "Wall20");
        cubeTypeDict.Add(CubeType.Wall21, "Wall21");
        cubeTypeDict.Add(CubeType.Wall22, "Wall22");
        cubeTypeDict.Add(CubeType.Wall23, "Wall23");
        cubeTypeDict.Add(CubeType.Wall24, "Wall24");
        cubeTypeDict.Add(CubeType.Wall25, "Wall25");
        cubeTypeDict.Add(CubeType.Wall26, "Wall26");
        cubeTypeDict.Add(CubeType.Wall27, "Wall27");
        cubeTypeDict.Add(CubeType.Wall28, "Wall28");
        cubeTypeDict.Add(CubeType.Wall29, "Wall29");
    }

person Jerry Zhao    schedule 23.12.2015    source источник
comment
Вы пробовали Image.sprite.texture.ToString()?   -  person Nika Kasradze    schedule 23.12.2015


Ответы (2)


Да, вы можете,

Image img;

Debug.Log("Image Name: " + img.sprite.name);

Кроме того, вы также можете изменить спрайт, указав Texture2D

img.sprite = Sprite.Create (spr.texture, img.sprite.rect, new Vector2 (0.5f, 0.5f));

Здесь spr — это спрайт, вы можете использовать Texture2D напрямую.

person Hamza Hasan    schedule 23.12.2015
comment
Опять вы :) но это имя игрового объекта, а не имя исходного изображения, верно? - person Jerry Zhao; 23.12.2015
comment
Это имя исходного изображения :) - person Hamza Hasan; 23.12.2015
comment
Кстати, а есть ли способ изменить изображение? Я имею в виду, что изменение касается не только имени изображения, но и самого изображения, например. от образа А к образу Б. - person Jerry Zhao; 23.12.2015
comment
Да, вторая часть моего ответа делает это - person Hamza Hasan; 23.12.2015

person    schedule
comment
Пожалуйста, добавьте объяснение и дополнительный контекст к вашему ответу. - person Nikolay Mihaylov; 16.06.2016